Shaders: pixel programs the console tests depth before keep early depth #2085

Open
github-bot wants to merge 3 commits from github-bot/gh-2085 into main AGit
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 04:31 UTC · original
0xkn0wh3r3:shader/early-depth-before-shader → main · +635 −1 · 4 files · 3 commits · open

The problem

Some console pixel programs run only for pixels that pass the depth test. On the host they ran for hidden pixels too, and kept what those pixels wrote.

A console pixel program compiled with [earlydepthstencil] runs with DB_SHADER_CONTROL.DEPTH_BEFORE_SHADER set (bit 12, as AMD's register headers name it, e.g. Linux's gc_10_3_0_sh_mask.h; bit 16 next to it is the ordered-section bit the translator already reads). Depth and stencil are then tested before the program runs, so it runs only for pixels that pass, even when it writes unordered views.

The translation never set DXIL's matching flag (ForceEarlyDepthStencil, shader flags bit 3, DxilShaderFlags.h). A host runs a pixel program that writes unordered views with the depth test after it. So for such programs it ran every hidden pixel too and kept those pixels' writes:

  • work the console skips;
  • writes the console never makes (counters, visibility or decal buffers written for occluded pixels).

The fix

  • emit/lower.rs: pixel programs with DEPTH_BEFORE_SHADER get flags::EARLY_DEPTH (new in emit/shader.rs, bit 3).
  • A program with the bit that also exports depth keeps the flag. The console tests the rasterized depth first then too, and DXIL's validator has no rule against the pair.

Programs without the bit are unchanged.

Testing

New tests in emit::synthetic_tests:

  • pixel_programs_tested_before_they_run_keep_that_order: lowers a pixel program that stores (1, 0, 0, 1) to an unordered view, with and without the bit, and draws it: one triangle at depth 0.5 over a D32 buffer, tested LESS.

    draw RTX 5070 Ti WARP
    depth cleared to 1 (visible), flagged stores stores
    depth cleared to 0 (hidden), flagged nothing stored nothing stored
    hidden, same program without the bit (main's translation) stores stores

    The first row shows the draw, depth test and view binding work. The last shows the host runs an unflagged program before the depth test and keeps its store, so the test tells the two apart. With the flag-setting line removed, the test fails.

  • a_program_tested_first_that_exports_depth_keeps_the_flag: the flag with an SV_Depth output; both devices create and draw the pipeline.

The test host gains:

  • a depth-tested graphics pipeline (Host::depth_tested_pipeline);
  • a vertex shader taking its position from the vertex (position_vs; the stub's position is zero);
  • a draw over a depth buffer with a texture UAV read back (Host::draw_behind_depth).

Runs:

  • cargo test -p victory-shader --lib -- --test-threads=1 --skip heap_direct_texture_reads_mark_their_heap_index on an RTX 5070 Ti (driver 621.24), re-run on 13f91ca: 268 passed (246 on the old base). The skipped test crashes the test process on NVIDIA on main too, so a full run needs the skip. The only failures are stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros and synthetic_tests::gathers_at_a_level_match_the_hardware. Those fail the same way on main on NVIDIA (the test host's heap and structured views, #1835; fixed by #1887 and #1777/#1779).
  • cargo clippy -p victory-shader --all-targets, with and without --features diagnostics: clean.

Not covered

  • No dxil.dll on this machine, so the validator branch of the tests did not run.
  • Not measured in a title run (no game data here).

Rebased onto 13f91ca

  • No code changes from the rebase. The early-depth flag, its tests and the test host additions are as before.
  • The new base brings more victory-shader tests: 268 now pass, against 246 before, and the same three fail as on main. Upstream's memory_tests::heap_direct_texture_reads_mark_their_heap_index crashes on NVIDIA on main, so the run skips it.

Rebased onto f3578e3

  • main now serializes WARP work in the test host behind one lock (bde8e7d, #244). Host::draw_behind_depth takes that lock too, as Host::draw and Host::dispatch do. The depth-tested pipeline goes through the same pipeline creation, which already takes it. The flag and the tests are otherwise unchanged.
  • cargo test -p victory-shader --lib -- --skip heap_direct_texture_reads_mark_their_heap_index on the RTX 5070 Ti: 300 passed. The same three tests fail on f3578e3 itself: the two stride_tests and gathers_at_a_level_match_the_hardware. Clippy is clean with and without --features diagnostics, and so is cargo xtask policy.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 04:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2085) `0xkn0wh3r3:shader/early-depth-before-shader` → `main` · +635 −1 · 4 files · 3 commits · open ## The problem Some console pixel programs run only for pixels that pass the depth test. On the host they ran for hidden pixels too, and kept what those pixels wrote. A console pixel program compiled with `[earlydepthstencil]` runs with `DB_SHADER_CONTROL.DEPTH_BEFORE_SHADER` set (bit 12, as AMD's register headers name it, e.g. Linux's `gc_10_3_0_sh_mask.h`; bit 16 next to it is the ordered-section bit the translator already reads). Depth and stencil are then tested before the program runs, so it runs only for pixels that pass, even when it writes unordered views. The translation never set DXIL's matching flag (`ForceEarlyDepthStencil`, shader flags bit 3, `DxilShaderFlags.h`). A host runs a pixel program that writes unordered views with the depth test after it. So for such programs it ran every hidden pixel too and kept those pixels' writes: - work the console skips; - writes the console never makes (counters, visibility or decal buffers written for occluded pixels). ## The fix - `emit/lower.rs`: pixel programs with `DEPTH_BEFORE_SHADER` get `flags::EARLY_DEPTH` (new in `emit/shader.rs`, bit 3). - A program with the bit that also exports depth keeps the flag. The console tests the rasterized depth first then too, and DXIL's validator has no rule against the pair. Programs without the bit are unchanged. ## Testing New tests in `emit::synthetic_tests`: - `pixel_programs_tested_before_they_run_keep_that_order`: lowers a pixel program that stores `(1, 0, 0, 1)` to an unordered view, with and without the bit, and draws it: one triangle at depth 0.5 over a D32 buffer, tested LESS. | draw | RTX 5070 Ti | WARP | |---|---|---| | depth cleared to 1 (visible), flagged | stores | stores | | depth cleared to 0 (hidden), flagged | **nothing stored** | **nothing stored** | | hidden, same program without the bit (main's translation) | stores | stores | The first row shows the draw, depth test and view binding work. The last shows the host runs an unflagged program before the depth test and keeps its store, so the test tells the two apart. With the flag-setting line removed, the test fails. - `a_program_tested_first_that_exports_depth_keeps_the_flag`: the flag with an `SV_Depth` output; both devices create and draw the pipeline. The test host gains: - a depth-tested graphics pipeline (`Host::depth_tested_pipeline`); - a vertex shader taking its position from the vertex (`position_vs`; the stub's position is zero); - a draw over a depth buffer with a texture UAV read back (`Host::draw_behind_depth`). Runs: - `cargo test -p victory-shader --lib -- --test-threads=1 --skip heap_direct_texture_reads_mark_their_heap_index` on an RTX 5070 Ti (driver 621.24), re-run on 13f91ca: 268 passed (246 on the old base). The skipped test crashes the test process on NVIDIA on `main` too, so a full run needs the skip. The only failures are `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` and `synthetic_tests::gathers_at_a_level_match_the_hardware`. Those fail the same way on `main` on NVIDIA (the test host's heap and structured views, #1835; fixed by #1887 and #1777/#1779). - `cargo clippy -p victory-shader --all-targets`, with and without `--features diagnostics`: clean. ## Not covered - No `dxil.dll` on this machine, so the validator branch of the tests did not run. - Not measured in a title run (no game data here). ### Rebased onto 13f91ca - No code changes from the rebase. The early-depth flag, its tests and the test host additions are as before. - The new base brings more `victory-shader` tests: 268 now pass, against 246 before, and the same three fail as on `main`. Upstream's `memory_tests::heap_direct_texture_reads_mark_their_heap_index` crashes on NVIDIA on `main`, so the run skips it. ### Rebased onto f3578e3 - `main` now serializes WARP work in the test host behind one lock (bde8e7d, #244). `Host::draw_behind_depth` takes that lock too, as `Host::draw` and `Host::dispatch` do. The depth-tested pipeline goes through the same pipeline creation, which already takes it. The flag and the tests are otherwise unchanged. - `cargo test -p victory-shader --lib -- --skip heap_direct_texture_reads_mark_their_heap_index` on the RTX 5070 Ti: 300 passed. The same three tests fail on `f3578e3` itself: the two `stride_tests` and `gathers_at_a_level_match_the_hardware`. Clippy is clean with and without `--features diagnostics`, and so is `cargo xtask policy`.
A console pixel program compiled with `[earlydepthstencil]` runs with
`DB_SHADER_CONTROL.DEPTH_BEFORE_SHADER` (bit 12, as AMD's register
headers name it; the bit 16 next to it is the ordered-section bit the
translator already reads): depth and stencil are tested before it runs,
so it runs only for pixels that pass, even when it writes unordered
views. The translation never set DXIL's matching flag
(`ForceEarlyDepthStencil`, shader flags bit 3). A host runs a pixel
program that writes unordered views with the depth test after it, so for
such programs it ran every hidden pixel too and kept those pixels'
writes: work the console skips, and writes it never makes (counters,
visibility or decal buffers written for occluded pixels).

The flag is now set for pixel programs with the bit.

The new test lowers a pixel program that stores to an unordered view
with and without the bit, checks the flag follows it, and has the
hardware device and WARP take the flagged program into a graphics
pipeline (both did, on an RTX 5070 Ti and WARP).
The test of the early-depth flag checked only that the flag follows
DEPTH_BEFORE_SHADER and that the host takes the program. It now draws
it: one triangle at depth 0.5 over a depth buffer, tested LESS, with the
program storing (1, 0, 0, 1) to an unordered view.

- Depth cleared to 1 (visible): the flagged program stores, so the
  draw, the test and the view binding work.
- Depth cleared to 0 (hidden): the flagged program stores nothing.
- Hidden, the same program without the bit: the host runs it before the
  depth test and keeps its store. This is what the flag prevents, and
  shows the test tells the two apart.

All three hold on the RTX 5070 Ti and on WARP.

A program with the bit that also exports depth keeps the flag: the
console tests the rasterized depth first then too, DXIL's validator has
no rule against the pair, and both devices take and draw it (new test).

The test host gains a depth-tested graphics pipeline, a vertex shader
that takes its position from the vertex (the stub's is zero) and a draw
over a depth buffer with a texture UAV, read back.
Review (#2085): the hidden-pixel check expected the UAV texel to read
zero, which rested on the committed texture's initial contents.
`Host::draw_behind_depth` now clears the UAV to a known value
(`Host::UAV_SEED`) before the draw, with a UAV barrier ordering the
clear first, and the tests expect that value where nothing was stored:
hidden pixels of the flagged program, and every texel but the one
written.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:54:25 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-25 04:41 UTC · original

Triage verdict — Keep early-depth lowering, initialize the UAV readback fixture (3202102)

Evidence

  • @⁠0xkn0wh3r3 preserves the console’s early-depth flag in DXIL. The new fixture covers the observable difference: a depth-rejected pixel leaves the UAV alone with the flag and writes without it. The fixture clears depth but does not explicitly seed the committed UAV, so the no-store expectation currently relies on its initial contents. UAV fixture · Depth clear

Checks and limits

  • Both exact-head tests passed on hardware D3D12 and WARP. A disposable extension explicitly validated the flagged SV_Depth shader with DXIL validation and its draw also passed.
  • The SV_Depth fixture disables depth writes and uses equal rasterized and exported depth. That establishes acceptance of the combination. It leaves stored-depth behavior untested. Depth-export fixture

Next step

  • Seed the UAV to a known value and order that initialization before the draw, so no-store is deterministic. If validating depth-export parity later, use different rasterized and exported values with depth writes enabled and inspect the stored depth.

This verification was AI-assisted.

**@⁠jeremygold02** on GitHub · 2026-11-25 04:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2085#issuecomment-7153074706) **Triage verdict — Keep early-depth lowering, initialize the UAV readback fixture** (`3202102`) **Evidence** - @⁠0xkn0wh3r3 preserves the console’s early-depth flag in DXIL. The new fixture covers the observable difference: a depth-rejected pixel leaves the UAV alone with the flag and writes without it. The fixture clears depth but does not explicitly seed the committed UAV, so the no-store expectation currently relies on its initial contents. [UAV fixture](https://github.com/Marvisak/VIctory/blob/320210254c947e7225379400e9d043795f15839f/crates/victory-shader/src/emit/synthetic_tests.rs#L372-L530) · [Depth clear](https://github.com/Marvisak/VIctory/blob/320210254c947e7225379400e9d043795f15839f/crates/victory-shader/src/emit/host.rs#L1405-L1422) **Checks and limits** - Both exact-head tests passed on hardware D3D12 and WARP. A disposable extension explicitly validated the flagged `SV_Depth` shader with DXIL validation and its draw also passed. - The `SV_Depth` fixture disables depth writes and uses equal rasterized and exported depth. That establishes acceptance of the combination. It leaves stored-depth behavior untested. [Depth-export fixture](https://github.com/Marvisak/VIctory/blob/320210254c947e7225379400e9d043795f15839f/crates/victory-shader/src/emit/synthetic_tests.rs#L531-L600) **Next step** - Seed the UAV to a known value and order that initialization before the draw, so no-store is deterministic. If validating depth-export parity later, use different rasterized and exported values with depth writes enabled and inspect the stored depth. This verification was AI-assisted.
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 06:20 UTC · original

Thanks @⁠jeremygold02, done in 3c76d58. draw_behind_depth now clears the UAV to a known value (Host::UAV_SEED, [0.25, 0.5, 0.75, 0.125]) before the draw, with a UAV barrier ordering the clear first. The tests expect that value wherever nothing was stored: the hidden pixels of the flagged program, and every texel except the one written. So "no store" no longer depends on what a new texture happens to contain. Both tests pass on an RTX 5070 Ti. Separate depth-export parity, with different rasterised and exported depths and depth writes on, is a good follow-up; I have left it out of this PR.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 06:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2085#issuecomment-7154690408) Thanks @⁠jeremygold02, done in `3c76d58`. `draw_behind_depth` now clears the UAV to a known value (`Host::UAV_SEED`, `[0.25, 0.5, 0.75, 0.125]`) before the draw, with a UAV barrier ordering the clear first. The tests expect that value wherever nothing was stored: the hidden pixels of the flagged program, and every texel except the one written. So "no store" no longer depends on what a new texture happens to contain. Both tests pass on an RTX 5070 Ti. Separate depth-export parity, with different rasterised and exported depths and depth writes on, is a good follow-up; I have left it out of this PR.
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 08:59 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head 3c76d58d onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 08:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2085#issuecomment-7157735066) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 3c76d58d onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:32 UTC · original · edited 2026-11-26 01:24 UTC

Automated triage for the maintainers.

Merge candidate. Rebased onto current main; three commits, merges cleanly.

The change is as before: Lower in crates/victory-shader/src/emit/lower.rs sets flags::EARLY_DEPTH (ShaderFlags bit 3, emit/shader.rs) for pixel programs whose DB_SHADER_CONTROL has DEPTH_BEFORE_SHADER (bit 12, which matches the public AMD register headers cited). Programs without the bit are unchanged. pixel_programs_tested_before_they_run_keep_that_order now seeds the UAV with Host::UAV_SEED behind a barrier, so "nothing stored" no longer depends on what a new texture happens to contain. The depth-export test only checks that the pipeline is accepted and draws.

Small fix still open from the last triage: in crates/victory-shader/src/emit/host.rs the draw_behind_depth doc paragraph sits on UAV_SEED, merged with that constant's doc, and still says the UAV is "(zeroed)". Move it back onto the method and update that word.

CI: passing (check). Recommending a look, not approving.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2085#issuecomment-7159843137) · edited 2026-11-26 01:24 UTC <!-- victory-triage v1 head=d364f7760ccf1a3aa1a02d41562bc16e47a12ccf verdict=merge-candidate at=2026-11-26T01:24:19Z --> Automated triage for the maintainers. **Merge candidate.** Rebased onto current `main`; three commits, merges cleanly. The change is as before: `Lower` in `crates/victory-shader/src/emit/lower.rs` sets `flags::EARLY_DEPTH` (ShaderFlags bit 3, `emit/shader.rs`) for pixel programs whose `DB_SHADER_CONTROL` has `DEPTH_BEFORE_SHADER` (bit 12, which matches the public AMD register headers cited). Programs without the bit are unchanged. `pixel_programs_tested_before_they_run_keep_that_order` now seeds the UAV with `Host::UAV_SEED` behind a barrier, so "nothing stored" no longer depends on what a new texture happens to contain. The depth-export test only checks that the pipeline is accepted and draws. Small fix still open from the last triage: in `crates/victory-shader/src/emit/host.rs` the `draw_behind_depth` doc paragraph sits on `UAV_SEED`, merged with that constant's doc, and still says the UAV is "(zeroed)". Move it back onto the method and update that word. CI: passing (`check`). Recommending a look, not approving. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2085/head:github-bot/gh-2085'
git switch 'github-bot/gh-2085'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2085'
git switch 'github-bot/gh-2085'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2085'
git switch 'github-bot/gh-2085'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2085'
git switch 'main'
git merge --squash 'github-bot/gh-2085'
git switch 'main'
git merge --ff-only 'github-bot/gh-2085'
git switch 'main'
git merge 'github-bot/gh-2085'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2085
No description provided.