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

Open
github-bot wants to merge 2 commits from github-bot/gh-388 into main AGit
Owner

@⁠fromrivertothesea on GitHub · 2026-11-27 21:49 UTC · original
fromrivertothesea:pr/meshlets-wave32 → main · +105 −16 · 1 files · 2 commits · draft

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

**@⁠fromrivertothesea** on GitHub · 2026-11-27 21:49 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/388) `fromrivertothesea:pr/meshlets-wave32` → `main` · +105 −16 · 1 files · 2 commits · draft ## 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
vfx_triangleClip:CS_CollectTriangles (#6832a9da15c2e584) and _Meshlets
(#6b82bc7d22016cb5), groups of 1024 using all 32 KiB of LDS, stopped with
"no wave32 lowering for this wave64 program" on 32-lane hosts, and their
dispatches were dropped. Wave-wide branches cannot take them: their meetings
need 177 dwords past the program's 8192, which a D3D12 group never has.

Their LDS is only shared across the title's own barriers; between them it holds
atomics, reads of what the last barrier fixed, and one region thread 0 runs
alone. Their wave operations are the allocation idiom, with the reservation on
an LDS counter (ds_add_rtn_u32) instead of a buffer. So each host wave can run
as a wave of its own:

- wave_local takes an LDS atomic of the total's operation (ds_add/min/max/or/
  and/xor, with or without _rtn) as a reservation, as it takes buffer atomics.
- Local waves compute LdsOrder too, but only for a program whose LDS accesses
  cannot be ordered without it; every other program keeps its barriers.
- tight_lds: with local waves, a one-dimensional group whose own LDS leaves no
  room makes neither the exchange dwords (local waves never exchange) nor
  wave_base's counter (the flat id's 32-aligned runs are the host waves).

All 26177 programs of GTA VI 1.0.2.1 translated before and after (32-lane host):
only these two differ, both from refused to emitted; every other program's DXIL
is the same. victory-shader tests: 288 passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FsQtBz4aDhUTip3jBagKEX
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 21:52:42 +00:00
Author
Owner

@⁠Castyan on GitHub · 2026-11-27 22:20 UTC · original

i'm on it for testing

**@⁠Castyan** on GitHub · 2026-11-27 22:20 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/388#issuecomment-7229238860) i'm on it for testing
Author
Owner

@⁠Castyan on GitHub · 2026-11-27 22:29 UTC · original · edited 2026-11-27 23:05 UTC

#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.

**@⁠Castyan** on GitHub · 2026-11-27 22:29 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/388#issuecomment-7229377757) · edited 2026-11-27 23:05 UTC **#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.
`wave_local` took a VGPR that a guarded write left with a wave-dependent value
in the lanes outside the guard as mixed for every later read. A read in the same
block under the same guard only runs in the lanes that wrote it, so it now reads
the new value. Another guarded write over such a value keeps it that way.

`CS_CollectTriangles(_Meshlets)` load into the VGPR that held the wave's count
(0x3acc / 0x34c4) and read it only under the load's guard: both now pass as
the exact `local waves (idiom)` form, with the same DXIL as the approximate
form gave them. Every other program of GTA VI 1.0.2.1 is unchanged
(VICTORY_HOST_WAVE=32, all outcomes and DXIL hashes identical).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/388/head:github-bot/gh-388'
git switch 'github-bot/gh-388'

Merge

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