Shaders: a wave64 lane mask written by halves tests its low dword in lanes 32-63 #2780

Open
opened 2026-11-26 05:14:01 +00:00 by github-bot · 5 comments
Owner

@⁠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 as Atom::Opaque(lo), which drops the high value (structure.rs, Lanes::mask). Lowering then guesses the high dword with Lower::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:

s_mov_b32 s10, 0
s_mov_b32 s11, -1
v_mbcnt_lo_u32_b32 v2, -1, 0
v_cndmask_b32 v1, 0, -1, s[10:11]

The same happens with vcc_lo and vcc_hi written apart. LLVM splits a 64-bit constant that isn't inline into two s_mov_b32, so a half-wave mask such as 0xFFFFFFFF_00000000 is the typical case.

What happens on main 13f91ca.

  • pair_high finds nothing, so lane_bit(lo, None) makes lanes 32-63 test s10. The program above yields the same DXIL whether s11 is -1 or 0.
  • If the high dword is rewritten after a 64-bit write, pair_high returns the stale value.
  • Affected consumers: v_cndmask_b32 with an SGPR-pair mask (reachable since #1221), and s_cbranch_vccz/vccnz and 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:

  • #2633 notes this symptom ("reads its low dword for all 64 lanes") and leaves it unfixed.
  • #660 refuses the stale-high-dword case and says "the full fix is an opaque atom that carries both dwords".

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.

**@⁠BastienRodz** on GitHub · 2026-11-25 20:21 UTC · [original](https://github.com/Marvisak/VIctory/issues/2780) 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 as `Atom::Opaque(lo)`, which drops the high value (`structure.rs`, `Lanes::mask`). Lowering then guesses the high dword with `Lower::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: ``` s_mov_b32 s10, 0 s_mov_b32 s11, -1 v_mbcnt_lo_u32_b32 v2, -1, 0 v_cndmask_b32 v1, 0, -1, s[10:11] ``` The same happens with `vcc_lo` and `vcc_hi` written apart. LLVM splits a 64-bit constant that isn't inline into two `s_mov_b32`, so a half-wave mask such as `0xFFFFFFFF_00000000` is the typical case. **What happens on main 13f91ca.** - `pair_high` finds nothing, so `lane_bit(lo, None)` makes lanes 32-63 test `s10`. The program above yields the same DXIL whether `s11` is `-1` or `0`. - If the high dword is rewritten after a 64-bit write, `pair_high` returns the stale value. - Affected consumers: `v_cndmask_b32` with an SGPR-pair mask (reachable since #1221), and `s_cbranch_vccz`/`vccnz` and 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: - #2633 notes this symptom ("reads its low dword for all 64 lanes") and leaves it unfixed. - #660 refuses the stale-high-dword case and says "the full fix is an opaque atom that carries both dwords". 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:14:01 +00:00
Author
Owner

@⁠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). In crates/victory-shader/src/structure.rs, Lanes::mask turns a pair whose dwords come from different instructions into Atom::Opaque(k.0) and drops k.1. Only inline 64-bit constants become Atom::Constant (in operand). In crates/victory-shader/src/emit/lower.rs, Lower::pair_high only looks at the low dword's writing instruction, a program input or a phi. For two separate s_mov_b32 writes it returns None, and lane_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 in structure.rs. Both still make s_cbranch_vccz/s_cbranch_vccnz test each lane's own bit of VCC (consistent with the per-lane design described at the top of structure.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

**@⁠Marvisak** on GitHub · 2026-11-25 21:45 UTC · [original](https://github.com/Marvisak/VIctory/issues/2780#issuecomment-7175508596) · edited 2026-11-26 06:48 UTC <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-26T04:29:54Z at=2026-11-26T07:24:30Z --> Automated triage for the maintainers. Confirmed on `main` (63bcca4). In `crates/victory-shader/src/structure.rs`, `Lanes::mask` turns a pair whose dwords come from different instructions into `Atom::Opaque(k.0)` and drops `k.1`. Only inline 64-bit constants become `Atom::Constant` (in `operand`). In `crates/victory-shader/src/emit/lower.rs`, `Lower::pair_high` only looks at the low dword's writing instruction, a program input or a phi. For two separate `s_mov_b32` writes it returns `None`, and `lane_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 in `structure.rs`. Both still make `s_cbranch_vccz`/`s_cbranch_vccnz` test each lane's own bit of `VCC` (consistent with the per-lane design described at the top of `structure.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](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 21:47 UTC · original

Fixed in #2836 — Atom::Opaque now carries both dwords of the pair as read, so the emitter tests the real high dword instead of pair_high guessing the register next to the low one (removed). Covers the v_cndmask_b32 path and the s_cbranch_vccz/vccnz/guard consumers of Lanes::mask. Regression test reproduces the issue's observable (identical DXIL for s13 of -1 vs 0 on main, differing after).

**@⁠kotekompotek** on GitHub · 2026-11-25 21:47 UTC · [original](https://github.com/Marvisak/VIctory/issues/2780#issuecomment-7175540460) Fixed in #2836 — `Atom::Opaque` now carries both dwords of the pair as read, so the emitter tests the real high dword instead of `pair_high` guessing the register next to the low one (removed). Covers the `v_cndmask_b32` path and the `s_cbranch_vccz`/`vccnz`/guard consumers of `Lanes::mask`. Regression test reproduces the issue's observable (identical DXIL for `s13` of -1 vs 0 on main, differing after).
Author
Owner

@⁠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_HI changed neither branch on main. On both #2783 and #2836, it flipped the decision for lane 32 alone. With full EXEC, both instructions should make one decision for the entire wave because they test the full VCC for zero or nonzero. AMD RDNA 2 ISA, §12.5

Each cell counts how many of the 64 lanes took the branch. VCC_LO was zero throughout.

Instruction VCC_HI Expected main (f3578e38) #2783 (39ba8d3b) #2836 (bdadc5e1)
s_cbranch_vccz 0 64 64 64 64
s_cbranch_vccz 1 0 64 63 63
s_cbranch_vccnz 0 0 0 0 0
s_cbranch_vccnz 1 64 0 1 1

I 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 43 on the taken path or 17 on fallthrough at byte offset 4 * 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 for VCC_HI = 0 and 1 were 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 of VCC, which explains why the other 63 lanes kept their previous result.

**@⁠rezioliver-collab** on GitHub · 2026-11-25 22:19 UTC · [original](https://github.com/Marvisak/VIctory/issues/2780#issuecomment-7176223660) I tested the two scalar branch instructions on an Apple M1. **Setting bit 0 of `VCC_HI` changed neither branch on `main`. On both #2783 and #2836, it flipped the decision for lane 32 alone.** With full `EXEC`, both instructions should make one decision for the entire wave because they test the full `VCC` for zero or nonzero. [AMD RDNA 2 ISA, §12.5](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) Each cell counts how many of the 64 lanes took the branch. `VCC_LO` was zero throughout. | Instruction | `VCC_HI` | Expected | `main` (`f3578e38`) | #2783 (`39ba8d3b`) | #2836 (`bdadc5e1`) | |---|---:|---:|---:|---:|---:| | `s_cbranch_vccz` | 0 | 64 | 64 | 64 | 64 | | `s_cbranch_vccz` | 1 | 0 | 64 | 63 | 63 | | `s_cbranch_vccnz` | 0 | 0 | 0 | 0 | 0 | | `s_cbranch_vccnz` | 1 | 64 | 0 | 1 | 1 | I 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 `43` on the taken path or `17` on fallthrough at byte offset `4 * 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 for `VCC_HI = 0` and `1` were 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 of `VCC`, which explains why the other 63 lanes kept their previous result.
Author
Owner

@⁠wwwwwwww3333333 on GitHub · 2026-11-26 03:37 UTC · original

#3023 settles the open point above with a GPU run: s_cbranch_vccz/vccnz on 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 taking s_cbranch_vccz were 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.

**@⁠wwwwwwww3333333** on GitHub · 2026-11-26 03:37 UTC · [original](https://github.com/Marvisak/VIctory/issues/2780#issuecomment-7181881118) #3023 settles the open point above with a GPU run: `s_cbranch_vccz`/`vccnz` on 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 taking `s_cbranch_vccz` were 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.
Author
Owner

@⁠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.

PR head own test own test on main (test hunk only) other PR's test with this fix clippy -D warnings merges onto 63bcca43 victory-shader suite (merged) defects found
#2783 39ba8d3b emit::lower::tests::a_wave64_select_on_a_mask_set_by_halves_reads_its_high_dword: pass fails (lanes 32-63 tested s10's bits) #2836's a_half_written_mask_tests_its_high_dword: pass clean (victory-shader + victory, all targets; victory-shader --all-features) clean 299 passed, 3 failed, 3 ignored none
#2836 5b737dea emit::valu_tests::a_half_written_mask_tests_its_high_dword: pass fails (lanes 32-63 read the mask's high dword) #2783's test: pass clean (same set) clean (the earlier valu_tests.rs conflict is gone at this head) 299 passed, 3 failed, 3 ignored none (one redundant check, below)

main alone 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_zeros and gathers_at_a_level_match_the_hardware. They still fail when run alone with --test-threads=1, on main as 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 against main+#2836, leaving out tests. In both:

  • Atom::Opaque becomes Opaque(lo, hi).
  • Lanes::mask dates the atom by born(k.0).max(born(k.1)).
  • Lower::boolean reads hi only in wave64.
  • pair_high is removed.
  • Lower::touches treats a tainted high dword as tainted.
  • translate.rs gets the same one-line pattern change.

What is left is variable names, comments and the shape of touches. In #2836, lower.rs:10398-10403 returns early if lo or hi is tainted and then returns Some(lo), so the lo check that follows always fails. That is redundant but harmless. #2783 checks hi first and leaves the existing lo path as it was.

The tests differ in level:

  • #2783's test lowers the program with lower_wave and compares the DXIL.
  • #2836's test goes through the full compute-shader build (try_build_valu_cs_wave, a new wave64 variant of the existing helper) and compares HostShader::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/vccnz with only VCC_HI set changes lane 32's decision alone. That matches the design on main. structure.rs:4-12 says a wave-wide mask test becomes a test of the lane's own bit, and structure.rs:1352 builds vcc & 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 touches change 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).

**@⁠pawrenity** on GitHub · 2026-11-26 04:29 UTC · [original](https://github.com/Marvisak/VIctory/issues/2780#issuecomment-7182646567) ## #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`. | PR | head | own test | own test on `main` (test hunk only) | other PR's test with this fix | clippy `-D warnings` | merges onto `63bcca43` | `victory-shader` suite (merged) | defects found | |---|---|---|---|---|---|---|---|---| | #2783 | `39ba8d3b` | `emit::lower::tests::a_wave64_select_on_a_mask_set_by_halves_reads_its_high_dword`: pass | **fails** (`lanes 32-63 tested s10's bits`) | #2836's `a_half_written_mask_tests_its_high_dword`: pass | clean (`victory-shader` + `victory`, all targets; `victory-shader` `--all-features`) | clean | 299 passed, 3 failed, 3 ignored | none | | #2836 | `5b737dea` | `emit::valu_tests::a_half_written_mask_tests_its_high_dword`: pass | **fails** (`lanes 32-63 read the mask's high dword`) | #2783's test: pass | clean (same set) | clean (the earlier `valu_tests.rs` conflict is gone at this head) | 299 passed, 3 failed, 3 ignored | none (one redundant check, below) | `main` alone 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_zeros` and `gathers_at_a_level_match_the_hardware`. They still fail when run alone with `--test-threads=1`, on `main` as 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 against `main`+#2836, leaving out tests. In both: - `Atom::Opaque` becomes `Opaque(lo, hi)`. - `Lanes::mask` dates the atom by `born(k.0).max(born(k.1))`. - `Lower::boolean` reads `hi` only in wave64. - `pair_high` is removed. - `Lower::touches` treats a tainted high dword as tainted. - `translate.rs` gets the same one-line pattern change. What is left is variable names, comments and the shape of `touches`. In #2836, `lower.rs:10398-10403` returns early if `lo` or `hi` is tainted and then returns `Some(lo)`, so the `lo` check that follows always fails. That is redundant but harmless. #2783 checks `hi` first and leaves the existing `lo` path as it was. The tests differ in level: - #2783's test lowers the program with `lower_wave` and compares the DXIL. - #2836's test goes through the full compute-shader build (`try_build_valu_cs_wave`, a new wave64 variant of the existing helper) and compares `HostShader::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`/`vccnz` with only `VCC_HI` set changes lane 32's decision alone. That matches the design on `main`. `structure.rs:4-12` says a wave-wide mask test becomes a test of the lane's own bit, and `structure.rs:1352` builds `vcc & 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 `touches` change 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).
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#2780
No description provided.