Skip to content

fix: Metal depth24 crash on Apple Silicon (M1/M2/M3/M4)#87

Merged
kolkov merged 2 commits intomainfrom
fix/metal-depth24-apple-silicon
Mar 1, 2026
Merged

fix: Metal depth24 crash on Apple Silicon (M1/M2/M3/M4)#87
kolkov merged 2 commits intomainfrom
fix/metal-depth24-apple-silicon

Conversation

@kolkov
Copy link
Contributor

@kolkov kolkov commented Mar 1, 2026

Summary

  • Fix Metal backend crash on all Apple Silicon Macs (M1/M2/M3/M4) when creating depth/stencil textures
  • Depth24PlusStencil8 was hardcoded to MTLPixelFormatDepth24UnormStencil8 (255) — unsupported on Apple Silicon (only legacy AMD GPUs in Intel-era Macs)
  • Depth24Plus was completely missing from the format mapping — returned MTLPixelFormatInvalid (0)
  • Detect isDepth24Stencil8PixelFormatSupported at adapter enumeration and fall back to Depth32Float/Depth32FloatStencil8 on Apple Silicon
  • Follows the wgpu-rs reference pattern (wgpu-hal/src/metal/adapter.rs:668)

Fixes gogpu/ui#23

Changes

File Change
hal/metal/adapter.go Add formatDepth24Stencil8 capability field + mapTextureFormat() method
hal/metal/api.go Query isDepth24Stencil8PixelFormatSupported at adapter enumeration
hal/metal/conv.go Add missing Depth24Plus case, change D24S8 default to safe D32FS8
hal/metal/device.go Replace 3 textureFormatToMTL() calls with capability-aware mapTextureFormat()
CHANGELOG.md Add v0.19.1 entry

Test plan

  • GOOS=darwin GOARCH=arm64 go build ./... — cross-compile passes
  • go test ./... — all existing tests pass
  • golangci-lint run — 0 issues
  • Downstream gogpu and gg builds pass
  • Real device testing by reporter (rcarlier) on Apple M3

kolkov added 2 commits March 1, 2026 12:10
Depth24PlusStencil8 was hardcoded to MTLPixelFormatDepth24UnormStencil8 (255),
unsupported on Apple Silicon. Depth24Plus was missing entirely.

- Detect isDepth24Stencil8PixelFormatSupported at adapter enumeration
- Fall back to Depth32Float/Depth32FloatStencil8 on Apple Silicon
- Use capability-aware mapTextureFormat() in CreateTexture, CreateTextureView,
  CreateRenderPipeline

Follows wgpu-rs pattern (wgpu-hal/src/metal/adapter.rs).
Fixes gogpu/ui#23.
@kolkov kolkov merged commit c6dc16f into main Mar 1, 2026
10 checks passed
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.

Bug on M3 ?

1 participant