shader: lower ds_append and ds_consume on split wave64 compute waves (#414) #424

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

@⁠Sheffy007 on GitHub · 2026-11-27 17:31 UTC · original
Sheffy007:feat/split-wave-ds-append-consume → main · +208 −21 · 5 files · 1 commits · open

Summary

In world runs on main (#4 refusal table: 3 | 3 | 0 | ds_append or ds_consume in a console wave the host splits), wave64 compute shaders with more than 32 threads per group that execute ds_append or ds_consume were refused under Options::wave32_host.

On RDNA2, ds_append / ds_consume performs one atomic add/subtract of popcount(EXEC) at LDS[M0 + offset] for the 64-lane console wave and returns that wave-wide old value to every active lane in the console wave.

Changes

  • Add Lower::wide_append in crates/victory-shader/src/emit/lower/halves.rs and call it from Lower::ds_gds when self.halves is true:
    1. Checks exchange_site(self.cur_ir)?, automatically enabling ir::keep_lanes_to_end and single-wave lockstep retries on divergent 64-lane shaders while keeping genuinely divergent multi-wave sites refused with DIVERGENT_EXCHANGE.
    2. Gathers the console wave's 64-bit active ballot (lo, hi) via wide_ballot (zeroing missing upper halves when the group size is not a multiple of 64) and computes n = popcount(lo) + popcount(hi).
    3. Has the console wave's first active lane (firstbitlow(lo), or 32 + firstbitlow(hi) when lo == 0, gated on n != 0) perform the single Rmw::Add / Rmw::Sub on LDS[M0 + offset] and publish old to xchg[wave] between xchg_barriers so every active lane in both 32-lane host halves receives old while inactive lanes keep outside.
  • Update gfx_refusal_tests::lds_instructions_addressed_by_m0_translate and wave32_tests::a_barrier_block_behind_a_branch_on_an_lds_word_read_after_a_barrier (which now exercises barrier_reads's ds_append write-hazard rule directly to DIVERGENT_EXCHANGE).
  • Add Metal GPU compute test ds_append_and_consume_across_split_host_waves in split_wave_tests.rs verifying both:
    1. Single-wave 64-thread divergent if (v0 < 40) ds_append across lower (32) + upper (8) halves;
    2. Two-wave 128-thread ds_append + ds_consume with odd lanes active (console lane 0 inactive in both waves).

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

Closes #418
Refs #4, #258

**@⁠Sheffy007** on GitHub · 2026-11-27 17:31 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/420) `Sheffy007:feat/split-wave-ds-append-consume` → `main` · +208 −21 · 5 files · 1 commits · open ## Summary In world runs on `main` (#4 refusal table: `3 | 3 | 0 | ds_append or ds_consume in a console wave the host splits`), wave64 compute shaders with more than 32 threads per group that execute `ds_append` or `ds_consume` were refused under `Options::wave32_host`. On RDNA2, `ds_append` / `ds_consume` performs **one** atomic add/subtract of `popcount(EXEC)` at `LDS[M0 + offset]` for the 64-lane console wave and returns that wave-wide `old` value to every active lane in the console wave. ## Changes - Add `Lower::wide_append` in `crates/victory-shader/src/emit/lower/halves.rs` and call it from `Lower::ds_gds` when `self.halves` is true: 1. Checks `exchange_site(self.cur_ir)?`, automatically enabling `ir::keep_lanes_to_end` and single-wave `lockstep` retries on divergent 64-lane shaders while keeping genuinely divergent multi-wave sites refused with `DIVERGENT_EXCHANGE`. 2. Gathers the console wave's 64-bit active ballot `(lo, hi)` via `wide_ballot` (zeroing missing upper halves when the group size is not a multiple of 64) and computes `n = popcount(lo) + popcount(hi)`. 3. Has the console wave's first active lane (`firstbitlow(lo)`, or `32 + firstbitlow(hi)` when `lo == 0`, gated on `n != 0`) perform the single `Rmw::Add` / `Rmw::Sub` on `LDS[M0 + offset]` and publish `old` to `xchg[wave]` between `xchg_barrier`s so every active lane in both 32-lane host halves receives `old` while inactive lanes keep `outside`. - Update `gfx_refusal_tests::lds_instructions_addressed_by_m0_translate` and `wave32_tests::a_barrier_block_behind_a_branch_on_an_lds_word_read_after_a_barrier` (which now exercises `barrier_reads`'s `ds_append` write-hazard rule directly to `DIVERGENT_EXCHANGE`). - Add Metal GPU compute test `ds_append_and_consume_across_split_host_waves` in `split_wave_tests.rs` verifying both: 1. Single-wave 64-thread divergent `if (v0 < 40)` `ds_append` across lower (32) + upper (8) halves; 2. Two-wave 128-thread `ds_append` + `ds_consume` with odd lanes active (console lane 0 inactive in both waves). ## 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 Closes #418 Refs #4, #258
Wave64 compute shaders with more than 32 threads per group executing
ds_append or ds_consume were refused under Options::wave32_host (3 compute
shaders in world runs, #4).

Add Lower::wide_append in lower/halves.rs:
- Require exchange_site(self.cur_ir)? so divergent single-wave sites retry
  through keep_lanes_to_end / lockstep while divergent multi-wave sites
  remain safely refused with DIVERGENT_EXCHANGE.
- Gather the 64-lane active ballot (lo, hi) via wide_ballot and compute the
  active lane count across both 32-lane host halves.
- Have the console wave's first active lane (when n != 0) perform the single
  atomic add/sub on LDS[M0 + offset] and publish old via xchg[wave] between
  group barriers, preserving outside for inactive lanes.

Add lowering tests in gfx_refusal_tests.rs and wave32_tests.rs plus an
end-to-end Metal GPU compute test in split_wave_tests.rs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 17:39:14 +00:00
github-bot force-pushed github-bot/gh-420 from b2d0b88f53 to 3062bbf39e 2026-11-28 00:42:44 +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/420#pullrequestreview-6094669103) · **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/420#issuecomment-7231186903) 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 b2d0b88f. The current head 3062bbf3 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.

#420 alone:

  • Newly translated: 16 compute, all previously refused for "ds_append or ds_consume in a console wave the host splits".
  • Refused for another reason now: 5 (4 now stop at "a cross-lane operation between host waves in divergent code", 1 at "… written by a scalar instruction of the other width").
  • Outputs changed: 0.
  • Regressions: 0.
  • Passes/frame: about 17, the largest of the eight.

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/420#issuecomment-7232065071) Thanks for this PR! An offline check of b2d0b88f. The current head 3062bbf3 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. **#420 alone:** - **Newly translated:** 16 compute, all previously refused for "ds_append or ds_consume in a console wave the host splits". - **Refused for another reason now:** 5 (4 now stop at "a cross-lane operation between host waves in divergent code", 1 at "… written by a scalar instruction of the other width"). - **Outputs changed:** 0. - **Regressions:** 0. - **Passes/frame:** about 17, the largest of the eight. **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/424/head:github-bot/gh-420'
git switch 'github-bot/gh-420'

Merge

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