Shaders: pixel programs the console tests depth before keep early depth #2085
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2085
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@0xkn0wh3r3 on GitHub · 2026-11-25 04:31 UTC · original
0xkn0wh3r3:shader/early-depth-before-shader→main· +635 −1 · 4 files · 3 commits · openThe 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.@jeremygold02 on GitHub · 2026-11-25 04:41 UTC · original
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.
@0xkn0wh3r3 on GitHub · 2026-11-25 06:20 UTC · original
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.@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
main940d32f(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).
@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:
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
@DenRakEiw on GitHub · 2026-11-25 04:36 UTC · original · approved these changes
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).
@catminou4 on GitHub · 2026-11-25 05:09 UTC · original · approved these changes
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).
@fuzeofficlal on GitHub · 2026-11-26 19:50 UTC · original · approved these changes
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.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.