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

Open
github-bot wants to merge 3 commits from github-bot/gh-434 into main AGit
Owner

@⁠NolanCotter on GitHub · 2026-11-24 03:20 UTC · original
NolanCotter:agent/host-wave-mask-halves → main · +263 −13 · 2 files · 3 commits · open

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

**@⁠NolanCotter** on GitHub · 2026-11-24 03:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/434) `NolanCotter:agent/host-wave-mask-halves` → `main` · +263 −13 · 2 files · 3 commits · open 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)
For MaskData::Host (pixel and vertex stages, whose programs declare no
WaveSize) a host wave may have 64 lanes; its upper half is a second
console wave whose bits land in the ballot's second dword. mask_dword
returned the first dword for every lane, so mask reads as data
(s_bcnt1_i32_*, s_ff1_i32_*, v_mbcnt_*, s_cmp_eq/lg_u32/u64) gave the
upper half's lanes the lower console wave's mask values.

mask_dword now selects the ballot half by the reader's host lane.
v_mbcnt_lo counts bits of the lane's own half below its lane in it, and
v_mbcnt_hi is src1 alone on wave32, whose mask has no high half. Both are
unchanged when the host wave is 32 lanes.

Fixes #131.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The wave32 mask-read test now asserts the pick's shape: an unsigned
`lane >= 32` compare selecting the ballot's second dword over the first,
`lane & 31` for v_mbcnt_lo, and a bit count of a constant zero for
v_mbcnt_hi. A second test covers the paths that must not pick: wave64
programs (own dwords) and compute (the whole host wave is the console's).

emit::bitcode::Module gains a test-only inst_lines dump to support that.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Under MaskData::Host a wave32 program's lane numbers stay host
lanes, so a v_mbcnt_lo rank of the upper half's console wave takes
its 32-lane base: v_mbcnt_lo(-1) still reports the lane index, and
the value composes with host-lane reads like v_readlane. The mask
itself stays per console wave, so s_bcnt1, s_ff1 and s_cmp keep
their own wave's count and the first wave's divergence never feeds
a second wave's scalars.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:03:51 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 03:36 UTC · original

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).

**@⁠DaviTostes** on GitHub · 2026-11-24 03:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/434#issuecomment-7121259671) 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).
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 03:44 UTC · original

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).

**@⁠marquezinii** on GitHub · 2026-11-24 03:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/434#issuecomment-7121376614) 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).
Author
Owner

@⁠NolanCotter on GitHub · 2026-11-24 04:10 UTC · original

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.

**@⁠NolanCotter** on GitHub · 2026-11-24 04:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/434#issuecomment-7121779806) 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.
Author
Owner

@⁠QemmHD on GitHub · 2026-11-24 05:11 UTC · original

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.

**@⁠QemmHD** on GitHub · 2026-11-24 05:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/434#issuecomment-7122710769) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:17 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 00:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/434#issuecomment-7148355836) <!-- 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 has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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