shader: lower host-wave lane-mask joins and EXEC-masked skip reads (#444) #452

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

@⁠Sheffy007 on GitHub · 2026-11-27 19:53 UTC · original
Sheffy007:feat/host-lanes-mask-joins → main · +599 −16 · 5 files · 1 commits · open

Closes #448
Refs #4, #258

Summary

  • Lower host-wave (MaskData::Host) lane-mask joins between tracked masks (st.masks) and untracked host-wave masks (s_bitset0(mask, s_ff1(mask)) waterfall peel loops, uniform 0/-1 broadcasts from width-1 s_bfe_i32 / s_bfe_i64, s_mul_i32 by -1, and s_bitreplicate_b64_b32 of quad-invariant bitmasks) via Lower::host_number, plus s_bfe_i64 SOP2 scalar lowering and uniform loop-header mask joins in mesh programs (MaskData::None).
  • Prove uniform incoming edges on MaskData::Host joins via Lower::host_uniform_join (Bools::literal + BDD meet check verifying no two lanes at the join with equal Atom::Uniform values take different incoming edges), keeping divergent per-lane jump arms refused.
  • Extend Lower::unneeded_edges (keeps_exec_read) so s_cbranch_execz skip edges carrying stale SGPR data are recognized as unneeded when the joined mask is read under the narrowed EXEC only by v_cndmask_b32, s_nor_*, s_orn2_* / s_andn2_* with EXEC in either operand slot, or s_*_{saveexec,wrexec}_*.
  • Add unit tests in gfx_refusal_tests (positive + negative cases) and an end-to-end Metal GPU readback test (scaled_vertex_tests::pixel_waterfall_and_exec_skip_mask_joins_run_on_the_gpu) covering wave32 and wave64 pixel shaders.

Verification

  • 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

cc @⁠Olima34

**@⁠Sheffy007** on GitHub · 2026-11-27 19:53 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/448) `Sheffy007:feat/host-lanes-mask-joins` → `main` · +599 −16 · 5 files · 1 commits · open Closes #448 Refs #4, #258 ## Summary - Lower host-wave (`MaskData::Host`) lane-mask joins between tracked masks (`st.masks`) and untracked host-wave masks (`s_bitset0(mask, s_ff1(mask))` waterfall peel loops, uniform `0`/`-1` broadcasts from width-1 `s_bfe_i32` / `s_bfe_i64`, `s_mul_i32` by `-1`, and `s_bitreplicate_b64_b32` of quad-invariant bitmasks) via `Lower::host_number`, plus `s_bfe_i64` SOP2 scalar lowering and uniform loop-header mask joins in mesh programs (`MaskData::None`). - Prove uniform incoming edges on `MaskData::Host` joins via `Lower::host_uniform_join` (`Bools::literal` + BDD `meet` check verifying no two lanes at the join with equal `Atom::Uniform` values take different incoming edges), keeping divergent per-lane jump arms refused. - Extend `Lower::unneeded_edges` (`keeps_exec_read`) so `s_cbranch_execz` skip edges carrying stale SGPR data are recognized as unneeded when the joined mask is read under the narrowed `EXEC` only by `v_cndmask_b32`, `s_nor_*`, `s_orn2_*` / `s_andn2_*` with `EXEC` in either operand slot, or `s_*_{saveexec,wrexec}_*`. - Add unit tests in `gfx_refusal_tests` (positive + negative cases) and an end-to-end Metal GPU readback test (`scaled_vertex_tests::pixel_waterfall_and_exec_skip_mask_joins_run_on_the_gpu`) covering wave32 and wave64 pixel shaders. ## Verification - `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` cc @⁠Olima34
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 19:57:11 +00:00
github-bot force-pushed github-bot/gh-448 from cb9b1d7397 to fa47d4c6f3 2026-11-28 01:48:17 +00:00 Compare
Author
Owner

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

Thanks for this PR! An offline check of cb9b1d73. The current head fa47d4c6 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.

#448 alone:

  • Newly translated: 2 compute (compute_288d43370f94f9e2 and compute_c0fb3abb461b27ed, previously refused for "a lane-mask join of an untracked mask: data, at a join of several edges").
  • Outputs changed: 2,170 (2,142 pixel, 22 vertex, 6 compute).
  • Regressions: 0.

The world shaders refused for "… data, on the host's lanes" are not translated by #452 alone. In the combination, 6 vertex shaders of that class translate, and #470 alone translates them too.

Merging: #452 and #470 add code at the same spot in emit/lower.rs. Keeping both sides compiles, so whichever lands second needs only a trivial rebase.

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/448#issuecomment-7232065365) Thanks for this PR! An offline check of cb9b1d73. The current head fa47d4c6 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. **#448 alone:** - **Newly translated:** 2 compute (compute_288d43370f94f9e2 and compute_c0fb3abb461b27ed, previously refused for "a lane-mask join of an untracked mask: data, at a join of several edges"). - **Outputs changed:** 2,170 (2,142 pixel, 22 vertex, 6 compute). - **Regressions:** 0. The world shaders refused for "… data, on the host's lanes" are not translated by #452 alone. In the combination, 6 vertex shaders of that class translate, and #470 alone translates them too. **Merging:** #452 and #470 add code at the same spot in `emit/lower.rs`. Keeping both sides compiles, so whichever lands second needs only a trivial rebase. **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/452/head:github-bot/gh-448'
git switch 'github-bot/gh-448'

Merge

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