2023 Developer ToolsGraphics & Games
WWDC23 · 19 min · Developer Tools / Graphics & Games
Bring your game to Mac, Part 2: Compile your shaders
Discover how the Metal shader converter streamlines the process of bringing your HLSL shaders to Metal as we continue our three-part series on bringing your game to Mac. Find out how to build a fast, end-to-end shader pipeline from DXIL that supports all shader stages and allows you to leverage the advanced features of Apple GPUs. We’ll also show you how to reduce app launch time and stutters by generating GPU binaries with the offline compiler. To get the most out of this session, we recommend first watching “Bring your game to Mac, Part 1: Make a game plan." And once you’re ready to level up, check out “Bring your game to Mac, Part 3: Render with Metal" from WWDC23.
Watch at developer.apple.com ↗Chapters
Code shown on screen · 3 snippets
Json Metal Script
{“libraries": {
"paths": [
{"path": “ba.metallib”, "label": "myMetalLib"}
]
},
"pipelines": {
"render_pipelines": [{
"vertex_function": "alias:myMetalLib#v",
"fragment_function": "alias:myMetalLib#f",
"raster_sample_count": 2,
"color_attachments": [{
"pixel_format": "BGRA8Unorm"
}],
"depth_attachment_pixel_format":
"Depth32Float"
}]
}
} Testing Binary Archive hit
// Create Pipeline Descriptor
MTLComputePipelineDescriptor *computeDesc = [MTLComputePipelineDescriptor new];
computeDesc.binaryArchives = @[existingBinaryArchive];
computeDesc.computeFunction = computeFn;
id<MTLComputePipelineState> computePS =
[device newComputePipelineStateWithDescriptor:computeDesc
options:MTLPipelineOptionFailonBinaryArchiveMiss
error:&err];
if(computePS == nil)
{
// Binary archive is missing compiled shader.
} Loading appropriate Binary Archive
// Load OS-specific binary archives
MTLComputePipelineDescriptor *computeDesc = [MTLComputePipelineDescriptor new];
if (@available(macOS 14, *)) {
computeDesc.binaryArchives = @[binaryArchive_macOS14];
} else {
computeDesc.binaryArchives = @[binaryArchive_macOS13_3];
}
computeDesc.computeFunction = computeFn;
id<MTLComputePipelineState> computePS =
[device newComputePipelineStateWithDescriptor:computeDesc
options:nil
error:&err]; Resources
Related sessions
-
15 min -
27 min -
34 min -
14 min -
25 min -
36 min