Shaders: a wave64 mask set by halves tests its high dword in lanes 32-63 (#2780) #2783
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!2783
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2783/head"
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?
@BastienRodz on GitHub · 2026-11-25 20:21 UTC · original
BastienRodz:shader/wave64-split-mask-high-dword→main· +45 −44 · 3 files · 1 commits · closed without mergingWhat'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 #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
@BastienRodz on GitHub · 2026-11-25 20:29 UTC · original
Windows run of this head (
eff0cd0) onwindows-latest, WARP,cargo test --workspace --locked --no-fail-fast -- --test-threads=1: https://github.com/BastienRodz/VIctory/actions/runs/45694794941victory-shaderlib: 271 passed, 0 failed, 3 ignored, includingemit::lower::tests::a_wave64_select_on_a_mask_set_by_halves_reads_its_high_dword.The first push (
8b62a0b) missed theAtom::Opaque(_)pattern inapps/victory/src/translate.rs.eff0cd0fixes it, andcargo clippy --workspace --all-targets --locked -- -D warningsis clean.@kotekompotek on GitHub · 2026-11-25 20:38 UTC · original
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.
@fuzeofficlal on GitHub · 2026-11-25 20:46 UTC · original
Reviewed and verified
eff0cd02on Windows 11 (RTX 5090 + WARP + Windows SDK10.0.26100.0dxil.dll) againstmain(13f91ca).Code review
Atom::Opaque(Value)toAtom::Opaque(Value, Value)cleanly carries both halves in wave64:Lanes::maskadvancesborntoself.born(k.0).max(self.born(k.1)), derives from either half, and keys masks by(lo, hi)so masks sharing a low dword no longer collide;Lower::booleanresolveshionly whenwave64is set and feedslane_bit.Lower::touches(lower.rs:10088) still matchesAtom::Opaque(v, _) => Some(v)and only checks the low dword againsttainted. If only the high dword derives from a tainted register in wave64,guard/whenwould miss it—checking bothloandhiintoucheswould close that edge case cleanly.Verification (Windows 11, RTX 5090 + WARP +
dxil.dll)a_wave64_select_on_a_mask,v_cndmask,an_exec_high_write,flow_tests::,mask): 17 passed, 0 failed (includinga_wave64_select_on_a_mask_set_by_halves_reads_its_high_dword).cargo clippy --locked(victory-shaderdefault &--features host, plusvictory): 0 warnings;cargo xtask policy: 184 files ok.git merge-treeagainst13f91ca,#2668,#2387,#2711, and#2789.@oni-swr on GitHub · 2026-11-25 20:57 UTC · original
Independent WARP/CPU verification of head
eff0cd02aa0994ea5d8e4f16639987ac6124fa4bmerged cleanly ontoorigin/main13f91caee25f2fdf2c062be5f7a27f058e51cbca.Environment: Windows 11 x64, WARP/CPU only (
VICTORY_WARP=1,VICTORY_D3D12_WARP=1), no physical GPU, no game files; Windows SDK 10.0.26100.0 x64dxil.dll1.8.2502.11.Tests (
cargo test --no-fail-fast): victory-shader: 268 passed, 3 failed, 3 ignored (baseline 267 passed, 3 failed, 3 ignored; +1 new test). victory app: 10 + 2 passed (same as baseline). victory-shader baseline onorigin/main: 267 passed, 3 failed, 3 ignored; the 3 failures (synthetic_tests::a_mask_joined_with_data_at_a_uniform_loop_is_its_number,gathers_at_a_level_match_the_hardware,permutes_read_the_lane_named_and_zero_from_lanes_left_out) fail identically onorigin/mainunder WARP, so they are not caused by this PR.Negative control: reading
vinstead ofhfor the high dword in theAtom::Opaque(v, h)lowering makesa_wave64_select_on_a_mask_set_by_halves_reads_its_high_dwordfail; restored afterwards.Clippy:
cargo clippy -p <affected crates> --all-targets -- -D warningsclean (exit 0).fmt:
cargo fmt --checkis not clean onorigin/mainitself (891 diff hunks across many files); this PR: 891 hunks (same as main).Review: Carrying both dwords in
Atom::Opaqueand dating the atom by the later of the two replaces thepair_highregister-adjacency search, which is correct when the halves come from separate writes. The test checks DXIL differs in s11 only. Callers intranslate.rsare updated mechanically. Diff contains no game files, dumps, shader names or retail hashes.AI disclosure: this verification was done by Claude Code (Claude Sonnet 5.5).
@BastienRodz on GitHub · 2026-11-25 20:58 UTC · original
Thanks for the review and the runs. You're right about
Lower::touches: with the high dword now part of the atom, a tainted high dword has to count as well.39ba8d3adds that check, in 6 lines in the same function.After the change, the whole
victory-shaderlib, run one test per process under Wine and vkd3d-proton, gives the same results as before it (255 ok, with the same host-quirk failures).cargo clippy --workspace --all-targets --locked -- -D warningsis clean.@Marvisak on GitHub · 2026-11-25 23:24 UTC · original
Automated triage for the maintainers.
This makes
structure::Atom::Opaquecarry both dwords of the mask's register pair.Lanes::maskdates the atom by the later of the two definitions,Lower::booleanreads the high dword as it is at the point of use in wave64, and thepair_highguess is removed. It also checks the high dword inLower::touches, as a reviewer asked. I checked thebornordering and that the call sites inapps/victory/src/translate.rsandlower.rswere updated to match. The behaviour follows the public RDNA2 ISA definition of VCC/VCC_HI that the description quotes. The new test only shows that the DXIL changes with s11, not the lane values. The description names expected conflicts with #660 and #2210. CI passes.This is a recommendation for a maintainer to look, not an approval.
Generated by Claude Code
@wwwwwwww3333333 on GitHub · 2026-11-26 03:38 UTC · original
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
s_cbranch_vcczon #2836, matching the CPU replay reported on #2780 for both PRs. #3023 (on #2836) makes it one decision for the wave; I did not run this PR itself.@BastienRodz on GitHub · 2026-11-26 04:44 UTC · original
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
s_cbranch_vccz/vccnzon a VCC written by halves test each lane's own bit. The ISA makes that one decision for the wave (RDNA2 §12.5). With onlyVCC_HIset, 63 of 64 lanes took the branch where the hardware takes none. That is worse thanmain's wrong but uniform answer.#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.
Pull request closed