Get started with Metal shader converter

Metal shader converter converts shader intermediate representations in LLVM IR bytecode into bytecode suitable to be loaded into Metal. It's available as a command-line tool (metal-shaderconverter) and a dynamic library (libmetalirconverter). Every feature available in the tool is also available in the library.

    System requirements

    Metal shader converter requires macOS 13 Ventura and Xcode 15, or later.

    Metal shader converter for Windows requires Microsoft Windows 10 and Microsoft Visual Studio 2019, or later.

    Metal libraries built using Metal shader converter tools require a device that supports Argument Buffers Tier 2, running macOS 14 Sonoma, iOS 17 or later. If you build a Metal library for earlier OS versions, not all features will be supported.

    Downloads

    Your first conversion

    Command line

    The Metal shader converter executable offers several options to customize code generation. In its most basic form, Metal shader converter takes a DXIL file as input and produces a metallib.

    % metal-shaderconverter shader.dxil -o shader.metallib

    Dynamic library (libmetalirconverter)

    libmetalirconverter offers a C interface for easy integration into C, C++, Objective-C, and Swift codebases.

    IRCompiler* compiler = IRCompilerCreate();
    IRCompilerSetEntryPointName(compiler, "MainVS");
    
    IRObject* dxil = IRObjectCreateFromDXIL(bytecode, size, IRBytecodeOwnershipNone);
    
    IRError* error = nullptr;
    IRObject* outIR = IRCompilerAllocCompileAndLink(compiler, NULL, dxil, &error);
    
    // Retrieve metallib bytes:
    IRMetalLibBinary* metallib = IRMetalLibBinaryCreate();
    IRObjectGetMetalLibBinary(outIR, stage, metallib);
    size_t metallibSize = IRMetalLibGetBytecodeSize(metallib);
    uint8_t* metallibBytes = new uint8_t[metallibSize];
    IRMetalLibGetBytecode(metallib, metallibBytes);
    
    // Clean up:
    delete [] metallibBytes;
    IRMetalLibBinaryDestroy(metallib);
    IRObjectDestroy(dxil);
    IRObjectDestroy(outIR);
    IRCompilerDestroy(compiler);

    Supported shader models

    Shader model Notable features
    SM6.0Wave intrinsics, 64-bit integers
    SM6.1Barycentrics (linear interpolation)
    SM6.216-bit scalar types
    SM6.3Ray tracing
    SM6.4Packed dot-product intrinsics
    SM6.5Mesh and Amplification shaders
    SM6.6Dynamic resources, compute derivatives, IsHelperLane

    Version history

    Version Highlights
    4.02D compute derivatives; NaN/Inf optimization on by default
    3.1libmetalirconverter on iOS
    3Function constants, framebuffer fetch, Metal intersection function buffers, non-array texture types by default
    2Shader debug info, globally-coherent memory, ray generation as compute kernels
    1.1Ray tracing shaders
    1Initial release