Repository navigation
Shaders: CS_CollectTriangles(_Meshlets) on 32-lane hosts (local waves with LDS atomics) - #388
fromrivertothesea wants to merge 2 commits into
Conversation
… 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
|
i'm on it for testing |
|
#388 + #403 merged on #388 adds no test of its own. In game (RTX 5060 8 GB, 15 GB RAM, below the README's 32 GB): |
`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>
…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>
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 atwith_pair_meetingsalready namesCS_CollectTriangles_Meshletsas 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 owns_barriers. Between them there are only:ds_or_b32,ds_add_u32,ds_max_i32), where order doesn't matter;Its wave operations are the allocation idiom that
with_local_wavesalready handles:s_ff1/s_bcnt1/v_mbcnt, the first lane reserving the wave's count, andv_readfirstlaneof 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)wave_localaccepts 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.LdsOrder, but only for a program whose LDS accesseslds_meetingscan't order without it. Every program that translated before keeps its barriers exactly as they were.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 andscc_someall return or refuse onself.local) norwave_base's counter.thread_idthen 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
mainand 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 loweringgoes from 22 to 20.)cargo test -p victory-shader --release: 288 passed.Exact, not approximate (second commit)
wave_localstopped at0x3ad8(_Meshlets) and0x34c4(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.local waves (idiom)form, and emit the same DXIL as the approximate form did (12e1b822fe8f9131,4f14a4f603d4fe0e). That confirms the reading from the disassembly.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)
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