shader: static Wave32 LDS alias & lane-private analysis for native Wave32 compute #1137
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1140"
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 fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-25T21:26:36Z.
Summary
AI-assisted port of static Wave32 LDS alias/hazard proof analysis (
crates/victory-shader/src/emit/lds.rs) ontofxceless/victory-forkmain, unlocking native Wave32 execution on NVIDIA/32-wide GPUs for compute shaders whose LDS (ds_*) operations live inside control flow or use disjoint/lane-private addressing, while preservingwave64fallback whenever safety cannot be statically proven.Key Details & Soundness Guarantees
MAX_OFFSET = 1 MiB32-bit bounds (<4-byte unaligned vs>=4-byte dword collision guard, zero RMWs, acyclic!allregions, symmetric RAW/WAR/WAW).v_mbcntconsole_lane(group <= 64), aligned, sub-array split, non-wrapping, and cross-cluster disjoint.dstverification (is_primary_sop_dst/is_primary_valu_dst) prevents VOP3Bv.carry/Reg::Sccmisidentification as group-uniform values.c < cs.user_sgprs()+Input::GroupId, refusingscratch_wave_offsetand uninitialized SGPRs).!allregions contains_barrieror non-inline special SOP constants (c != 253).wave64_testspreserved intact.Verification (
86e93bb1c)git merge-tree --write-tree origin/main HEADagainst latestmain(c36971b2).cargo clippy -p victory-shader --all-targets -- -D warnings: exit 0, 0 warnings.VICTORY_REQUIRE_HW_GPU=1 cargo test -p victory-shader --lib emit::wave64_tests::lds_ -- --nocapture: 4 passed; 0 failed on hardware D3D12 (no skip).cargo test -p victory-shader --all-targets: 233 passed; 0 failed; 3 ignored (14/14emit::lds::tests::*).Co-Authored-By: AI Assistant
Imported from fxceless/victory-fork. Originally posted by GDKAYKY on 2026-11-25T21:28:47Z.
does this have improvement on frametime,fps or VRAM usage?
Imported from fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-25T23:10:02Z.
@GDKAYKY Target and effect summary:
ds_*) operations sit inside control flow or per-lane offsets.emit/lds.rs) proves native Wave32 execution produces identical results. The exact full-frame FPS delta depends on how many active compute shaders in a given scene hit that Wave64 LDS fallback path, and hasn't been measured in a live title run yet.Imported from fxceless/victory-fork. Originally posted by HAL9000RELOADED on 2026-11-26T09:29:29Z.
RX 7900 XTX (RDNA3), driver 32.0.32015.7029, Windows 10 22H2,
86e93bbon main32b31f7+ #402 (Agility, WARP skips here).victory-shader234 passed, 0 failed; the 18 new tests pass, including the three*_execute_wave32_on_hardwareruns on the card.lds_*_execute_wave32_on_hardwareget 64 instead of 32,lds_shared_returning_atomic_stays_wave64gets 32 instead of 64).AI-assisted (Claude Code): tests run on my machine, text drafted with Claude.
Imported from fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-26T09:46:59Z.
Pushed follow-up commit
d12852cincorporating live 32-lane NVIDIA review findings and diagnostic improvements:32-lane opt-in
VICTORY_LDS_WRITE_ONLY_OK=1+has_plain_read(emit/lds.rs):has_plain_readstrictly onKind::Read(ds_read*), distinct fromKind::Rmw(LDS atomics).host_max_wave() == 32andVICTORY_LDS_WRITE_ONLY_OK=1(off by default, always disabled on 64-lane hosts). When enabled on 32-lane hosts,!allwrite-only regions and!allLDS atomic regions with no plainds_read*are accepted for native Wave32, while divergents_barrier, unhandled DS instructions, and mixed regions with an explicit plainds_read*remain refused.Specific
VICTORY_WAVE_WHY=1refusal diagnostics (emit/lds.rs,emit/lower.rs):lds::Refusalvariants vialds::analyze(...)soVICTORY_WAVE_WHY=1accurately distinguishes overlapping plain writes, atomics with no plain LDS read, mixed regions with an explicit plainds_read*, divergent barriers, unhandled DS ops, and cyclic shared writes.Note on @GDKAYKY's question (frame pacing / NVIDIA skinning shaders):
WaveSize(64)is rejected by D3D12CreateComputePipelineState(E_INVALIDARG), which drops those dispatches (including skinning compute passes) or forces slower fallback paths. Proving more branched-LDS compute shaders safe for native Wave32 keeps those pipelines compiling and executing cleanly on 32-lane hardware without Wave64 software emulation overhead, directly helping frame pacing and rendering completeness on NVIDIA.Verification:
ds_read*, 32-lane vs 64-lane host gating, the 4-kernel lowering matrix (same-dword write-only, separate writes, overlapping read+write, disjoint read + writes), negatives_barrier/ds_nopchecks, andVICTORY_WAVE_WHYreason strings.cargo test -p victory-shader -- --test-threads=4: 235 passed; 0 failed; 3 ignored (including the 3 hardware D3D12 Wave32 LDS execution tests).cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.Imported from fxceless/victory-fork. Originally posted by Dathinel on 2026-11-26T20:16:04Z.
At
c629faf, the CPU-side LDS analysis accepts a cross-lane byte alias in a partial workgroup. I compiled the PR's region_lane_private, injective_lane_disp and ranges_may_overlap functions in isolation with Rust and supplied two synthetic Access records. No GPU or game input is needed.Use threads = [n, 1, 1], no uniforms, uniform_tz = 32, console_lane = 0. The write has width 1, tid = [1,0,0], off = 0. The read has width 1, tid = [0,0,0], off = n-1. Thread n-1 writes the byte that every thread reads. The two accesses therefore cannot be proven lane-private.
For n=33 the aggregate write footprint is [0,33). The cross-cluster check passes 33 as an instruction width to ranges_may_overlap, which rounds the upper bound down to 32 on the aligned path. The final byte disappears. Compare the already-computed half-open footprint bounds directly at this call site, retaining the existing alignment guard, and add the 33-thread case as a regression. This reproduces the analyzer decision only. AI-assisted review.
CPU check of the proposed change: I compiled both versions of region_lane_private and enumerated byte writes at initial + stride * tid.x and a uniform byte read at offset r. Parameters were n=32..65 inclusive, stride in {1,2,4}, initial=0..3, and r=0..n*stride+4 inclusive. The oracle enumerated all n write addresses and checked whether any equaled r. Every thread reads r, so a match is cross-thread sharing.
Across 48,212 inputs the original accepted 442 sharing cases as private. Replacing only the cross-cluster ranges_may_overlap call with (a.min_lo < b.max_hi && b.min_lo < a.max_hi) reduced that count to zero. Conservative rejections of genuinely disjoint cases changed from 26,282 to 25,840, including 170 safe cases newly rejected. Bounding intervals can include holes between strided writes. These results cover byte accesses in this family only.
Imported from fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-27T07:10:33Z.
Thank you @Dathinel for isolating this bug and verifying the oracle bounds.
Updated in
40ca614(and cleanly rebased ontomain9a9091d, preservingVICTORY_LDS_FLAGS/lds_flag_regionandall_lane_blocks_with_loop_exits):emit/lds.rs,region_lane_private): Replaced the cross-clusterranges_may_overlap(a.min_lo, a.max_hi - a.min_lo, ...)call with direct half-open interval comparison(a.min_lo < b.max_hi && b.min_lo < a.max_hi), retaining the existing((a.max_width >= 4 || b.max_width >= 4) && !align4)alignment guard so non-4-multiple aggregate footprints (e.g. partial workgroupsn = 33..63) no longer truncate trailing bytes.emit/lds.rs):partial_workgroup_byte_alias_is_refused: coversthreads = [n, 1, 1]forn in [32, 33, 63, 64](both access orders + disjointoff = ncontrol) plus end-to-end lowering checks forn = 33andn = 63.exhaustive_byte_access_oracle_has_zero_false_accepts: enumeratesn = 32..=65,stride in [1, 2, 4],initial in 0..4,r in 0..=n*stride+4(48,212cases,0false accepts).VICTORY_D3D12_DEBUG=1):cargo clippy -p victory-shader --all-targets: 0 warnings in PR files.cargo test -p victory-shader -- --test-threads=1: 274 passed; 0 failed; 19 ignored (all 18emit::lds::tests::*and 4emit::wave64_tests::lds_*tests passing).Imported from fxceless/victory-fork. Originally posted by Filip722 on 2026-11-27T14:25:31Z.
Independent Linux coverage on the current head
40ca6144f1111e471a931d24453eb924c219c002. Windows MSVC release tests ran through GE-Proton11-14 and vkd3d-protoncae8353ed7959c4+on an RTX 5060 Laptop GPU (8 GiB, NVIDIA 615.78.08, Bazzite).emit::lds::testspassed all 18 cases, including the partial-workgroup byte alias and exhaustive byte-access oracle.emit::wave64_tests::lds_passed all four cases withVICTORY_REQUIRE_HW_GPU=1. All three positive Wave32 cases executed on the NVIDIA device, including the returning-atomic fixture. The fourth asserted retention of Wave64 for the shared-atomic case.These were synthetic tests. Gameplay and frame rate were outside this check.
Assisted by Codex (GPT-6.2-Sol High).
Imported from fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-27T21:33:54Z.
@Filip722 Thank you for testing
40ca614on the RTX 5060 Laptop and confirming the Wave32 fix!Rebased cleanly onto latest
main(2eade68) asshader/wave32-lds-disjoint(f2d68c9):e9e0f58,e3de72b,d743bea,40ca614), including theregion_lane_privatebyte-footprint overlap fix, VOP3B carry / divergent-barrier guards, andVICTORY_LDS_WRITE_ONLY_OK/WAVE64-WHYdiagnostics.2eade68lds_order.unordered/unstableand water-light lowering paths, and keyedshader_cacheonVICTORY_LDS_WRITE_ONLY_OK/VICTORY_LDS_FLAGS.cargo xtask policy,cargo clippy(-p victory-shader -p victory-gpu, default &diagnostics, 0 warnings in PR files),emit::lds::tests,emit::wave64_tests,emit::water_tile_slots::tests,shader_cache::tests, andVICTORY_REQUIRE_HW_GPU=1Wave32 LDS hardware tests.Imported from fxceless/victory-fork. Originally posted by Dathinel on 2026-11-27T22:10:52Z.
Tested
f2d68c9on a physical RTX 3050 Laptop 4 GB (Windows D3D12, NVIDIA 610.62). All 18 LDS analysis tests passed. The five tests matchingemit::wave64_tests::lds_passed withVICTORY_REQUIRE_HW_GPU=1. Three of those tests dispatched six times and matched all 896 expected 32-bit values: disjoint ranges (3 × 128), dual/128-bit accesses (128), and lane-private returning atomics (2 × 192). The shared returning atomic control kept Wave64.I built the focused Rust test executable from this head's shader sources using cached dependencies. This covers the synthetic shader outputs on Ampere. I didn't measure game performance or run full workspace CI. AI-assisted verification.
Imported from fxceless/victory-fork. Originally posted by Vladimir-Human on 2026-11-28T06:39:59Z.
Thanks for testing and confirming on RTX 3050 Laptop 4 GB! Let us know if anything regresses or if you capture a before/after capture on an 8 GB / 4 GB run.
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.