Skip to content

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

Open
7ROBE wants to merge 1 commit into
Marvisak:mainfrom
7ROBE:fix/host-wave-mask-high-half
Open

7ROBE wants to merge 1 commit into
Marvisak:mainfrom
7ROBE:fix/host-wave-mask-high-half

Conversation

@7ROBE

@7ROBE 7ROBE commented Nov 24, 2026

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

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

@TheHoracio

Copy link
Copy Markdown

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.

@Luislariosss

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown

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

qntic commented Nov 24, 2026

Copy link
Copy Markdown

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 (comment)

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.

Copy link
Copy Markdown
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

7 participants