Modern syntax highlighting and language configuration for Apple's Metal Shading Language (MSL) in Visual Studio Code — fully updated through Metal 4.1 (C++17).
Original Source & Attribution
This project is a revised and modernized continuation of tdecroyere/vscode-metal-shader by Thomas Decroyère (MIT License). The original extension provided basic Metal 2.x syntax highlighting in 2019; this revised edition completely rebuilds the TextMate grammar, language configuration, and test suite for modern Metal 3.x, Metal 4.0, and Metal 4.1 development.
Features
- Shader Stages & Function Qualifiers
vertex, fragment, kernel, object, mesh, visible, stitchable
- C++ attribute forms (
[[vertex]], [[fragment]], [[kernel]], [[object]], [[mesh]], [[visible]], [[stitchable]], [[intersection(...)]], [[patch(...)]])
- Stage metadata attributes (
[[early_fragment_tests]], [[max_total_threads_per_threadgroup(...)]], [[required_threads_per_threadgroup(...)]], [[max_total_threadgroups_per_mesh_grid(...)]], [[host_name(...)]], [[user_annotation(...)]], [[function_groups(...)]])
- Address Spaces, Coherency & Memory Ordering
device, constant, thread, threadgroup, threadgroup_imageblock, ray_data, object_data
coherent, coherent(device), memory_coherence_device, memory_coherence_threadgroup
memory_order_relaxed, memory_order_acquire, memory_order_release, memory_order_acq_rel, memory_order_seq_cst, thread_scope_*, mem_flags::*
- Data Types
- All scalar, vector, packed vector, and matrix types (
half/float 2x2–4x4), plus bfloat / bfloat{2,3,4} / packed_bfloat{2,3,4}
- SIMD-group matrices (
simdgroup_matrix, simdgroup_float8x8, simdgroup_half8x8, simdgroup_bfloat8x8)
- Atomics (
atomic, atomic_bool, atomic_int, atomic_uint, atomic_ulong, atomic_float) and pixel types (r8unorm–srgba8unorm, rgb10a2, rg11b10f, rgb9e5)
- All texture, depth texture, sampler (including Metal 4
reduction & bias), imageblock, interpolant, Metal 4 per-vertex values (vertex_value, vertex_index), mesh shader (mesh, mesh_grid_properties), and indirect command buffer types
- Full ray-tracing support (
ray, intersector, intersection_query, intersection_result, intersection_result_ref, intersection_function_table, intersection_function_buffer, acceleration_structure, curve_data, [[function_id]], [[curve_parameter]])
- Metal 4.0 & 4.1 Machine Learning, Tensors & MPP
- Tensors (
tensor, tensor_blockwise, tensor_handle, tensor_inline, tensor_offset, tensor_plane_data, tensor_plane_scales, cooperative_tensor, extents, dextents, dynamic_extent)
- Packed numeric block-scaling formats (
packed_numeric_type, metal_fp4_e2m1_format, metal_fp8_e4m3_format, metal_fp8_e5m2_format, metal_fp8_ue8m0_format, int4b_format, uint4b_format, int2b_format, uint2b_format, pack, unpack, rounding_mode::*, saturation_mode::*)
- Metal Performance Primitives (
mpp::tensor_ops::matmul2d, matmul2d_descriptor, convolution2d, convolution2d_descriptor, execution_thread, execution_simdgroup, execution_simdgroups, dynamic_length_v, reduce_rows, reduce_columns, reduction_operation, reduction_operation_identity, is_iterator_compatible)
- Standard Library, Attributes & C++17 Syntax
- Complete
[[...]] attribute highlighting (single-line, multi-line, comma-separated, and parameterized)
- Built-in namespaces (
metal::, raytracing::, mpp::, tensor_ops::, fast::, precise::) and scoped enums (access::*, coord::*, address::*, filter::*, topology::*, interpolation::*, etc.)
- Standard library functions including math, integer (
deinterleave, interleave), geometric, SIMD-group, quad-group, atomic, pack/unpack (including snorm10a2), synchronization barriers/fences, and os_log
- Full preprocessor support (
#include, #import, #define, #undef, #if/#ifdef/#ifndef/#elif/#else/#endif, #pragma, #error, #warning, #line, __METAL* predefined macros)
- C++17 raw and quoted strings with
os_log format specifiers, doc comments (/** */, ///), binary/hex/hex-float/half/bfloat numeric literals, digit separators, if constexpr, and placement new
Live Compiler Diagnostics (macOS)
- Real-time Metal compiler error and warning squiggles powered by Apple's
xcrun metal -fsyntax-only
- Checks unsaved edits as you type (debounced) or on save, with clickable related notes for included headers
- Status bar indicator showing pass/warning/error status and target SDK / MSL standard
- Graceful fallback on non-macOS systems (syntax highlighting stays active with zero errors) and actionable setup guidance if Xcode's Metal Toolchain component isn't installed yet
- Commands:
Metal: Check Current Shader (metal.checkShader)
Metal: Check Compiler Toolchain (metal.checkToolchain)
Settings
| Setting |
Default |
Description |
metal.diagnostics.enable |
true |
Enable live xcrun metal compiler diagnostics on macOS |
metal.diagnostics.run |
"onType" |
Run diagnostics "onType" (debounced) or "onSave" |
metal.diagnostics.debounceMs |
400 |
Delay in ms before checking after edits (onType) |
metal.compiler.sdk |
"macosx" |
Apple SDK (macosx, iphoneos, iphonesimulator, appletvos, appletvsimulator, xros, xrsimulator) |
metal.compiler.languageVersion |
"auto" |
MSL standard (auto, metal2.4–metal4.1) |
metal.compiler.includePaths |
[] |
Extra -I header paths (supports ${workspaceFolder}, ${fileDirname}) |
metal.compiler.extraArgs |
[] |
Extra flags passed to xcrun metal (e.g. ["-Wall", "-DFOO=1"]) |
metal.compiler.xcrunPath |
"/usr/bin/xcrun" |
Path to xcrun executable |
Editor Experience
- Supports both
.metal and .msl shader files
- Smart bracket matching, quote/block-comment auto-closing,
/** */ doc-comment continuation, C-style indentation rules, and #pragma region / // region code folding
Example
#include <metal_stdlib>
#include <metal_tensor>
#include <metal_packed_numeric>
#include <MetalPerformancePrimitives/MetalPerformancePrimitives.h>
using namespace metal;
using namespace mpp::tensor_ops;
[[kernel, max_total_threads_per_threadgroup(128)]]
void matmul_fp4(
tensor<device half, dextents<int32_t, 2>> A [[buffer(0)]],
tensor<device metal_fp4_e2m1_format, dextents<int32_t, 2>, tensor_inline,
tensor_blockwise<tensor_plane_scales, device metal_fp8_ue8m0_format, extents<size_t, 32, 1>>> B [[buffer(1)]],
tensor<device float, dextents<int32_t, 2>> C [[buffer(2)]]
) {
constexpr auto desc = matmul2d_descriptor(
64, 64, dynamic_length_v<int>,
false, false, false,
matmul2d_descriptor::mode::multiply_accumulate
);
matmul2d<desc, execution_simdgroups<4>> op;
auto tileC = op.get_destination_cooperative_tensor<decltype(A), decltype(B), float>();
op.run(A, B, tileC);
}
Development & Testing
npm install
npm test
npm run package
License
MIT License — see LICENSE for full details.
Original work Copyright (c) 2019 Thomas Decroyère (tdecroyere/vscode-metal-shader).
Revised work Copyright (c) 2026 Conlan Sykes.
| |