Shaders: a lane mask written a dword at a time keeps its high dword #3402

Open
github-bot wants to merge 1 commit from github-bot/gh-3402 into main AGit
Owner

@⁠Lyrnc on GitHub · 2026-11-29 22:50 UTC · original
Lyrnc:fix/w64-mask-halves-apart → main · +84 −12 · 3 files · 1 commits · open

No issue filed: found while checking wave64 programs on a host of 32-lane waves against a wave64 card with hand-written programs.

What it changes

What was wrong. On a host of 32-lane waves, a wave64 lane mask that is a number, not an EXEC or VALU result, becomes an opaque atom named by its low dword (Atom::Opaque), and lowering took the high dword from the instruction that wrote the low one (pair_high). The compiler writes a 64-bit constant mask as two s_mov_b32. There the low dword's instruction writes no high dword, and lanes 32-63 took the low dword's bits. With EXEC set from such a pair:

  • a write under that EXEC landed in the wrong upper lanes;
  • v_mbcnt_hi_u32_b32 and s_bcnt1_i32_b64 of EXEC counted the low dword twice;
  • a v_cndmask_b32 on the pair picked by the low dword.

A mask whose halves are equal (alternate lanes) came out right by chance.

What this does. structure exports, for such pairs, the high dword each low dword is read with (Structured::opaque_highs, wave64 only; none for a low dword that is split or read with two different high dwords), and pair_high takes it where the low dword's own instruction has no high dword. Every other pair is lowered as before. A low dword read with two high dwords still takes the low dword's bits; the comment in structure.rs says so.

This is in the plain lowering of wave64 programs for 32-lane hosts, not in crate::fold: the measured programs took the first form, with no retry. Folding being off by default on main (5c262d7b, 05d1c564) does not change where it applies.

Rebased onto main 7995b81b as ae160865 (the commit is unchanged; none of the three files has changed on main since 829188e9).

Credit: no code from other pull requests.

How it was tested

  • GPU and profile: RTX 5080 and the Ryzen 7 9800X3D's integrated Radeon (gfx1036), Windows 11. Shader tests on the cards, not a run of the game; no Series X/S profile, resolution, DLSS, frame generation or ray tracing involved.
  • Oracle: 219 hand-written one-wave GFX10 wave64 programs (one 64-thread group), run natively in wave64 on the gfx1036 with hw_oracle. The same programs are translated by emit::emit for a host of 32-lane waves (every form it tries), run on the RTX 5080 and on the Radeon as a 32-lane host, and all 16 outputs of all 64 lanes are compared. The harness is local (emit::fw64_local_tests, not in this branch): VICTORY_ADAPTER=nvidia|radeon LOCAL_FW64_HOSTWAVE=32 LOCAL_FW64_OUT=<file> VICTORY_WAVE_WHY=1 <test exe> --ignored --exact --nocapture --test-threads=1 emit::fw64_local_tests::<local_fw64_wave_wide|local_fw64x_wave_wide|local_nx_cases>.
  • Before (829188e9): 156 exact, 51 differ, 12 refused, the same on both cards. Of the five programs that set EXEC from two s_mov_b32 and then read it (v_readfirstlane_b32, v_mbcnt, s_bcnt1_i32_b64, s_ff1_i32_b64, a write under it), 4 differ (upper half, lane 40, a sparse mask, lanes 31-32); alternate lanes is exact.
  • After (ad9709c1): 160 exact, 47 differ, 12 refused, the same on both cards. Those 4 are exact; no other program changed.
  • New test a_lane_mask_written_a_dword_at_a_time_keeps_its_high_dword (masks: upper half, lane 40, sparse, lanes 31-32, alternate lanes; a write, v_mbcnt and s_bcnt1 of EXEC and a v_cndmask_b32 on the pair; the DXIL validated when a validator is found): passes on both cards. The same test on 829188e9 fails on both (mask 0xffffffff00000000, lane 32).
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): console wave64 programs on a host of 32-lane waves (RTX 5080, and the Radeon held to 32), checked against the gfx1036 in wave64. Not on a host of 64-lane waves.
  • cargo test passed for the crates it touches: yes, apart from 3 tests that fail on main in the same way. On ae160865 (main 7995b81b + this commit), RTX 5080:
    • cargo test -p victory-shader --lib -- --test-threads=6: 460 passed, 3 failed, 9 ignored. The new test passes. The 3 failures are emit::barycentric_tests::first_half_values_render_on_hardware_and_warp, emit::rect::tests::rectangles_are_drawn_whole and emit::rect::tests::the_rectangle_stage_is_a_geometry_shader, all with Container part 'Pipeline State Validation' does not match expected for module from the local DXIL validator. The same 3 fail the same way on main 7995b81b without this change.
    • cargo check -p victory-gpu: passes.
    • cargo clippy -p victory-shader --all-targets -- -D warnings: fails on main's own code (unused imports PAIR_MEETINGS in emit/lower/analysis.rs:6 and analysis::lane_regions in emit/lower.rs:594, while_immutable_condition in emit/lower/analysis.rs:467, too_many_arguments in native.rs:1655). None is on a line this change touches.
  • Earlier, on ad9709c1 (829188e9 base) plus a two-line mod for the local harness, built with cargo test -j 6 -p victory-shader --lib --no-run, then the test binary:
    • VICTORY_ADAPTER=nvidia|radeon <exe> --exact --nocapture --test-threads=1 emit::wave64_tests::a_lane_mask_written_a_dword_at_a_time_keeps_its_high_dword: 1 passed on each card; on 829188e9 with the test added, 1 failed on each card;
    • <exe> --test-threads=4 structure emit::wave64_tests emit::folded_tests emit::lower fold:: emit::crosslane_tests (RTX 5080): 114 passed, 0 failed, 1 ignored; on 829188e9 with the new test added, 113 passed, 1 failed (the new test).
  • Not tested: the game (how many of the title's programs write a mask this way was not counted); the oracle counts on current main (they are on 829188e9, whose copies of these files main still has; only the cargo test run above is on main); Series S; cards other than the RTX 5080 and the gfx1036.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related:
    • #108 (closed; bundled into #479): lanes 32-63 took the low dword in halves mode because the lane index was the host lane's. That part (console_lane and lane_bit with halves) is on main already. Same symptom, another cause: here the lane index is right and the high dword's value was wrong.
    • #479 (open; its shader half reverted from main): changes other functions of lower.rs (scalar splits, first-lane reads, v_writelane, mask phis through loops); nothing on the high dword of a pair, no shared hunks.
    • #2265, #2261 (open): folded programs (folded(), the order in emit_strict), not this lowering; no shared files.
    • #2993 (open): structure.rs, Lanes::join: joins fed by a scalar load are taken as data. Next to this change's function but other lines. Such joins land in the same non-derived set (other) that opaque_highs is taken from; the two were not tested together.
    • #2059 (open): v_cndmask_b32 masks intersected with partial_active on 32-lane hosts, about lanes past the dispatch count; other lines of lower.rs, not the high dword.

AI use

Claude Code (Claude Opus 5.5) found the cause with the oracle programs, wrote the change, the test and the oracle programs, ran the measurements and wrote this description. No code from other authors.

🤖 Generated with Claude Code

**@⁠Lyrnc** on GitHub · 2026-11-29 22:50 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3402) `Lyrnc:fix/w64-mask-halves-apart` → `main` · +84 −12 · 3 files · 1 commits · open No issue filed: found while checking wave64 programs on a host of 32-lane waves against a wave64 card with hand-written programs. ## What it changes **What was wrong.** On a host of 32-lane waves, a wave64 lane mask that is a number, not an EXEC or VALU result, becomes an opaque atom named by its low dword (`Atom::Opaque`), and lowering took the high dword from the instruction that wrote the low one (`pair_high`). The compiler writes a 64-bit constant mask as two `s_mov_b32`. There the low dword's instruction writes no high dword, and lanes 32-63 took the low dword's bits. With EXEC set from such a pair: - a write under that EXEC landed in the wrong upper lanes; - `v_mbcnt_hi_u32_b32` and `s_bcnt1_i32_b64` of EXEC counted the low dword twice; - a `v_cndmask_b32` on the pair picked by the low dword. A mask whose halves are equal (alternate lanes) came out right by chance. **What this does.** `structure` exports, for such pairs, the high dword each low dword is read with (`Structured::opaque_highs`, wave64 only; none for a low dword that is split or read with two different high dwords), and `pair_high` takes it where the low dword's own instruction has no high dword. Every other pair is lowered as before. A low dword read with two high dwords still takes the low dword's bits; the comment in `structure.rs` says so. This is in the plain lowering of wave64 programs for 32-lane hosts, not in `crate::fold`: the measured programs took the first form, with no retry. Folding being off by default on main (5c262d7b, 05d1c564) does not change where it applies. Rebased onto main 7995b81b as ae160865 (the commit is unchanged; none of the three files has changed on main since 829188e9). Credit: no code from other pull requests. ## How it was tested - GPU and profile: RTX 5080 and the Ryzen 7 9800X3D's integrated Radeon (gfx1036), Windows 11. Shader tests on the cards, not a run of the game; no Series X/S profile, resolution, DLSS, frame generation or ray tracing involved. - Oracle: 219 hand-written one-wave GFX10 wave64 programs (one 64-thread group), run natively in wave64 on the gfx1036 with hw_oracle. The same programs are translated by `emit::emit` for a host of 32-lane waves (every form it tries), run on the RTX 5080 and on the Radeon as a 32-lane host, and all 16 outputs of all 64 lanes are compared. The harness is local (`emit::fw64_local_tests`, not in this branch): `VICTORY_ADAPTER=nvidia|radeon LOCAL_FW64_HOSTWAVE=32 LOCAL_FW64_OUT=<file> VICTORY_WAVE_WHY=1 <test exe> --ignored --exact --nocapture --test-threads=1 emit::fw64_local_tests::<local_fw64_wave_wide|local_fw64x_wave_wide|local_nx_cases>`. - Before (829188e9): 156 exact, 51 differ, 12 refused, the same on both cards. Of the five programs that set EXEC from two `s_mov_b32` and then read it (`v_readfirstlane_b32`, `v_mbcnt`, `s_bcnt1_i32_b64`, `s_ff1_i32_b64`, a write under it), 4 differ (upper half, lane 40, a sparse mask, lanes 31-32); alternate lanes is exact. - After (ad9709c1): 160 exact, 47 differ, 12 refused, the same on both cards. Those 4 are exact; no other program changed. - New test `a_lane_mask_written_a_dword_at_a_time_keeps_its_high_dword` (masks: upper half, lane 40, sparse, lanes 31-32, alternate lanes; a write, `v_mbcnt` and `s_bcnt1` of EXEC and a `v_cndmask_b32` on the pair; the DXIL validated when a validator is found): passes on both cards. The same test on 829188e9 fails on both (`mask 0xffffffff00000000, lane 32`). - For shader changes, the wave sizes tested (32 and/or 64 lanes): console wave64 programs on a host of 32-lane waves (RTX 5080, and the Radeon held to 32), checked against the gfx1036 in wave64. Not on a host of 64-lane waves. - `cargo test` passed for the crates it touches: yes, apart from 3 tests that fail on main in the same way. On ae160865 (main 7995b81b + this commit), RTX 5080: - `cargo test -p victory-shader --lib -- --test-threads=6`: 460 passed, 3 failed, 9 ignored. The new test passes. The 3 failures are `emit::barycentric_tests::first_half_values_render_on_hardware_and_warp`, `emit::rect::tests::rectangles_are_drawn_whole` and `emit::rect::tests::the_rectangle_stage_is_a_geometry_shader`, all with `Container part 'Pipeline State Validation' does not match expected for module` from the local DXIL validator. The same 3 fail the same way on main 7995b81b without this change. - `cargo check -p victory-gpu`: passes. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: fails on main's own code (unused imports `PAIR_MEETINGS` in `emit/lower/analysis.rs:6` and `analysis::lane_regions` in `emit/lower.rs:594`, `while_immutable_condition` in `emit/lower/analysis.rs:467`, `too_many_arguments` in `native.rs:1655`). None is on a line this change touches. - Earlier, on ad9709c1 (829188e9 base) plus a two-line `mod` for the local harness, built with `cargo test -j 6 -p victory-shader --lib --no-run`, then the test binary: - `VICTORY_ADAPTER=nvidia|radeon <exe> --exact --nocapture --test-threads=1 emit::wave64_tests::a_lane_mask_written_a_dword_at_a_time_keeps_its_high_dword`: 1 passed on each card; on 829188e9 with the test added, 1 failed on each card; - `<exe> --test-threads=4 structure emit::wave64_tests emit::folded_tests emit::lower fold:: emit::crosslane_tests` (RTX 5080): 114 passed, 0 failed, 1 ignored; on 829188e9 with the new test added, 113 passed, 1 failed (the new test). - Not tested: the game (how many of the title's programs write a mask this way was not counted); the oracle counts on current main (they are on 829188e9, whose copies of these files main still has; only the `cargo test` run above is on main); Series S; cards other than the RTX 5080 and the gfx1036. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: - #108 (closed; bundled into #479): lanes 32-63 took the low dword in halves mode because the lane index was the host lane's. That part (`console_lane` and `lane_bit` with `halves`) is on main already. Same symptom, another cause: here the lane index is right and the high dword's value was wrong. - #479 (open; its shader half reverted from main): changes other functions of `lower.rs` (scalar splits, first-lane reads, `v_writelane`, mask phis through loops); nothing on the high dword of a pair, no shared hunks. - #2265, #2261 (open): folded programs (`folded()`, the order in `emit_strict`), not this lowering; no shared files. - #2993 (open): `structure.rs`, `Lanes::join`: joins fed by a scalar load are taken as data. Next to this change's function but other lines. Such joins land in the same non-derived set (`other`) that `opaque_highs` is taken from; the two were not tested together. - #2059 (open): `v_cndmask_b32` masks intersected with `partial_active` on 32-lane hosts, about lanes past the dispatch count; other lines of `lower.rs`, not the high dword. ## AI use Claude Code (Claude Opus 5.5) found the cause with the oracle programs, wrote the change, the test and the oracle programs, ran the measurements and wrote this description. No code from other authors. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A wave64 lane mask that is a number, not an EXEC or VALU result, becomes
an opaque atom named by its low dword, and lowering took the high dword
from the instruction that wrote the low one. The compiler writes a 64-bit
constant mask as two s_mov_b32; there that instruction writes no high
dword, and lanes 32-63 took the low dword's bits: a write under EXEC set
from such a pair landed in the wrong upper lanes, v_mbcnt and s_bcnt1 of
EXEC counted the low dword twice, a v_cndmask_b32 on the pair picked by
the low dword.

The structure now exports the high dword each such pair is read with
(Structured::opaque_highs; none for a low dword read with two high
dwords), and pair_high takes it where the low dword's own instruction has
none.

Measured against gfx1036 in wave64 (hand-written programs, hw_oracle) on
the RTX 5080 and the Radeon iGPU (32-lane host): EXEC from two s_mov_b32
with the masks hi32, lane 40, sparse, lanes 31-32 and alternate lanes.

Test: a_lane_mask_written_a_dword_at_a_time_keeps_its_high_dword.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 22:52:18 +00:00
Author
Owner

@⁠nick0451 on GitHub · 2026-11-30 01:51 UTC · original

Exact translation check, with no game run: the title's shaders (game folder: 26,599 containers, 26,180 programs, 25,789 with emitted DXIL hashes), victory translate --list with VICTORY_HOST_WAVE=32, main 41adb551 (v2026.11.29.05) against this PR merged onto it.

Result: the output is the same for every program. All 25,789 output hashes match main, nothing fails to translate, and the summary counts are unchanged. So this title doesn't hit the pattern this PR changes, and the PR changes nothing for it, which also means no risk of a regression there. The fix may still matter for other titles or for the hand-written cases in the PR's tests.

(RTX 3090 host. The listing doesn't depend on the card, only on VICTORY_HOST_WAVE.)

🤖 Generated with Claude Code

**@⁠nick0451** on GitHub · 2026-11-30 01:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3402#issuecomment-7266495214) Exact translation check, with no game run: the title's shaders (game folder: 26,599 containers, 26,180 programs, 25,789 with emitted DXIL hashes), `victory translate --list` with `VICTORY_HOST_WAVE=32`, main `41adb551` (v2026.11.29.05) against this PR merged onto it. **Result: the output is the same for every program.** All 25,789 output hashes match main, nothing fails to translate, and the summary counts are unchanged. So this title doesn't hit the pattern this PR changes, and the PR changes nothing for it, which also means no risk of a regression there. The fix may still matter for other titles or for the hand-written cases in the PR's tests. (RTX 3090 host. The listing doesn't depend on the card, only on `VICTORY_HOST_WAVE`.) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

@⁠dyshay on GitHub · 2026-11-30 03:12 UTC · original

Merged into our fork's integration branch for testing (dyshay/VIctory-NVIDIA, branch janus-prs). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with --profile diag --features diagnostics. A run on an RTX 4090 is queued (Series S with ray tracing, DLSS Quality). Frame times will follow here.

**@⁠dyshay** on GitHub · 2026-11-30 03:12 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3402#issuecomment-7267677118) Merged into our fork's integration branch for testing ([dyshay/VIctory-NVIDIA](https://github.com/dyshay/VIctory-NVIDIA/tree/janus-prs), branch `janus-prs`). I read the full diff first: no network access, process spawning, binaries, build or dependency changes, or game data. It builds with `--profile diag --features diagnostics`. A run on an RTX 4090 is queued (Series S with ray tracing, DLSS Quality). Frame times will follow here.
github-bot force-pushed github-bot/gh-3402 from ae16086533 to 2a8ed4f660 2026-11-30 18:40:01 +00:00 Compare
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-30 18:59 UTC · original

@⁠nick0451, thanks. So no program of this title writes a lane mask a dword at a time and then uses its high half the way this PR handles: every output hash matches main. That makes this PR a correctness fix with no effect on this title's translations, and no risk to them. The case was found and tested with hand-written programs, checked against gfx1036 in wave64 (the test in the PR).

The branch is rebased onto main 84bd61e2 (v2026.11.30.02) and force-pushed (now 2a8ed4f6). The only conflict was in wave64_tests.rs, where main and this branch both add tests at the end; both are kept. lower.rs and structure.rs applied unchanged.

Checks on 2a8ed4f6 (Windows 11, rustc 1.98.1, its own target dir): cargo check -p victory-shader passes. cargo test -p victory-shader --lib -- wave64_tests: 48 passed, a_lane_mask_written_a_dword_at_a_time_keeps_its_high_dword among them (it dispatches on this PC's RTX 5080).

@⁠dyshay, the head changed, so janus-prs needs the new one.

AI use: Claude Code (Claude Opus 5.5) did the rebase, ran the tests and wrote this reply.

**@⁠Lyrnc** on GitHub · 2026-11-30 18:59 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3402#issuecomment-7288666295) @⁠nick0451, thanks. So no program of this title writes a lane mask a dword at a time and then uses its high half the way this PR handles: every output hash matches main. That makes this PR a correctness fix with no effect on this title's translations, and no risk to them. The case was found and tested with hand-written programs, checked against gfx1036 in wave64 (the test in the PR). The branch is rebased onto main 84bd61e2 (v2026.11.30.02) and force-pushed (now 2a8ed4f6). The only conflict was in `wave64_tests.rs`, where main and this branch both add tests at the end; both are kept. `lower.rs` and `structure.rs` applied unchanged. Checks on 2a8ed4f6 (Windows 11, rustc 1.98.1, its own target dir): `cargo check -p victory-shader` passes. `cargo test -p victory-shader --lib -- wave64_tests`: 48 passed, `a_lane_mask_written_a_dword_at_a_time_keeps_its_high_dword` among them (it dispatches on this PC's RTX 5080). @⁠dyshay, the head changed, so janus-prs needs the new one. AI use: Claude Code (Claude Opus 5.5) did the rebase, ran the tests and wrote this reply.
github-bot force-pushed github-bot/gh-3402 from 2a8ed4f660 to e01c659c02 2026-12-01 04:53:59 +00:00 Compare
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3402/head:github-bot/gh-3402'
git switch 'github-bot/gh-3402'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3402'
git switch 'github-bot/gh-3402'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3402'
git switch 'github-bot/gh-3402'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3402'
git switch 'main'
git merge --squash 'github-bot/gh-3402'
git switch 'main'
git merge --ff-only 'github-bot/gh-3402'
git switch 'main'
git merge 'github-bot/gh-3402'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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/trustno1-coder--VIctory-NVIDIA!3402
No description provided.