Shaders: CS_CollectTriangles(_Meshlets) on 32-lane hosts (local waves with LDS atomics) #388

Open
fromrivertothesea wants to merge 2 commits from upstream-pr/388 into main
fromrivertothesea commented 2026-11-27 21:49:05 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by fromrivertothesea on 2026-11-27T21:49:05Z.


Problem

On NVIDIA (32-lane waves), two of the triangle clip's compute programs stop with no wave32 lowering for this wave64 program, so their dispatches are dropped:

  • vfx_triangleClip:CS_CollectTriangles (#6832a9da15c2e584)
  • vfx_triangleClip:CS_CollectTriangles_Meshlets (#6b82bc7d22016cb5)

Both use groups of 1024 threads and all 32 KiB of LDS themselves. Wave-wide branches with console-wave meetings (VICTORY_WAVE_WIDE=1) can't take them: the meetings and exchange need 177 dwords past the program's 8192, and a D3D12 group never has more than 8192 (the comment at with_pair_meetings already names CS_CollectTriangles_Meshlets as not fitting). PR #259's split-wave64 fallback doesn't take them either (WAVE64-SPLIT round 0: wave Some(64)).

Why local waves are right for them

Reading the program (shader-info --disasm), the LDS is only ever shared across the title's own s_barriers. Between them there are only:

  • atomics (ds_or_b32, ds_add_u32, ds_max_i32), where order doesn't matter;
  • reads of what the last barrier fixed;
  • one region that thread 0 runs alone.

Its wave operations are the allocation idiom that with_local_waves already handles: s_ff1 / s_bcnt1 / v_mbcnt, the first lane reserving the wave's count, and v_readfirstlane of the base. The only difference is that the reservation is on an LDS counter (ds_add_rtn_u32 ... offset:4) instead of a buffer atomic. So each host wave can run as a wave of its own.

Change (emit/lower.rs)

  1. wave_local accepts an LDS atomic of the total's operation (ds_add/min/max/or/and/xor, with or without _rtn) as the reservation, as it does buffer atomics. Its operand is read like a buffer atomic's; its address must still not depend on the wave.
  2. Local waves compute LdsOrder, but only for a program whose LDS accesses lds_meetings can't order without it. Every program that translated before keeps its barriers exactly as they were.
  3. tight_lds: with local waves, a one-dimensional group whose own LDS leaves no room reserves neither the exchange dwords (local waves never exchange: exchange_halves, lane reads and scc_some all return or refuse on self.local) nor wave_base's counter. thread_id then uses the flat id's 32-aligned runs, which are the host waves for a 1-D group. 2-D and 3-D groups keep the counter (#1243).

Tested

  • All 26,177 programs of GTA VI 1.0.2.1, translated with main and with this branch (translate D:\GTAVI --list, VICTORY_HOST_WAVE=32): only these two differ, both from refused to emitted. Every other program's DXIL hash is identical. (no wave32 lowering goes from 22 to 20.)
  • Both now emit in waves of 32 within 8192 LDS dwords.
  • cargo test -p victory-shader --release: 288 passed.

Exact, not approximate (second commit)

wave_local stopped at 0x3ad8 (_Meshlets) and 0x34c4 (the other): a load into the VGPR that held the wave's count, under a guard, was taken as mixed, even though it is read only under that same guard. Now a read in the same block under the same guard reads the guarded write's own value. Another guarded write over such a value keeps it that way, and every other read still sees it as mixed.

  • Both programs now take the exact local waves (idiom) form, and emit the same DXIL as the approximate form did (12e1b822fe8f9131, 4f14a4f603d4fe0e). That confirms the reading from the disassembly.
  • All programs of GTA VI 1.0.2.1 translated before and after it (VICTORY_HOST_WAVE=32): every outcome and DXIL hash is identical.
  • cargo test -p victory-shader --release: 288 passed.

Not yet tested: in game (why this is a draft)

  • The pipeline hasn't been created by the driver in a run yet, and nothing has been compared visually.

I'll mark it ready once it's been checked in a run on an RTX card.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FsQtBz4aDhUTip3jBagKEX

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5533520841 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/388). Originally posted by [fromrivertothesea](https://github.com/fromrivertothesea) on 2026-11-27T21:49:05Z. --- ## Problem On NVIDIA (32-lane waves), two of the triangle clip's compute programs stop with `no wave32 lowering for this wave64 program`, so their dispatches are dropped: - `vfx_triangleClip:CS_CollectTriangles` (`#6832a9da15c2e584`) - `vfx_triangleClip:CS_CollectTriangles_Meshlets` (`#6b82bc7d22016cb5`) Both use groups of 1024 threads and **all 32 KiB of LDS** themselves. Wave-wide branches with console-wave meetings (`VICTORY_WAVE_WIDE=1`) can't take them: the meetings and exchange need 177 dwords past the program's 8192, and a D3D12 group never has more than 8192 (the comment at `with_pair_meetings` already names `CS_CollectTriangles_Meshlets` as not fitting). PR #259's split-wave64 fallback doesn't take them either (`WAVE64-SPLIT round 0: wave Some(64)`). ## Why local waves are right for them Reading the program (`shader-info --disasm`), the LDS is only ever shared across the title's own `s_barrier`s. Between them there are only: - atomics (`ds_or_b32`, `ds_add_u32`, `ds_max_i32`), where order doesn't matter; - reads of what the last barrier fixed; - one region that thread 0 runs alone. Its wave operations are the allocation idiom that `with_local_waves` already handles: `s_ff1` / `s_bcnt1` / `v_mbcnt`, the first lane reserving the wave's count, and `v_readfirstlane` of the base. The only difference is that the reservation is on an **LDS** counter (`ds_add_rtn_u32 ... offset:4`) instead of a buffer atomic. So each host wave can run as a wave of its own. ## Change (`emit/lower.rs`) 1. **`wave_local`** accepts an LDS atomic of the total's operation (`ds_add/min/max/or/and/xor`, with or without `_rtn`) as the reservation, as it does buffer atomics. Its operand is read like a buffer atomic's; its address must still not depend on the wave. 2. **Local waves compute `LdsOrder`**, but only for a program whose LDS accesses `lds_meetings` can't order without it. Every program that translated before keeps its barriers exactly as they were. 3. **`tight_lds`**: with local waves, a **one-dimensional** group whose own LDS leaves no room reserves neither the exchange dwords (local waves never exchange: `exchange_halves`, lane reads and `scc_some` all return or refuse on `self.local`) nor `wave_base`'s counter. `thread_id` then uses the flat id's 32-aligned runs, which are the host waves for a 1-D group. 2-D and 3-D groups keep the counter (#1243). ## Tested - **All 26,177 programs** of GTA VI 1.0.2.1, translated with `main` and with this branch (`translate D:\GTAVI --list`, `VICTORY_HOST_WAVE=32`): **only these two differ**, both from refused to emitted. Every other program's DXIL hash is identical. (`no wave32 lowering` goes from 22 to 20.) - Both now emit in waves of 32 within 8192 LDS dwords. - `cargo test -p victory-shader --release`: 288 passed. ## Exact, not approximate (second commit) `wave_local` stopped at `0x3ad8` (`_Meshlets`) and `0x34c4` (the other): a load into the VGPR that held the wave's count, under a guard, was taken as mixed, even though it is read only under that same guard. Now a read in the same block under the same guard reads the guarded write's own value. Another guarded write over such a value keeps it that way, and every other read still sees it as mixed. - Both programs now take the exact `local waves (idiom)` form, and emit **the same DXIL** as the approximate form did (`12e1b822fe8f9131`, `4f14a4f603d4fe0e`). That confirms the reading from the disassembly. - All programs of GTA VI 1.0.2.1 translated before and after it (`VICTORY_HOST_WAVE=32`): every outcome and DXIL hash is identical. - `cargo test -p victory-shader --release`: 288 passed. ## Not yet tested: in game (why this is a draft) - The pipeline hasn't been created by the driver in a run yet, and nothing has been compared visually. I'll mark it ready once it's been checked in a run on an RTX card. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01FsQtBz4aDhUTip3jBagKEX
Castyan commented 2026-11-27 22:20:05 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Castyan on 2026-11-27T22:20:05Z.


i'm on it for testing

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7229238860 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/388#issuecomment-7229238860). Originally posted by [Castyan](https://github.com/Castyan) on 2026-11-27T22:20:05Z. --- i'm on it for testing
Castyan commented 2026-11-27 22:29:58 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Castyan on 2026-11-27T22:29:58Z.


#388 + #403 merged on main (df2daaf): no conflict, no new failure. Windows, RTX 5060, cargo test --workspace --no-fail-fast: 1070 passed (main 1064, the +6 are #403's new tests), 2 failed (victory-gpu indirect::tests, the same 2 on main). The clippy error at victory-formats/src/texture.rs:1346 is on main too. Not tested in game or with translate --list.

#388 adds no test of its own.

In game (RTX 5060 8 GB, 15 GB RAM, below the README's 32 GB): CS_CollectTriangles_Meshlets translates and gets its host pipeline. Series S + 2x frame gen ran 11 min, then device removed (0x887A0007). Series X runs out of memory after 2-3 min (E_OUTOFMEMORY), with main too (driver access violation in nvwgf2umx.dll). So the crashes look like this PC's memory, not these PRs. Not a like-for-like comparison.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7229377757 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/388#issuecomment-7229377757). Originally posted by [Castyan](https://github.com/Castyan) on 2026-11-27T22:29:58Z. --- **#388 + #403 merged on `main` (`df2daaf`): no conflict, no new failure.** Windows, RTX 5060, `cargo test --workspace --no-fail-fast`: 1070 passed (main 1064, the +6 are #403's new tests), 2 failed (`victory-gpu` `indirect::tests`, the same 2 on `main`). The clippy error at `victory-formats/src/texture.rs:1346` is on `main` too. Not tested in game or with `translate --list`. #388 adds no test of its own. **In game** (RTX 5060 8 GB, 15 GB RAM, below the README's 32 GB): `CS_CollectTriangles_Meshlets` translates and gets its host pipeline. Series S + 2x frame gen ran 11 min, then device removed (`0x887A0007`). Series X runs out of memory after 2-3 min (`E_OUTOFMEMORY`), with `main` too (driver access violation in `nvwgf2umx.dll`). So the crashes look like this PC's memory, not these PRs. Not a like-for-like comparison.
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/388:upstream-pr/388'
git switch 'upstream-pr/388'

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