Skip to content

metal: use 256-byte uniform alignment on iOS simulator#636

Open
benface wants to merge 1 commit into
not-fl3:masterfrom
benface:metal-simulator-uniform-align
Open

metal: use 256-byte uniform alignment on iOS simulator#636
benface wants to merge 1 commit into
not-fl3:masterfrom
benface:metal-simulator-uniform-align

Conversation

@benface

@benface benface commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Problem

The iOS simulator on Apple Silicon Macs (aarch64-apple-ios-sim, target_abi = "sim") runs the iOS arm64 binary but issues Metal commands against the host Mac's GPU subsystem. That subsystem validates with the 256-byte uniform buffer offset rule — not the 16-byte rule for Apple GPUs on real iOS devices.

The existing cfg matched the simulator into the target_arch = "aarch64" branch with the iOS device's 16-byte constant. The first draw asserts:

-[MTLDebugRenderCommandEncoder validateCommonDrawErrors:]:6032: failed assertion `Draw Errors Validation
Vertex Function(vertexShader): the offset into the buffer uniforms that is bound at Buffer index 0 must be a multiple of 256 but was set to 144.

Fix

Add target_abi = "sim" to the cfg group that selects the 256-byte constant. Both the legacy x86_64 simulator and the modern arm64 simulator now pick the same alignment as macOS. Real arm64 iOS devices keep the 16-byte alignment they correctly used before.

Tested on

iPhone 17 simulator on iOS 27 beta (Apple Silicon Mac host) — uniform-alignment assert gone, draws complete.

The simulator on Apple Silicon Macs (`aarch64-apple-ios-sim`,
`target_abi = "sim"`) runs the iOS arm64 binary but issues Metal
commands against the host Mac's GPU subsystem. That subsystem
validates with the 256-byte rule — not the 16-byte rule for Apple
GPUs on real iOS devices. The existing cfg matched the simulator
into the `target_arch = "aarch64"` branch with the iOS device
constant, and the first draw asserted:

    -[MTLDebugRenderCommandEncoder validateCommonDrawErrors:]:6032:
    failed assertion `Draw Errors Validation
    Vertex Function(vertexShader): the offset into the buffer
    uniforms that is bound at Buffer index 0 must be a multiple
    of 256 but was set to 144.`

Add `target_abi = "sim"` to the cfg group that selects the 256-byte
constant so both the legacy x86_64 simulator and the modern arm64
simulator pick the same alignment as macOS. Real arm64 iOS devices
keep the 16-byte alignment they correctly used before.
@benface benface force-pushed the metal-simulator-uniform-align branch from 45d4051 to 9114737 Compare June 13, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant