Shaders: a wave32 program's mask read picks its half of a 64-lane ballot #434

Open
NolanCotter wants to merge 3 commits from upstream-pr/434 into main
NolanCotter commented 2026-11-24 03:20:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by NolanCotter on 2026-11-24T03:20:11Z.


AI-assisted (Devin). Fixes #131.

Summary

For MaskData::Host (pixel and vertex stages — no WaveSize attribute, so the host wave size is whatever the driver picks) a host wave may have 64 lanes. Its upper half is then a second console wave whose bits land in the ballot's second dword — but mask_dword returned the first dword for every lane. Every lane mask read as a number (s_bcnt1_i32_*, s_ff1_i32_*, v_mbcnt_*, s_cmp_eq/lg_u32/u64) therefore gave the upper half's lanes the lower console wave's mask values: a ballot on a 64-lane host wave drops its high half.

  • mask_dword now selects the ballot half by the reader's host lane (lane >= 32 ? y : x) for MaskData::Host wave32 programs. Unchanged on 32-lane host waves (lane < 32 always selects the first dword).
  • v_mbcnt_lo in that mode counts bits of the lane's own half's mask below lane & 31.
  • v_mbcnt_hi in that mode is src1 alone — a wave32 mask has no high half.

Out of scope (noted in #131): the host-lane vs console-lane space for v_readlane/v_writelane computed lanes is the lane-space problem #225/#320 handle in the console flow; it is not a mask read.

Test plan

  • cargo test -p victory-shader — 57/57 pass on Linux (added a_wave32_mask_read_takes_its_ballot_half: a synthetic wave32 pixel program — v_cmp mask read by s_bcnt1, exported via exp — asserting the emitted DXIL declares dx.op.waveGetLaneIndex; the test fails on the unfixed lowering)
  • cargo build -p victory-shader clean; cargo fmt --check -p victory-shader clean
  • cargo test -p victory-gpu — not run: victory-gpu does not build on Linux (pre-existing E0425 in crates/victory-gpu/src/resource.rs:284, tracked by #90 / PRs #112, #235). No GPU run: none available in this environment.
  • DXIL validation by dxil.dll — Windows-only path; not run.

The synthetic test asserts the new lowering emits the lane index needed to pick the ballot half. To see the emitted module's declared functions in tests, emit::bitcode::Module gained a #[cfg(test)] func_names accessor and Lowered a #[cfg(test)] op_names field.

No game data: the fixture is a five-instruction hand-encoded program.

Generated with Devin

<!-- greyfinch-sync:Marvisak/VIctory:issue:6573860183 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/434). Originally posted by [NolanCotter](https://github.com/NolanCotter) on 2026-11-24T03:20:11Z. --- AI-assisted (Devin). Fixes #131. ## Summary For `MaskData::Host` (pixel and vertex stages — no `WaveSize` attribute, so the host wave size is whatever the driver picks) a host wave may have 64 lanes. Its upper half is then a second console wave whose bits land in the ballot's second dword — but `mask_dword` returned the first dword for every lane. Every lane mask read as a number (`s_bcnt1_i32_*`, `s_ff1_i32_*`, `v_mbcnt_*`, `s_cmp_eq/lg_u32/u64`) therefore gave the upper half's lanes the lower console wave's mask values: a ballot on a 64-lane host wave drops its high half. - `mask_dword` now selects the ballot half by the reader's host lane (`lane >= 32 ? y : x`) for `MaskData::Host` wave32 programs. Unchanged on 32-lane host waves (lane < 32 always selects the first dword). - `v_mbcnt_lo` in that mode counts bits of the lane's own half's mask below `lane & 31`. - `v_mbcnt_hi` in that mode is `src1` alone — a wave32 mask has no high half. Out of scope (noted in #131): the host-lane vs console-lane space for `v_readlane`/`v_writelane` computed lanes is the lane-space problem #225/#320 handle in the console flow; it is not a mask read. ## Test plan - [x] `cargo test -p victory-shader` — 57/57 pass on Linux (added `a_wave32_mask_read_takes_its_ballot_half`: a synthetic wave32 pixel program — `v_cmp` mask read by `s_bcnt1`, exported via `exp` — asserting the emitted DXIL declares `dx.op.waveGetLaneIndex`; the test fails on the unfixed lowering) - [x] `cargo build -p victory-shader` clean; `cargo fmt --check -p victory-shader` clean - [ ] `cargo test -p victory-gpu` — not run: `victory-gpu` does not build on Linux (pre-existing `E0425` in `crates/victory-gpu/src/resource.rs:284`, tracked by #90 / PRs #112, #235). No GPU run: none available in this environment. - [ ] DXIL validation by `dxil.dll` — Windows-only path; not run. The synthetic test asserts the new lowering emits the lane index needed to pick the ballot half. To see the emitted module's declared functions in tests, `emit::bitcode::Module` gained a `#[cfg(test)]` `func_names` accessor and `Lowered` a `#[cfg(test)]` `op_names` field. No game data: the fixture is a five-instruction hand-encoded program. Generated with [Devin](https://devin.ai)
DaviTostes commented 2026-11-24 06:55:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T03:36:47Z.


Verified 588a0e2 on Arch Linux x86_64 (rustc 1.98.1, cargo test -p victory-shader): 57 passed, 0 failed, 0 ignored.

Not covered: running the new ballot/mask paths on a Windows/Wine GPU and title behaviour (no game data here).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121259671 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/434#issuecomment-7121259671). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T03:36:47Z. --- Verified `588a0e2` on **Arch Linux x86_64** (rustc 1.98.1, `cargo test -p victory-shader`): **57 passed, 0 failed, 0 ignored**. Not covered: running the new ballot/mask paths on a Windows/Wine GPU and title behaviour (no game data here).
marquezinii commented 2026-11-24 06:55:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T03:44:32Z.


Ran 588a0e2 on Windows 11 with an NVIDIA RTX 5070 (driver 621.24, 32-lane waves, the only adapter), rustc 1.98.1, debug, in its own target directory:

  • cargo test -p victory-shader: 70 passed, 0 failed, 3 runs. The validator picked up the Windows SDK's dxil.dll (10.0.26100.0), so the suite's modules were validated here, which the Linux runs skip.
  • a_wave32_mask_read_takes_its_ballot_half only checks the op list, so I also passed its lowered container through dxil.dll locally (a temporary three-line addition, not pushed): it validates.
  • On this host waves are 32 lanes, so the new half pick always takes the first dword. This run shows nothing regresses there; it does not exercise the 64-lane case the PR is about.

Not covered: a host that runs pixel shaders 64 wide, and the title (no game data here).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121376614 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/434#issuecomment-7121376614). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T03:44:32Z. --- Ran `588a0e2` on Windows 11 with an NVIDIA RTX 5070 (driver 621.24, 32-lane waves, the only adapter), rustc 1.98.1, debug, in its own target directory: - `cargo test -p victory-shader`: 70 passed, 0 failed, 3 runs. The validator picked up the Windows SDK's `dxil.dll` (10.0.26100.0), so the suite's modules were validated here, which the Linux runs skip. - `a_wave32_mask_read_takes_its_ballot_half` only checks the op list, so I also passed its lowered container through `dxil.dll` locally (a temporary three-line addition, not pushed): it validates. - On this host waves are 32 lanes, so the new half pick always takes the first dword. This run shows nothing regresses there; it does not exercise the 64-lane case the PR is about. Not covered: a host that runs pixel shaders 64 wide, and the title (no game data here).
NolanCotter commented 2026-11-24 06:55:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by NolanCotter on 2026-11-24T04:10:47Z.


Update (head 48f92e2): v_mbcnt_lo now reports its rank as a host lane number.

Relationship to #145 — I missed it when I scoped this (it covers #125, and #131 is the same defect): both PRs read the upper ballot half, but pick different lane-space models for a wave32 program on a 64-lane host wave:

  • #145 (host-whole): mask ops see the full 64-bit host ballot. s_bcnt1(exec) counts both console waves, s_cmp tests both waves' bits, and v_mbcnt_lo yields a unique index per host lane. It's GPU-verified, but its mask scalars and mbcnt ranks are polluted by the other console wave's divergence (a second wave's rank varies with the first wave's active count, and s_bcnt1(exec) reports 64 where the console program's wave expects 32).
  • This PR (per-half + host base): mask_dword selects the lane's own console wave's dword, so s_bcnt1/s_ff1/s_cmp keep their own wave's value regardless of the other wave's divergence. v_mbcnt_lo counts within its own half and then adds the wave's 32-lane base, so v_mbcnt_lo(-1) still reports the host lane index and the result stays a valid host lane for v_readlane composition — stable whether or not the other wave is fully active.

Both fix the reported defect on the common all-active case; the difference is only observable when the two console waves' tracked masks diverge. The test now asserts the emitted instruction structure (half select, lane & 31 mask, wave-base add), and v_mbcnt_lo(-1) is covered in the synthetic program.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121779806 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/434#issuecomment-7121779806). Originally posted by [NolanCotter](https://github.com/NolanCotter) on 2026-11-24T04:10:47Z. --- Update (head 48f92e2): v_mbcnt_lo now reports its rank as a host lane number. **Relationship to #145** — I missed it when I scoped this (it covers #125, and #131 is the same defect): both PRs read the upper ballot half, but pick different lane-space models for a wave32 program on a 64-lane host wave: - **#145 (host-whole)**: mask ops see the full 64-bit host ballot. `s_bcnt1(exec)` counts both console waves, `s_cmp` tests both waves' bits, and `v_mbcnt_lo` yields a unique index per host lane. It's GPU-verified, but its mask scalars and mbcnt ranks are polluted by the *other* console wave's divergence (a second wave's rank varies with the first wave's active count, and `s_bcnt1(exec)` reports 64 where the console program's wave expects 32). - **This PR (per-half + host base)**: `mask_dword` selects the lane's own console wave's dword, so `s_bcnt1`/`s_ff1`/`s_cmp` keep their own wave's value regardless of the other wave's divergence. `v_mbcnt_lo` counts within its own half and then adds the wave's 32-lane base, so `v_mbcnt_lo(-1)` still reports the host lane index and the result stays a valid host lane for `v_readlane` composition — stable whether or not the other wave is fully active. Both fix the reported defect on the common all-active case; the difference is only observable when the two console waves' tracked masks diverge. The test now asserts the emitted instruction structure (half select, `lane & 31` mask, wave-base add), and `v_mbcnt_lo(-1)` is covered in the synthetic program.
QemmHD commented 2026-11-24 06:55:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by QemmHD on 2026-11-24T05:11:31Z.


Tested 48f92e2 on main d2a4bae, native Windows 11, RTX 4070 SUPER (32-lane waves), driver 621.24.

  • cargo test --workspace --locked: 266 passed, 0 failed, 4 ignored (main: 264 / 0 / 4). New warning: unused variable: i at lower.rs:6767.
  • With only the mask_dword / v_mbcnt hunks reverse-applied, a_wave32_mask_read_takes_its_ballot_half fails, so the test does cover the change; only_host_wave32_reads_take_a_ballot_half passes either way.
  • On NVIDIA this is a no-op (lane >= 32 never holds, so lane & 31 == lane and lane & 32 == 0). Both tests are structural, so the 64-lane case still needs an RDNA run. It conflicts with #145 (same defect, GPU-checked on RDNA) and #233 in lower.rs.

No game data used.

AI-assisted (Claude Code, Claude Opus 5.5).
Discord: bigpeppa.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122710769 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/434#issuecomment-7122710769). Originally posted by [QemmHD](https://github.com/QemmHD) on 2026-11-24T05:11:31Z. --- Tested `48f92e2` on `main` `d2a4bae`, native Windows 11, RTX 4070 SUPER (32-lane waves), driver 621.24. - `cargo test --workspace --locked`: 266 passed, 0 failed, 4 ignored (main: 264 / 0 / 4). New warning: `unused variable: i` at `lower.rs:6767`. - With only the `mask_dword` / `v_mbcnt` hunks reverse-applied, `a_wave32_mask_read_takes_its_ballot_half` fails, so the test does cover the change; `only_host_wave32_reads_take_a_ballot_half` passes either way. - On NVIDIA this is a no-op (`lane >= 32` never holds, so `lane & 31 == lane` and `lane & 32 == 0`). Both tests are structural, so the 64-lane case still needs an RDNA run. It conflicts with #145 (same defect, GPU-checked on RDNA) and #233 in `lower.rs`. No game data used. AI-assisted (Claude Code, Claude Opus 5.5). Discord: bigpeppa.
catminou4 commented 2026-11-24 14:03:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T13:19:30Z.

Review: COMMENTED


Test-merge with current main (ffe310e) conflicts — needs a rebase. Main moved recently (PR #566 waterfall loops touched lower.rs/resource.rs/valu_tests.rs), so shader PRs opened before it need rebasing. I'll re-review once it merges cleanly.

<!-- greyfinch-sync:Marvisak/VIctory:review:6039897094 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/434#pullrequestreview-6039897094). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T13:19:30Z. **Review:** COMMENTED --- Test-merge with current main (`ffe310e`) **conflicts** — needs a rebase. Main moved recently (PR #566 waterfall loops touched `lower.rs`/`resource.rs`/`valu_tests.rs`), so shader PRs opened before it need rebasing. I'll re-review once it merges cleanly.
Marvisak commented 2026-11-25 01:07:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:17:32Z.


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148355836 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/434#issuecomment-7148355836). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:17:32Z. --- <!-- victory-triage v1 head=48f92e23c152fbef4f4434b8b9341e357e2220aa verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-shader/src/emit/lower.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/434:upstream-pr/434'
git switch 'upstream-pr/434'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/434'
git switch 'upstream-pr/434'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/434'
git switch 'upstream-pr/434'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/434'
git switch 'main'
git merge --squash 'upstream-pr/434'
git switch 'main'
git merge --ff-only 'upstream-pr/434'
git switch 'main'
git merge 'upstream-pr/434'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!434
No description provided.