shader: lower 32-bit scalar ops on wave64 lane-mask halves (#423) #437

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

@⁠Sheffy007 on GitHub · 2026-11-27 18:03 UTC · original
Sheffy007:feat/wave64-split-32bit-mask-data → main · +475 −61 · 5 files · 1 commits · open

Summary

Lowers 32-bit scalar ALU writes to individual halves of wave64 lane masks when read as data (addressing the 9 world compute shaders hitting "a lane mask holding lanes elsewhere read as data: written by a scalar instruction of the other width"):

  • Lower::mask_dword & Lower::mask_half_number: When a wave64 mask half is written by a 1-dword scalar ALU instruction that does not touch EXEC, evaluate that half's 32-bit operation directly on its 32-bit scalar/constant operands (s_mov_b32, s_movk_i32, s_not_b32, s_wqm_b32, s_lshl_b32, s_lshr_b32, s_bitset0_b32, s_bitset1_b32, s_bfm_b32, s_brev_b32, s_quadmask_b32, s_cselect_b32, s_cmov_b32, s_cmovk_i32, and bitwise and/or/xor/andn2/orn2/andn1/orn1/nand/nor/xnor), enforcing the existing MaskData::Host wave-size safety guards (SHIFT on cross-lane/non-uniform constants and zeroing the high half on 32-lane host waves). Also models s_bitreplicate_b64_b32 in mask_number for MaskData::Console, and records mask_scc for 1-dword mask writes via is_mask.
  • Exact (lo, hi) pair tracking across partial 32-bit updates:
    • Keeps paired_other alongside paired_masks (Structured::mask_or_other) and looks up exact (lo, hi) pairs in mask_dword, v_cndmask_b32, v_*_co_ci_u32, and uniform_with_exec so updating only one 32-bit half ((lo, hi_old) -> (lo, hi_new)) does not collide on lo.
    • Carries both dwords in Atom::Opaque(lo, hi) instead of guessing pair_high(lo), and avoids marking k.0 in Structured::active when a 1-dword instruction writes only k.1.
    • Fixes an accidental s9 register collision with saved s[8:9] in a_wave64_prefix_sum_whose_rows_s_bitreplicate_and_s_bfm_select_runs.

Verification

  • Unit tests in crates/victory-shader/src/emit/mask_tests.rs (split_32bit_wave64_mask_halves_and_partial_updates_lower_as_data + existing negative tests).
  • Metal GPU compute test in crates/victory-gpu/src/native/split_wave_tests.rs (split_32bit_wave64_mask_halves_and_partial_updates_run_on_the_gpu, checking all 64 lanes across split 32-lane host waves).
  • cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask
  • cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo xtask policy

Closes #427
Refs #4, #258

cc @⁠Olima34

**@⁠Sheffy007** on GitHub · 2026-11-27 18:03 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/433) `Sheffy007:feat/wave64-split-32bit-mask-data` → `main` · +475 −61 · 5 files · 1 commits · open ## Summary Lowers 32-bit scalar ALU writes to individual halves of wave64 lane masks when read as data (addressing the 9 world compute shaders hitting `"a lane mask holding lanes elsewhere read as data: written by a scalar instruction of the other width"`): - **`Lower::mask_dword` & `Lower::mask_half_number`:** When a wave64 mask half is written by a 1-dword scalar ALU instruction that does not touch `EXEC`, evaluate that half's 32-bit operation directly on its 32-bit scalar/constant operands (`s_mov_b32`, `s_movk_i32`, `s_not_b32`, `s_wqm_b32`, `s_lshl_b32`, `s_lshr_b32`, `s_bitset0_b32`, `s_bitset1_b32`, `s_bfm_b32`, `s_brev_b32`, `s_quadmask_b32`, `s_cselect_b32`, `s_cmov_b32`, `s_cmovk_i32`, and bitwise `and`/`or`/`xor`/`andn2`/`orn2`/`andn1`/`orn1`/`nand`/`nor`/`xnor`), enforcing the existing `MaskData::Host` wave-size safety guards (`SHIFT` on cross-lane/non-uniform constants and zeroing the high half on 32-lane host waves). Also models `s_bitreplicate_b64_b32` in `mask_number` for `MaskData::Console`, and records `mask_scc` for 1-dword mask writes via `is_mask`. - **Exact `(lo, hi)` pair tracking across partial 32-bit updates:** - Keeps `paired_other` alongside `paired_masks` (`Structured::mask_or_other`) and looks up exact `(lo, hi)` pairs in `mask_dword`, `v_cndmask_b32`, `v_*_co_ci_u32`, and `uniform_with_exec` so updating only one 32-bit half (`(lo, hi_old)` -> `(lo, hi_new)`) does not collide on `lo`. - Carries both dwords in `Atom::Opaque(lo, hi)` instead of guessing `pair_high(lo)`, and avoids marking `k.0` in `Structured::active` when a 1-dword instruction writes only `k.1`. - Fixes an accidental `s9` register collision with saved `s[8:9]` in `a_wave64_prefix_sum_whose_rows_s_bitreplicate_and_s_bfm_select_runs`. ## Verification - Unit tests in `crates/victory-shader/src/emit/mask_tests.rs` (`split_32bit_wave64_mask_halves_and_partial_updates_lower_as_data` + existing negative tests). - Metal GPU compute test in `crates/victory-gpu/src/native/split_wave_tests.rs` (`split_32bit_wave64_mask_halves_and_partial_updates_run_on_the_gpu`, checking all 64 lanes across split 32-lane host waves). - `cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask` - `cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo xtask policy` Closes #427 Refs #4, #258 cc @⁠Olima34
Lower 1-dword scalar ALU writes to wave64 lane-mask halves via mask_half_number when read as data, preserve exact (lo, hi) pairs in Structured (paired_other, mask_or_other, Atom::Opaque(lo, hi), and active tracking), and model s_bitreplicate_b64_b32 in mask_number.

Closes #423
Refs #4, #258
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 18:03:57 +00:00
github-bot force-pushed github-bot/gh-433 from 56b7137b67 to 635c777630 2026-11-27 23:55:10 +00:00 Compare
github-bot force-pushed github-bot/gh-433 from 635c777630 to b607dfad6a 2026-11-28 00:42:41 +00:00 Compare
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 00:37 UTC · original · requested changes

Thanks for this PR! We're helping the maintainer clear the queue tonight, and main has moved a lot (the preview branch landed as 86cefd22, then a batch of PRs; main is now a6a58361). This branch now conflicts with main in crates/victory-gpu/src/native/split_wave_tests.rs.

Could you merge current main into the branch (a merge commit is fine, no need to rebase) and resolve the conflict? It looks like tests appended at the same spot as tests that landed on main; keep both sides. Once GitHub shows it as mergeable and CI is green on the new head, we'll read it through and merge it if it holds up.

**@⁠Olima34** on GitHub · 2026-11-28 00:37 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/433#pullrequestreview-6094669269) · **requested changes** Thanks for this PR! We're helping the maintainer clear the queue tonight, and main has moved a lot (the preview branch landed as 86cefd22, then a batch of PRs; main is now a6a58361). This branch now conflicts with main in `crates/victory-gpu/src/native/split_wave_tests.rs`. Could you merge current `main` into the branch (a merge commit is fine, no need to rebase) and resolve the conflict? It looks like tests appended at the same spot as tests that landed on main; keep both sides. Once GitHub shows it as mergeable and CI is green on the new head, we'll read it through and merge it if it holds up.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 00:46 UTC · original

The maintainer is handling this one himself; please follow his lead rather than my review.

**@⁠Olima34** on GitHub · 2026-11-28 00:46 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/433#issuecomment-7231186300) The maintainer is handling this one himself; please follow his lead rather than my review.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 02:00 UTC · original

Thanks for this PR! An offline check of 635c7776. The current head b607dfad has the same non-test code.

Measured offline on main 86cefd22 with examples/sweep + tools/corpus/compare.sh, on our 21,600-shader world corpus. The PR alone was swept over the 10,319 world shaders that the combination below changes. "Passes/frame" is an estimate from four traced world frames of an earlier preview run: the dropped passes whose only refused shader this PR translates.

#433 alone:

  • Newly translated: 9 compute, previously refused for "a lane mask holding lanes elsewhere read as data: written by a scalar instruction of the other width".
  • Outputs changed: 4.
  • Refused for another reason now: 10 (4 now stop at "a lane mask whose lanes depend on its own value").
  • Passes/frame: about 4.
  • Regression, 1: vertex_9aae2e2d80abafe1 translates on main and is refused with #437 for "a lane-mask join of an untracked mask: a value the translation could not make". This is the only regression in the whole combination, and it comes from #437 alone.

Merging: the only conflicts are in test files: mask_tests.rs and split_wave_tests.rs, which other PRs also append to.

In combination with #422 #470 #424 #413 #452 #437 #499 #501 on 86cefd22 (a local integration build, plus the pass-trace fix from #513):

  • World corpus: 302 shaders newly translated and 1 regression (see #437).
  • Windowed run (6 min): no GPU errors, and the GPU memory drained afterwards. About 1.4 fps in the world. 351 passes dropped per world frame, against 456 in an earlier census of the preview branch; these are different runs, so not a clean A/B.
**@⁠Olima34** on GitHub · 2026-11-28 02:00 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/433#issuecomment-7232065644) Thanks for this PR! An offline check of 635c7776. The current head b607dfad has the same non-test code. Measured offline on main 86cefd22 with `examples/sweep` + `tools/corpus/compare.sh`, on our 21,600-shader world corpus. The PR alone was swept over the 10,319 world shaders that the combination below changes. "Passes/frame" is an estimate from four traced world frames of an earlier preview run: the dropped passes whose only refused shader this PR translates. **#433 alone:** - **Newly translated:** 9 compute, previously refused for "a lane mask holding lanes elsewhere read as data: written by a scalar instruction of the other width". - **Outputs changed:** 4. - **Refused for another reason now:** 10 (4 now stop at "a lane mask whose lanes depend on its own value"). - **Passes/frame:** about 4. - **Regression, 1:** `vertex_9aae2e2d80abafe1` translates on main and is refused with #437 for "a lane-mask join of an untracked mask: a value the translation could not make". This is the only regression in the whole combination, and it comes from #437 alone. **Merging:** the only conflicts are in test files: `mask_tests.rs` and `split_wave_tests.rs`, which other PRs also append to. **In combination** with #422 #470 #424 #413 #452 #437 #499 #501 on 86cefd22 (a local integration build, plus the pass-trace fix from #513): - **World corpus:** 302 shaders newly translated and 1 regression (see #437). - **Windowed run (6 min):** no GPU errors, and the GPU memory drained afterwards. About 1.4 fps in the world. 351 passes dropped per world frame, against 456 in an earlier census of the preview branch; these are different runs, so not a clean A/B.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-433'
git switch 'github-bot/gh-433'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-433'
git switch 'github-bot/gh-433'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-433'
git switch 'main'
git merge --squash 'github-bot/gh-433'
git switch 'main'
git merge --ff-only 'github-bot/gh-433'
git switch 'main'
git merge 'github-bot/gh-433'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.