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

Open
Sheffy007 wants to merge 1 commit from upstream-pr/448 into main
Sheffy007 commented 2026-11-27 19:53:11 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T19:53:11Z.


Closes #444
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

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5532322779 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/448). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T19:53:11Z. --- Closes #444 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
Olima34 commented 2026-11-28 02:00:34 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T02:00:34Z.


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 #448 alone. In the combination, 6 vertex shaders of that class translate, and #466 alone translates them too.

Merging: #448 and #466 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 #418 #466 #420 #409 #448 #433 #495 #497 on 86cefd22 (a local integration build, plus the pass-trace fix from #509):

  • World corpus: 302 shaders newly translated and 1 regression (see #433).
  • 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.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7232065365 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/448#issuecomment-7232065365). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T02:00:34Z. --- 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 #448 alone. In the combination, 6 vertex shaders of that class translate, and #466 alone translates them too. **Merging:** #448 and #466 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 #418 #466 #420 #409 #448 #433 #495 #497 on 86cefd22 (a local integration build, plus the pass-trace fix from #509): - **World corpus:** 302 shaders newly translated and 1 regression (see #433). - **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 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/448:upstream-pr/448'
git switch 'upstream-pr/448'

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