wave64: never emit a barrier a group cannot reach, and cover the whole group in the wave-wide decision #81

Open
github-bot wants to merge 4 commits from github-bot/gh-81 into main AGit
Owner

@⁠Pavl3000 on GitHub · 2026-11-26 02:27 UTC · original
Pavl3000:pr/wave64-wide → main · +233 −19 · 2 files · 4 commits · draft

Four changes to the wave-wide form (widen) for console wave64 compute programs on a 32-lane host. Measured on an RTX 3080 Ti (D3D12 min=32 max=32), tree 0a43566; the context and the numbers are in #37.

What it does

  1. A barrier is never emitted where not every lane runs. exchange_halves puts two group barriers in the current block, and wave_wide only checked that the branch block is all-lane. group_sync now records need(block) for a block that is not, which is the need widen already reacts to, and widen treats an emission that leaves needs as stuck and refuses the program when nothing is left to widen. Such a barrier is a guaranteed 0x887A0006.
  2. The branches that leave a loop holding a barrier are taken wave-wide too (loop_exits_around): a barrier inside a loop whose two halves leave on different iterations waits for threads that are not there.
  3. The wave-wide decision covers the whole group. Each console wave already writes its own pair of exchange dwords (exchange_pair: slot + 2 * (thread >> 6)) and the barrier at the end of exchange_halves has them all in place, so wave_wide ORs every pair of threads.div_ceil(64) instead of only its own half's. No new primitive; 2n LDS loads per thread at a widened branch. widen no longer refuses a group holding several console waves.
  4. all_lanes no longer says a block is left out by some lanes when the structure has no entry for it: all.get(b).copied().unwrap_or(true). false there put spurious needs in front of the widening, which then looked for branches around a block no lane region holds and gave up (WAVE64-WIDE stopped with 1 branches wave-wide: a branch around it cannot be).

Measured

At pipeline creation on the title's nine refused programs (verified by making the pipelines, not by reading logs):

9 refused → 1. Now created: CS_Visibility, CS_Tiling_Generate_Opaque, CS_TransmissionVolumetrics_Tiled, _LocalLights, _Submerged, _VolumePortalsOnly, CS_DefragHeap_ComputeRelocations (128-thread group), CS_CollectTriangles_Meshlets (1024-thread group). Still refused: CS_AlphTransmissionPrefilterMip (2da4beb386509b77, 256).

With VICTORY_WAVE_WHY=1 the barriers each emits and how many stand in a block not every lane runs: 3/0, 51/0, 613/0, 767/0, 255/0, 326/30, 2854/78. The five that ran in a game run, including both world passes, had none.

What is still wrong

The card is still lost (0x887A0006) after about 74 s of frames in the open world. So legality and a group-wide decision are necessary but not sufficient: what is left is v_mbcnt and lane masks read as data inside divergent regions, and the 32 KiB shared-memory budget of the 1024-thread group — the two items #37 names beyond these.

How it can be tested cheaply

A branch of mine also lets translate --warm <file of hashes> take --pipelines, which makes the pipeline for each named hash and drops it: nine programs in about two seconds instead of a sweep of all 26 000 (that sweep cost 2.7 CPU-hours and produced nothing). I left it out of this PR to keep it to the translator; it can be a second one if wanted.

**@⁠Pavl3000** on GitHub · 2026-11-26 02:27 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/81) `Pavl3000:pr/wave64-wide` → `main` · +233 −19 · 2 files · 4 commits · draft Four changes to the wave-wide form (`widen`) for console wave64 compute programs on a 32-lane host. Measured on an RTX 3080 Ti (D3D12 `min=32 max=32`), tree `0a43566`; the context and the numbers are in #37. ## What it does 1. **A barrier is never emitted where not every lane runs.** `exchange_halves` puts two group barriers in the current block, and `wave_wide` only checked that the *branch* block is all-lane. `group_sync` now records `need(block)` for a block that is not, which is the need `widen` already reacts to, and `widen` treats an emission that leaves needs as stuck and refuses the program when nothing is left to widen. Such a barrier is a guaranteed `0x887A0006`. 2. **The branches that leave a loop holding a barrier are taken wave-wide too** (`loop_exits_around`): a barrier inside a loop whose two halves leave on different iterations waits for threads that are not there. 3. **The wave-wide decision covers the whole group.** Each console wave already writes its own pair of exchange dwords (`exchange_pair`: `slot + 2 * (thread >> 6)`) and the barrier at the end of `exchange_halves` has them all in place, so `wave_wide` ORs every pair of `threads.div_ceil(64)` instead of only its own half's. No new primitive; `2n` LDS loads per thread at a widened branch. `widen` no longer refuses a group holding several console waves. 4. **`all_lanes` no longer says a block is left out by some lanes when the structure has no entry for it**: `all.get(b).copied().unwrap_or(true)`. `false` there put spurious needs in front of the widening, which then looked for branches around a block no lane region holds and gave up (`WAVE64-WIDE stopped with 1 branches wave-wide: a branch around it cannot be`). ## Measured At pipeline creation on the title's nine refused programs (verified by making the pipelines, not by reading logs): **9 refused → 1.** Now created: `CS_Visibility`, `CS_Tiling_Generate_Opaque`, `CS_TransmissionVolumetrics_Tiled`, `_LocalLights`, `_Submerged`, `_VolumePortalsOnly`, `CS_DefragHeap_ComputeRelocations` (128-thread group), `CS_CollectTriangles_Meshlets` (1024-thread group). Still refused: `CS_AlphTransmissionPrefilterMip` (`2da4beb386509b77`, 256). With `VICTORY_WAVE_WHY=1` the barriers each emits and how many stand in a block not every lane runs: 3/0, 51/0, 613/0, 767/0, 255/0, 326/30, 2854/78. The five that ran in a game run, including both world passes, had none. ## What is still wrong The card is still lost (`0x887A0006`) after about 74 s of frames in the open world. So legality and a group-wide decision are necessary but not sufficient: what is left is `v_mbcnt` and lane masks read as data inside divergent regions, and the 32 KiB shared-memory budget of the 1024-thread group — the two items #37 names beyond these. ## How it can be tested cheaply A branch of mine also lets `translate --warm <file of hashes>` take `--pipelines`, which makes the pipeline for each named hash and drops it: nine programs in about two seconds instead of a sweep of all 26 000 (that sweep cost 2.7 CPU-hours and produced nothing). I left it out of this PR to keep it to the translator; it can be a second one if wanted.
exchange_halves puts two group barriers in the current block, and wave_wide only checks that the branch block is all-lane; branches_around chose work by lane_regions, which knows per-lane branch regions but nothing about loop membership. A barrier in an all-lane block inside a loop whose halves leave on different iterations waits for threads that are not there: with VICTORY_WAVE_WIDE=1 that lost the card (0x887A0006) after 21-253 lines of frames, on three runs.

loop_exits_around finds, per need block, the blocks in the same cycle that have an edge out of it; where such an exit's test is a lane's own bits (wave_any Some) it is widened as well, and where it is scalar (None) both halves already agree and nothing is needed. branches_around now also says when a loop's exit cannot be followed at all (an indirect exit, or lane_regions None), so widen refuses the program instead of emitting a barrier one host wave may never reach.

Measured on the title's nine refused programs with --warm --pipelines: the same six are created (visibility, tiling, four volumetrics passes) and the three of multi-wave groups are still refused, as before.
VICTORY_WAVE_WHY=1 instrumentation of the barrier sites answered where the device loss came from: of 2 000 group barriers in the three deadlocking programs, 108 stood in blocks not every lane runs - a barrier such a block can never satisfy. Those are not loops; the loops are scalar-conditioned (exits_known=false) and harmless.

group_sync now records need(block) where the block is not all-lane, which is the same need the widening loop already reacts to, and widen treats any emission that leaves needs as stuck rather than done. When nothing is left to widen it returns Unsupported instead of the program, so a pipeline that would hang the group is never created.

After the change, of the nine refused programs three create with every barrier in an all-lane block (measured: 1 383 barriers, 0 in a block not every lane runs): CS_Visibility, CS_TransmissionVolumetrics_Tiled and _LocalLights. The other six - including CS_Tiling_Generate_Opaque - are refused rather than emitted. Not yet run in the game.
Each console wave already writes its own pair of dwords in the exchange slots (exchange_pair: slot + 2 * (thread >> 6)) and the barrier at the end of exchange_halves has them all in place, so the group's decision is the OR of every pair: wave_wide reads them for waves = threads.div_ceil(64) and ORs them into the answer. widen no longer refuses a group holding more than one console wave, because a branch taken this way is entered by every thread and the barriers inside it are reached by all.

Measured on the title's nine: unchanged - the same three create (CS_Visibility, CS_TransmissionVolumetrics_Tiled, _LocalLights) and the same six are refused, the three multi-wave ones for reasons other than this guard (mask as data / v_mbcnt, resource::track, and the 32 KiB shared-memory limit of the 1024-thread group, as #37 lists them). Groundwork that stands on its own; not the missing piece.
all_lanes answered false when the exchange's all-lane map had no entry for the block, which said 'not every lane runs it' about blocks the analysis never saw. That put spurious needs in front of widen, which then looked for branches around a block no lane region holds and gave up ('WAVE64-WIDE stopped with 1 branches wave-wide: a branch around it cannot be').

After the change, eight of the title's nine refused programs create their compute pipeline on a 32-lane host: CS_Visibility, CS_Tiling_Generate_Opaque, four transmission-volumetrics passes, and the three groups of several console waves (128, 256 and 1024 threads) that were refused before. The ninth, CS_AlphTransmissionPrefilterMip (256), is still refused.

Not yet safe to run: 4 922 barriers were recorded in the eight and 124 of them still stand in blocks not every lane runs, so at least one of the eight would hang the group. Which one is the next step, two seconds per program with VICTORY_WAVE_WHY=1.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:31:51 +00:00
Author
Owner

@⁠Bladureau on GitHub · 2026-11-26 14:47 UTC · original

Tested on an RTX 4060 Laptop GPU 8 GB (driver 617.14, D3D12 min=32 max=32), Windows 11, title 1.0.2.1: avatarmanz/main a9400a6 + #209 + this PR, VICTORY_WAVE_WIDE=1, VICTORY_SHADER_KEY=source, every shader translated beforehand with the same settings, Series S.

The device hung during the world load, 3.6 minutes in; the process exited with 0x887A0005. DRED (light): in the first list that did not finish, 8 of 17 commands completed. The first uncompleted one is an indirect dispatch of 2561af9577c47289 (ptfx_CS_lightAtlas_Sprite), followed in the same barrier interval by dispatches of cabb87599722e59a (its NonLocalLights variant).

Offline, the forms these two programs take:

2561af9577c47289 cabb87599722e59a
#209, VICTORY_WAVE_WIDE=1 2 branches taken wave-wide 4e964d2f953f1c29
#209 + this PR, VICTORY_WAVE_WIDE=1 4 branches taken wave-wide 4e964d2f953f1c29
#209 + this PR, no VICTORY_WAVE_WIDE local waves (APPROXIMATE), without early-outs 4e964d2f953f1c29

Without VICTORY_WAVE_WIDE, the same build ran 6.8 minutes with no device removal. So on this GPU the wave-wide form of ptfx_CS_lightAtlas_Sprite still hangs with this PR, although the PR widens two more of its branches. That is the program emit/mod.rs names as the reason VICTORY_WAVE_WIDE is off by default. I did not run #209 with VICTORY_WAVE_WIDE=1 but without this PR in game.

**@⁠Bladureau** on GitHub · 2026-11-26 14:47 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/81#issuecomment-7195328331) Tested on an RTX 4060 Laptop GPU 8 GB (driver 617.14, D3D12 `min=32 max=32`), Windows 11, title 1.0.2.1: avatarmanz/main `a9400a6` + #209 + this PR, `VICTORY_WAVE_WIDE=1`, `VICTORY_SHADER_KEY=source`, every shader translated beforehand with the same settings, Series S. The device hung during the world load, 3.6 minutes in; the process exited with 0x887A0005. DRED (`light`): in the first list that did not finish, 8 of 17 commands completed. The first uncompleted one is an indirect dispatch of `2561af9577c47289` (`ptfx_CS_lightAtlas_Sprite`), followed in the same barrier interval by dispatches of `cabb87599722e59a` (its `NonLocalLights` variant). Offline, the forms these two programs take: | | `2561af9577c47289` | `cabb87599722e59a` | |---|---|---| | #209, `VICTORY_WAVE_WIDE=1` | 2 branches taken wave-wide | `4e964d2f953f1c29` | | #209 + this PR, `VICTORY_WAVE_WIDE=1` | 4 branches taken wave-wide | `4e964d2f953f1c29` | | #209 + this PR, no `VICTORY_WAVE_WIDE` | local waves (APPROXIMATE), without early-outs | `4e964d2f953f1c29` | Without `VICTORY_WAVE_WIDE`, the same build ran 6.8 minutes with no device removal. So on this GPU the wave-wide form of `ptfx_CS_lightAtlas_Sprite` still hangs with this PR, although the PR widens two more of its branches. That is the program `emit/mod.rs` names as the reason `VICTORY_WAVE_WIDE` is off by default. I did not run #209 with `VICTORY_WAVE_WIDE=1` but without this PR in game.
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/81/head:github-bot/gh-81'
git switch 'github-bot/gh-81'

Merge

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