Shaders: read both ballot halves for wave32 host-wave mask ops #145

Open
7ROBE wants to merge 1 commit from upstream-pr/145 into main
7ROBE commented 2026-11-24 00:57:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 7ROBE on 2026-11-24T00:57:40Z.


Fixes #131, #125.

What is in it

Under MaskData::Host (pixel and vertex programs), s.wave_size is None and mask_ballot takes a ballot over the host wave, producing a (lo, hi) pair via waveActiveBallot. Previously, the 32-bit mask-reading sites in wave32 console programs only read lo and dropped hi, losing lanes 32-63 when a driver runs the stage 64-wide (e.g., AMD RDNA):

  • s_bcnt1_i32_b32 / s_ff1_i32_b32: factored bcnt1_64 and ff1_64 helpers (shared with s_bcnt1_i32_b64 / s_ff1_i32_b64) and use both ballot halves when the operand is a tracked wave32 host mask.
  • s_cmp_eq_u32 / s_cmp_lg_u32: compare both (lo, hi) ballot halves when comparing two tracked host masks or comparing a tracked host mask against 0.
  • v_mbcnt_lo_u32_b32:
    • For -1 (all-lanes mask) in a wave32 host-mask program, lower directly to waveGetLaneIndex() + src1 instead of clamping to 32 at lane >= 32.
    • For a tracked host mask, count bits below lane across both lo and hi using a shared below_mask helper and bcnt1_64.
  • Tests: added #[cfg(test)] Module::uses_of in crates/victory-shader/src/emit/bitcode.rs and synthetic wave32 pixel shader test host_wave32_mask_ops_use_both_ballot_halves in crates/victory-shader/src/emit/lower.rs (no game data).

Tested

  • rustfmt --check --edition 2024 crates/victory-shader/src/emit/bitcode.rs crates/victory-shader/src/emit/lower.rs: passed
  • cargo xtask policy: asset policy: 151 files ok
  • cargo clippy -p victory-shader --all-targets -- -D warnings: passed (0 warnings)
  • cargo test -p victory-shader: 70 passed; 0 failed (including GPU diff tests on RX 9060 XT + new synthetic test)
  • cargo test --workspace --exclude victory-gpu --lib --tests: all passed (note: victory-gpu test build on main 9aef3d9 has a pre-existing duplicate mod tests in host.rs:1974)

AI use

AI-assisted (Antigravity / Gemini 3.1 Pro) on Windows 11, Intel i5-14600KF, AMD Radeon RX 9060 XT (Adrenalin 26.11.2). No game data was used.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5464020278 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/145). Originally posted by [7ROBE](https://github.com/7ROBE) on 2026-11-24T00:57:40Z. --- Fixes #131, #125. ## What is in it Under `MaskData::Host` (pixel and vertex programs), `s.wave_size` is `None` and `mask_ballot` takes a ballot over the **host** wave, producing a `(lo, hi)` pair via `waveActiveBallot`. Previously, the 32-bit mask-reading sites in wave32 console programs only read `lo` and dropped `hi`, losing lanes 32-63 when a driver runs the stage 64-wide (e.g., AMD RDNA): - **`s_bcnt1_i32_b32` / `s_ff1_i32_b32`**: factored `bcnt1_64` and `ff1_64` helpers (shared with `s_bcnt1_i32_b64` / `s_ff1_i32_b64`) and use both ballot halves when the operand is a tracked wave32 host mask. - **`s_cmp_eq_u32` / `s_cmp_lg_u32`**: compare both `(lo, hi)` ballot halves when comparing two tracked host masks or comparing a tracked host mask against `0`. - **`v_mbcnt_lo_u32_b32`**: - For `-1` (all-lanes mask) in a wave32 host-mask program, lower directly to `waveGetLaneIndex() + src1` instead of clamping to 32 at `lane >= 32`. - For a tracked host mask, count bits below `lane` across both `lo` and `hi` using a shared `below_mask` helper and `bcnt1_64`. - **Tests**: added `#[cfg(test)] Module::uses_of` in `crates/victory-shader/src/emit/bitcode.rs` and synthetic wave32 pixel shader test `host_wave32_mask_ops_use_both_ballot_halves` in `crates/victory-shader/src/emit/lower.rs` (no game data). ## Tested - `rustfmt --check --edition 2024 crates/victory-shader/src/emit/bitcode.rs crates/victory-shader/src/emit/lower.rs`: passed - `cargo xtask policy`: `asset policy: 151 files ok` - `cargo clippy -p victory-shader --all-targets -- -D warnings`: passed (0 warnings) - `cargo test -p victory-shader`: `70 passed; 0 failed` (including GPU diff tests on RX 9060 XT + new synthetic test) - `cargo test --workspace --exclude victory-gpu --lib --tests`: all passed (note: `victory-gpu` test build on `main` `9aef3d9` has a pre-existing duplicate `mod tests` in `host.rs:1974`) ## AI use AI-assisted (Antigravity / Gemini 3.1 Pro) on Windows 11, Intel i5-14600KF, AMD Radeon RX 9060 XT (Adrenalin 26.11.2). No game data was used.
DaviTostes commented 2026-11-24 06:54:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:05:41Z.


Tested ecc4eb6 on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 57 passed, 0 failed (2 test binaries), including the test this PR adds.
  • Scope note: #147 ("a host-wave lane mask uses both ballot dwords", fixes #125) covers the same fix and is also open; the two should converge on one PR.
  • The full workspace still needs #112 for the victory-gpu E0425.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118748578 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/145#issuecomment-7118748578). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:05:41Z. --- Tested `ecc4eb6` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **57 passed, 0 failed** (2 test binaries), including the test this PR adds. - Scope note: **#147 ("a host-wave lane mask uses both ballot dwords", fixes #125) covers the same fix** and is also open; the two should converge on one PR. - The full workspace still needs #112 for the `victory-gpu` E0425. No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
TheHoracio commented 2026-11-24 06:54:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TheHoracio on 2026-11-24T01:19:39Z.


GPU check of this PR on an RX 7800 XT (RDNA3, 64-lane pixel waves): a synthetic wave32 pixel program drawn through lower + Host::draw passes on ecc4eb6. All 64 lanes are counted, and v_mbcnt_lo(-1) gives lane indices 0-63. The same test fails on main. Details, table and test code: https://github.com/Marvisak/VIctory/issues/125

AI use: Claude Code (Claude Opus 5.5) wrote and ran the test.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118989671 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/145#issuecomment-7118989671). Originally posted by [TheHoracio](https://github.com/TheHoracio) on 2026-11-24T01:19:39Z. --- GPU check of this PR on an RX 7800 XT (RDNA3, 64-lane pixel waves): a synthetic wave32 pixel program drawn through `lower` + `Host::draw` **passes** on `ecc4eb6`. All 64 lanes are counted, and `v_mbcnt_lo(-1)` gives lane indices 0-63. The same test fails on `main`. Details, table and test code: https://github.com/Marvisak/VIctory/issues/125 AI use: Claude Code (Claude Opus 5.5) wrote and ran the test.
Luislariosss commented 2026-11-24 06:54:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Luislariosss on 2026-11-24T01:31:15Z.


Independent check on an AMD RDNA4 Windows machine, and the reason the workspace was red for you:

The E0428 / victory-gpu failure is the base, not this PR. Your head ecc4eb668 predates the merge of #129 (d2a4bae, "rename the second test module in host.rs"), so the duplicate #[cfg(test)] mod tests is still in host.rs on your branch. Merging current main (d2a4bae) into it is clean, and then the whole workspace compiles.

What I ran

Machine: Windows 11 build 26200, AMD Radeon RX 9060 XT (RDNA4, gfx1200), Adrenalin 26.10.1 / Windows driver 32.0.32015.7029, Rust 1.98.1 from rust-toolchain.toml, MSVC from VS Build Tools 2022.

git merge main            # d2a4bae into ecc4eb668 -> 25818acf0, clean
cargo test --workspace    # exit 0
blocks: 22 | passed: 265 | ignored: 4 | test result: FAILED: 0

victory-shader on its own, on your unmerged head:

cargo test -p victory-shader   ->  70 passed, 0 failed

So the fix and its test are green on this card, and the workspace is only blocked by the base. A rebase onto main should turn your CI-equivalent run green without touching the change.

Scope note, since #145 and #147 were opened 12 seconds apart with the same fix (mask_ballot here, ballot_pair there): #147 is closed, so this is the one to land. The reproduction that fails on main before any fix is on the fork branch verify/wave32-mask (7004dfe3b, test-only) if you want a red-first check that does not depend on how the fix is written.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7119180442 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/145#issuecomment-7119180442). Originally posted by [Luislariosss](https://github.com/Luislariosss) on 2026-11-24T01:31:15Z. --- Independent check on an AMD RDNA4 Windows machine, and the reason the workspace was red for you: **The `E0428` / `victory-gpu` failure is the base, not this PR.** Your head `ecc4eb668` predates the merge of #129 (`d2a4bae`, "rename the second test module in host.rs"), so the duplicate `#[cfg(test)] mod tests` is still in `host.rs` on your branch. Merging current `main` (`d2a4bae`) into it is clean, and then the whole workspace compiles. ## What I ran Machine: Windows 11 build 26200, AMD Radeon RX 9060 XT (RDNA4, gfx1200), Adrenalin 26.10.1 / Windows driver `32.0.32015.7029`, Rust `1.98.1` from `rust-toolchain.toml`, MSVC from VS Build Tools 2022. ``` git merge main # d2a4bae into ecc4eb668 -> 25818acf0, clean cargo test --workspace # exit 0 ``` ``` blocks: 22 | passed: 265 | ignored: 4 | test result: FAILED: 0 ``` `victory-shader` on its own, on your unmerged head: ``` cargo test -p victory-shader -> 70 passed, 0 failed ``` So the fix and its test are green on this card, and the workspace is only blocked by the base. A rebase onto `main` should turn your CI-equivalent run green without touching the change. Scope note, since #145 and #147 were opened 12 seconds apart with the same fix (`mask_ballot` here, `ballot_pair` there): #147 is closed, so this is the one to land. The reproduction that fails on `main` before any fix is on the fork branch `verify/wave32-mask` (`7004dfe3b`, test-only) if you want a red-first check that does not depend on how the fix is written. AI-assisted.
DarX-Oren commented 2026-11-24 06:55:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DarX-Oren on 2026-11-24T02:39:18Z.


Independent RDNA2 hardware validation — RX 6700 XT

Reproduced the host-wave mask issue using the public synthetic pixel shader test from #125.

Hardware:

  • AMD RX 6700 XT (12 GB, Navi 22)
  • Driver: 32.0.21045.29003
  • Windows 11 25H2
  • Rust 1.100.0 MSVC
Result Main d2a4bae With #145
Active lanes counted 32 64
Maximum lane index 32 63
Incorrect pixels 2048/4096 0/4096
Workspace tests passed 264 266
Failed tests 0 0
Ignored tests 4 4

The tested local branch (b22541a) applies the changes from #145 to main.

Four additional tests reported success but internally skipped comparisons because the console compiler was unavailable.

This confirms the pixel-shader mask count and prefix behavior on RDNA2. Vertex shaders and other affected mask operations were not independently verified.

No commercial game data was used. Raw logs and pixel readbacks are available if needed.

AI use: OpenAI Codex assisted with compilation, testing and analysis on physical hardware.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7120354618 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/145#issuecomment-7120354618). Originally posted by [DarX-Oren](https://github.com/DarX-Oren) on 2026-11-24T02:39:18Z. --- ## Independent RDNA2 hardware validation — RX 6700 XT Reproduced the host-wave mask issue using the public synthetic pixel shader test from #125. Hardware: - AMD RX 6700 XT (12 GB, Navi 22) - Driver: 32.0.21045.29003 - Windows 11 25H2 - Rust 1.100.0 MSVC | Result | Main d2a4bae | With #145 | |---|---:|---:| | Active lanes counted | 32 | 64 | | Maximum lane index | 32 | 63 | | Incorrect pixels | 2048/4096 | 0/4096 | | Workspace tests passed | 264 | 266 | | Failed tests | 0 | 0 | | Ignored tests | 4 | 4 | The tested local branch (`b22541a`) applies the changes from #145 to main. Four additional tests reported success but internally skipped comparisons because the console compiler was unavailable. This confirms the pixel-shader mask count and prefix behavior on RDNA2. Vertex shaders and other affected mask operations were not independently verified. No commercial game data was used. Raw logs and pixel readbacks are available if needed. AI use: OpenAI Codex assisted with compilation, testing and analysis on physical hardware.
qntic commented 2026-11-24 08:02:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by qntic on 2026-11-24T07:49:22Z.


Tested this branch on an RX 6600 XT (RDNA 2), which runs pixel shaders in wave64, with hardware regression tests that check every pixel against wave32 semantics. Details and the full results: https://github.com/Marvisak/VIctory/pull/599#issuecomment-7125172405

With this change, s_bcnt1_i32_b32 of a wave32 pixel program's EXEC returns 64 instead of 32. The count covers both console waves in the host wave, so lanes 0-31 become wrong as well (4096 of 4096 pixels wrong, against 2048 on main). The same happens for a v_cmp mask's count and for EXEC counts in a loop.

A wave32 mask read should only use its own half of the ballot, as #434 does. With #434 + #599, all 11 tests pass on this GPU.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7125409931 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/145#issuecomment-7125409931). Originally posted by [qntic](https://github.com/qntic) on 2026-11-24T07:49:22Z. --- Tested this branch on an **RX 6600 XT** (RDNA 2), which runs pixel shaders in **wave64**, with hardware regression tests that check every pixel against wave32 semantics. Details and the full results: https://github.com/Marvisak/VIctory/pull/599#issuecomment-7125172405 With this change, `s_bcnt1_i32_b32` of a wave32 pixel program's EXEC returns **64 instead of 32**. The count covers both console waves in the host wave, so lanes 0-31 become wrong as well (4096 of 4096 pixels wrong, against 2048 on `main`). The same happens for a `v_cmp` mask's count and for EXEC counts in a loop. A wave32 mask read should only use its own half of the ballot, as #434 does. With #434 + #599, all 11 tests pass on this GPU.
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:43Z.


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:7148359131 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/145#issuecomment-7148359131). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:17:43Z. --- <!-- victory-triage v1 head=ecc4eb668db7e61b42e90a7bf06517fe34cc062a 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)_
ColorMeBoom commented 2026-11-27 06:05:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T06:05:12Z.


Rebased onto current main 63bcca4 and tested on an RX 5700 XT (RDNA1) and WARP. Branch: ColorMeBoom:pr145-rebase, one merge commit on top of ecc4eb6, so it fast-forwards:

git fetch https://github.com/ColorMeBoom/VIctory pr145-rebase
git merge --ff-only FETCH_HEAD

The new helpers and your unit test moved to emit/lower/host_masks.rs, to keep lower.rs under the 512 KiB policy limit. mask_ballot() keeps main's console-mode mask_number. The workspace suite passes (874 passed, 0 failed), and so does the GPU test from #125 (64-lane pixel waves on this card). Details and the before/after are on #125.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7211203460 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/145#issuecomment-7211203460). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-27T06:05:12Z. --- Rebased onto current main `63bcca4` and tested on an RX 5700 XT (RDNA1) and WARP. Branch: [`ColorMeBoom:pr145-rebase`](https://github.com/ColorMeBoom/VIctory/tree/pr145-rebase), one merge commit on top of `ecc4eb6`, so it fast-forwards: ``` git fetch https://github.com/ColorMeBoom/VIctory pr145-rebase git merge --ff-only FETCH_HEAD ``` The new helpers and your unit test moved to `emit/lower/host_masks.rs`, to keep `lower.rs` under the 512 KiB policy limit. `mask_ballot()` keeps main's console-mode `mask_number`. The workspace suite passes (874 passed, 0 failed), and so does the GPU test from #125 (64-lane pixel waves on this card). Details and the before/after are [on #125](https://github.com/Marvisak/VIctory/issues/125#issuecomment-7211198508). AI use: Claude Code (Claude Opus 5.5).
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/145:upstream-pr/145'
git switch 'upstream-pr/145'

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/145'
git switch 'upstream-pr/145'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/145'
git switch 'upstream-pr/145'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/145'
git switch 'main'
git merge --squash 'upstream-pr/145'
git switch 'main'
git merge --ff-only 'upstream-pr/145'
git switch 'main'
git merge 'upstream-pr/145'
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!145
No description provided.