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

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

@⁠7ROBE on GitHub · 2026-11-24 00:57 UTC · original
7ROBE:fix/host-wave-mask-high-half → main · +299 −75 · 2 files · 1 commits · open

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.

**@⁠7ROBE** on GitHub · 2026-11-24 00:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/145) `7ROBE:fix/host-wave-mask-high-half` → `main` · +299 −75 · 2 files · 1 commits · open 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:52:07 +00:00
Author
Owner

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

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

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

@⁠TheHoracio on GitHub · 2026-11-24 01:19 UTC · original

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: #125

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

**@⁠TheHoracio** on GitHub · 2026-11-24 01:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/145#issuecomment-7118989671) 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://git.gtahub.st/github/Marvisak--VIctory/issues/125 AI use: Claude Code (Claude Opus 5.5) wrote and ran the test.
Author
Owner

@⁠Luislariosss on GitHub · 2026-11-24 01:31 UTC · original

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.

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

@⁠DarX-Oren on GitHub · 2026-11-24 02:39 UTC · original

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.

**@⁠DarX-Oren** on GitHub · 2026-11-24 02:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/145#issuecomment-7120354618) ## 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.
Author
Owner

@⁠qntic on GitHub · 2026-11-24 07:49 UTC · original

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: #599

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.

**@⁠qntic** on GitHub · 2026-11-24 07:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/145#issuecomment-7125409931) 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://git.gtahub.st/github/Marvisak--VIctory/pulls/599 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.
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/145#issuecomment-7148359131) <!-- 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)_
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/145/head:github-bot/gh-145'
git switch 'github-bot/gh-145'

Merge

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