# Debug Metal Shaders Remotely on a Rented Mac

Canonical: https://figment.so/blog/mac-metal-shader-debugger-remote

Enable GPU Frame Capture in the scheme, run the app on an Apple silicon Mac, and capture a frame from the Xcode debug bar. We have not measured Metal debugging inside a VM, so test on the Dedicated M4 Pro 48 GB, a whole Mac by the month.

**To debug a Metal shader, turn on GPU Frame Capture in your scheme, run the app on an Apple silicon Mac, capture a frame from the Xcode debug bar, then open the shader debugger on the draw call that looks wrong.** Both tools live in the Xcode GUI, as described in Apple's [Metal debugger documentation](https://developer.apple.com/documentation/xcode/metal-debugger), so you reach them over encrypted remote desktop.

We have not measured Metal or GPU debugging inside a Figment VM. If you need it, rent the [Dedicated M4 Pro 48 GB](/mac-hosting#dedicated-m4-pro) by the month ($349, cancel any time) and run your own capture in the first days.

## Which Mac do I need to debug Metal shaders?

An Apple silicon Mac, and for this task we recommend the Dedicated M4 Pro (whole Mac: M4 Pro, 48GB RAM, 512GB SSD). The shader debugger and GPU Timeline view are built around Apple's GPUs, which in practice means Apple silicon. The Intel Mac VM cannot run Apple silicon-only tools, and the Apple Silicon Mac VM is untested for GPU capture by us. A whole Mac with no other customer on it removes the one variable we cannot vouch for.

Xcode on an Intel Mac can still compile and sign Metal code for other targets, so the Intel Mac VM ($25 a month) remains fine for the non-GPU parts of a pipeline, on Xcode 26.3 or earlier.

## What do I set up before capturing?

Confirm each item in this table before you press the capture button. The details come from Apple's [guide to capturing a Metal workload in Xcode](https://developer.apple.com/documentation/xcode/capturing-a-metal-workload-in-xcode).

| Item | Where to set it | Notes |
|---|---|---|
| GPU Frame Capture enabled | Scheme → Run → Options → GPU Frame Capture: Metal | Required for the capture button to appear |
| Metal API Validation | Scheme → Run → Diagnostics → Metal API Validation: Enabled | Surfaces API misuse before you capture |
| Shader debug info | Build Settings → `MTL_ENABLE_DEBUG_INFO`: Yes, with source map (Debug) | Needed for line-level shader stepping |
| Capture scope (programmatic) | `MTLCaptureDescriptor.captureObject` = device or command queue | Narrow the capture to one queue when you can |
| GPU Timeline | Apple GPU only | Not available on third-party GPUs |

Keep `MTL_ENABLE_DEBUG_INFO` off for Release builds so symbols do not ship with your binary. If you need to debug an optimized build, archive the matching `.metallibsym` separately and keep it with your dSYMs. Menu wording and build-setting labels move between Xcode versions, so verify against the Xcode you have installed.

## How do I connect to the Mac?

Open an encrypted remote desktop session from the Figment dashboard and sign in to Xcode with your Apple ID. Use a client with at least 24-bit colour so the debugger's heatmaps, buffer previews and attachment thumbnails render correctly. If the project lives in a remote repository, clone it from the Mac's terminal over SSH rather than copying a working tree through the viewer.

Network latency shows up as paint delay in the viewer, not as debugger inaccuracy. The captured frame is replayed locally on the Mac, so shader stepping does not depend on remote desktop round-trip time.

## How do I trigger a capture?

Run the app on the Mac. The Metal capture button appears in the Xcode debug bar once a Metal command queue is detected; press it and Xcode records the next frame and opens the GPU Frame Capture view.

To trigger a capture programmatically from a specific frame in your renderer:

```swift
#if DEBUG
import Metal

func captureOneFrame(commandQueue: MTLCommandQueue) {
    let manager = MTLCaptureManager.shared()
    let descriptor = MTLCaptureDescriptor()
    descriptor.captureObject = commandQueue
    descriptor.destination = .developerTools

    guard manager.supportsDestination(.developerTools) else { return }
    do {
        try manager.startCapture(with: descriptor)
    } catch {
        NSLog("Metal capture failed: \(error)")
    }
}
#endif
```

Call `MTLCaptureManager.shared().stopCapture()` after the frame you want recorded ends. This example is illustrative, not a benchmark. Run it against your own renderer to confirm the capture appears in Xcode.

## How do I find the draw call and shader?

Use the render pass tree in the left panel. Expand a pass to see its draw calls, pipeline states, and the vertex and fragment functions bound to each, then click the draw call that produces the pixels you are investigating.

- **Attachments** shows colour and depth textures before and after the draw. Comparing them locates the corrupted region.
- **Bound Resources** lists vertex buffers, textures and uniform buffers with their values. This is where you spot a wrong stride on an attribute buffer or a transposed matrix.
- **Geometry** shows post-vertex-shader positions. If the error is in the vertex stage, the preview often makes it obvious.

## How do I step through shader execution?

Click a shader function name in the pipeline state row. Xcode opens the shader debugger with MSL source and a thread picker at the top.

1. Pick a thread: a pixel coordinate for fragment shaders or a vertex index for vertex shaders. For a vertex offset bug, choose the index you suspect.
2. Step line by line. Each line shows the computed value of every variable in that thread.
3. Click a variable to expand its components. For a `float4` position you can read x, y, z and w at the line that wrote them.
4. Open an adjacent known-good thread and watch where the two diverge. This usually points directly at the wrong input.

## How do I analyse stalls and intermittent errors?

Open Instruments, choose the Metal System Trace template, attach to your app process on the Mac and record a few seconds of rendering. The trace shows GPU work duration and gaps, vertex and fragment stage execution on Apple silicon, and per-draw occupancy.

If a vertex pass and the fragment pass that consumes its output show an unexpected gap, it usually points at a missing barrier or fence between a compute write and a vertex read. Select the two encoders in the trace and read the dependency annotation Xcode inserts.

## How long should a shader-debugging trial run?

For GPU Frame Capture and the shader debugger, start with a month of the Dedicated M4 Pro 48 GB ($349, cancel any time), and keep it if the workflow works for you. If a test of your own on the Apple Silicon Mac VM ($39 a month, $6 a day) shows it captures what you need, it is the cheaper long-term seat. Disconnecting does not stop billing, so stop an hourly or daily VM in Figment when you no longer need it.

**Related guides:**
- [Run the visionOS Simulator on a Rented Mac](/blog/mac-visionos-simulator-rented-mac)
- [Test watchOS Apps Using a Remote Mac Simulator](/blog/mac-watchos-simulator-remote-mac)
- [Mac GitHub Actions Self-Hosted Runner](/blog/mac-github-actions-self-hosted-runner)
