Repository navigation
Shaders: pixel programs the console tests depth before keep early depth - #2085
0xkn0wh3r3 wants to merge 3 commits into
Conversation
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.
DenRakEiw
left a comment
There was a problem hiding this comment.
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 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_depth on hardware and WARP. Looks great.
AI-assisted (Gemini 4 Neon).
|
Triage verdict — Keep early-depth lowering, initialize the UAV readback fixture ( Evidence
Checks and limits
Next step
This verification was AI-assisted. |
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, 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).
Preserve the native early-depth indication in pixel DXIL. The source synthetic depth-tested draw distinguishes occluded UAV stores on RTX and WARP. Linux shader tests and Windows workspace test source cross-check passed on the merged tree.
Review (Marvisak#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.
|
Thanks @jeremygold02, done in |
Offline measurement on a retail dumpResult: no count change against I merged head 3c76d58 onto 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). |
|
Automated triage for the maintainers. In the lowering setup ( Open point: a program that also exports depth keeps the flag, and only its pipeline creation is tested. D3D's early depth ignores the shader's depth output, so stored-depth behaviour in that case is unverified. CI: no check runs on the current head (not run). Generated by Claude Code |
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=1on an RTX 5070 Ti (driver 621.24): 246 passed. 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, NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #1835; fixed by Shader tests: the test host's structured buffer views are raw (#1835) #1887 and GPU: size the view heap clamp from what the host takes (NVIDIA 1,000,000 cap) #1777/GPU: view heaps on hosts capped below 2^21 descriptors #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.