Repository navigation
Shaders: s_cbranch_vccz/vccnz on a scalar VCC decide once for the wave (#2780, on #2836) - #3023
wwwwwwww3333333 wants to merge 5 commits into
Conversation
…he register next to the low one In wave64 a mask the structure pass cannot see into was kept as Atom::Opaque of the pair's low value alone, and lowering guessed the high dword from the register next to it (Marvisak#2780). A mask whose dwords are written apart — LLVM splits a 64-bit constant that is not inline into two s_mov_b32, and vcc_lo/vcc_hi are written apart the same way — got no guess, so lanes 32-63 tested the low dword's bits again; a high dword rewritten after a 64-bit write could be guessed stale. The opaque atom now names both dwords of the pair as they were read, and the emitter tests them directly (no guessing, so pair_high goes); two masks sharing a low dword with different high dwords are different masks. The atom's birth index is the later of the pair's, so forgetting masks when a region's values are redefined drops a pair the region assembled. A wave64 cndmask over s[12:13] written by halves now differs in DXIL for a high dword of -1 versus 0 (identical before), matching the console. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
s_cbranch_vccz and s_cbranch_vccnz test VCC as a whole (RDNA2 ISA, 12.5: VCCZ is VCC == 0), one decision for the wave. The structure pass gave them each lane's own bit of VCC under EXEC. With VCC written by halves from scalars, and only VCC_HI set, lanes 0-31 and 33-63 took the branch and lane 32 did not, on Marvisak#2836 (all 64 took it on main). A VCC that is a pair the pass cannot see into (Atom::Opaque, both dwords since Marvisak#2836) now gives Atom::Nonzero, the same in every lane and lowered as (lo | hi) != 0, so the branch is uniform; a constant VCC other than all lanes or none is taken. No wave operation and no forced wave size. shortcut: a VCC from lane results (compares) still branches per lane, the same while VCC is set only in lanes of EXEC and the skipped block does nothing in lanes whose bit is clear. Tests: synthetic_tests::vcc_branches_test_the_whole_mask (wave64, VCC_HI only, VCC zero and VCC_LO only, for both branches; every lane takes the same path, on the hardware adapter and WARP) and structure::tests::vcc_branches_on_scalar_masks_are_uniform. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LwHmoV6jP696CZH3DVW7V1
fuzeofficlal
left a comment
There was a problem hiding this comment.
Reviewed 8fc606d0 against main (63bcca43; emit/lower.rs stays at 520,714 bytes, safely under the 512 KiB limit). Two concrete issues to fix before merge:
-
Scalar
VCCexpressions beyond a single positiveAtom::Opaque/Atom::Constantstill fall back to a per-lane branch (crates/victory-shader/src/structure.rs:1371-1383)wholeonly matchesSome((Atom::Opaque(lo, hi), Bool::FALSE, Bool::TRUE))andSome((Atom::Constant(_), Bool::FALSE, Bool::TRUE)).- Any scalar wave64 mask operation that produces a negated or compound BDD over scalar atoms — for example:
s_not_b64 vcc, s[2:3](produces(Atom::Opaque(lo, hi), Bool::TRUE, Bool::FALSE)),s_cselect_b64 vcc, 1, 2(instructure.rs:1120, buildsite(Atom::Uniform(scc), Atom::Constant(1), Atom::Constant(2)), whose root isAtom::Uniform(scc)), or- scalar masks merged at a CFG join (
Atom::Phi)
misseswholeand falls through toself.b.and(vcc, exec). Fors_cselect_b64 vcc, 1, 2+s_cbranch_vccnz, the whole wave must take the branch for eitherSCCvalue, but falling back to per-lanevcc & execcauses only lane 0 or lane 1 to take it (and a CFG join can produce a mask PHI whose scalar inputs the wave64 emitter rejects).
-
Test coverage gaps (
crates/victory-shader/src/emit/synthetic_tests.rs:681-684,crates/victory-shader/src/structure.rs:1767)- In
vcc_branches_test_the_whole_mask,host.compute_pipeline(&shader)errorscontinueandassert!(ran > 0)is only checked once across all 6 cases. If the keyvcc_hi = 1case fails pipeline creation whilevcc = 0succeeds, the test still passes silently. Tracking a per-case run count (or failing on pipeline creation once a valid SM 6.6 device is created) avoids hiding regressions. - In
structure.rs:1767, the second fixture setsvcc_lo = 0andvcc_hi = -1via twos_mov_b32instructions, which createsAtom::Opaque(lo, hi)rather thanAtom::Constant, so theAtom::Constantarm atstructure.rs:1377isn't actually exercised (and the assertion accepts eitherBool::TRUEorAtom::Nonzero). Using a 64-bit constant move (e.g.s_mov_b64 vcc, 1) or testings_cselect_b64/s_not_b64would directly cover the non-Opaquepaths.
- In
|
Measured offline on the title's shaders (the method in #1247): head |
|
On The fixture initializes
That’s 378/512 wrong lane values per device across the eight cases. With lane 0 selected, WARP 1.0.22 also gives 63/64 wrong on parent I put a conservative guard and low/high-word regression on the fork. It follows scalar inputs through copies and operations before treating a VCC word as wave-wide. When a contributing scalar phi can select different incoming edges across lanes, it returns an explicit refusal. The regression fails on this PR head and passes with the guard. On all three devices the six original readbacks still pass, along with 1,728/1,728 additional results for constant VCC values under empty, single-lane and full EXEC. This guard covers the joined scalar input. The reviewer’s git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr3023-vcc-scalar-join
git cherry-pick 6e9e8463cad4b34841543c34968bef93a2dfc022
cargo test -p victory-shader --lib --locked vcc_branchShader Clippy with |
kotekompotek
left a comment
There was a problem hiding this comment.
LGTM — making Atom::Opaque carry the pair (lo,hi) explicitly removes the fragile pair_high lookup; Nonzero ORs both dwords under wave64 with the hi!=lo dedup. cbranch_vccz/vccnz on a scalar VCC deciding on pair-nonzero matches hardware.
Follow scalar inputs and reachable phi edges before treating a VCC word as wave-wide. A lane-local DXIL phi can feed an ordinary SGPR copy even when the final VCC value is opaque. Check both dwords in wave64 and preserve the original comparison for proven inputs. Cover a lane-selected write to s12 copied into either word. On a 64-lane synthetic dispatch the unguarded comparison wrongly branches in just one lane on RTX 5080, built-in WARP and WARP 1.0.22.
s_cbranch_vccz/vccnz decided once for the wave only when VCC was one positive opaque pair or one constant. s_not_b64, s_cselect_b64 (an SCC select), s_and_b64 with a constant and the like over scalar masks fell back to each lane's own bit: s_cselect_b64 vcc, 1, 2 took the branch in lane 1 alone. A VCC whose diagram tests only atoms held in scalars is now one condition for the wave. With constants and SCC alone it is decided in the structure pass, lane by lane over the constants. With opaque pairs it becomes Atom::Any, lowered as the scalar mask's two words and tested for zero (VCC_LO alone in wave32). A VCC from compares or a mask join keeps the per-lane shortcut. vcc_branches_test_the_whole_mask also fails when a device runs some cases but makes no pipeline for others, and covers the new forms; the structure test covers s_mov_b64, s_cselect_b64, s_not_b64 and s_and_b64. Review by fuzeofficlal on Marvisak#3023. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LwHmoV6jP696CZH3DVW7V1
s_cbranch_vccz/vccnz decided once for the wave only when VCC was one positive opaque pair or one constant. s_not_b64, s_cselect_b64 (an SCC select), s_and_b64 with a constant and the like over scalar masks fell back to each lane's own bit: s_cselect_b64 vcc, 1, 2 took the branch in lane 1 alone. A VCC whose diagram tests only atoms held in scalars is now one condition for the wave. With constants and SCC alone it is decided in the structure pass, lane by lane over the constants. With opaque pairs it becomes Atom::Any, lowered as the scalar mask's two words and tested for zero (VCC_LO alone in wave32). A VCC from compares or a mask join keeps the per-lane shortcut. vcc_branches_test_the_whole_mask also fails when a device runs some cases but makes no pipeline for others, and covers the new forms; the structure test covers s_mov_b64, s_cselect_b64, s_not_b64 and s_and_b64. Review by fuzeofficlal on Marvisak#3023. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LwHmoV6jP696CZH3DVW7V1
d42d2e1 to
3228393
Compare
|
Thanks @fuzeofficlal, both points were right, and thanks @steven-seagull27 for the guard.
On an RX 6750 XT and WARP, every lane took the expected path in all 14 cases, both ways. Before this, |
|
Automated triage for the maintainers. The direction is right and the evidence is cited: RDNA2 ISA 12.5 (VCCZ tests the whole of VCC), with GPU readbacks on an RX 6750 XT and WARP. The change spans
Update after the author's reply: merge order is settled. The first two commits here ( What is still needed before it can be recommended:
CI Generated by Claude Code |
|
Thanks for the triage. Merge order: #3023 carries #2836's two commits unchanged, so I'd suggest closing #2836 in favour of this PR and reviewing one stack. If you'd rather land #2836 first, say so and I'll rebase this PR onto it so only the guard and the whole-VCC commits remain. Title count: I can't measure the title's shaders on 3228393 (I have no dump here). The new parts since 8fc606d are Unit tests only, no game files. |
Fixes the open point of #2780 that both #2783 and #2836 leave (noted in the triage there):
s_cbranch_vccz/s_cbranch_vccnztest VCC as a whole (RDNA2 ISA, 12.5: VCCZ is VCC == 0), one decision for the wave, not each lane's bit.Built on #2836: its two commits are kept as they are (Devin, @kotekompotek), rebased onto main 63bcca4. The third commit is this change.
What changes
Atom::Opaque, both dwords since Shaders: a lane mask's high dword is the pair's own, not a guess at the register next to the low one #2836) now gives a newAtom::Nonzero(lo, hi)at the branch, the same in every lane, lowered as(lo | hi) != 0. The branch is uniform (uniform_joinand the translate counts treat it so).GPU test
synthetic_tests::vcc_branches_test_the_whole_mask: a full wave64 group, VCC written by twos_mov_b32, v4 = 17 on the taken path and 43 otherwise. Lanes takings_cbranch_vcczwith only VCC_HI set (the hardware takes none):RX 6750 XT (driver 32.0.21045.29003) and WARP. This replaces a CPU replay with a GPU run; the numbers for main and #2836 match the ones reported on #2780.
Also:
structure::tests::vcc_branches_on_scalar_masks_are_uniformchecks the branch's condition isAtom::Nonzeroalone, without a GPU.Suites (Windows 11, Rust 1.98.1 MSVC): victory-shader 305 passed, twice.
cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo check -p victory: clean.Not measured: any title. Unit tests only, no game files.
🤖 Generated with Claude Code
https://claude.ai/code/session_01LwHmoV6jP696CZH3DVW7V1