Skip to content

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

Draft
fromrivertothesea wants to merge 2 commits into
trustno1-coder:mainfrom
fromrivertothesea:pr/meshlets-wave32
Draft

fromrivertothesea wants to merge 2 commits into
trustno1-coder:mainfrom
fromrivertothesea:pr/meshlets-wave32

Conversation

@fromrivertothesea

@fromrivertothesea fromrivertothesea commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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 (perf(shadow): lock-free pending check, merge ranged under copied lock, chunk wide_each #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

… with LDS atomics, no room past a full LDS)

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FsQtBz4aDhUTip3jBagKEX
@Castyan

Castyan commented Nov 27, 2026

Copy link
Copy Markdown

i'm on it for testing

@Castyan

Castyan commented Nov 27, 2026 •

Copy link
Copy Markdown

#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 <noreply@anthropic.com>
whoalin1 added a commit to whoalin1/victory-altracing-prs that referenced this pull request Nov 28, 2026
…n 32-lane hosts

Cherry-picked from trustno1-coder#388 (fromrivertothesea, both commits).

vfx_triangleClip:CS_CollectTriangles (6832a9da15c2e584) and _Meshlets
(6b82bc7d22016cb5) use 1024-thread groups and all 32 KiB of LDS, so on NVIDIA they
stopped with "no wave32 lowering for this wave64 program" and their dispatches were
dropped (6b82bc7d22016cb5 was on our untranslated list). Their LDS is shared only
across the title's own barriers, and their wave ops are the allocation idiom local
waves already handle, with the reservation on an LDS counter. wave_local accepts an
LDS atomic of the total's operation as the reservation; local waves order LDS only
where lds_meetings cannot; tight_lds leaves out the exchange dwords and wave_base's
counter for 1-D groups whose own LDS fills the host's. A read under the same guard
in the same block reads the guarded write's own value (exact, not approximate).

Upstream measured: of all 26,177 programs only these two change, refused -> emitted.
cargo test -p victory-shader --release: 292 passed, 4 ignored.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants