Shaders: pixel programs the console tests depth before keep early depth #2083
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2085"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 withDB_SHADER_CONTROL.DEPTH_BEFORE_SHADERset (bit 12, as AMD's register headers name it, e.g. Linux'sgc_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:The fix
emit/lower.rs: pixel programs withDEPTH_BEFORE_SHADERgetflags::EARLY_DEPTH(new inemit/shader.rs, bit 3).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.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 anSV_Depthoutput; both devices create and draw the pipeline.The test host gains:
Host::depth_tested_pipeline);position_vs; the stub's position is zero);Host::draw_behind_depth).Runs:
cargo test -p victory-shader --lib -- --test-threads=1 --skip heap_direct_texture_reads_mark_their_heap_indexon an RTX 5070 Ti (driver 621.24), re-run on13f91ca: 268 passed (246 on the old base). The skipped test crashes the test process on NVIDIA onmaintoo, so a full run needs the skip. The only failures arestride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zerosandsynthetic_tests::gathers_at_a_level_match_the_hardware. Those fail the same way onmainon 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
dxil.dllon this machine, so the validator branch of the tests did not run.Rebased onto
13f91cavictory-shadertests: 268 now pass, against 246 before, and the same three fail as onmain. Upstream'smemory_tests::heap_direct_texture_reads_mark_their_heap_indexcrashes on NVIDIA onmain, so the run skips it.Rebased onto
f3578e3mainnow serializes WARP work in the test host behind one lock (bde8e7d, #244).Host::draw_behind_depthtakes that lock too, asHost::drawandHost::dispatchdo. 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_indexon the RTX 5070 Ti: 300 passed. The same three tests fail onf3578e3itself: the twostride_testsandgathers_at_a_level_match_the_hardware. Clippy is clean with and without--features diagnostics, and so iscargo xtask policy.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, withdxil.dllvalidator):cargo test -p victory-shader --lib pixel_programs_tested_before_they_run_keep_that_order— passed on both RTX 5090 hardware andVICTORY_D3D12_WARP=1cargo clippy -p victory-shader --all-targets— 0 warningscargo 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_depthon hardware and WARP. Looks great.AI-assisted (Gemini 4 Neon).
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
Checks and limits
SV_Depthshader with DXIL validation and its draw also passed.SV_Depthfixture disables depth writes and uses equal rasterized and exported depth. That establishes acceptance of the combination. It leaves stored-depth behavior untested. Depth-export fixtureNext step
This verification was AI-assisted.
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).
Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T06:20:29Z.
Thanks @jeremygold02, done in
3c76d58.draw_behind_depthnow 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.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
3c76d58dontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 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).
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:
Lowerincrates/victory-shader/src/emit/lower.rssetsflags::EARLY_DEPTH(ShaderFlags bit 3,emit/shader.rs) for pixel programs whoseDB_SHADER_CONTROLhasDEPTH_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_ordernow seeds the UAV withHost::UAV_SEEDbehind 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.rsthedraw_behind_depthdoc paragraph sits onUAV_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
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_SHADERas DXILForceEarlyDepthStencil, with deterministic UAV-seeded early-Z rejection verified on both hardware and WARP.Verified locally on Windows 11 with head
d364f776cleanly merged ontomain(63bcca43):crates/victory-shader/src/emit/lower.rsis521,494bytes (2,794bytes below the524,288limit).lower.rs:614-625andshader.rs:60:flags::EARLY_DEPTH(1 << 3) is set strictly whenStageIo::PsdeclaresDEPTH_BEFORE_SHADER(1 << 12), leaving late-Z programs unchanged and remaining compatible withdiscard, UAV/ROV (bit 16POPS), andSV_Depthexports per D3D12/DXIL rules.rustfmt --edition 2024 --config skip_children=true) shows no diffs on the PR's added/modified lines acrossshader.rs,lower.rs,host.rs, andsynthetic_tests.rs.cargo run -p xtask -- policy(191 files ok) andcargo clippy --locked -p victory-shader --all-targets -- -D warnings(both default and--all-features) pass.Windows Kits\10\bin\10.0.26100.0\x64\dxil.dllpresent:pixel_programs_tested_before_they_run_keep_that_order: passes under bothVICTORY_WARP=0(RTX 5090,0.40s, including thedxil.dllvalidator path) andVICTORY_WARP=1(WARP,0.03s).a_program_tested_first_that_exports_depth_keeps_the_flag: passes under bothVICTORY_WARP=0(0.25s) andVICTORY_WARP=1(0.03s).emit::lower:33 passed; 0 failed(0.02s). (Running fullemit::synthetic_testsunderVICTORY_WARP=0hit12 passed; 1 failedon the pre-existing NVIDIAgathers_at_a_level_match_the_hardwareissue noted in the PR description.)Minor non-blocking notes:
crates/victory-shader/src/emit/host.rs:1355-1363, the doc comment fordraw_behind_depthcurrently sits abovepub const UAV_SEEDand still describes the UAV as(zeroed).host.rs:1606-1611,while fence.GetCompletedValue() < 1would exit immediately on device removal (UINT64_MAX), so adding a post-loopGetDeviceRemovedReason()check likehost.rs:1333would be safer.a_program_tested_first_that_exports_depth_keeps_the_flagtests PSO acceptance/draw with depth writes disabled and equal rasterized/exported depths (0.5), leaving DSV depth-export suppression unverified.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.
main. The PR applies cleanly to63bcca4.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.
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(branchearlyz-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:
DB_SHADER_CONTROLenables none;The switch
VICTORY_SHADER_EARLY_Zcontrols it:consolekeeps only this PR's rule,0turns 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.Frame time doesn't change, because CPU preparation bounds the intro. There were 0 errors and 0 dropped draws in every run.
victory-shader --libpasses (311 tests), and all 14,247 vertex and pixel programs pass the offline validator with the flag on or off.Trade-offs to weigh.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.