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

Open
0xkn0wh3r3 wants to merge 3 commits from upstream-pr/2085 into main
0xkn0wh3r3 commented 2026-11-25 04:31:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T04:31:58Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5485213631 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2085). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T04:31:58Z. --- ## 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`.
DenRakEiw commented 2026-11-25 04:36:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T04:36:20Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):

  • cargo test -p victory-shader --lib pixel_programs_tested_before_they_run_keep_that_order — passed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean preservation of early depth testing for pixel shaders whose console flags request it, verified end-to-end with draw_behind_depth on hardware and WARP. Looks great.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6051918688 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2085#pullrequestreview-6051918688). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T04:36:20Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with `dxil.dll` validator): - `cargo test -p victory-shader --lib pixel_programs_tested_before_they_run_keep_that_order` — passed on both RTX 5090 hardware and `VICTORY_D3D12_WARP=1` - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean preservation of early depth testing for pixel shaders whose console flags request it, verified end-to-end with `draw_behind_depth` on hardware and WARP. Looks great. AI-assisted (Gemini 4 Neon).
jeremygold02 commented 2026-11-25 05:06:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T04:41:23Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7153074706 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2085#issuecomment-7153074706). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T04:41:23Z. --- **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.
catminou4 commented 2026-11-25 05:09:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T05:09:21Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. Pixel programs the console tests depth before keep early — early-depth-test ordering fix; pairs with #2085's console-behavior theme (#2043 discard lanes).

<!-- greyfinch-sync:Marvisak/VIctory:review:6052154579 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2085#pullrequestreview-6052154579). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T05:09:21Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 144 passed / 0 failed / 2 ignored. Pixel programs the console tests depth before keep early — early-depth-test ordering fix; pairs with #2085's console-behavior theme (#2043 discard lanes).
0xkn0wh3r3 commented 2026-11-25 07:03:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T06:20:29Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154690408 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2085#issuecomment-7154690408). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T06:20:29Z. --- 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.
sinan-cmyk commented 2026-11-25 09:06:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T08:59:45Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7157735066 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2085#issuecomment-7157735066). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T08:59:45Z. --- ### 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).
Marvisak commented 2026-11-25 11:05:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T10:32:46Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7159843137 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2085#issuecomment-7159843137). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T10:32:46Z. --- <!-- 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)_
fuzeofficlal commented 2026-11-26 19:50:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T19:50:46Z.

Review: APPROVED


Looks good to me — clean preservation of DB_SHADER_CONTROL.DEPTH_BEFORE_SHADER as DXIL ForceEarlyDepthStencil, with deterministic UAV-seeded early-Z rejection verified on both hardware and WARP.

Verified locally on Windows 11 with head d364f776 cleanly merged onto main (63bcca43):

  • Byte-size check: crates/victory-shader/src/emit/lower.rs is 521,494 bytes (2,794 bytes below the 524,288 limit).
  • Audited lower.rs:614-625 and shader.rs:60: flags::EARLY_DEPTH (1 << 3) is set strictly when StageIo::Ps declares DEPTH_BEFORE_SHADER (1 << 12), leaving late-Z programs unchanged and remaining compatible with discard, UAV/ROV (bit 16 POPS), and SV_Depth exports per D3D12/DXIL rules.
  • Formatting check (rustfmt --edition 2024 --config skip_children=true) shows no diffs on the PR's added/modified lines across shader.rs, lower.rs, host.rs, and synthetic_tests.rs.
  • cargo run -p xtask -- policy (191 files ok) and cargo clippy --locked -p victory-shader --all-targets -- -D warnings (both default and --all-features) pass.
  • Targeted tests with Windows Kits\10\bin\10.0.26100.0\x64\dxil.dll present:
    • pixel_programs_tested_before_they_run_keep_that_order: passes under both VICTORY_WARP=0 (RTX 5090, 0.40s, including the dxil.dll validator path) and VICTORY_WARP=1 (WARP, 0.03s).
    • a_program_tested_first_that_exports_depth_keeps_the_flag: passes under both VICTORY_WARP=0 (0.25s) and VICTORY_WARP=1 (0.03s).
    • emit::lower: 33 passed; 0 failed (0.02s). (Running full emit::synthetic_tests under VICTORY_WARP=0 hit 12 passed; 1 failed on the pre-existing NVIDIA gathers_at_a_level_match_the_hardware issue noted in the PR description.)

Minor non-blocking notes:

  • In crates/victory-shader/src/emit/host.rs:1355-1363, the doc comment for draw_behind_depth currently sits above pub const UAV_SEED and still describes the UAV as (zeroed).
  • In host.rs:1606-1611, while fence.GetCompletedValue() < 1 would exit immediately on device removal (UINT64_MAX), so adding a post-loop GetDeviceRemovedReason() check like host.rs:1333 would be safer.
  • a_program_tested_first_that_exports_depth_keeps_the_flag tests PSO acceptance/draw with depth writes disabled and equal rasterized/exported depths (0.5), leaving DSV depth-export suppression unverified.
<!-- greyfinch-sync:Marvisak/VIctory:review:6079776699 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2085#pullrequestreview-6079776699). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T19:50:46Z. **Review:** APPROVED --- Looks good to me — clean preservation of `DB_SHADER_CONTROL.DEPTH_BEFORE_SHADER` as DXIL `ForceEarlyDepthStencil`, with deterministic UAV-seeded early-Z rejection verified on both hardware and WARP. Verified locally on Windows 11 with head `d364f776` cleanly merged onto `main` (`63bcca43`): - Byte-size check: `crates/victory-shader/src/emit/lower.rs` is `521,494` bytes (`2,794` bytes below the `524,288` limit). - Audited `lower.rs:614-625` and `shader.rs:60`: `flags::EARLY_DEPTH` (`1 << 3`) is set strictly when `StageIo::Ps` declares `DEPTH_BEFORE_SHADER` (`1 << 12`), leaving late-Z programs unchanged and remaining compatible with `discard`, UAV/ROV (`bit 16` POPS), and `SV_Depth` exports per D3D12/DXIL rules. - Formatting check (`rustfmt --edition 2024 --config skip_children=true`) shows no diffs on the PR's added/modified lines across `shader.rs`, `lower.rs`, `host.rs`, and `synthetic_tests.rs`. - `cargo run -p xtask -- policy` (`191 files ok`) and `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (both default and `--all-features`) pass. - Targeted tests with `Windows Kits\10\bin\10.0.26100.0\x64\dxil.dll` present: - `pixel_programs_tested_before_they_run_keep_that_order`: passes under both `VICTORY_WARP=0` (RTX 5090, `0.40s`, including the `dxil.dll` validator path) and `VICTORY_WARP=1` (WARP, `0.03s`). - `a_program_tested_first_that_exports_depth_keeps_the_flag`: passes under both `VICTORY_WARP=0` (`0.25s`) and `VICTORY_WARP=1` (`0.03s`). - `emit::lower`: `33 passed; 0 failed` (`0.02s`). (Running full `emit::synthetic_tests` under `VICTORY_WARP=0` hit `12 passed; 1 failed` on the pre-existing NVIDIA `gathers_at_a_level_match_the_hardware` issue noted in the PR description.) Minor non-blocking notes: - In `crates/victory-shader/src/emit/host.rs:1355-1363`, the doc comment for `draw_behind_depth` currently sits above `pub const UAV_SEED` and still describes the UAV as `(zeroed)`. - In `host.rs:1606-1611`, `while fence.GetCompletedValue() < 1` would exit immediately on device removal (`UINT64_MAX`), so adding a post-loop `GetDeviceRemovedReason()` check like `host.rs:1333` would be safer. - `a_program_tested_first_that_exports_depth_keeps_the_flag` tests PSO acceptance/draw with depth writes disabled and equal rasterized/exported depths (`0.5`), leaving DSV depth-export suppression unverified.
zed6000 commented 2026-11-27 12:11:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by zed6000 on 2026-11-27T12:11:08Z.


An AMD measurement, RX 7900 XTX (driver 32.0.32029.2010), Series X profile, intro cutscene.

  • What it flags in this title: about 3,009 of 12,056 pixel programs (25 %) test depth early on the console. 919 of those write to title UAVs, which today also run for hidden pixels, so this is a correctness fix for them as well.
  • GPU time per frame: without this PR 154.4, 153.1 and 155.6 ms; with it 148.8 and 148.4 ms. That is about −5 ms (−3.4 %). Each figure is the median of an intro run, with the runs alternating. Whole-frame time doesn't move, because CPU preparation bounds the intro here.
  • 0 errors, 0 dropped draws and the same warning kinds with and without it. Every changed pixel pipeline (about 3,400 here) is rebuilt once.
  • Caveat: measured merged onto a branch that also carries several other open shader PRs, not on plain main. The PR applies cleanly to 63bcca4.

One side effect worth knowing: a hidden pixel no longer runs at all, so it doesn't set the runtime's read mark either. A texture read only by hidden pixels gets its view and refresh one submission later when it first becomes visible. That matches what the console's own early test does, and we saw no missing or stale textures in captures.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7217938875 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2085#issuecomment-7217938875). Originally posted by [zed6000](https://github.com/zed6000) on 2026-11-27T12:11:08Z. --- An AMD measurement, RX 7900 XTX (driver 32.0.32029.2010), Series X profile, intro cutscene. - **What it flags in this title:** about 3,009 of 12,056 pixel programs (25 %) test depth early on the console. 919 of those write to title UAVs, which today also run for hidden pixels, so this is a correctness fix for them as well. - **GPU time per frame:** without this PR 154.4, 153.1 and 155.6 ms; with it 148.8 and 148.4 ms. That is about −5 ms (−3.4 %). Each figure is the median of an intro run, with the runs alternating. Whole-frame time doesn't move, because CPU preparation bounds the intro here. - 0 errors, 0 dropped draws and the same warning kinds with and without it. Every changed pixel pipeline (about 3,400 here) is rebuilt once. - **Caveat:** measured merged onto a branch that also carries several other open shader PRs, not on plain `main`. The PR applies cleanly to `63bcca4`. One side effect worth knowing: a hidden pixel no longer runs at all, so it doesn't set the runtime's read mark either. A texture read only by hidden pixels gets its view and refresh one submission later when it first becomes visible. That matches what the console's own early test does, and we saw no missing or stale textures in captures.
zed6000 commented 2026-11-27 13:18:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by zed6000 on 2026-11-27T13:18:11Z.


A possible follow-up on top of this PR, offered in case it's useful. It's one commit on this PR's head: github.com/zed6000/VIctory@cb147771 (branch earlyz-on-2085). Feel free to take it into this PR or leave it.

What it adds. The read marks are atomics, so the host driver can't cull any heap-reading pixel program early, even where the console's program has no visible side effects. The commit also declares early depth for programs where testing first changes nothing the title sees:

  • render-target outputs only, with no depth, stencil or coverage output, and DB_SHADER_CONTROL enables none;
  • no coverage input, and not primitive-ordered;
  • no discard except the translator's loop-limit abort;
  • no store or atomic except the read marks.

The switch VICTORY_SHADER_EARLY_Z controls it: console keeps only this PR's rule, 0 turns early depth off entirely, and unset applies both. Its value is part of the shader cache key.

Measured on an RX 7900 XTX in the intro cutscene, on a branch that also carries several other open shader PRs (not plain main). The rule covers 7,239 of 12,038 pixel programs (60 %), against about 3,009 (25 %) for this PR alone.

GPU ms/frame
no early depth 154.4, 153.1, 155.6
this PR 148.8, 148.4
this PR + follow-up 145.0, 144.6, 144.9

Frame time doesn't change, because CPU preparation bounds the intro. There were 0 errors and 0 dropped draws in every run. victory-shader --lib passes (311 tests), and all 14,247 vertex and pixel programs pass the offline validator with the flag on or off.

Trade-offs to weigh.

  • Hidden pixels of these programs no longer set read marks. A texture read only by hidden pixels gets its lazy view, refresh and eviction stamp one submission late when it first becomes visible. This PR has the same effect for its own programs. We saw no missing textures in captures, but the intro is time-driven, so that check is weak.
  • The loop-limit abort is deliberately not counted as a discard; 676 programs depend on that choice.
  • The gain is about 4 ms of GPU time on top of this PR. It's invisible in frame time today.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7219308650 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2085#issuecomment-7219308650). Originally posted by [zed6000](https://github.com/zed6000) on 2026-11-27T13:18:11Z. --- A possible follow-up on top of this PR, offered in case it's useful. It's one commit on this PR's head: https://github.com/zed6000/VIctory/commit/cb147771 (branch `earlyz-on-2085`). Feel free to take it into this PR or leave it. **What it adds.** The read marks are atomics, so the host driver can't cull any heap-reading pixel program early, even where the console's program has no visible side effects. The commit also declares early depth for programs where testing first changes nothing the title sees: - render-target outputs only, with no depth, stencil or coverage output, and `DB_SHADER_CONTROL` enables none; - no coverage input, and not primitive-ordered; - no discard except the translator's loop-limit abort; - no store or atomic except the read marks. The switch `VICTORY_SHADER_EARLY_Z` controls it: `console` keeps only this PR's rule, `0` turns early depth off entirely, and unset applies both. Its value is part of the shader cache key. **Measured** on an RX 7900 XTX in the intro cutscene, on a branch that also carries several other open shader PRs (not plain `main`). The rule covers 7,239 of 12,038 pixel programs (60 %), against about 3,009 (25 %) for this PR alone. | | GPU ms/frame | |---|---| | no early depth | 154.4, 153.1, 155.6 | | this PR | 148.8, 148.4 | | this PR + follow-up | 145.0, 144.6, 144.9 | Frame time doesn't change, because CPU preparation bounds the intro. There were 0 errors and 0 dropped draws in every run. `victory-shader --lib` passes (311 tests), and all 14,247 vertex and pixel programs pass the offline validator with the flag on or off. **Trade-offs to weigh.** - Hidden pixels of these programs no longer set read marks. A texture read only by hidden pixels gets its lazy view, refresh and eviction stamp one submission late when it first becomes visible. This PR has the same effect for its own programs. We saw no missing textures in captures, but the intro is time-driven, so that check is weak. - The loop-limit abort is deliberately not counted as a discard; 676 programs depend on that choice. - The gain is about 4 ms of GPU time on top of this PR. It's invisible in frame time today.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2085:upstream-pr/2085'
git switch 'upstream-pr/2085'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2085'
git switch 'upstream-pr/2085'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2085'
git switch 'upstream-pr/2085'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2085'
git switch 'main'
git merge --squash 'upstream-pr/2085'
git switch 'main'
git merge --ff-only 'upstream-pr/2085'
git switch 'main'
git merge 'upstream-pr/2085'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2083
No description provided.