ALWAYS use when creating Metal pipeline state objects with Metal 4 descriptors (MTL4RenderPipelineDescriptor, MTL4ComputePipelineDescriptor, MTL4MeshRenderPipelineDescriptor) via MTL4Compiler. Covers function…
---
name: creating-metal4-shader-pipelines
description: ALWAYS use when creating Metal pipeline state objects with Metal 4 descriptors (MTL4RenderPipelineDescriptor, MTL4ComputePipelineDescriptor, MTL4MeshRenderPipelineDescriptor) via MTL4Compiler. Covers function descriptors, function constant specialization, flexible/unspecialized PSOs, color-attachment mapping, async compilation (MTL4CompilerTask), pipeline caching (MTL4Archive, MTL4PipelineDataSetSerializer), static/binary shader linking, and pipeline reflection. Do NOT trigger for HLSL/DXIL → metallib — use compiling-with-metal-shaderconverter.
---
# Pipeline Creation
## Overview
Covers Metal 4 pipeline state creation when porting games: loading pre-compiled metallibs, building render/compute/mesh PSOs via `MTL4Compiler`, function constants, flexible PSOs, color-attachment mapping, async compilation, and pipeline caching.
For compiling HLSL/DXIL shaders to metallibs, see the `compiling-with-metal-shaderconverter` skill.
For compiling Metal shader language (MSL) source, see MSL Source Compilation below.
## References
**Read the relevant Metal 4 SDK header before writing pipeline code** — the headers are the source of truth for property names, types, and method signatures.
- Metal 4 SDK headers - `$(xcrun --show-sdk-path)/System/Library/Frameworks/Metal.framework/Headers/` — focus on `MTL4Compiler.h`, `MTL4RenderPipeline.h`, `MTL4ComputePipeline.h`, `MTL4MeshRenderPipeline.h`, `MTL4TileRenderPipeline.h`, `MTL4LinkingDescriptor.h`
- Apple documentation - [Using the Metal 4 compilation API](https://developer.apple.com/documentation/metal/using-the-metal-4-compilation-api)
## Cross-API PSO Compatibility
Metal 3 PSOs work on Metal 4 encoders (and vice versa). This enables incremental porting — pipeline creation can be migrated to `MTL4Compiler` independently of encoder migration.
… install to load the full skill