Shaders: the SCC a waterfall loop's s_andn2_wrexec leaves is false after the loop #3016
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!3016
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3016"
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?
@Anzymanz on GitHub · 2026-11-26 03:29 UTC · original
Anzymanz:waterfall-scc→main· +103 −1 · 2 files · 2 commits · openProblem
The console compiler's waterfall loop runs, one pass per distinct value, the lanes holding the first active lane's value. Its form, as this PR's test writes it:
sop()refuses any SALU that writes EXEC, and the refusal marks every value the instruction writes, its SCC included, asa lane mask read as data. When a block after the loop reads that SCC (ans_cselect,s_cbranch_scc*ors_addc), the program is refused, though nothing reads a lane mask as a number.Change
emit/lower.rs,sop(): when the instruction writing EXEC is ans_andn2_wrexec_b32/_b64that is the second-last instruction of a block whose last iss_cbranch_execnzback to the same block, its SCC is the constantfalse. The loop is left only on its not-taken edge, that is once EXEC is 0, soEXEC != 0is false wherever a later block reads it. If one of the loop block's own phis takes the SCC (a later iteration's, on the back edge), the old refusal stands. Its other writes (EXEC and the SGPR) staya lane mask read as data, as before.Tests
valu_tests::the_scc_a_waterfall_loop_leaves_is_false(GPU): the loop above overv1, thens_cselect_b32 s23, s1, s2after it;s2expected. Fails on main at lowering (a lane mask read as data); passes with this commit on an RX 9070 XT (RADV through vkd3d-proton, GE-Proton 11-14, DXC'sdxil.dll).Measured over the title's shader pack
All 25,889 distinct containers in
shaders.rpfwent throughemit::translate_withoffline, on main63bcca4and then with this commit:63bcca4a lane mask read as data827b309e779552d7,82a2ad6d07417d36,90a0692af4320129,9ffcaff533995118, all refused before)Every other program's output is byte-identical. Two of the four are the title's skinning kernels that put animated characters into the ray-tracing structures.
All four programs' DXIL converts with dxil-spirv (master). On main + #2348 + #2978 + #385 the same commit changes exactly four programs as well (
a lane mask read as data: 202 → 198 refused there), with 0 going from translated to refused.Windows test binary under Proton on the RX 9070 XT: 301 passed and 2 failed. The 2 failures (
hosts_that_do_not_fuse_are_named,stub_pipeline_is_created) fail on main in the same environment too.cargo clippy -p victory-shader -- -D warningsis clean,cargo xtask policyis ok, andlower.rsis 521,918 bytes (+1,355 B).Not run: the differential tests (no console compiler here) and NVIDIA.
🤖 Generated with Claude Code
The console compiler's waterfall loop (v_readfirstlane, v_cmpx_eq, s_andn2_wrexec, s_cbranch_execnz back to the same block) is left only once the s_andn2_wrexec leaves no lane, so the SCC it writes (EXEC != 0) is 0 wherever a block after the loop reads it. That SCC was refused with the EXEC write ('a lane mask read as data'), and a later s_cselect or s_cbranch_scc reading it stopped the program. It is now the constant false; the loop's own phis taking it (a later iteration's) still refuse. Co-Authored-By: Claude Opus 5.5 <[email protected]>@steven-seagull27 on GitHub · 2026-11-26 03:40 UTC · original
I extended the single-thread check to groups with 1, 2, 4 and 8 distinct keys. All 1,152 lane outputs per adapter matched on the RTX 5080, Windows built-in WARP and WARP 1.0.22 at
84a02d8. The 24 synthetic shader containers use both the 32-lane guest form (s_andn2_wrexec_b32) and the 64-lane guest form (_b64). Each lane saves its own key inside the loop, then writes a value that also depends on the exit flag. The three consumers weres_cselect_b32,s_cbranch_scc1ands_addc_u32. The emitted DXIL validated. These are guest wave sizes; the RTX 5080 uses 32 physical lanes.Parent
63bcca4refused the new selected-key fixture at lowering witha lane mask read as data. A separate compile-only check exercises your guard: ans_cselect_b32at the loop header reads the preceding iteration's SCC. The PR kept the refusal for this program. Removing the loop-phi check made the translator accept it, which the regression caught.The test-only commit
672c4bcapplies to your head. Runcargo test --locked -p victory-shader --lib waterfall_scc_tests -- --nocapture --test-threads=1. I also ran your original check, strict Clippy and asset policy. Your title-pack census remains the evidence for the four game shaders.@zed6000 on GitHub · 2026-11-26 04:09 UTC · original
Measured offline on the title's shaders (the method in #1247): head
84a02d8merged ontomain63bcca4(a clean merge, security-reviewed first): +4, 0 lost. The 4 are compute programs that fail onmainwithemit: a lane mask read as data. They're the last 4 of that refusal onmain, and exactly the 4 #2289 gained before it was closed for rework.cargo test -p victory-shader --lib --lockedpasses 303/0 on an RX 7900 XTX.It also stacks. On top of #1924 (port) + #2978 + #385 + #2999 + #1737 on
63bcca4, it conflicts inemit/lower.rswhere yours_andn2_wrexechelper and #1924'sstore_lds_outputssit at the same spot. Keep both. The result is 26,011 of 26,084 programs validated (+1,161, 0 lost), and 334/0 tests. Offline counts only; no program names or data.@Anzymanz on GitHub · 2026-11-26 04:43 UTC · original
Thanks all. @fuzeofficlal, you're right about the limiter: a
Branchloop cut short byVICTORY_SHADER_LOOP_LIMITexits through its normal successor with lanes still pending (onlyJumpback edges go to the abort block), so SCC isn't 0 there. Fixed in7872701by narrowing the fold rather than changing the limiter:v_readfirstlane_b32result with the same VGPR value it read (v_cmpx_eq_*reading both). Each pass then drops at least the first active lane, so the loop runs at most 64 passes.super::loop_limit() >= 64is required, so the limiter can never cut such a loop short. With a smaller diagnostic limit, the old refusal stands.s_cbranch_execnz, the wrexec just before it, no phi of the block taking the SCC) are unchanged.Multi-lane coverage. New
the_scc_a_waterfall_loop_over_many_keys_leaves_is_falseruns the loop over a 32-thread group keyedlane & s0(1, 2, 8 and 32 distinct keys), so the back edge is taken up to 31 times before the SCC is read. Thanks @steven-seagull27 for the much wider check (1/2/4/8 keys, b32/b64, three consumers) on an RTX 5080 and WARP. It addstry_build_valu_cs_lanes, the same edit #2978 makes, so the two merge cleanly in either order.Re-measured (main
63bcca4+7872701), whole shader pack: refused 220 → 216, the same 4 programs as before (827b309e,82a2ad6d,90a0692a,9ffcaff5; all keyed waterfalls, so the narrower check keeps them), every output identical to the first version, 0 programs lost. Both GPU tests pass on an RX 9070 XT (RADV via vkd3d-proton). The full Windows suite is at 302 passed and 2 failed; the 2 (hosts_that_do_not_fuse_are_named,stub_pipeline_is_created) fail on main in this environment too.cargo clippy -p victory-shader --all-targets -- -D warnings(Windows target) is clean,xtask policyis ok, andlower.rsis 522,757 B.@zed6000: thanks for the stacked numbers. Noted on the
store_lds_outputsneighbour from #1924; keep both.AI-assisted (Claude Code).
@zed6000 on GitHub · 2026-11-26 04:54 UTC · original
Re-measured the narrowed head
7872701onmain63bcca4: still +4, 0 lost, the same 4 programs as84a02d8.cargo test -p victory-shader --lib --lockedpasses 304/0 on the RX 7900 XTX. So the narrower fold still covers this title's waterfall loops. Offline counts only; no program names or data.@pawrenity on GitHub · 2026-11-26 05:04 UTC · original
VERIFY-3016: verified
7872701on NVIDIA GeForce RTX 4070, Windows 11, and on WARP. The earlier verifications were at84a02d8; this is the current head.Review (reading). The fold matches the
s_andn2_wrexecrule (EXEC = S0 & ~EXEC, D = EXEC, SCC = EXEC != 0).leaves_with_no_lane(crates/victory-shader/src/emit/lower.rs:3574) requires three things:s_cbranch_execnzis the last instruction and loops back to the same block;Two guards make the fold safe:
enter_loop) and increments on the back edge (count_iteration). The keyedv_readfirstlane/v_cmpx_eq_*form drops at least the first lane on each pass. Requiringloop_limit() >= 64therefore means the limiter cannot end this loop early.I found no defects. One edge case: an
f32/f16key that is NaN never compares equal to itself, so no lane drops. That loop also never ends on hardware, so I don't count it as a defect.Regression check. I put the PR's test hunk alone (
valu_tests.rs) onorigin/main63bcca4. Both new tests fail at build withUnsupported { what: "a lane mask read as data" }.At head:
the_scc_a_waterfall_loop_leaves_is_falseandthe_scc_a_waterfall_loop_over_many_keys_leaves_is_falsepass on hardware and WARP. Neither backend was skipped.falsetotrue, both tests fail. They check the value, not only that the shader compiles.keyed,loop_limit() >= 64, the phi check). The fullvictory-shaderlib suite still gives 300 passed and the same 3 known failures. No test in this PR covers the guards. The test-only commit672c4bcposted earlier covers the phi guard, but it is not in the PR.cargo test --locked -p victory-shader --lib(one test skipped because it crashes the process on NVIDIA): 300 passed, 3 failed. The 3 (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,synthetic_tests::gathers_at_a_level_match_the_hardware) also fail on main on this card.cargo clippy --locked -p victory-shader --all-targets -- -D warnings: clean.origin/main63bcca4is clean.Not checked: the shader-pack counts (no pack here) and the differential tests.
AI-assisted (Claude Code).
@Marvisak on GitHub · 2026-11-26 06:15 UTC · original
Automated triage for the maintainers.
In
crates/victory-shader/src/emit/lower.rs,sop()now folds the SCC of ans_andn2_wrexec_b32/_b64tofalsewhen it is the second-last instruction of a self-loop closed bys_cbranch_execnz. The newleaves_with_no_lanealso requires the keyed waterfall form (v_readfirstlane_b32result compared with the same VGPR value byv_cmpx_eq_*),loop_limit() >= 64, and no phi of the loop block taking that SCC. That follows the RDNA2 rule SCC = (EXEC != 0): the loop is left only on the not-taken edge, where EXEC is 0, and the limit guard covers the diagnostic limiter's early exit. The other writes stay refused as lane masks, as before. Two GPU tests invalu_tests.rscheck the selected value, with 1 lane and with 32 lanes and several key counts. Title-pack counts posted by the author and a second contributor show +4, 0 lost. CIcheck: passing.Suggestion, not a blocker: no test in the PR exercises the guards (a reviewer reports that removing all three leaves the suite green). Adding the phi-guard regression from the test-only commit offered in this thread would cover that.
Generated by Claude Code
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.