/game-porting-skills:using-metal-validationfrom game-porting-skills
Enables and configures Metal API validation (MTL_DEBUG_LAYER) and shader validation (MTL_SHADER_VALIDATION) for debugging GPU memory errors, API misuse, and render artifacts.
Ships in game-porting-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Metal provides two validation modes, both configured via environment variables read at MTLDevice creation:
MTL_DEBUG_LAYER) — CPU-side. Cheap; enable broadly during development.MTL_SHADER_VALIDATION) — GPU-side. Potentially significant perf cost; enable selectively or per-pipeline.Env vars must be set before any MTLDevice is created. Changes after device creation have no effect.
The man page is the authoritative reference for all env vars, their valid mode values, and pipeline scoping syntax. Read it before configuring anything beyond the quick-start:
man MetalValidation | col -b
open -a MyGame.app \
--env MTL_DEBUG_LAYER=1 \
--env MTL_SHADER_VALIDATION=1 \
--env MTL_SHADER_VALIDATION_REPORT_TO_STDERR=1
The man page documents every variable, but a few workflow points are easy to miss:
.app bundles via open --env, instead of invoking the binary inside the bundle directly (e.g., MyGame.app/Contents/MacOS/MyGame). Use open -a MyGame.app --env KEY=VALUE (one --env per variable) for every run that needs validation.MTL_SHADER_VALIDATION_REPORT_TO_STDERR=1, errors are invisible from a terminal-launched build. Always pair the two.MTL_SHADER_VALIDATION=1 is too expensive, set MTL4PipelineOptions.shaderValidation = MTLShaderValidationEnabled on the descriptor for shaders under active iteration. Env-var allow-list / deny-list (MTL_SHADER_VALIDATION_ENABLE_PIPELINES / _DISABLE_PIPELINES) is the equivalent for pre-Metal-4 codebases.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub apple/game-porting-toolkit --plugin game-porting-skills24 skills in this plugin
/compiling-with-metal-shaderconverterALWAYS use when compiling DXIL/HLSL to metallib with Metal shader converter (commonly referred to as MSC) via the metal-shaderconverter CLI or libmetalirconverter (IRCompiler, IRObject, IRShaderReflection) at runtime. Covers offline/runtime DXIL compilation, root signatures, reflection output, ray tracing shaders, geometry/tessellation emulation compilation, framebuffer fetch in HLSL, programmable blending in HLSL, Metal_HLSL.inc, and compatibility flags. Do NOT trigger for binding compiled shaders to encoders — use integrating-metal-shaderconverter-shaders for that./creating-metal4-shader-pipelinesALWAYS 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./debugging-rendering-issuesALWAYS use when a user porting a game to Metal reports a rendering issue — blank screen, wrong output, or anything that looks incorrect on Metal vs. the source platform. Covers black screen, missing geometry, wrong colors, gamma/sRGB problems, texture artifacts, z-fighting, alpha blending, flickering, visual corruption, and upside-down/mirrored geometry. Works with or without a GPU trace. Do NOT trigger when the user just wants to inspect an existing .gputrace./integrating-metal-shaderconverter-shadersALWAYS use when integrating Metal shader converter (commonly referred to as MSC) shaders at runtime — binding model, top-level argument buffer (TLAB), root signature resource locations, descriptor/sampler heaps, static samplers, bindless resources, vertex fetch, separate stage-in, geometry/tessellation emulation, compute dispatch, unbounded arrays, and append/consume buffers. Do NOT trigger for compiling DXIL/HLSL to metallib — use compiling-with-metal-shaderconverter for that./managing-metal4-resourcesALWAYS use when working with Metal 4 resources — buffer / texture / heap creation, storage modes, `MTLResidencySet` management, heap aliasing, purgeable state, texture view pools, GPU lossless compression, and deferred destruction. Trigger for MTLBuffer, MTLTexture, MTLHeap, MTLResidencySet, addAllocation, requestResidency, useResidencySet, addResidencySet, MTLStorageMode*, MTLPurgeableState, MTLTextureViewPool, MTLResourceViewPool, newTextureViewWithPixelFormat:, copyFromBuffer:toTexture:, "GPU fault on resource", "non-resident resource", heap aliasing. Do NOT trigger for TBDR architecture or Metal 3 → Metal 4 namespace tables — use `translating-to-metal4-api`. Barrier visibility / `MTL4VisibilityOption*` / render-pass transition barriers — use `managing-metal4-synchronization`. `CAMetalLayer.residencySet` — use `presenting-metal-drawables`. `NS::SharedPtr` / autorelease pool / ARC bridging — use `managing-metal-cpp-lifetimes`./managing-metal4-synchronizationMetal 4 explicit synchronization — barriers, fences, events, and cross-API state translation (from D3D12, Vulkan, OpenGL). Use when porting GPU synchronization, translating resource state transitions, or debugging barrier-related visual corruption.Other plugins' skills for the same job