Skip to content

fix(metal): configure stencil attachment in BeginRenderPass#101

Merged
kolkov merged 2 commits intomainfrom
fix/metal-stencil-attachment
Mar 11, 2026
Merged

fix(metal): configure stencil attachment in BeginRenderPass#101
kolkov merged 2 commits intomainfrom
fix/metal-stencil-attachment

Conversation

@kolkov
Copy link
Contributor

@kolkov kolkov commented Mar 11, 2026

Summary

  • Fix missing stencil attachment configuration in Metal HAL BeginRenderPass — only depth attachment was configured, stencil was completely skipped
  • Add explicit setClearDepth: call for depth attachment (was relying on Metal's default)
  • Matches Rust wgpu-hal metal/command.rs:705-727 and aligns with Vulkan/DX12 backends which already handle stencil correctly

Problem

On Apple Silicon TBDR GPUs with combined Depth32FloatStencil8 format, the missing stencil attachment left MTLLoadActionDontCare as default. This caused undefined stencil values between frames and progressive rendering artifacts on macOS Retina displays.

Ref: gogpu/gg#171

Test plan

  • Build passes (Windows + darwin/arm64 cross-compile)
  • All tests pass (go test ./... — 14 packages)
  • Lint clean (golangci-lint run — 0 issues)
  • go fmt clean
  • CI green
  • Verify on macOS Retina (awaiting @sverrehu testing)

BeginRenderPass configured only the depth attachment, completely
skipping rpDesc.stencilAttachment. On Apple Silicon TBDR GPUs with
combined Depth32FloatStencil8 format, the stencil load action defaulted
to MTLLoadActionDontCare, leaving stencil values undefined between
frames and causing progressive rendering artifacts on Retina displays.

Now configures stencilAttachment with texture, load/store actions, and
clear value. Also adds explicit setClearDepth: call for depth attachment.

Matches Rust wgpu-hal metal/command.rs:705-727 and aligns with the
Vulkan and DX12 backends which already handle stencil correctly.

Ref: gogpu/gg#171
@codecov
Copy link

codecov bot commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kolkov kolkov merged commit 382e354 into main Mar 11, 2026
11 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.

1 participant