Est. 2014 Advanced

MSL (Metal Shading Language)

Apple's C++-based shading language for programming the GPU directly — a single unified language for both graphics and compute that compiles through Clang and LLVM and powers the Metal API across iPhone, iPad, Mac, Apple TV, and Vision Pro.

Created by Apple Inc.

Paradigm Procedural shading language: a single unified language for GPU graphics (vertex, fragment, mesh) and compute (kernel) functions
Typing Static, strong
First Appeared 2014
Latest Version Metal Shading Language Specification Version 4 (2025), aligned with Metal 4

MSL (Metal Shading Language) is the programming language Apple created for writing code that runs directly on the GPU. It is the shader language of Metal, Apple’s low-overhead graphics and compute API, and it is unusual among shading languages in being a genuine variant of C++ rather than a purpose-built C-like dialect. A single MSL source can express both graphics work — vertex, fragment, and (later) mesh functions that feed the rendering pipeline — and compute work — general-purpose “kernel” functions that run massively parallel calculations on the GPU. Because MSL is compiled with Clang and LLVM, the same industrial-strength toolchain behind C and C++ on Apple’s platforms, it inherits familiar C++ syntax, function overloading, and template support while adding GPU-specific types, attributes, and address spaces.

Metal was unveiled at Apple’s Worldwide Developers Conference on June 2, 2014, alongside iOS 8, with the explicit goal of cutting the driver overhead that older APIs like OpenGL ES imposed. MSL was the language layer of that effort: a modern, statically typed, C++-derived language designed from the start to unify graphics and compute under one syntax and one tool chain.

History and Origins

By the early 2010s, the dominant graphics APIs — OpenGL and OpenGL ES, with their GLSL shading language — carried significant per-draw-call driver overhead and exposed a state machine that made it hard for developers to feed modern GPUs efficiently. The wider industry was moving toward “explicit,” low-overhead APIs that handed more control (and more responsibility) to the application; this same wave produced Direct3D 12 and, soon after, Vulkan.

Apple’s answer was Metal, announced at WWDC 2014. Rather than adopt GLSL, Apple introduced its own shading language. The design decision that most defines MSL is its foundation on C++: instead of inventing a brand-new shader dialect, Apple built MSL as a variant of standard C++ (historically described as being based on the C++14 standard, with GPU-oriented extensions and a set of restrictions), implemented on top of Clang and LLVM. This gave developers a powerful, well-understood language with templates, overloading, and a familiar type system, while letting Apple add the constructs a GPU needs.

Metal began as iOS-only, requiring an Apple A7 or later GPU. In 2015, with OS X El Capitan (10.11), Metal — and therefore MSL — arrived on the Mac, and the surrounding frameworks MetalKit and Metal Performance Shaders made it easier to adopt.

Design Philosophy

MSL is shaped by a few clear principles:

  • One language for graphics and compute. The same language, syntax, and compiler serve both the rendering pipeline and general-purpose GPU computation. A developer does not switch dialects to move from a fragment shader to a compute kernel.
  • Familiar C++ foundations. Because MSL is a C++ variant, programmers can use overloading, templates, structs, and a strong static type system. The learning curve for an experienced C++ developer is largely about GPU concepts, not new syntax.
  • Explicit GPU semantics. MSL exposes hardware realities directly: distinct address spaces (device, constant, threadgroup, thread) describe where memory lives; attributes (written with C++ attribute syntax, e.g. [[stage_in]], [[buffer(0)]], [[position]]) bind shader inputs and outputs to the pipeline; and qualifiers describe how textures are sampled and how data flows between stages.
  • Compiled, not interpreted. MSL is compiled — typically ahead of time into a Metal library (.metallib), or at runtime — through Clang/LLVM, which produces high-quality GPU code and allows offline shader compilation as part of the app build.

Key Features

A few elements characterize day-to-day MSL:

  • Function qualifiers. Shader entry points are tagged by role — vertex, fragment, and kernel (with mesh and related stages added later) — telling Metal how each function participates in the pipeline.
  • Rich built-in types. MSL provides GPU-native vector and matrix types (float4, float4x4, half, and so on), texture and sampler types, and the operations expected of a shading language, layered onto C++ semantics.
  • Address spaces and attributes. Memory address-space qualifiers and [[...]] attribute bindings make the mapping between shader code and the Metal API explicit and type-checked.
  • Unified graphics + compute. Because compute kernels share the language with graphics shaders, GPU-driven techniques — culling, particle simulation, image processing, and machine-learning kernels — are written in the same MSL a renderer uses.

A minimal pair of MSL functions — a pass-through vertex shader and a solid-color fragment shader — illustrates the C++ flavor and the attribute syntax:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include <metal_stdlib>
using namespace metal;

struct VertexOut {
    float4 position [[position]];
};

vertex VertexOut vertex_main(uint vid [[vertex_id]],
                             constant float4 *positions [[buffer(0)]]) {
    VertexOut out;
    out.position = positions[vid];
    return out;
}

fragment float4 fragment_main(VertexOut in [[stage_in]]) {
    return float4(1.0, 0.0, 0.0, 1.0); // opaque red
}

Evolution

MSL has advanced in step with the Metal API across the platform’s major versions:

  • Metal 2 (2017) — announced at WWDC on June 5, 2017 and shipped with macOS High Sierra, iOS 11, and tvOS 11 — added argument buffers to group shader resources, and the A11 Bionic chip introduced tile shaders and imageblocks for tile-based deferred rendering expressed in MSL.
  • Ray tracing (from 2018) arrived first through the Metal Performance Shaders intersector and later as a more general GPU ray-tracing capability usable from MSL, letting kernels traverse acceleration structures on the GPU.
  • Apple silicon (from 2020) unified Apple’s GPU architecture across iPhone, iPad, and Mac, making MSL the single shading language across every Apple platform that has a GPU.
  • Metal 3 (2022) — announced June 6, 2022 with macOS Ventura, iOS 16, and iPadOS 16 — introduced mesh shaders, an alternative geometry pipeline written in MSL, along with the MetalFX upscaling framework and a faster resource-loading path.
  • Metal 4 (2025) — announced June 9, 2025 — added a C++17 language basis to the Metal Shading Language Specification (alongside its existing C++14 foundation) and introduced support for neural rendering, a unified command-encoder model, MetalFX Frame Interpolation, and a ray-tracing denoiser.

Current Relevance

MSL is the native shading language for every modern Apple platform that exposes a GPU — iOS, iPadOS, macOS, tvOS, and visionOS. Since Apple has positioned Metal as the successor to OpenGL/OpenGL ES on its devices (OpenGL is deprecated on Apple platforms), MSL is effectively the way to write GPU code natively on Apple hardware. Major game engines such as Unity and Unreal Engine ship Metal backends whose shader toolchains emit MSL, and the MoltenVK layer translates Vulkan/SPIR-V shaders into MSL so that Vulkan applications can run on top of Metal.

Beyond explicit graphics programming, MSL underpins a great deal of GPU work that developers never see directly: Apple’s own frameworks — Core Image, Core ML, and others — lower their filters and neural-network kernels onto Metal compute, and the arrival of neural-rendering features in Metal 4 extends MSL’s role into machine-learning-driven graphics.

Why It Matters

MSL is a notable experiment in shading-language design: it showed that a real C++ variant, compiled with a production Clang/LLVM toolchain, could serve as a practical GPU language unifying graphics and compute under one syntax. That choice contrasts with the purpose-built C-like dialects of GLSL and (historically) HLSL, and it gave Apple’s developers a familiar, powerful language for everything from mobile games to scientific compute. As the language layer beneath Metal — the foundation for graphics, compute, and increasingly machine learning across Apple’s entire device lineup — MSL is one of the most widely deployed shading languages in use today, even though it runs exclusively on Apple’s own hardware.

Timeline

2014
Apple announces Metal at WWDC on June 2, 2014, alongside iOS 8. The Metal Shading Language (MSL) ships as part of the framework — a single C++-based language used for both graphics shaders and compute kernels, compiled with Clang and LLVM. Metal initially required an Apple A7 or later GPU.
2015
Metal comes to the Mac with OS X El Capitan (10.11), bringing MSL to desktop GPUs. The MetalKit and Metal Performance Shaders frameworks debut to simplify rendering and provide tuned compute kernels.
2017
Metal 2 is announced at WWDC on June 5, 2017, shipping with macOS High Sierra, iOS 11, and tvOS 11. MSL gains argument buffers, and the A11 Bionic chip introduces tile shaders and imageblocks for tile-based deferred rendering.
2018
Apple adds GPU-accelerated ray tracing intersection through the Metal Performance Shaders framework (MPSRayIntersector), and indirect command buffers let MSL kernels encode reusable GPU command sequences.
2020
At WWDC 2020 Apple announces the transition of the Mac to Apple silicon, unifying Apple's GPU architecture across iPhone, iPad, and Mac and making MSL the single shading language across all of Apple's platforms.
2022
Metal 3 is announced at WWDC on June 6, 2022, shipping with macOS Ventura, iOS 16, and iPadOS 16. It introduces the MetalFX upscaling framework, mesh shaders (an alternative geometry pipeline expressed in MSL), and a fast resource-loading API.
2025
Metal 4 is announced at WWDC on June 9, 2025. The accompanying Metal Shading Language Specification (Version 4) adds a C++17 language basis while retaining C++14 support, and the platform adds a unified command-encoder model, neural-rendering support, MetalFX Frame Interpolation, and a ray-tracing denoiser.

Notable Uses & Legacy

Apple platform games and graphics

Metal is the native graphics and GPU-compute API on Apple platforms, so games and 3D apps that target iPhone, iPad, Mac, Apple TV, or Vision Pro natively write their shaders in MSL — including AAA titles brought to Apple silicon Macs.

Game engines (Unity, Unreal Engine)

Major cross-platform engines implement a Metal backend; their shader toolchains cross-compile authored shaders to MSL so that content runs on Apple GPUs through the Metal API.

Core Image, Core ML, and system frameworks

Apple's own media and machine-learning frameworks lower their image filters and neural-network kernels onto Metal compute shaders, making MSL the substrate beneath much of the GPU work on Apple devices.

MoltenVK and the Vulkan ecosystem

MoltenVK, part of the Khronos Vulkan Portability effort, translates Vulkan/SPIR-V shaders into MSL so Vulkan applications can run on top of Metal on macOS and iOS.

Professional creative and scientific software

Apps such as video editors, 3D content tools, and scientific and machine-learning workloads use Metal compute, with their GPU kernels written in or compiled to MSL to exploit Apple GPUs.

Language Influence

Influenced By

C++ OpenCL C HLSL GLSL

Running Today

Run examples using the official Docker image:

docker pull
Last updated: