shader: follow constant/uniform prefix terms, u32 products, and readfirstlane in wave sections #512

Open
Sheffy007 wants to merge 1 commit from upstream-pr/512 into main
Sheffy007 commented 2026-11-27 23:17:14 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T23:17:14Z.


Summary

  • Follow constant (Sym::K), uniform (Sym::Uni), and idempotent reduction (Sym::Red) active-lane terms in v_cndmask_b32 inside whole-wave sections (for example v_cndmask_b32 vdst, 0, s_stride, s_mask for constant-stride prefix scans), as well as constant scalar lane-select masks (s_mov_b32 / s_mov_b64 of row or half bitmasks) without requiring EXEC saves/restores.
  • Record per-lane uniform shapes (such as lane wave - 1 of a Shape::Prefix inclusive scan) in Lower::section_lanes so a constant-lane v_readlane_b32 after the section evaluates the total reduction cleanly even when lane wave - 1 was inactive before the section.
  • Follow 32-bit integer WaveActiveProduct reductions (v_mul_lo_u32 and s_mul_i32, identity 1) across single and split wave64 host waves (halves_reduce), while keeping prefix products refused.
  • Follow v_readfirstlane_b32 under a known constant EXEC mask (exec.trailing_zeros()) both inside a whole-wave section and immediately after one (Lower::section_rfl).

Verification

  • Unit tests in victory_shader::emit::wave::tests:
    • whole_wave_const_uniform_cndmask_const_masks_mulu_and_readfirstlane_lower (covering both wave64 single-wave and wave32_host split-wave translation, plus negative refusal checks for prefix products and non-identity inactive inputs)
  • Metal GPU value test in victory_gpu::native::tests::split_wave_tests:
    • whole_wave_const_uniform_prefixes_integer_products_and_readfirstlane_run_across_halves
  • 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 #508
Refs #4, #258
cc @Olima34

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5534334362 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/512). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T23:17:14Z. --- ## Summary - Follow constant (`Sym::K`), uniform (`Sym::Uni`), and idempotent reduction (`Sym::Red`) active-lane terms in `v_cndmask_b32` inside whole-wave sections (for example `v_cndmask_b32 vdst, 0, s_stride, s_mask` for constant-stride prefix scans), as well as constant scalar lane-select masks (`s_mov_b32` / `s_mov_b64` of row or half bitmasks) without requiring `EXEC` saves/restores. - Record per-lane uniform shapes (such as lane `wave - 1` of a `Shape::Prefix` inclusive scan) in `Lower::section_lanes` so a constant-lane `v_readlane_b32` after the section evaluates the total reduction cleanly even when lane `wave - 1` was inactive before the section. - Follow 32-bit integer `WaveActiveProduct` reductions (`v_mul_lo_u32` and `s_mul_i32`, identity `1`) across single and split wave64 host waves (`halves_reduce`), while keeping prefix products refused. - Follow `v_readfirstlane_b32` under a known constant `EXEC` mask (`exec.trailing_zeros()`) both inside a whole-wave section and immediately after one (`Lower::section_rfl`). ## Verification - Unit tests in `victory_shader::emit::wave::tests`: - `whole_wave_const_uniform_cndmask_const_masks_mulu_and_readfirstlane_lower` (covering both wave64 single-wave and `wave32_host` split-wave translation, plus negative refusal checks for prefix products and non-identity inactive inputs) - Metal GPU value test in `victory_gpu::native::tests::split_wave_tests`: - `whole_wave_const_uniform_prefixes_integer_products_and_readfirstlane_run_across_halves` - `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 #508 Refs #4, #258 cc @Olima34
Olima34 commented 2026-11-27 23:21:05 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T23:21:05Z.


Thanks @Sheffy007, this is right on our current focus. We're now working on translator coverage, to get as many refused world shaders as possible to translate, and whole-wave sections are one of the larger families. We'll run #512 over our boot corpora (4,921 translated and 4,129 refused containers), by output fingerprint as for #464, and post gained / lost / changed per stage here. We'll also note the overlap with marcus-4's #438 and with your own #448 and #464 where they touch the same sections.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7230073436 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/512#issuecomment-7230073436). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T23:21:05Z. --- Thanks @Sheffy007, this is right on our current focus. We're now working on translator coverage, to get as many refused world shaders as possible to translate, and whole-wave sections are one of the larger families. We'll run #512 over our boot corpora (4,921 translated and 4,129 refused containers), by output fingerprint as for #464, and post gained / lost / changed per stage here. We'll also note the overlap with marcus-4's #438 and with your own #448 and #464 where they touch the same sections.
Olima34 commented 2026-11-28 01:31:54 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T01:31:54Z.


Thanks for this PR! An offline check of b864cf72, with no game run:

Corpus sweep (examples/sweep + tools/corpus/compare.sh), measured on main a6a58361, which translates shaders the same way as current main 226645f9. Main → main + #512:

set newly translated output changed regressions
A (4,921 boot shaders) 0 0 0
B (4,129 boot shaders) 0 0 0
W (21,600 world shaders) 0 0 0

No shader in these three sets has a whole-wave section of the kind #512 handles as its first refusal, so this is a no-regression check rather than a coverage measurement.

Checks: on an earlier main (b998bb65) + #512, the tests (victory-gpu on arm64, victory-hle, victory, xtask, victory-shader), Windows clippy (-D warnings) and cargo xtask policy all pass. CI is green on b864cf72.

Merging on a6a58361:

  • #512 merges cleanly with #448, #464 and #516.
  • With #438, the only conflict is in split_wave_tests.rs: both PRs add GPU tests at the same spot.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7231731611 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/512#issuecomment-7231731611). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T01:31:54Z. --- Thanks for this PR! An offline check of b864cf72, with no game run: **Corpus sweep** (`examples/sweep` + `tools/corpus/compare.sh`), measured on main a6a58361, which translates shaders the same way as current main 226645f9. Main → main + #512: | set | newly translated | output changed | regressions | |---|---|---|---| | A (4,921 boot shaders) | 0 | 0 | 0 | | B (4,129 boot shaders) | 0 | 0 | 0 | | W (21,600 world shaders) | 0 | 0 | 0 | No shader in these three sets has a whole-wave section of the kind #512 handles as its first refusal, so this is a no-regression check rather than a coverage measurement. **Checks:** on an earlier main (b998bb65) + #512, the tests (victory-gpu on arm64, victory-hle, victory, xtask, victory-shader), Windows clippy (`-D warnings`) and `cargo xtask policy` all pass. CI is green on b864cf72. **Merging on a6a58361:** - #512 merges cleanly with #448, #464 and #516. - With #438, the only conflict is in `split_wave_tests.rs`: both PRs add GPU tests at the same spot.
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/512:upstream-pr/512'
git switch 'upstream-pr/512'

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