Shaders: a divergent aggregated atomic aggregates per host half in wave64 emulation #3822

Open
omarsaifuddin wants to merge 21 commits from upstream-pr/3822 into main
omarsaifuddin commented 2026-11-29 05:34:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by omarsaifuddin on 2026-11-29T05:34:31Z.


Stacked on #189 (base 3e39e34). The change is the last two commits; the rest of the diff is #189's branch:

  • a98b70a Shaders: a divergent aggregated atomic aggregates per host half in wave64 emulation
  • fe81664 Shaders: tests for the divergent aggregated atomic

What

Under Wave64Mode::Emulate, a 64-lane ballot in divergent control flow is refused (a 64-lane wave ballot in divergent control flow). That refusal also catches the compiler's append idiom: elect the first active lane (s_ff1_i32_b64), popcount the mask (s_bcnt1_i32_b64), one buffer_atomic_add from the elected lane, then broadcast the base so every lane adds its own rank. Several of the heaviest dropped world programs are this shape.

This lets each host half ballot only its own lanes when that cannot change the result:

  • every data use of the lane mask is a count (s_bcnt1_i32_b64), a first lane (s_ff1_i32_b64), or a lane rank (v_mbcnt_*);
  • the count flows only into an atomic add, and the election is present; or a wave reduction flows only into a no-return atomic of the same kind (add / min / max / and / or / xor).

Each half then aggregates its own lanes into its own distinct slot; only the order the two halves append differs from the console. Anything else — the count read as data, a returned atomic, a reduction used as a value, a different atomic kind — still refuses, so the path is proof-gated rather than an unconditional per-half fallback.

Measured

RTX 3070 Ti, Windows 11, scripted from boot into the prologue (#189 comment); the stack was the one reported in #3330: main 63bcca4 + #3226 + #2323 + #2885 + #3518 + #3016 + #2348 + #3670 + #3496 + #3587 + #3588 + #189 + #3200.

  • Shaders refused at runtime: 117 → 95, including the heaviest dropped program.
  • No device removal.
  • On that stack: victory-shader 304 passed / 0 failed / 3 ignored, victory-gpu 236 / 0 / 1.

One card and one scripted path, so this is a data point, not proof.

Tests

Two unit tests in emit::wave64_tests:

  • divergent_count_added_by_an_atomic_emits_under_emulate — the idiom emits under Emulate.
  • divergent_count_used_as_data_besides_an_atomic_is_refused — the same count also used as data is still refused.

Both pass at 3e39e34 + these commits, and cargo clippy -p victory-shader --all-targets --locked -- -D warnings is clean.

Relation to other wave64 work

This is the proof-gated counterpart to #1890's unconditional per-half shortcut: in divergent code: #1890 lets each half use its own lanes for everything divergent and notes that is right for wave-aggregated atomics; this PR takes only the atomic shapes it can prove and keeps refusing the rest.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5547939841 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3822). Originally posted by [omarsaifuddin](https://github.com/omarsaifuddin) on 2026-11-29T05:34:31Z. --- Stacked on #189 (base `3e39e34`). The change is the **last two commits**; the rest of the diff is #189's branch: - `a98b70a` Shaders: a divergent aggregated atomic aggregates per host half in wave64 emulation - `fe81664` Shaders: tests for the divergent aggregated atomic ## What Under `Wave64Mode::Emulate`, a 64-lane ballot in divergent control flow is refused (`a 64-lane wave ballot in divergent control flow`). That refusal also catches the compiler's append idiom: elect the first active lane (`s_ff1_i32_b64`), popcount the mask (`s_bcnt1_i32_b64`), one `buffer_atomic_add` from the elected lane, then broadcast the base so every lane adds its own rank. Several of the heaviest dropped world programs are this shape. This lets each host half ballot only its own lanes when that cannot change the result: - every data use of the lane mask is a count (`s_bcnt1_i32_b64`), a first lane (`s_ff1_i32_b64`), or a lane rank (`v_mbcnt_*`); - the count flows only into an atomic add, and the election is present; or a wave reduction flows only into a no-return atomic of the same kind (add / min / max / and / or / xor). Each half then aggregates its own lanes into its own distinct slot; only the order the two halves append differs from the console. Anything else — the count read as data, a returned atomic, a reduction used as a value, a different atomic kind — still refuses, so the path is proof-gated rather than an unconditional per-half fallback. ## Measured RTX 3070 Ti, Windows 11, scripted from boot into the prologue ([#189 comment](https://github.com/Marvisak/VIctory/pull/189#issuecomment-7243234077)); the stack was the one reported in [#3330](https://github.com/Marvisak/VIctory/issues/3330#issuecomment-7240498162): main `63bcca4` + #3226 + #2323 + #2885 + #3518 + #3016 + #2348 + #3670 + #3496 + #3587 + #3588 + #189 + #3200. - Shaders refused at runtime: **117 → 95**, including the heaviest dropped program. - No device removal. - On that stack: `victory-shader` 304 passed / 0 failed / 3 ignored, `victory-gpu` 236 / 0 / 1. One card and one scripted path, so this is a data point, not proof. ## Tests Two unit tests in `emit::wave64_tests`: - `divergent_count_added_by_an_atomic_emits_under_emulate` — the idiom emits under Emulate. - `divergent_count_used_as_data_besides_an_atomic_is_refused` — the same count also used as data is still refused. Both pass at `3e39e34` + these commits, and `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` is clean. ## Relation to other wave64 work This is the proof-gated counterpart to #1890's unconditional per-half `shortcut:` in divergent code: #1890 lets each half use its own lanes for everything divergent and notes that is right for wave-aggregated atomics; this PR takes only the atomic shapes it can prove and keeps refusing the rest.
kilolimaVI commented 2026-11-29 17:17:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-29T17:17:01Z.


AMD run on a Radeon 780M (RDNA3, wave32 and wave64), head merged as is onto main 63bcca4, cargo test --profile diag -p <crate> --locked --lib:

victory-shader victory-gpu
main 302 passed, 0 failed 231 passed, 0 failed
this PR 340 passed, 0 failed 232 passed, 0 failed
this PR, VICTORY_WAVE64_EMULATE=emulate 340 passed, 0 failed 232 passed, 0 failed
this PR, VICTORY_WAVE64_EMULATE=wave32 340 passed, 0 failed 232 passed, 0 failed

No regressions on AMD. The three runs are identical, so I'd guess the variable only reaches the runtime shader cache and the tests pick their own mode; if there's a way to force the emulated path in the GPU tests on a wave64-capable card, I can rerun with it. For what it's worth, #3823 (stacked with #3824 and #3830) also passes everything on the same card (356 / 232), and the two conflict.

AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7259567941 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3822#issuecomment-7259567941). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-29T17:17:01Z. --- AMD run on a Radeon 780M (RDNA3, wave32 and wave64), head merged as is onto main 63bcca4, `cargo test --profile diag -p <crate> --locked --lib`: | | victory-shader | victory-gpu | |---|---|---| | main | 302 passed, 0 failed | 231 passed, 0 failed | | this PR | 340 passed, 0 failed | 232 passed, 0 failed | | this PR, `VICTORY_WAVE64_EMULATE=emulate` | 340 passed, 0 failed | 232 passed, 0 failed | | this PR, `VICTORY_WAVE64_EMULATE=wave32` | 340 passed, 0 failed | 232 passed, 0 failed | No regressions on AMD. The three runs are identical, so I'd guess the variable only reaches the runtime shader cache and the tests pick their own mode; if there's a way to force the emulated path in the GPU tests on a wave64-capable card, I can rerun with it. For what it's worth, #3823 (stacked with #3824 and #3830) also passes everything on the same card (356 / 232), and the two conflict. AI-assisted (Claude).
omarsaifuddin commented 2026-11-30 07:37:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by omarsaifuddin on 2026-11-30T07:37:21Z.


Ran the full stack through the prologue on an RTX 3070 Ti (Windows 11, driver 32.0.16.2140, 1440p). Stack: main 63bcca4 + #189 + #3200 + #2703 + #2118 + #3016 + #2348 + #3670 + #3496 + #3587 + #3588 + #3226 + #2323 + #2885 + #3518 (+ the local capped-heap edits from #3330) + this PR.

  • A 20-minute run reached the prologue (captures at frames 2400-3200); no device removal.
  • Runtime refusals: 95 distinct shaders — 51 LDS without a uniform fence, 22 divergent 64-lane ballots, 15 divergent reductions, 4 divergent cross-lane reads, 2 LDS >32 KiB, 1 descriptor read only as data.
  • Full-pack cache census: 485 refused containers without the two commits, 457 with them — 28 programs now translate.
  • A/B: a build from the same stack without the two commits renders the same cutscene frames the same way (a layered/ghosted shot at frame 2400), so that ghosting is not from this change.

Caveat: the run also hits host view heap overflow slots exhausted (noted in #3870) and the world is still about 1 fps, so this shows the patch runs in the title, not that every accepted idiom is right.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7271937570 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3822#issuecomment-7271937570). Originally posted by [omarsaifuddin](https://github.com/omarsaifuddin) on 2026-11-30T07:37:21Z. --- Ran the full stack through the prologue on an RTX 3070 Ti (Windows 11, driver 32.0.16.2140, 1440p). Stack: `main` `63bcca4` + #189 + #3200 + #2703 + #2118 + #3016 + #2348 + #3670 + #3496 + #3587 + #3588 + #3226 + #2323 + #2885 + #3518 (+ the local capped-heap edits from #3330) + this PR. - A 20-minute run reached the prologue (captures at frames 2400-3200); **no device removal**. - Runtime refusals: **95** distinct shaders — 51 LDS without a uniform fence, 22 divergent 64-lane ballots, 15 divergent reductions, 4 divergent cross-lane reads, 2 LDS >32 KiB, 1 descriptor read only as data. - Full-pack cache census: **485 refused** containers without the two commits, **457** with them — 28 programs now translate. - A/B: a build from the same stack without the two commits renders the same cutscene frames the same way (a layered/ghosted shot at frame 2400), so that ghosting is not from this change. Caveat: the run also hits `host view heap overflow slots exhausted` (noted in #3870) and the world is still about 1 fps, so this shows the patch runs in the title, not that every accepted idiom is right.
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/3822:upstream-pr/3822'
git switch 'upstream-pr/3822'

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