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

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

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T17:31:51Z.


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 #414
Refs #4, #258

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5530708585 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/420). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T17:31:51Z. --- ## 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 #414 Refs #4, #258
Olima34 commented 2026-11-28 00:37:10 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T00:37:10Z.

Review: CHANGES_REQUESTED


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6094669103 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/420#pullrequestreview-6094669103). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T00:37:10Z. **Review:** CHANGES_REQUESTED --- 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 commented 2026-11-28 00:46:56 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-28T00:46:56Z.


The maintainer is handling this one himself; please follow his lead rather than my review.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7231186903 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/420#issuecomment-7231186903). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T00:46:56Z. --- The maintainer is handling this one himself; please follow his lead rather than my review.
Olima34 commented 2026-11-28 02:00:33 +00:00 (Migrated from github.com)

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


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 #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:7232065071 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/420#issuecomment-7232065071). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-28T02:00:33Z. --- 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 #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/420:upstream-pr/420'
git switch 'upstream-pr/420'

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