Repository navigation
Shaders: a wave64 mask set by halves tests its high dword in lanes 32-63 (#2780) - #2783
BastienRodz wants to merge 1 commit into
Conversation
8b62a0b to
eff0cd0
Compare
|
Windows run of this head (
The first push ( |
|
Right fix for #2780: pair_high inferred the high dword by register+1 / phi matching, which breaks when the wave64 pair's halves are written separately. Carrying the high Value in Opaque(v, h) makes the mask's two dwords resolve independently at use time - lanes 32-63 now test their real bit. |
|
Reviewed and verified Code review
Verification (Windows 11, RTX 5090 + WARP +
|
|
Independent WARP/CPU verification of head Environment: Windows 11 x64, WARP/CPU only ( Tests ( Negative control: reading Clippy: Review: Carrying both dwords in AI disclosure: this verification was done by Claude Code (Claude Sonnet 5.5). |
What's wrong: a lane mask the structure pass cannot see into became `Atom::Opaque(lo)`, named by its low dword alone, and lowering guessed the high dword as the one written beside the low dword (`pair_high`: the same instruction, input or block's phis). A wave64 mask whose dwords come from separate writes (`s_mov_b32 s10, ...; s_mov_b32 s11, ...`, or `vcc_lo`/`vcc_hi`) found no such dword, so lanes 32-63 tested the low dword's bits; one whose high dword was rewritten after a 64-bit write took the stale one. RDNA2: V_CNDMASK_B32 "D.u32 = VCC ? S1.u32 : S0.u32", VCC holding one bit per thread and VCC_HI vcc[63:32]. It translated wrongly for `v_cndmask_b32` (since Marvisak#1221) and for `s_cbranch_vccz/vccnz` and guards on such a mask (before). Fix: the atom carries both dwords of the pair the mask was read from, and lowering tests the high one in wave64. `pair_high` goes. The atom is born where the later of the two dwords is defined, so a loop redefining only the high dword forgets it. `Lower::touches` looks at the high dword as well as the low one. Tests: `a_wave64_select_on_a_mask_set_by_halves_reads_its_high_dword` lowers the same select with s11 = -1 and s11 = 0; on main both give the same DXIL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
eff0cd0 to
39ba8d3
Compare
|
Thanks for the review and the runs. You're right about After the change, the whole |
|
Automated triage for the maintainers. This makes This is a recommendation for a maintainer to look, not an approval. Generated by Claude Code |
Dukestar69
left a comment
There was a problem hiding this comment.
Tested merged onto origin/main (63bcca4) on Windows 11 x64:
cargo test -p victory-shader --lib emit::lower::tests: 34 passed, 0 failed (including newa_wave64_select_on_a_mask_set_by_halves_reads_its_high_dword).cargo test -p victory-shader --lib structure::tests: 13 passed, 0 failed, 1 ignored.cargo clippy -p victory-shader -p victory --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
|
For the scalar branches from the #2780 triage: on an RX 6750 XT, with only VCC_HI set, the same synthetic program had 63 of 64 lanes take |
|
Closing in favour of #2836 + #3023. As @rezioliver-collab measured on #2780 and @wwwwwwww3333333 confirmed on an RX 6750 XT, this PR (like #2836) makes #3023 settles it on top of #2836 with a whole-pair test, and it doesn't apply cleanly here. Two equivalent PRs would only cost review time, so #2836 + #3023 is the complete fix for #2780. Thanks to everyone who reviewed and ran this one. |
What's wrong
The structure pass reads a lane mask as a register pair
(lo, hi), but stores a mask it cannot see into asAtom::Opaque(lo), so the high value is lost. Lowering then guesses the high dword withLower::pair_high, which only looks in three places: the instruction that wrote the low dword, the matching input, or a phi in the same block.That leaves two cases wrong in a wave64 program with console lanes:
s_mov_b32 s10, ...; s_mov_b32 s11, ..., orvcc_loandvcc_hiwritten apart. Nothing is found, so lanes 32-63 test the low dword.This affects
v_cndmask_b32with an SGPR-pair mask (reachable since #1221), ands_cbranch_vccz/vccnzand guards on such a mask.RDNA2 ISA, V_CNDMASK_B32: "D.u32 = VCC ? S1.u32 : S0.u32". VCC is "a bit mask with one bit per thread", and VCC_HI holds vcc[63:32].
What the fix does
Atom::Opaquecarries both dwords of the pair the mask was read from (the same value twice in wave32). Lowering tests the high one in wave64, as it is at the point of use, andpair_highis removed.Lower::touches(whether deciding a guard may test a tainted value) checks the high dword as well as the low one.apps/victory/src/translate.rs's count of guards on opaque masks matches the new variant shape (Atom::Opaque(..)).This is the "opaque atom that carries both dwords" that #660 names as the full fix.
Tests
New
emit::lower::tests::a_wave64_select_on_a_mask_set_by_halves_reads_its_high_dwordlowerss_mov_b32 s10, 0; s_mov_b32 s11, X; v_mbcnt_lo; v_cndmask_b32 v1, 0, -1, s[10:11]; ds_writeonce withX = -1and once withX = 0.The whole
victory-shaderlib was run one test per process under Wine and vkd3d-proton, on this head and on main with only the new test added. The results are identical except for the new test: 255 ok, 14 failed, 2 crashed and 3 ignored with the fix. The failures and crashes are the same tests on both builds, host quirks of Wine and lavapipe: the semantics and hardware comparisons, 64-bit image atomics,stub_pipeline_is_created, and a few synthetic DPP or gather tests.an_exec_high_write_does_not_overflow_the_stackandv_cndmask_accepts_uniform_and_constant_masksstill pass.cargo clippy --workspace --all-targets --locked -- -D warningsis clean.Not tested
v_cndmaskor a carry-in, still uses the compare's bits. That is the case Shaders: drop a wave64 mask whose low dword is seen with two high dwords #660 refuses, and this PR doesn't change it.Conflicts to expect: #660 edits the same
mask()arm instructure.rs, and #2210 rewritespair_high, which this PR removes.Fixes #2780
No game data. Found and written with AI assistance (Claude Code), reviewed and run locally.
🤖 Generated with Claude Code