shader: order cross-half UAV write-then-read in wave64 compute without lane reads #2421
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2421"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by steven-seagull27 on 2026-11-29T12:53:55Z.
Fixes Marvisak/VIctory#3766
What it changes
Console wave64 compute shaders (
group > 32) with no lane reads (!console_lanes) and no LDS (lds == 0) can still rely on implicit intra-wave ordering when one half of a 64-lane wave stores to a UAV and the other half subsequently loads from it without an intervenings_barrier. Previously, lowering neither requestedWaveSize(64)on 64-lane hosts (allowing drivers to compile them as Wave32) nor synchronized the two 32-lane host halves on 32-lane hosts like NVIDIA.uav_orderforward dataflow analysis incrates/victory-shader/src/emit/lower/analysis.rsto detect wave64 compute shaders (x.native.wave64 && group > 32) where a UAV load is reachable after a UAV store/atomic (or a UAV atomic after a plain UAV store) without an intervening convergents_barrier. Read-only, write-only, straight-line read-then-write, and wave32 compute shaders are unaffected (zero added barriers, zero metadata change).host_max_wave() >= 64): setss.wave_size = Some(64)so the console wave remains intact at zero barrier cost.host_max_wave() == 32): emits minimaldx.op.barrier(1 | 2)(thread-group sync + global UAV fence) before convergent UAV loads or before exiting convergent blocks into divergent UAV loads (usingall_lane_blocksforgroup <= 64andevery_thread_blocksforgroup > 64, skipping syncs undercut_short). Inside divergent-only regions with no intervening convergent block, emits fence-onlydx.op.barrier(2)so divergent branches can never deadlock.crates/victory-shader/src/emit/wave64_tests.rscovering5 -> 40and40 -> 5cross-half UAV ordering (both branched and masked forms),WaveSize(64)emission on 64-lane hosts,dxil.dllvalidation, hardware D3D12 execution (including a negative control without the barrier), zero-barrier negative controls, and divergent-branch deadlock safety.How it was tested
victory-shader5 -> 40and40 -> 5branched) emitted 0 barriers on 32-lane hosts (noWaveSize(64)on 64-lane hosts) and reproduced 8,192 / 8,192 stale reads across hardware dispatches on RTX 5080 (negative control).TEST_HOST_WAVE = Some(64)): emitsWaveSize(64)metadata with 0 barriers and validates cleanly withdxil.dll.TEST_HOST_WAVE = Some(32)): emitsdx.op.barrier(3)(mode1 | 2), validates cleanly withdxil.dll, and passes 0 / 256 stale dispatches (4,096 hardware waves per variant) on RTX 5080 across all four variants (5->40branched,40->5branched,5->40masked,40->5masked).dx.op.barrier(2)and runs on RTX 5080 without deadlock when half 1 skips the branch.dxil.dll) and 64-lane (DXIL lowering +WaveSize(64)metadata +dxil.dll)cargo testpassed for the crates it touches: yescargo test --locked -j 3 -p victory-shader --lib -- wave64_tests --test-threads=1: 46 passed; 0 failedcargo test --locked -j 3 -p victory-shader --lib -- --test-threads=1: 464 passed; 0 failed; 9 ignoredcargo clippy --locked -j 3 -p victory-shader --lib --tests: 0 warnings in touched codegit diff --check: cleanChecked for overlap