fix(victory-shader): prove lane-private LDS stacks for wave64-to-wave32 lowering #489
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/489"
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 LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T07:57:24Z.
Current behavior
Set
VICTORY_LDS_PRIVATE=1to enable experimental lane-private LDS lowering on wave32 hosts. The opt-in mode uses a distinct shader-cache key. The port includes #317's first-lane lowering and uses the test-host SRV support from #476.The LDS analysis tests, cache-fingerprint regression, and four synthetic NVIDIA traversal cases passed. In-game validation is still needed before enabling this by default.
Earlier description and measurements
Change
Prove when LDS accesses in a console
wave64compute shader are strictly lane-private within each 64-lane console wave (emit/lds_private.rs), solower.rscan lower ray-tracing traversal shaders with per-thread LDS BVH stacks to Wave32 hosts (NVIDIA) withoutloose_ldsapproximation and without emittingsplit_ldsGroupMemoryBarrierWithGroupSyncbarriers around every LDS read/write.Root Cause
Console
wave64ray-tracing traversal shaders store a per-thread BVH traversal stack in LDS (e.g. bank-conflict-free SoA(sp << 8) + (tid << 2)/ pointer-stepped+= 256and-= 256, or AoS per-thread slices(tid << k) | ((sp & mask) << 2)). On 32-lane hosts (host_max_wave() == 32, NVIDIA RTX 5070 Ti),lower.rspreviously treated all LDS in groups larger than 32 threads as intra-wave shared:ds_write_b32) and pop (ds_read_b32) sit inside a lane-branch region (s_and_saveexec_b64+s_cbranch_execz),lds_meetingsrejectsreads[r] && writes[r]. Exact lowering therefore keepsWaveSize(64), which NVIDIA D3D12 rejects withE_INVALIDARG(0x80070057).split_lds = trueemits adx.op.barrierbefore every singleds_readandds_writein the traversal loop, andone_wave && s.lds_dwords > 0forcesWaveSize(32)+halvesLDS atomic ticket relabeling even when the shader has no cross-lane wave operations.What This PR Adds
third_party/victory/crates/victory-shader/src/emit/lds_private.rs: sound fixed-point abstract interpretation over SSAValues (LdsAddr) proving that every plain LDS read/write in awave64compute shader accesses disjoint 32-bit LDS dwords across the 64 lanes of each console wave (((addr - base) & (M - 1)) >> sh == (lane6 * odd) & 63with2 <= sh <= 10,M = 64 << sh | 65536).(sp << 8) + (tid << 2)and loop-carried+= 256/-= 256), AoS per-thread slices ((tid << k) | ((sp & m) << 2)), 2D flattened groups ([8, 8, 1]), and odd-stride bijections (v0 * 12).lds: true), LDS atomics/counters, constant addresses, cross-half aliases ((v0 ^ 32) << 2,(v0 & 31) << 2), 2D groups indexing onlyv0, overlapping offsets (offset:4onsh = 2), mixed strides, AoS slice overflows, and unbounded loop pointer increments.VICTORY_LDS_PRIVATE(default enabled;0restores legacy behavior for A/B comparison).third_party/victory/crates/victory-shader/src/emit/lower.rs,mod.rs,shader.rs: wirelds_private::is_lane_privateintoshared_ldsinLower::new, and expose#[cfg(test)] Lowered::barriers(dx.op.barriercount).third_party/victory/crates/victory-shader/src/emit/wave64_tests.rs,host.rs(#[cfg(test)]):image_bvh64_intersect_ray+ per-thread SoA LDS stack) verified bit-for-bit againstcrate::bvh::intersecton RTX 5070 Ti and WARP across hits, misses, and occluders (divergent_loop,uniform_loop,divergent_loop_with_wave_op,uniform_loop_with_wave_op).lds_lane_private_accepts_soa_aos_and_2d_group_stacks) and negative (lds_lane_private_rejects_shared_and_unsafe_patterns) unit tests.bench_wave64_bvh_traversal_lds_stack_on_gpu, 1,048,576 rays × 32 steps over a 4-level synthetic BVH, 10 warmups + 40 timed dispatches).GPU Measurement (NVIDIA GeForce RTX 5070 Ti, Driver 621.40, Wave32 SM 6.6)
Same 4-level synthetic BVH, 16,384 groups (1,048,576 rays) × 32 steps, bit-exact match against
cpu_traverse(crate::bvh::intersect) across all variants, verified across two independent runs (Run AandRun B):WaveSizedx.op.barrieruniform_no_waveop_legacy(VICTORY_LDS_PRIVATE=0)Some(32)60.2352 / 0.23610.2350 / 0.2361uniform_no_waveop_privateNone00.2250 / 0.22780.2244 / 0.2259uniform_with_waveop_legacy(VICTORY_LDS_PRIVATE=0)Some(32)90.2352 / 0.23610.2351 / 0.2362uniform_with_waveop_privateSome(32)30.2247 / 0.22600.2247 / 0.2264divergent_no_waveop_privateNone00.1999 / 0.20170.2000 / 0.2012WaveSize(64)) onmainVerification
Oracle and test data
crate::bvh::intersectCPU reference traversal (cpu_traverseinwave64_tests.rs), compared bit-for-bit ([t, det, i, j]andbvh::MISS) on both NVIDIA GeForce RTX 5070 Ti and WARP, plusdxil.dllDXIL validation.synthetic_bvh_scene,synthetic_bvh_scene_deep), synthetic rays, and hand-assembled RDNA 2 compute programs built from source insidewave64_tests.rs. No game, console, or SDK files.origin/main(b62053fe) or withVICTORY_LDS_PRIVATE=0,wave64_bvh_traversal_with_private_lds_stack_runs_on_wave32_without_barriersfails ondivergent_loopanddivergent_loop_with_wave_opbecauselower::lowerkeepswave_size == Some(64)(which NVIDIA D3D12 refuses withE_INVALIDARG), anduniform_loopemits 6dx.op.barriercalls (split_lds = true).Checklist
E_NOTIMPL), never a fake success.This pull request was prepared with AI coding assistance (Antigravity), with all code reviewed, compiled, and validated locally on an NVIDIA GeForce RTX 5070 Ti and WARP.
Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T12:24:05Z.
Review: VICTORY_LDS_PRIVATE is read in lower.rs and default-on, but shader caches are keyed only by TRANSLATOR_VERSION, so toggling it yields stale results. Include the flag in the cache key or make it opt-in. Lane-private LDS soundness needs a game-run confirmation.
Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T17:02:29Z.
Updated this PR to
a4453083and reused the test-host support already landed in #476. Lane-private LDS lowering now requiresVICTORY_LDS_PRIVATE=1and uses a separate shader-cache key. The cache regression, LDS analysis tests, and all four synthetic NVIDIA traversal cases passed. In-game validation is still needed before enabling this by default.Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-28T00:15:25Z.
Main just took #563 (the VIctory copy moved to Vice-Tay
4f15f09e) and #564 (memory stack), and this PR now conflicts inthird_party/victory/crates/victory-shader/src/emit/lower.rs,third_party/victory/crates/victory-shader/src/emit/mod.rs. Please rebase on current main, rerun the tests for the files you touch, and force-push. If your change bumpsTRANSLATOR_VERSION, main is now at 16: take the next free value (17 is suggested for #535, so 18).Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-28T00:16:16Z.
Correction to my note above: #456 already takes 17 and #535 is asked to take 18, so if this PR bumps
TRANSLATOR_VERSION, please use 19.Imported from LooperSalty/AnyXboxX. Originally posted by akimfomin on 2026-11-28T01:30:30Z.
For a possible combined test with #524, Git finds conflicts in
emit/lower.rsandemit/mod.rson1a7dd21cplus3e9fc637. Separate from the translator version issue: make a small three-program check (proven lane-private, cross-lane LDS, genuine wave pairs). When the switches are combined, the third case should not silently go through the private LDS lowering, and cross-lane input should preserve its existing fallback. This is a source-level merge check only.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.