Shaders: wave32 lane masks on 64-lane host waves take their half's dword #3556

Open
github-bot wants to merge 2 commits from github-bot/gh-3556 into main AGit
Owner

@⁠kilolimaVI on GitHub · 2026-11-27 17:26 UTC · original
kilolimaVI:shader/wave32-masks-64-lane-host → main · +293 −4 · 4 files · 2 commits · open

On hosts that run pixel waves of 64 lanes (AMD: RDNA pixel shaders run wave64; measured on a Radeon 780M, RDNA3), a wave32 pixel or vertex program's 32-bit lane masks were the ballot's low dword in every lane. Lanes 32-63 tested the bits of lanes 0-31, so the console compiler's loop that serves one value per pass (s_ff1 of EXEC, v_readlane at that lane, v_cmpx_eq) never served them: those pixels kept whatever they held before the loop.

NVIDIA (32-lane pixel waves) and WARP never show it, which is likely why it went unnoticed.

Fix (emit/lower.rs)

With MaskData::Host and a wave32 program, a 64-lane host wave is treated as two console waves:

  • mask_dword: each lane takes its own half's dword of the ballot (Lower::host_half, waveGetLaneIndex >= 32).
  • v_readlane at a computed (host) lane adds the half's base (Lower::host_lane).
  • v_mbcnt counts within the half (lane & 31).

On a 32-lane host the upper half never exists, so nothing changes there; wave64 programs and compute (MaskData::Console) are untouched (wave64 DXIL is byte-identical).

Test (emit/lane_mask_tests.rs)

wave32_lane_mask_loops_serve_every_lane_of_a_64_lane_host_wave: a hand-assembled pixel program runs that loop over a per-pixel key, drawn over a 16x16 target (no helper lanes), wave32 and wave64, on the hardware adapter and WARP. Pixels served a wrong key:

before after
wave32, Radeon 780M 88 / 256 0
wave64, Radeon 780M 0 0
wave32 / wave64, WARP 0 / 0 0 / 0

0/5 failures over 5 runs. cargo test -p victory-shader on the 780M: 303 passed, 0 failed. cargo clippy -p victory-shader --all-targets [--all-features] -- -D warnings clean. cargo fmt --check reports no new sites (main already has 33 in lower.rs and 2 in mod.rs).

Related: helper lanes at triangle edges are a separate issue (#2373); this test draws a full-coverage triangle so it measures only the mask width.

AI-assisted (Claude).

**@⁠kilolimaVI** on GitHub · 2026-11-27 17:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/3556) `kilolimaVI:shader/wave32-masks-64-lane-host` → `main` · +293 −4 · 4 files · 2 commits · open On hosts that run pixel waves of 64 lanes (AMD: RDNA pixel shaders run wave64; measured on a Radeon 780M, RDNA3), a wave32 pixel or vertex program's 32-bit lane masks were the ballot's low dword in every lane. Lanes 32-63 tested the bits of lanes 0-31, so the console compiler's loop that serves one value per pass (`s_ff1` of EXEC, `v_readlane` at that lane, `v_cmpx_eq`) never served them: those pixels kept whatever they held before the loop. NVIDIA (32-lane pixel waves) and WARP never show it, which is likely why it went unnoticed. ## Fix (`emit/lower.rs`) With `MaskData::Host` and a wave32 program, a 64-lane host wave is treated as two console waves: - `mask_dword`: each lane takes its own half's dword of the ballot (`Lower::host_half`, `waveGetLaneIndex >= 32`). - `v_readlane` at a computed (host) lane adds the half's base (`Lower::host_lane`). - `v_mbcnt` counts within the half (`lane & 31`). On a 32-lane host the upper half never exists, so nothing changes there; wave64 programs and compute (`MaskData::Console`) are untouched (wave64 DXIL is byte-identical). ## Test (`emit/lane_mask_tests.rs`) `wave32_lane_mask_loops_serve_every_lane_of_a_64_lane_host_wave`: a hand-assembled pixel program runs that loop over a per-pixel key, drawn over a 16x16 target (no helper lanes), wave32 and wave64, on the hardware adapter and WARP. Pixels served a wrong key: | | before | after | |---|---|---| | wave32, Radeon 780M | 88 / 256 | 0 | | wave64, Radeon 780M | 0 | 0 | | wave32 / wave64, WARP | 0 / 0 | 0 / 0 | 0/5 failures over 5 runs. `cargo test -p victory-shader` on the 780M: 303 passed, 0 failed. `cargo clippy -p victory-shader --all-targets [--all-features] -- -D warnings` clean. `cargo fmt --check` reports no new sites (main already has 33 in `lower.rs` and 2 in `mod.rs`). Related: helper lanes at triangle edges are a separate issue (#2373); this test draws a full-coverage triangle so it measures only the mask width. AI-assisted (Claude).
On a host that runs pixel waves of 64 lanes (AMD; a Radeon 780M here), a
wave32 pixel or vertex program's 32-bit lane masks were the ballot's low
dword in every lane: lanes 32-63 tested the bits of lanes 0-31, so a loop
that serves one value per pass (s_ff1 of EXEC, v_readlane, v_cmpx) never
served them. Each 32-lane half now takes its own dword, as two console
waves would, and lane numbers from masks (v_readlane at a computed lane,
v_mbcnt) count within the half. Hosts running 32 lanes (NVIDIA, WARP) are
unchanged; wave64 programs emit the same DXIL.

Test: lane_mask_tests draws such a loop over a 16x16 target in wave32 and
wave64. Before, the 780M served 88 of 256 pixels a wrong key in wave32
(0 in wave64, 0 on WARP); now 0 everywhere.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 17:38:15 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-27 17:44 UTC · original

I checked the merge order for the Wave32 mask fix alongside #3421. The exact heads of #3556 (48f1646) and #3421 (c2698c3) merge cleanly, but the resulting lower.rs is 524,618 bytes, 330 bytes over the 512 KiB asset-policy limit.

Adding the barycentric lowering split from #3335 (e495d2d) also merges cleanly. On the combined commit, lower.rs is 508,704 bytes and the asset policy passes for all 194 files. Both merge commits preserve the original parent commits.

  • The 9 wave lowering tests and 9 barycentric tests pass.
  • App-local D3D12 and WARP ran the pixel comparison. Both guest wave widths returned the expected keys for all 256 pixels. The WARP DPP row-mask and quad-swizzle plus first-lane readbacks passed as well.
  • Clippy passes for all shader targets with both default and all features.

These are local software-rendering results. The Radeon 780M measurement above is the hardware evidence for #3556. Its Windows workflow is still awaiting approval.

The next step is for the maintainers to choose a merge order that puts the split in place before both wave changes are in main. If you reuse the integration work, please retain Git authorship, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding it into another commit.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-27 17:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/3556#issuecomment-7224741076) I checked the merge order for the Wave32 mask fix alongside #3421. The exact heads of #3556 (`48f1646`) and #3421 (`c2698c3`) merge cleanly, but the resulting `lower.rs` is 524,618 bytes, 330 bytes over the 512 KiB asset-policy limit. Adding the barycentric lowering split from #3335 (`e495d2d`) also merges cleanly. On [the combined commit](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/cf42f0390bf94b17f98bc3a0051f5006f6d46ccd), `lower.rs` is 508,704 bytes and the asset policy passes for all 194 files. Both merge commits preserve the original parent commits. - The 9 wave lowering tests and 9 barycentric tests pass. - App-local D3D12 and WARP ran the pixel comparison. Both guest wave widths returned the expected keys for all 256 pixels. The WARP DPP row-mask and quad-swizzle plus first-lane readbacks passed as well. - Clippy passes for all shader targets with both default and all features. These are local software-rendering results. The Radeon 780M measurement above is the hardware evidence for #3556. Its Windows workflow is still awaiting approval. The next step is for the maintainers to choose a merge order that puts the split in place before both wave changes are in `main`. If you reuse the integration work, please retain Git authorship, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding it into another commit.
host_half and host_lane move to lower/lanes.rs, as lower/bvh.rs, so lower.rs
stays under the asset policy's 512 KiB with #3421 merged beside this.
No change in behaviour.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠ColorMeBoom on GitHub · 2026-11-27 17:49 UTC · original

RDNA1 run, and an overlap with #125 / #145. RX 5700 XT (RDNA1), driver 32.0.21045.29003, Windows 11 26200, no game files. All trees are merged onto main 63bcca4.

wave32_lane_mask_loops_serve_every_lane_of_a_64_lane_host_wave (your test):

tree wave32, RX 5700 XT wave64, RX 5700 XT WARP (both)
main + this test only 88 / 256 pixels wrong, first (3, 4): 0 instead of 30 0 0
this PR (48f1646) 0 0 0
#145 rebased on main (ColorMeBoom:pr145-rebase, dec8a5b) + this test 0 0 0

So RDNA1 shows the same 88/256 as your 780M, and this PR fixes it. Full victory-shader --lib --features host on this PR: 303 passed, 0 failed.

Overlap: this is the bug #125 tracks: a wave32 pixel/vertex program's lane masks only use the low ballot dword on a 64-lane host wave, which I confirmed on this card earlier today. #145 (TheHoracio's) fixes it a different way: a 64-bit host ballot for mask ops (emit/lower/host_masks.rs). Its head conflicts with main. The rebase above merges cleanly, and its own pixel_lane_masks_count_every_lane_of_the_host_wave fails on main here ("the host wave is wider than 32 lanes and its high half is lost") and passes with it. The two PRs conflict in lower.rs, and as the table shows, both pass your test on this card. So they look like two fixes for one bug, and it's worth settling which one lands.

Not run: #145's test on this PR. Windows Application Control on this machine blocked that test binary on every rebuild.

AI use: Claude Code (Claude Opus 5.5).

**@⁠ColorMeBoom** on GitHub · 2026-11-27 17:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/3556#issuecomment-7224819009) **RDNA1 run, and an overlap with #125 / #145.** RX 5700 XT (RDNA1), driver 32.0.21045.29003, Windows 11 26200, no game files. All trees are merged onto `main` `63bcca4`. `wave32_lane_mask_loops_serve_every_lane_of_a_64_lane_host_wave` (your test): | tree | wave32, RX 5700 XT | wave64, RX 5700 XT | WARP (both) | | --- | --- | --- | --- | | `main` + this test only | **88 / 256** pixels wrong, first (3, 4): 0 instead of 30 | 0 | 0 | | this PR (`48f1646`) | **0** | 0 | 0 | | #145 rebased on `main` ([`ColorMeBoom:pr145-rebase`](https://github.com/ColorMeBoom/VIctory/tree/pr145-rebase), `dec8a5b`) + this test | **0** | 0 | 0 | So RDNA1 shows the same 88/256 as your 780M, and this PR fixes it. Full `victory-shader --lib --features host` on this PR: 303 passed, 0 failed. **Overlap:** this is the bug #125 tracks: a wave32 pixel/vertex program's lane masks only use the low ballot dword on a 64-lane host wave, which [I confirmed on this card](https://git.gtahub.st/github/Marvisak--VIctory/issues/125) earlier today. #145 (TheHoracio's) fixes it a different way: a 64-bit host ballot for mask ops (`emit/lower/host_masks.rs`). Its head conflicts with `main`. The rebase above merges cleanly, and its own `pixel_lane_masks_count_every_lane_of_the_host_wave` fails on `main` here ("the host wave is wider than 32 lanes and its high half is lost") and passes with it. The two PRs conflict in `lower.rs`, and as the table shows, both pass your test on this card. So they look like two fixes for one bug, and it's worth settling which one lands. Not run: #145's test on this PR. Windows Application Control on this machine blocked that test binary on every rebuild. AI use: Claude Code (Claude Opus 5.5).
Author
Owner

@⁠kilolimaVI on GitHub · 2026-11-27 17:54 UTC · original

Thanks for checking the merge order. Rather than depend on #3335 landing first, I moved the two helpers (host_half, host_lane) into lower/lanes.rs, as lower/bvh.rs already is. This PR now adds about 0.8 KB to lower.rs instead of 2.2 KB, so with #3421 beside it the file is about 523.3 KB, under the 512 KiB limit in either merge order. No change in behaviour: the hardware test still gives 0 of 256 on the 780M, and clippy is clean.

AI-assisted (Claude).

**@⁠kilolimaVI** on GitHub · 2026-11-27 17:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/3556#issuecomment-7224909487) Thanks for checking the merge order. Rather than depend on #3335 landing first, I moved the two helpers (`host_half`, `host_lane`) into `lower/lanes.rs`, as `lower/bvh.rs` already is. This PR now adds about 0.8 KB to `lower.rs` instead of 2.2 KB, so with #3421 beside it the file is about 523.3 KB, under the 512 KiB limit in either merge order. No change in behaviour: the hardware test still gives 0 of 256 on the 780M, and clippy is clean. AI-assisted (Claude).
Author
Owner

@⁠kilolimaVI on GitHub · 2026-11-27 17:54 UTC · original

Thanks for the RDNA1 run and for spotting #125 / #145. That overlap is my miss: my check of open PRs didn't go back that far, and #145 was first.

The two fixes differ in shape. #145 widens a wave32 program's masks to the host's 64-bit ballot (lane numbers, counts and compares over the whole host wave). This PR treats a 64-lane host wave as two console waves: each lane reads its own half's dword, and lane numbers from masks count within the half (mask_dword, v_readlane at a computed lane, v_mbcnt; about 60 lines plus the test), so every 32-bit mask operation keeps its console meaning without tracking a second dword through the program. Either way your table shows the 88/256 gone on RDNA1 and RDNA3.

I'm happy for the maintainers to take whichever they prefer. If it's #145, I'll close this one, and the hardware test (emit/lane_mask_tests.rs) can go there with it.

AI-assisted (Claude).

**@⁠kilolimaVI** on GitHub · 2026-11-27 17:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/3556#issuecomment-7224914237) Thanks for the RDNA1 run and for spotting #125 / #145. That overlap is my miss: my check of open PRs didn't go back that far, and #145 was first. The two fixes differ in shape. #145 widens a wave32 program's masks to the host's 64-bit ballot (lane numbers, counts and compares over the whole host wave). This PR treats a 64-lane host wave as two console waves: each lane reads its own half's dword, and lane numbers from masks count within the half (`mask_dword`, `v_readlane` at a computed lane, `v_mbcnt`; about 60 lines plus the test), so every 32-bit mask operation keeps its console meaning without tracking a second dword through the program. Either way your table shows the 88/256 gone on RDNA1 and RDNA3. I'm happy for the maintainers to take whichever they prefer. If it's #145, I'll close this one, and the hardware test (`emit/lane_mask_tests.rs`) can go there with it. AI-assisted (Claude).
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-27 18:03 UTC · original

I retested the split on the exact new #3556 head dcc8ca4 with #3421 c2698c3. Git reports one conflict where both branches add a module declaration. Keeping mod lanes; and #[cfg(test)] mod wave_tests; resolves it. The rest merged automatically.

The combined commit keeps both exact parents. lower.rs is 523,263 bytes, 1,025 bytes below the 512 KiB limit. The asset policy passes for 194 files. This combination passes with the split in #3556 itself.

App-local WARP gave the expected keys for all 256 pixels at each guest wave width, and the DPP row-mask and quad-swizzle/first-lane readbacks passed. All nine wave lowering tests and both strict shader Clippy configurations passed. The author reported the same pixel result on the Radeon 780M after the split. The earlier RX 5700 XT result is for 48f1646. The new Windows workflow awaits approval.

The merge-order question is resolved for these two changes. The maintainers can now choose between the approaches in #3556 and #145. If reusing my merge resolution, please retain Git authorship, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding it into another commit.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-27 18:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/3556#issuecomment-7225082215) I retested the split on the exact new #3556 head `dcc8ca4` with #3421 `c2698c3`. Git reports one conflict where both branches add a module declaration. Keeping `mod lanes;` and `#[cfg(test)] mod wave_tests;` resolves it. The rest merged automatically. The [combined commit](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/17eda9bdb34b74ac74134d4927bd16fa5f41bad0) keeps both exact parents. `lower.rs` is 523,263 bytes, 1,025 bytes below the 512 KiB limit. The asset policy passes for 194 files. This combination passes with the split in #3556 itself. App-local WARP gave the expected keys for all 256 pixels at each guest wave width, and the DPP row-mask and quad-swizzle/first-lane readbacks passed. All nine wave lowering tests and both strict shader Clippy configurations passed. The author reported the same pixel result on the Radeon 780M after the split. The earlier RX 5700 XT result is for `48f1646`. The new Windows workflow awaits approval. The merge-order question is resolved for these two changes. The maintainers can now choose between the approaches in #3556 and #145. If reusing my merge resolution, please retain Git authorship, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding it into another commit.
Author
Owner

@⁠ColorMeBoom on GitHub · 2026-11-27 18:44 UTC · original

RX 5700 XT at the new head dcc8ca4 (merged onto main 63bcca4), and the cross-check that was blocked last time.

  • wave32_lane_mask_loops_serve_every_lane_of_a_64_lane_host_wave: 0 of 256 pixels wrong, wave32 and wave64, hardware and WARP. Full victory-shader --lib --features host: 303 passed, 0 failed.
  • #145's test on this PR (pixel_lane_masks_count_every_lane_of_the_host_wave, taken from the #145 rebase): passes. What it prints shows how the two fixes differ, on the same card:
tree probe line test
main up to 32 active lanes, lane indices up to 32 fails: "the host wave is wider than 32 lanes and its high half is lost"
#145 rebase up to 64 active lanes, lane indices up to 63 passes
this PR up to 32 active lanes, lane indices up to 31 passes

So the two agree on the bug, but disagree on what a wave32 program sees on a 64-lane host wave:

  • With #145 it sees one 64-lane wave: s_bcnt1 of EXEC up to 64, v_mbcnt up to 63.
  • With this PR it sees two 32-lane waves, as on the console: counts and lane numbers stay within 0–32 / 0–31.

A wave32 program on the console never sees a lane number above 31, so where its code depends on that (a lane number used as an index or a shift, a count compared with 32), this PR's form keeps the console's values. That could help the maintainers choose between the two.

AI use: Claude Code (Claude Opus 5.5).

**@⁠ColorMeBoom** on GitHub · 2026-11-27 18:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/3556#issuecomment-7225820691) **RX 5700 XT at the new head `dcc8ca4`** (merged onto `main` `63bcca4`), and the cross-check that was blocked last time. - `wave32_lane_mask_loops_serve_every_lane_of_a_64_lane_host_wave`: **0 of 256** pixels wrong, wave32 and wave64, hardware and WARP. Full `victory-shader --lib --features host`: **303 passed, 0 failed**. - **#145's test on this PR** (`pixel_lane_masks_count_every_lane_of_the_host_wave`, taken from the [#145 rebase](https://github.com/ColorMeBoom/VIctory/tree/pr145-rebase)): **passes**. What it prints shows how the two fixes differ, on the same card: | tree | probe line | test | | --- | --- | --- | | `main` | `up to 32 active lanes, lane indices up to 32` | fails: "the host wave is wider than 32 lanes and its high half is lost" | | #145 rebase | `up to 64 active lanes, lane indices up to 63` | passes | | this PR | `up to 32 active lanes, lane indices up to 31` | passes | So the two agree on the bug, but disagree on what a wave32 program sees on a 64-lane host wave: - With #145 it sees one 64-lane wave: `s_bcnt1` of EXEC up to 64, `v_mbcnt` up to 63. - With this PR it sees two 32-lane waves, as on the console: counts and lane numbers stay within 0–32 / 0–31. A wave32 program on the console never sees a lane number above 31, so where its code depends on that (a lane number used as an index or a shift, a count compared with 32), this PR's form keeps the console's values. That could help the maintainers choose between the two. AI use: Claude Code (Claude Opus 5.5).
This pull request can be merged automatically.
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/3556/head:github-bot/gh-3556'
git switch 'github-bot/gh-3556'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3556'
git switch 'github-bot/gh-3556'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3556'
git switch 'github-bot/gh-3556'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3556'
git switch 'main'
git merge --squash 'github-bot/gh-3556'
git switch 'main'
git merge --ff-only 'github-bot/gh-3556'
git switch 'main'
git merge 'github-bot/gh-3556'
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/Marvisak--VIctory!3556
No description provided.