Shaders: a wave64 lane mask written by halves tests its low dword in lanes 32-63 #2780
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#2780
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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
In a wave64 program that reads lanes the console's way (
console_lanes: cross-lane ops,v_mbcnt, masks read as numbers), lanes 32-63 test the low dword's bits of a lane mask whose two dwords were written separately.Where. The structure pass reads the mask as a register pair
(lo, hi), but stores a mask it cannot see into asAtom::Opaque(lo), which drops the high value (structure.rs,Lanes::mask). Lowering then guesses the high dword withLower::pair_high. That helper only looks in three places: the instruction that wrote the low dword, the matching program input, or a phi in the same block.Input that goes wrong. The mask's dwords come from separate writes:
The same happens with
vcc_loandvcc_hiwritten apart. LLVM splits a 64-bit constant that isn't inline into twos_mov_b32, so a half-wave mask such as0xFFFFFFFF_00000000is the typical case.What happens on main
13f91ca.pair_highfinds nothing, solane_bit(lo, None)makes lanes 32-63 tests10. The program above yields the same DXIL whethers11is-1or0.pair_highreturns the stale value.v_cndmask_b32with an SGPR-pair mask (reachable since #1221), ands_cbranch_vccz/vccnzand guards on such a mask (before #1221 too). Carry-ins are refused.Expected (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]. Lanes 32-63 must test the high dword as it is at the point of use.
Related:
Found by reading the code and checked with a synthetic program; I have no in-game observation. No game data. Analysis assisted by Claude Code.
@Marvisak on GitHub · 2026-11-25 21:45 UTC · original · edited 2026-11-26 06:48 UTC
Automated triage for the maintainers.
Confirmed on
main(63bcca4). Incrates/victory-shader/src/structure.rs,Lanes::maskturns a pair whose dwords come from different instructions intoAtom::Opaque(k.0)and dropsk.1. Only inline 64-bit constants becomeAtom::Constant(inoperand). Incrates/victory-shader/src/emit/lower.rs,Lower::pair_highonly looks at the low dword's writing instruction, a program input or a phi. For two separates_mov_b32writes it returnsNone, andlane_bit(at, lo, None)then tests the low dword in all 64 lanes.Open PRs: #2783 and #2836 address this issue; #660 refuses the stale-high-dword case. New since the last triage: a comparison on an RTX 4070 found #2783 and #2836 both fix it with the same production logic, merge cleanly onto
63bcca4, and conflict with each other instructure.rs. Both still makes_cbranch_vccz/s_cbranch_vccnztest each lane's own bit ofVCC(consistent with the per-lane design described at the top ofstructure.rs). #3023 keeps #2836's commits and adds one that makes those branches one decision for the wave, with a GPU test on an RX 6750 XT and WARP; it was not part of that comparison. Whether the branch should be per lane or per wave is the remaining design question for review.Generated by Claude Code
@kotekompotek on GitHub · 2026-11-25 21:47 UTC · original
Fixed in #2836 —
Atom::Opaquenow carries both dwords of the pair as read, so the emitter tests the real high dword instead ofpair_highguessing the register next to the low one (removed). Covers thev_cndmask_b32path and thes_cbranch_vccz/vccnz/guard consumers ofLanes::mask. Regression test reproduces the issue's observable (identical DXIL fors13of -1 vs 0 on main, differing after).@rezioliver-collab on GitHub · 2026-11-25 22:19 UTC · original
I tested the two scalar branch instructions on an Apple M1. Setting bit 0 of
VCC_HIchanged neither branch onmain. On both #2783 and #2836, it flipped the decision for lane 32 alone. With fullEXEC, both instructions should make one decision for the entire wave because they test the fullVCCfor zero or nonzero. AMD RDNA 2 ISA, §12.5Each cell counts how many of the 64 lanes took the branch.
VCC_LOwas zero throughout.VCC_HImain(f3578e38)39ba8d3b)bdadc5e1)s_cbranch_vcczs_cbranch_vcczs_cbranch_vccnzs_cbranch_vccnzI compiled the same four synthetic Wave64 compute shaders on each revision with native Rust 1.98.1 on macOS 14.7. Each shader wrote the two VCC halves separately, kept all 64 lanes active, and stored
43on the taken path or17on fallthrough at byte offset4 * lane. I replayed the emitted DXIL control flow on the M1 CPU with lane-ID and buffer-store stubs and checked the address and value of all 64 stores.On
main, the original DXIL containers forVCC_HI = 0and1were byte-identical for each opcode. The two PRs also produced byte-identical containers to each other for every matching input. In their DXIL, the branch tests the individual lane’s bit ofVCC, which explains why the other 63 lanes kept their previous result.@wwwwwwww3333333 on GitHub · 2026-11-26 03:37 UTC · original
#3023 settles the open point above with a GPU run:
s_cbranch_vccz/vccnzon a VCC written by halves from scalars now decide once for the wave. With only VCC_HI set, on an RX 6750 XT and WARP, the lanes takings_cbranch_vcczwere 64 on main, 63 on #2836 (all but lane 32) and 0 with #3023 (the hardware takes none); all six cases tested give every lane the same path. It is built on #2836, whose commits it keeps.@pawrenity on GitHub · 2026-11-26 04:29 UTC · original
#2780: #2783 and #2836 compared
Each PR was merged onto current
main(63bcca43) and tested there. Hardware: NVIDIA GeForce RTX 4070, Windows 11. Pinned toolchain,--locked.main(test hunk only)-D warnings63bcca43victory-shadersuite (merged)39ba8d3bemit::lower::tests::a_wave64_select_on_a_mask_set_by_halves_reads_its_high_dword: passlanes 32-63 tested s10's bits)a_half_written_mask_tests_its_high_dword: passvictory-shader+victory, all targets;victory-shader--all-features)5b737deaemit::valu_tests::a_half_written_mask_tests_its_high_dword: passlanes 32-63 read the mask's high dword)valu_tests.rsconflict is gone at this head)mainalone gives 298 passed and the same 3 failures:a_heap_buffer_read_by_element_takes_the_views_stride,a_heap_buffer_read_where_no_buffer_view_is_reads_zerosandgathers_at_a_level_match_the_hardware. They still fail when run alone with--test-threads=1, onmainas well, so they are not caused by either PR. All suites were run with--skip heap_direct_texture_reads_mark_their_heap_index(#2571).The two PRs conflict with each other in
structure.rs, so only one can land.What differs
The production code is the same. I diffed
main+#2783 againstmain+#2836, leaving out tests. In both:Atom::OpaquebecomesOpaque(lo, hi).Lanes::maskdates the atom byborn(k.0).max(born(k.1)).Lower::booleanreadshionly in wave64.pair_highis removed.Lower::touchestreats a tainted high dword as tainted.translate.rsgets the same one-line pattern change.What is left is variable names, comments and the shape of
touches. In #2836,lower.rs:10398-10403returns early ifloorhiis tainted and then returnsSome(lo), so thelocheck that follows always fails. That is redundant but harmless. #2783 checkshifirst and leaves the existinglopath as it was.The tests differ in level:
lower_waveand compares the DXIL.try_build_valu_cs_wave, a new wave64 variant of the existing helper) and comparesHostShader::dxil.Both only show that the DXIL depends on the high dword. Neither runs the program to check lane values.
Not a difference between the PRs
The Apple M1 comment above reports that
s_cbranch_vccz/vccnzwith onlyVCC_HIset changes lane 32's decision alone. That matches the design onmain.structure.rs:4-12says a wave-wide mask test becomes a test of the lane's own bit, andstructure.rs:1352buildsvcc & exec. Both PRs behave the same here: they only make that per-lane bit read the real high dword. I did not run that case myself.Recommendation
The fixes are equivalent, and every check above gave the same result for both. I found no reason in the code to prefer one. #2783 came first, from the issue's reporter, and its
toucheschange is slightly tidier. #2836's test goes through more of the pipeline. If #2783 lands, #2836's test could be carried over as a second check, since it passes against #2783's fix. Whichever lands, the other one needs closing.Not tested: running the program on the GPU (lane values), in game.
AI-assisted (Claude Code).