Skip to content

metal: size multisampled depth planes by their own swizzle blocks (3D map white wash) - #514

Merged
RINNECODER merged 1 commit into
mainfrom
fix/metal-map-glitch-2
Oct 15, 2026
Merged

RINNECODER merged 1 commit into
mainfrom
fix/metal-map-glitch-2

Conversation

@RINNECODER

@RINNECODER RINNECODER commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

What

The 3D map showed a white / pale-blue wash over terrain (unexplored hexes, water, fog). It is a regression from #484 (Metal depth, MSAA and fill-kernel correctness).

Root cause

A multisampled depth or stencil plane was sized as DepthSliceBytes(extent) * samples, which is the single-sample 128x128 block padding multiplied by the sample count. A 64 KiB swizzle block holds 64 KiB / (bytes per texel * samples) pixels, so a 4x 1920x1080 D32 plane pads to 64x64 blocks and takes 33.4 MB, not 35.4 MB.

Since #484 retires depth surfaces when another depth target is bound over their planes, the overstated extent reached a single-sample depth target that the title allocates 0x1FF0000 bytes after its 4x scene depth. Binding that target retired the 4x scene-depth surface. Every later pass that samples scene depth (fog of war, water, atmosphere) then read stale guest memory and washed the map out.

Fix

DepthPlaneBytes(extent, bytesPerTexel, samples) sizes a plane with its sample count's block dimensions. For a single sample it equals DepthSliceBytes. It replaces DepthSliceBytes * samples in the depth-surface overlap, retirement and mapping checks.

Evidence

Not changed

MSAA color targets still use bytes * samples. Their layout depends on the swizzle mode, and nothing showed them over-retiring.

Verification after rebase onto main (incl. #507, sync 11)

Review findings

Source Finding Action
chatgpt-codex-connector No findings (review completed on a105765, 👍) none

🤖 Generated with Claude Code

https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj

A multisampled depth or stencil plane was taken to span
DepthSliceBytes(extent) * samples: the single-sample 128x128 (or
256x128, 256x256) block padding times the sample count. A 64 KiB
swizzle block holds 64 KiB / (bytes per texel * samples) pixels, so a
4x 1920x1080 D32 plane pads to 64x64 blocks: 33.4 MB, not 35.4 MB.

Since depth surfaces are retired when another depth target is bound
over their planes (#484), the overstated extent reached a single-sample
depth target the title allocates right after its 4x scene depth.
Binding that target retired the 4x scene depth surface, so later passes
that sample scene depth (fog of war, water, atmosphere) read stale guest
memory and washed the 3D map out in white and pale blue.

DepthPlaneBytes(extent, bytes per texel, samples) gives the plane size
with the sample count's block dimensions (equal to DepthSliceBytes for a
single sample) and replaces DepthSliceBytes * samples in the depth
surface overlap, retirement and mapping checks.

Test: metal_utility_tests (DepthResource.mm, multisampledDepthPlane)
checks the plane sizes and that a single-sample target 0x1FF0000 bytes
after a 4x 1920x1080 one retires neither; it fails without this change
("Binding a depth target after a multisampled one retired it").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj
@coderabbitai

coderabbitai Bot commented Oct 15, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6b2ea39b-fafc-49e8-96c1-2440a12a2369
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T08:49:12.404548Z a105765 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@RINNECODER
RINNECODER merged commit acfc23e into main Oct 15, 2026
1 check passed
@RINNECODER
RINNECODER deleted the fix/metal-map-glitch-2 branch October 15, 2026 09:26
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