Shaders: multi-wave group_any widen, guarded resources, and s_setpc early-out strip #1124

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

@⁠nameermohammedkhan-art on GitHub · 2026-11-25 20:42 UTC · original
nameermohammedkhan-art:pr/wave32-group-any-widen → main · +820 −97 · 6 files · 1 commits · open

Summary

  • Extend Wave64->Wave32 widen to support multi-wave compute threadgroups (all_group_blocks convergence + wave_wide cross-wave LDS reduction for group_any / group_all).
  • Track per-instruction EXEC guards in resource::Tracer::active so resource provenance prunes unreachable lanes after without_early_outs strips s_cbranch_execz / s_setpc early-out paths (VICTORY_WAVE_DEEP_SKIPS=0 disables).
  • Skip cross-half exchange for singleton v_readfirstlane_b32 narrowed by v_cmpx_eq_{i,u}32 against v_mbcnt (single_lane_readfirstlane).
  • Keep lower.rs under the 512 KiB xtask policy limit by placing the group-convergence / singleton helpers in crates/victory-shader/src/emit/group_wide.rs.
  • Adds hardware/unit tests in wave64_tests.rs and resource.rs.

Validation

  • cargo xtask policy: asset policy: 184 files ok
  • cargo clippy -p victory-shader --all-targets -- -D warnings: passed (0 warnings)
  • cargo test -p victory-shader --lib: 220 passed; 0 failed; 3 ignored (includes hardware execution test multi_wave_widen_runs_group_any_on_hardware)
  • Tested in Series X 1.0.2.1 prologue on RTX 5070 Ti (Wave32).
**@⁠nameermohammedkhan-art** on GitHub · 2026-11-25 20:42 UTC · [original](https://github.com/fxceless/victory-fork/pull/1124) `nameermohammedkhan-art:pr/wave32-group-any-widen` → `main` · +820 −97 · 6 files · 1 commits · open ## Summary - Extend Wave64->Wave32 `widen` to support multi-wave compute threadgroups (`all_group_blocks` convergence + `wave_wide` cross-wave LDS reduction for `group_any` / `group_all`). - Track per-instruction `EXEC` guards in `resource::Tracer::active` so resource provenance prunes unreachable lanes after `without_early_outs` strips `s_cbranch_execz` / `s_setpc` early-out paths (`VICTORY_WAVE_DEEP_SKIPS=0` disables). - Skip cross-half exchange for singleton `v_readfirstlane_b32` narrowed by `v_cmpx_eq_{i,u}32` against `v_mbcnt` (`single_lane_readfirstlane`). - Keep `lower.rs` under the 512 KiB `xtask policy` limit by placing the group-convergence / singleton helpers in `crates/victory-shader/src/emit/group_wide.rs`. - Adds hardware/unit tests in `wave64_tests.rs` and `resource.rs`. ## Validation - `cargo xtask policy`: `asset policy: 184 files ok` - `cargo clippy -p victory-shader --all-targets -- -D warnings`: passed (0 warnings) - `cargo test -p victory-shader --lib`: `220 passed; 0 failed; 3 ignored` (includes hardware execution test `multi_wave_widen_runs_group_any_on_hardware`) - Tested in Series X 1.0.2.1 prologue on RTX 5070 Ti (Wave32).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:57:56 +00:00
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 23:40 UTC · original · edited 2026-11-26 00:12 UTC

Runnable two-store regression and experimental fix: fixture, patch and reproduction commands. On 887d053, the RTX 3050 Laptop produced 4,096 unexpected writes inside the branch and 4,096 after the join. Guarding only the in-branch store left all 4,096 post-join errors. Selecting the incoming EXEC mask of each skipped guest wave at the join also removed those errors (33,280 output words checked). This is a single-block synthetic case; visual impact and complex control flow remain unverified.

Correctness counterexample on PR head 887d053 (RTX 3050 Laptop, native wave32). With the public translator and VICTORY_WAVE_WIDE=1, a guest wave with empty EXEC loses a live scalar value when the other guest wave takes the body. This matters if enabling multi-wave widening for additional shaders.

Reproducer using the 128-thread per-lane variant below: preserve the per-thread byte offset in v9. Before s_and_saveexec_b64 initialize s7=5 (0xBE870385). Immediately after SAVEEXEC branch with s_cbranch_scc0 +20 (0xBF840014) over exactly WAVE_OR_V7_TO_S7. At the join restore EXEC from s[12:13], then copy s7 to v0 and store to each thread's own word. Keep the existing predicate t > threshold. With threshold 63, guest wave 0 skips all writes to s7 and must store 5 into words 0..63. It instead stores zero into all 64. Guest wave 1 produces the expected 0xffffffff. The retry diagnostic confirms wave-wide branches, wave Some(32).

Across thresholds 0..128 inclusive plus 200, precisely 63..126 fail, each by those first 64 words (4,096 of 16,640 comparisons). Both-active and both-empty controls pass. The earlier masked-store fixture below passed because it did not observe the scalar from an empty wave after reconvergence. Please retain the original rejection for this case until the per-wave scalar at the join is preserved. Synthetic fixture only, AI-assisted.


One additional hardware test case for multi_wave_widen_runs_group_any_on_hardware at 887d053: keep the 128-thread group, set s0 to 32, and give each lane its own output word (preserve its thread index before overwriting v0). With the existing t > s0 predicate and OR expression, lanes 0..32 should retain a sentinel, lanes 33..63 should write 0xffff0000, and lanes 64..127 should write 0xffffffff.

I checked those expectations with a synthetic CPU reference and a deliberately group-wide OR. The latter differs on 31 words here, versus zero at the current thresholds of 96 and 200. Distinct output words also avoid the two active guest waves racing on the same address. This is a coverage suggestion; I have not observed incorrect output on the PR. AI-assisted.

Hardware follow-up at the same head: tested the per-lane variant on an RTX 3050 Laptop (native wave32), with a zero-initialized 128-word UAV, for every threshold from 0 through 128 and also 200. All 16,640 output words across 130 dispatches matched the per-guest-wave CPU expectation. Pipeline creation and dispatch were required for the test to pass. This covers correctness of the synthetic fixture only.

Public translation path, parent versus head on the same RTX: in the per-lane fixture above, replace s_cbranch_execz +23 (0xBF880017) immediately following s_and_saveexec_b64 with s_cbranch_scc0 +23 (0xBF840017). SAVEEXEC sets SCC according to whether the resulting EXEC is nonempty, so the expected lane outputs are unchanged. With VICTORY_WAVE_WIDE=1, parent 085ee7c refuses multi-wave widening and falls through to approximate local waves (threshold 0, lane 1: 0x0000ffff instead of 0xffffffff). Head 887d053 takes the wave-wide retry and passes all 16,640 word checks. With the switch unset both commits take the approximation and fail at that same lane. Under VICTORY_WAVE_LOCAL=idiom with widening enabled, the parent refuses translation and the head passes. This isolates a correctness improvement through translate() on native wave32. No frame-time or title-shader claim.

**@⁠Dathinel** on GitHub · 2026-11-25 23:40 UTC · [original](https://github.com/fxceless/victory-fork/pull/1124#issuecomment-7177885870) · edited 2026-11-26 00:12 UTC **Runnable two-store regression and experimental fix:** [fixture, patch and reproduction commands](https://github.com/Dathinel/victory-fork/blob/ff8bca076e464b87d3e827b4e7176cb411975661/docs/wave32-exec-report.md). On 887d053, the RTX 3050 Laptop produced 4,096 unexpected writes inside the branch and 4,096 after the join. Guarding only the in-branch store left all 4,096 post-join errors. Selecting the incoming EXEC mask of each skipped guest wave at the join also removed those errors (33,280 output words checked). This is a single-block synthetic case; visual impact and complex control flow remain unverified. **Correctness counterexample on PR head 887d053 (RTX 3050 Laptop, native wave32).** With the public translator and VICTORY_WAVE_WIDE=1, a guest wave with empty EXEC loses a live scalar value when the other guest wave takes the body. This matters if enabling multi-wave widening for additional shaders. Reproducer using the 128-thread per-lane variant below: preserve the per-thread byte offset in v9. Before s_and_saveexec_b64 initialize s7=5 (0xBE870385). Immediately after SAVEEXEC branch with s_cbranch_scc0 +20 (0xBF840014) over exactly WAVE_OR_V7_TO_S7. At the join restore EXEC from s[12:13], then copy s7 to v0 and store to each thread's own word. Keep the existing predicate t > threshold. With threshold 63, guest wave 0 skips all writes to s7 and must store 5 into words 0..63. It instead stores zero into all 64. Guest wave 1 produces the expected 0xffffffff. The retry diagnostic confirms wave-wide branches, wave Some(32). Across thresholds 0..128 inclusive plus 200, precisely 63..126 fail, each by those first 64 words (4,096 of 16,640 comparisons). Both-active and both-empty controls pass. The earlier masked-store fixture below passed because it did not observe the scalar from an empty wave after reconvergence. Please retain the original rejection for this case until the per-wave scalar at the join is preserved. Synthetic fixture only, AI-assisted. --- One additional hardware test case for `multi_wave_widen_runs_group_any_on_hardware` at 887d053: keep the 128-thread group, set s0 to 32, and give each lane its own output word (preserve its thread index before overwriting v0). With the existing `t > s0` predicate and OR expression, lanes 0..32 should retain a sentinel, lanes 33..63 should write 0xffff0000, and lanes 64..127 should write 0xffffffff. I checked those expectations with a synthetic CPU reference and a deliberately group-wide OR. The latter differs on 31 words here, versus zero at the current thresholds of 96 and 200. Distinct output words also avoid the two active guest waves racing on the same address. This is a coverage suggestion; I have not observed incorrect output on the PR. AI-assisted. Hardware follow-up at the same head: tested the per-lane variant on an RTX 3050 Laptop (native wave32), with a zero-initialized 128-word UAV, for every threshold from 0 through 128 and also 200. All 16,640 output words across 130 dispatches matched the per-guest-wave CPU expectation. Pipeline creation and dispatch were required for the test to pass. This covers correctness of the synthetic fixture only. Public translation path, parent versus head on the same RTX: in the per-lane fixture above, replace s_cbranch_execz +23 (0xBF880017) immediately following s_and_saveexec_b64 with s_cbranch_scc0 +23 (0xBF840017). SAVEEXEC sets SCC according to whether the resulting EXEC is nonempty, so the expected lane outputs are unchanged. With VICTORY_WAVE_WIDE=1, parent 085ee7c refuses multi-wave widening and falls through to approximate local waves (threshold 0, lane 1: 0x0000ffff instead of 0xffffffff). Head 887d053 takes the wave-wide retry and passes all 16,640 word checks. With the switch unset both commits take the approximation and fail at that same lane. Under VICTORY_WAVE_LOCAL=idiom with widening enabled, the parent refuses translation and the head passes. This isolates a correctness improvement through translate() on native wave32. No frame-time or title-shader claim.
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-26 09:29 UTC · original

Dathinel's two-store regression on a second vendor: RX 7900 XTX (RDNA3), driver 32.0.32015.7029, Windows 10 22H2, 887d053 on main 46bf535 + #402 (Agility), VICTORY_WAVE_WIDE=1.

  • wave32-exec-regression.patch: the retry reports wave Some(32) and multi_wave_stores_respect_exec_after_the_join gives [4096, 4096], 2 runs of 2, the same counts as the RTX 3050.
  • Plus wave32-exec-candidate.patch: that test passes 2 of 2; with the switch set the whole victory-shader run is 223 passed, 0 failed.

So the counterexample is not NVIDIA-specific. The PR's own 5 new tests pass here too (221 passed, 0 failed without the patches, on main 32b31f7 + #402).

AI-assisted (Claude Code): tests run on my machine, text drafted with Claude.

**@⁠HAL9000RELOADED** on GitHub · 2026-11-26 09:29 UTC · [original](https://github.com/fxceless/victory-fork/pull/1124#issuecomment-7188062216) Dathinel's two-store regression on a second vendor: RX 7900 XTX (RDNA3), driver 32.0.32015.7029, Windows 10 22H2, `887d053` on main `46bf535` + #402 (Agility), `VICTORY_WAVE_WIDE=1`. - `wave32-exec-regression.patch`: the retry reports `wave Some(32)` and `multi_wave_stores_respect_exec_after_the_join` gives `[4096, 4096]`, 2 runs of 2, the same counts as the RTX 3050. - Plus `wave32-exec-candidate.patch`: that test passes 2 of 2; with the switch set the whole `victory-shader` run is 223 passed, 0 failed. So the counterexample is not NVIDIA-specific. The PR's own 5 new tests pass here too (221 passed, 0 failed without the patches, on main `32b31f7` + #402). _AI-assisted (Claude Code): tests run on my machine, text drafted with Claude._
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/wave64_tests.rs
  • crates/victory-shader/src/ir.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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