# Validate Metal GPU Filters on a Rented M-Series Mac

Canonical: https://figment.so/blog/mac-metal-gpu-filter-validation

Run the Swift program below on a real Apple silicon Mac. It renders a Core Image filter, hashes the output pixels with SHA-256 and prints median GPU time. We have not measured Metal on any Figment plan, so test on the Dedicated M4 Pro 48 GB, a whole Mac by the month.

Run the Swift program below on a real Apple silicon Mac. It applies a Core Image filter to a reference image through a Metal-backed context, reads the output pixels back, hashes them with SHA-256, and prints per-run GPU time computed from `gpuEndTime − gpuStartTime` on `MTLCommandBuffer` ([Apple: gpuStartTime](https://developer.apple.com/documentation/metal/mtlcommandbuffer/gpustarttime)). Metal 4 on Mac requires Apple silicon (M1 or later) per [developer.apple.com/metal](https://developer.apple.com/metal/).

We have not measured Metal or GPU work on any Figment plan, and GPU inside a VM is not measured. The honest test is the [Dedicated M4 Pro 48 GB](/mac-hosting#dedicated-m4-pro) ($349 a month, cancel any time), a whole Apple silicon Mac. The program prints the device name it ran on and exits with an error if there is no Metal device, so you can run it on any plan to see what that plan exposes. The Intel Mac VM cannot run Apple silicon-only features.

## Why are the Simulator and a VM not enough?

They render through whatever GPU the host exposes, which may not match the device you ship on. Four gaps come up repeatedly in filter work:

- **Threadgroup memory ceilings** are chip-specific. A kernel that compiles against an M4's limits can fail pipeline creation on an entry M1 if it asks for more threadgroup memory than the device advertises.
- **Float16 and fast-math rounding** can differ between the host renderer and the device GPU, producing pixel deltas that unit tests miss but a golden-image hash catches.
- **MetalFX and Metal 4 features** are hardware-gated. Apple's Metal page lists Metal 4 on Mac as Apple silicon (M1 or later), so those APIs are not a correctness fallback on an older or virtualised GPU.
- **Timing numbers** from the Simulator or a VM reflect host hardware or software rendering, not the shipping Apple silicon device.

If a filter passes in the Simulator and fails on-device, the first signal arrived in the wrong place.

## How do I prepare Xcode on the rented Mac?

Connect over SSH or remote desktop, install Xcode, and confirm which GPU you landed on.

1. Install a current Xcode from the Mac App Store, or transfer an `.xip` you have already downloaded. Xcode 26 and earlier run on supported Intel Macs. Xcode 26.4 and later need macOS Tahoe 26.2 or later, and Xcode 27 needs Tahoe 26.6 or later, so they need an Apple silicon plan. See Apple's [porting guide](https://developer.apple.com/documentation/apple-silicon/porting-your-macos-apps-to-apple-silicon) and check the macOS version Figment shows before purchase against Apple's Xcode table.
2. Sign in under **Xcode → Settings → Accounts** with your developer account only if you plan to drive a tethered device or build a signed deliverable. The program is a local macOS command-line tool and needs no provisioning profile.
3. Confirm the GPU you landed on with `system_profiler SPDisplaysDataType`, or read the first line the program prints. `device.name` is what you measured against.

The rented Mac is itself the Metal device under test. No tethered iPhone or iPad is needed for a macOS validation pass.

## How does the Swift program work?

It loads an image, applies a Core Image filter through a Metal-backed `CIContext`, reads the output texture back, hashes the bytes with SHA-256, and prints the median GPU time across `--repeats N` runs. `gpuStartTime` and `gpuEndTime` are host times (relative to system mach time) captured when the GPU starts and finishes command-buffer execution. Their difference is the GPU running time for that submission. Treat the code as an untested example: compile it with the Swift version your installed Xcode ships, and inspect the output of a controlled baseline before you accept it as the reference.

```swift
// MetalFilterValidator.swift
// Build: swiftc MetalFilterValidator.swift -o MetalFilterValidator
// Run:   ./MetalFilterValidator <input.png> <expected_sha256> [--repeats N]

import Foundation
import Metal
import CoreImage
import CoreImage.CIFilterBuiltins
import CoreGraphics
import CryptoKit

let args = CommandLine.arguments
guard args.count >= 3 else {
    FileHandle.standardError.write(Data(
        "Usage: MetalFilterValidator <input.png> <expected_sha256> [--repeats N]\n".utf8))
    exit(2)
}
let inputPath    = args[1]
let expectedHash = args[2].lowercased()
var repeats = 10
if let i = args.firstIndex(of: "--repeats"), i + 1 < args.count,
   let n = Int(args[i + 1]), n > 0 { repeats = n }

guard let device = MTLCreateSystemDefaultDevice(),
      let queue  = device.makeCommandQueue() else {
    FileHandle.standardError.write(Data("ERROR: No Metal device/queue.\n".utf8))
    exit(1)
}
print("GPU: \(device.name)")

guard let input = CIImage(contentsOf: URL(fileURLWithPath: inputPath)) else {
    FileHandle.standardError.write(Data("ERROR: Could not load \(inputPath)\n".utf8))
    exit(1)
}

// Replace with the filter under test.
let f = CIFilter.gaussianBlur()
f.inputImage = input
f.radius = 8.0
guard let output = f.outputImage?.cropped(to: input.extent) else {
    FileHandle.standardError.write(Data("ERROR: Filter produced no output.\n".utf8))
    exit(1)
}

let bounds = input.extent.integral
let width  = Int(bounds.width)
let height = Int(bounds.height)

let desc = MTLTextureDescriptor.texture2DDescriptor(
    pixelFormat: .rgba8Unorm, width: width, height: height, mipmapped: false)
desc.usage = [.renderTarget, .shaderRead]
desc.storageMode = .shared
guard let texture = device.makeTexture(descriptor: desc) else {
    FileHandle.standardError.write(Data("ERROR: Texture allocation failed.\n".utf8))
    exit(1)
}

guard let outputSpace = CGColorSpace(name: CGColorSpace.sRGB),
      let workingSpace = CGColorSpace(name: CGColorSpace.extendedLinearSRGB) else { exit(1) }
let ciContext = CIContext(mtlDevice: device, options: [.workingColorSpace: workingSpace])
var timings: [Double] = []

// One warm-up pass (not recorded), then `repeats` measured passes.
for run in 0...repeats {
    guard let cb = queue.makeCommandBuffer() else { exit(1) }
    ciContext.render(output, to: texture, commandBuffer: cb,
                     bounds: bounds, colorSpace: outputSpace)
    cb.commit()
    cb.waitUntilCompleted()
    if let err = cb.error {
        FileHandle.standardError.write(Data("ERROR: Command buffer failed: \(err)\n".utf8))
        exit(1)
    }
    let elapsed = cb.gpuEndTime - cb.gpuStartTime
    guard cb.gpuStartTime > 0, elapsed.isFinite, elapsed > 0 else {
        FileHandle.standardError.write(Data("ERROR: GPU timing unavailable.\n".utf8))
        exit(1)
    }
    if run > 0 { timings.append(elapsed) }
}

let bytesPerRow = 4 * width
var pixels = [UInt8](repeating: 0, count: bytesPerRow * height)
texture.getBytes(&pixels, bytesPerRow: bytesPerRow,
                 from: MTLRegionMake2D(0, 0, width, height), mipmapLevel: 0)
let actualHash = SHA256.hash(data: Data(pixels))
    .map { String(format: "%02x", $0) }.joined()

timings.sort()
let median = timings[timings.count / 2]
print(String(format: "GPU median over %d runs: %.4f ms", timings.count, median * 1000))
print("Expected: \(expectedHash)")
print("Actual  : \(actualHash)")

if actualHash == expectedHash { print("PASS"); exit(0) }
FileHandle.standardError.write(Data("FAIL: pixel output does not match reference.\n".utf8))
exit(1)
```

To establish the reference hash, run the program once on a configuration you trust, typically your workstation, capture the printed `Actual` value, and commit it to the test fixture beside the input image. Pass that stored hash as the second argument on the rented Mac. A mismatch flags a difference to investigate. Floating-point or colour-management differences across hardware and OS releases can be acceptable, and a hash alone cannot tell them from a defect. For cross-device acceptance, also compare pixels with an explicit tolerance and inspect the difference image.

Keep the repeat loop inside the program. Separate process runs change cache and initialisation conditions, so keep those conditions explicit even though the reported timing covers only the GPU command buffer. For a smaller worksheet, set `--repeats 5` and record the median. Extend the example to print individual timings if you need to inspect their spread.

## When can I trust a green run?

Treat PASS as evidence only when all of these are true:

- `device.name` in the output matches the chip generation you care about. An M2 median is not a stand-in for an M4 Pro budget.
- The reference hash in the fixture was produced on a configuration you controlled, not on the machine under test.
- The input image is bit-identical in both runs (compare its SHA-256 before loading).
- The filter under test is the one you exported from Xcode. Replacing `.gaussianBlur()` with another Core Image filter requires a reviewed reference. A raw Metal compute pipeline needs its own encoder implementation and is not a drop-in `CIFilter` replacement.
- A warm-up pass is present. A single-run timing on first launch is dominated by shader compilation and the Metal pipeline cache state.
- Xcode compatibility is pinned, and `swift --version` and `xcodebuild -version` are recorded alongside the hash.
- Colour space is explicit. The program uses extended linear sRGB for working space and sRGB output. Your real pipeline may need Display P3, and the reference hash will differ.

## Which plan should you test each Metal filter workload on?

| Workload | Plan to test | What to check |
|---|---|---|
| Single-pass Core Image, 1080p | [Dedicated M4 Pro 48 GB](/mac-hosting#dedicated-m4-pro), $349 a month | `device.name`, median GPU time |
| Multi-pass Metal compute, large tiles | Dedicated M4 Pro | Threadgroup memory of the M4 Pro against your kernel |
| MetalFX upscaling or denoising | Dedicated M4 Pro | Metal 4 features on the actual device |
| Scheduled filter validation | Dedicated M4 Pro, $349 a month | You run the schedule yourself. We do not manage CI. |

The [Apple Silicon Mac VM](/mac-hosting#apple-silicon-vm) ($6 a day) has 4 shared vCPUs. Whether it exposes a Metal device is not measured, so run the program there before you rely on it. Use it for the Xcode build step if the program reports a device. The Intel Mac VM ($2 a day) is for Intel toolchain work only. The Dedicated M4 Pro 48 GB is billed by the month, so a one-week validation sprint costs one month: $349.

## How does this compare on price with CloudMac?

CloudMac lists an M4 Mac mini (16 GB, 256 GB) at **$99.99/month** on [cloudmac.org/pricing](https://cloudmac.org/pricing) and an advertised annual rate of **$999/year**, which is $83.25 a month. Figment's Dedicated M4 Pro is a larger whole Mac, so the comparison is not equal hardware.

| Option | Monthly | 12-month cost |
|---|---|---|
| Figment Dedicated M4 Pro 48 GB (M4 Pro, 48GB, 512GB) | $349 | $3,228 paid up front |
| CloudMac M4, 16 GB, 256 GB, monthly | $99.99 | 12 × $99.99 = $1,199.88 |
| CloudMac M4, 16 GB, 256 GB, paid a year ahead | $83.25 | $999 |

Over a year, CloudMac's annual rate is $2,229 lower than Figment's whole Mac paid up front (3,228 − 999 = 2,229), and Figment's has 48GB of memory against 16 GB and a 512GB disk against 256 GB. For a short validation, Figment's month-to-month price ($349, cancel any time) avoids the year-long commitment. CloudMac's 512 GB and 1 TB rows currently show "Fully reserved" with no next allocation scheduled, so availability on that side is not blanket either.

**Related guides:**
- [ProRes GPU Export on an Apple silicon Mac](/blog/mac-prores-gpu-export-m-series)
- [Figma and Xcode Asset Export on a Remote Mac](/blog/mac-figma-xcode-asset-export-remote)
- [GitHub Actions Self-Hosted Runner on a Mac](/blog/mac-github-actions-self-hosted-runner)
