Files
cool_fox/docs/wave32-lds-lockstep.md

3.6 KiB

Wave32 lockstep for divergent LDS

Retirement in the skinned decal reduction

VICTORY_WAVE_RETIRE=1 opts into a specialization for CS_ComputeHitDetectionSkinnedResults when private wave scratch spills. Play-VIctory.cmd fast enables it unless explicitly overridden; VICTORY_WAVE_RETIRE=0 keeps baseline lockstep. Other kernels, including variants with different code or thread dimensions, are unaffected.

The audited loop halves an unsigned limit from 512 to 1. Its outer execz skips the body unless some guest thread ID is below that limit. Both host halves know the limit and their guest wave's first thread ID. Once the whole wave falls outside the prefix, it no longer exchanges votes at the head. Once the upper half falls outside, neither half needs the inter-half rendezvous around ordinary LDS accesses inside the guarded body. Both take the same decision, keep their counter generations in step, and retain the LDS fence and the original iteration-ending barrier. This is implicit retirement from specific rendezvous, not a general dynamic arrive-and-drop primitive; it never drops a group barrier or lets a half leave the loop early.

On a Radeon 610M, two isolated 12-group dispatches took 1.985 → 1.42 ms and 2.07 → 1.41 ms (GPU timestamp medians, eight alternating-order batches per variant, first three of 20 iterations discarded per batch). Both repeats matched native wave64 over the full 196,608-byte game output; the dispatches changed 143 and 161 bytes, respectively. These are dispatch timings, not game frame times.

On wave32 hosts, the translator automatically retries a wave64 compute shader after its normal translation fails with no wave32 lowering for this wave64 program. Set VICTORY_LDS_LOCKSTEP=0 to disable this retry for comparison; no setting is needed to enable it. For offline translation, set VICTORY_HOST_MAX_WAVE=32 to select the target. Both host halves take the same wave-wide branches; guest vector operations retain their EXEC predicates. Unrecognized control flow remains a refusal.

Every guest wave reuses a single pair of counters across all eligible synchronization sites. Neither half can advance more than one generation ahead of the other, so the signed difference between observed and expected generations also works across 32-bit wrap. This reduces LDS usage even without the fallback.

If the counters and cross-half exchange words do not fit, the lockstep retry keeps the guest's entire LDS allocation and moves translator-private words only into a root UAV. Direct dispatches allocate 512 bytes per group in a fresh buffer retained by the command list. The shader linearizes its 3D group ID with the actual dispatch dimensions; no scratch is shared between groups or dispatches. Scratch atomics are ordered with group-scoped UAV and LDS fences. Indirect dispatches with unknown dimensions and scratch allocations above 256 MiB are refused, not run with aliased storage. To test the spill on hardware, run cargo test -p victory-shader --lib full_lds_scratch -- --include-ignored --nocapture.

Run cargo test -p victory-shader --lib empty_half_loop -- --include-ignored --nocapture --test-threads=1 on a wave32 D3D12 device. One readback case retires half the lanes after the first iteration; after restoring EXEC all lanes must see the other half's final LDS writes. The timing case rotates between two, one and zero working halves for fixed trip counts. It measures one group's dispatch with GPU timestamps, discards three warm-ups, and reports the median of nine samples. The zero-work case skips the body; this is not an arrive-and-drop benchmark or a frame-time measurement.