shader: lower ds_append and ds_consume in wave64 compute shaders split across 32-lane host waves #414

Open
opened 2026-11-27 17:22:23 +00:00 by Sheffy007 · 2 comments
Sheffy007 commented 2026-11-27 17:22:23 +00:00 (Migrated from github.com)
Contributor

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


Problem

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 are refused under Options::wave32_host (Lower::ds_gds, crates/victory-shader/src/emit/lower.rs:5319).

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 (after which the shader typically adds its 64-lane v_mbcnt prefix). Issuing an independent atomic per 32-lane host half would either double-count the lower half's prefix or interleave waves non-contiguously.

Plan

  • Extend lower/halves.rs with Lower::wide_append:
    1. Require exchange_site(self.cur_ir)? (returns DIVERGENT_EXCHANGE when the halves may diverge, which automatically enables ir::keep_lanes_to_end and single-wave lockstep retries, while keeping genuinely divergent multi-wave sites refused).
    2. Gather 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 compute n = popcount(lo) + popcount(hi).
    3. Have 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 write old to xchg[wave], framed by xchg_barriers so every active lane in both 32-lane host halves reads old while inactive lanes keep outside.
  • Add lowering tests in gfx_refusal_tests.rs (64-lane uniform, s_cbranch_execz early-exit, single-wave divergent lockstep, 128-lane uniform, and 128-lane divergent refusal) plus a Metal GPU test in split_wave_tests.rs verifying ds_append + v_mbcnt and ds_consume across split 64-lane and 128-lane groups.

Refs #4, #258

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6651437262 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/414). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T17:22:23Z. --- ## Problem 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` are refused under `Options::wave32_host` (`Lower::ds_gds`, `crates/victory-shader/src/emit/lower.rs:5319`). 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 (after which the shader typically adds its 64-lane `v_mbcnt` prefix). Issuing an independent atomic per 32-lane host half would either double-count the lower half's prefix or interleave waves non-contiguously. ## Plan - Extend `lower/halves.rs` with `Lower::wide_append`: 1. Require `exchange_site(self.cur_ir)?` (returns `DIVERGENT_EXCHANGE` when the halves may diverge, which automatically enables `ir::keep_lanes_to_end` and single-wave `lockstep` retries, while keeping genuinely divergent multi-wave sites refused). 2. Gather 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 compute `n = popcount(lo) + popcount(hi)`. 3. Have 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 write `old` to `xchg[wave]`, framed by `xchg_barrier`s so every active lane in both 32-lane host halves reads `old` while inactive lanes keep `outside`. - Add lowering tests in `gfx_refusal_tests.rs` (64-lane uniform, `s_cbranch_execz` early-exit, single-wave divergent lockstep, 128-lane uniform, and 128-lane divergent refusal) plus a Metal GPU test in `split_wave_tests.rs` verifying `ds_append` + `v_mbcnt` and `ds_consume` across split 64-lane and 128-lane groups. Refs #4, #258
Sheffy007 commented 2026-11-27 17:22:24 +00:00 (Migrated from github.com)
Author
Contributor

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


/claim

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7224332936 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/414#issuecomment-7224332936). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-27T17:22:24Z. --- /claim
github-actions[bot] commented 2026-11-27 17:22:36 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T17:22:36Z.


Claimed by @Sheffy007. Open a draft pull request with Refs #414 in its description within 24 hours, or the claim expires.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7224336344 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/414#issuecomment-7224336344). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-27T17:22:36Z. --- Claimed by @Sheffy007. Open a draft pull request with `Refs #414` in its description within 24 hours, or the claim expires.
Sign in to join this conversation.
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#414
No description provided.