Skip to content

fix(shader): test depth first where the console's pixel shader does - #526

Merged
pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
hackgods:fix/early-depth-before-shader
Nov 27, 2026
Merged

pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
hackgods:fix/early-depth-before-shader

Conversation

@hackgods

Copy link
Copy Markdown
Contributor

What. A console pixel shader built with [earlydepthstencil] sets DB_SHADER_CONTROL.DEPTH_BEFORE_SHADER (bit 12). Such shaders now get DXIL ForceEarlyDepthStencil, even when they write UAVs or title memory or discard. The one exception is a shader that exports depth or stencil, which can't be tested first (the console doesn't combine the two either). The existing read-mark rule for early depth is unchanged.

Depends on the lower.rs refactor PR (#R). Main's lower.rs is 523,123 bytes, 1,165 under cargo xtask policy's 512 KiB file limit; this change alone would leave 36 bytes, and not fit beside DispatchX. The first commit here is that PR's; please review the second. lower.rs ends at 520,973 bytes (521,127 with the DispatchX PR).

Why. On the console, pixels behind closer geometry never run such a shader, so they never make its writes. The host tests depth after any shader that writes UAVs, so those pixels' writes landed. In GTA VI the alpha prepass writes velocity through a UAV: the window quad behind the player wrote its motion vectors over hers, inside the window's rectangle (seen in a render-target dump of the cell scene).

Tests

  • lower::tests::console_depth_before_shader_keeps_early_depth_stencil_with_uav_writes: with DEPTH_BEFORE_SHADER, a title UAV store (with and without view marks) and a conditional discard both get early depth, and validate. A depth export stays late.
  • The existing pixel_shader_skips_early_depth_stencil_with_discard_depth_or_uav still holds without the bit.
  • On this branch (base d2b4889): cargo test --workspace 723 passed; tools/macos/test-wine.sh --workspace --no-fail-fast 1444 passed, 1 failed (descriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_wait, intermittent on plain main too in our runs, which shared the machine with a game run); gnullvm clippy --workspace --all-targets -D warnings, with and without --all-features: clean; cargo xtask policy: ok.
  • In game (M5 Pro): it has been in our lit integration builds since v2, with no new refusals. We have not yet re-dumped the frame that showed the bug to confirm the player's motion vectors are right with it.

Update: rebased onto main f7dddb0 (after #518–#522 and #447); tests re-run there, clippy and policy clean. This change has also been in our play builds on the M5 Pro (integration v8/v9, lit and correct prison scene) for the last day.

🤖 Generated with Claude Code

A console pixel shader built with [earlydepthstencil] sets
DB_SHADER_CONTROL.DEPTH_BEFORE_SHADER (bit 12): pixels behind closer
geometry never run it. The host tests depth after any shader that writes
UAVs, so those pixels' writes landed. GTA VI's alpha prepass writes
velocity through a UAV; the window behind the player overwrote her
motion vectors inside the window's rectangle. Such shaders now get
ForceEarlyDepthStencil, unless they export depth or stencil.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pragyaangaur
pragyaangaur merged commit 705522e into pragyaangaur:main Nov 27, 2026
1 check 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.

2 participants