shader: exact static Wave32 LDS alias, lane-private, and commutative-atomic analysis #289
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/TaynanGT--Vice-Tay!289
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-289"
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?
@Vladimir-Human on GitHub · 2026-11-27 13:44 UTC · original
Vladimir-Human:shader/wave32-lds-hazard-analysis→main· +5793 −363 · 6 files · 1 commits · openSummary
Replaces coarse per-region LDS read+write refusal inside divergent (
!all) lane-branch regions with exact static Wave32 LDS hazard analysis incrates/victory-shader/src/emit/lds.rs, unlocking nativeWaveSize(32)lowering with zero approximation while preservingVICTORY_LDS_FLAGS,loose_lds, and opt-inVICTORY_LDS_WRITE_ONLY_OK=1(32-lane hosts only).What Changed
crates/victory-shader/src/emit/lds.rs,lower.rs,mod.rs):region_disjoint_ranges): Accepts acyclic!allregions whose accesses resolve to non-wrapping (MAX_OFFSET = 1 MiB) constant byte offsets on one shared group-uniform base (s < cs.user_sgprs()/GroupId, excludingscratch_wave_offset, uninitialized SGPRs, VOP3B carry/SCC, non-inline special constants, andOperand::Attr), with<4-byte enclosing-dword guards (ranges_may_overlap) and group-uniform stored data verified across every stored dword (is_uniform_ds_operand/is_uniform_val_at) so concurrent stores from both 32-lane halves are idempotent. Cyclic regions permit only disjoint reads and same-family commutative atomics.region_lane_private): Proves injective per-thread private slots across all active(x, y, z)workgroup dimensions and pairedv_mbcntconsole lanes (group <= 64) with half-open[min_lo, max_hi)cross-cluster footprint disjointness (covering partial workgroup sizesn = 33..63), optionally combined with disjoint constant reads and disjoint constant non-returning commutative atomics.region_commutative_atomics+ModCong): Accepts acyclic or cyclic!allregions of strictly non-returning (dst.is_none() && !name.contains("_rtn")) 32-bit integer commutative/associative atomics (ds_add_u32/ds_sub_u32,ds_or_b32,ds_and_b32,ds_xor_b32,ds_min_u32,ds_max_u32,ds_min_i32,ds_max_i32). Single-family regions allow arbitrary dynamic scatter addresses (e.g., histogram/bitmask loops); multi-family regions prove dword disjointness via wrap-safe modular congruencex == rem (mod 2^bits)(bits >= 3, e.g., dynamictile * 8 + 0vstile * 8 + 4) or disjoint constant offsets on a shared uniform base. All_rtnreturning atomics,ds_rsub_u32,ds_cmpst*,ds_wrxchg*,ds_min_f32/ds_max_f32, divergents_barrier, and unknown DS ops remain refused unless proven lane-private.!allregions are refused by default (CyclicSharedWrite/WriteWriteOverlap); the legacy write-only / returning-atomic shortcut stays strictly opt-in behindVICTORY_LDS_WRITE_ONLY_OK=1on 32-lane hosts only.eval_mod_val,eval_val, andis_uniform_val_at(mod_memo/val_memo/unif_memofor cycle-free nodes + per-queryEvalState::localfor cycle-hit nodes, checking dominance before lookup/insert) to keep deep shared/cyclic DAGs linear.lower.rs: Moveslds_flag_regionintoemit/lds.rs(lower.rsshrinks from604.5 KiBto577.9 KiB, well below the640 KiBpolicy cap) and refinesVICTORY_WAVE_WHYreasons viaRefusal::reason().crates/victory-shader/src/lib.rs,crates/victory-gpu/src/shader_cache.rs):TRANSLATOR_VERSION9 -> 10so cached Wave64 shaders affected by the exact analyzer re-translate cleanly."VICTORY_LDS_WRITE_ONLY_OK"alongside"VICTORY_LDS_FLAGS"inshader_cache.rs.Attribution
vitutu1/victory-perf#12), incorporating@Dathinel's partial-workgroup byte-alias half-open footprint fix; extended here with Refinement C commutative-atomic +ModConganalysis, Refinement A uniform-data enforcement, default write-only soundness refusal, and cycle-safe DAG memoization.Verification
Verified on Windows 11 (
NVIDIA GeForce RTX 4070 SUPER, native D3D12 SM 6.6 Wave32 hardware,dxil.dllvalidation,VICTORY_D3D12_DEBUG=1,--test-threads=1,0D3D12 debug errors):cargo run -p xtask -- policy(314 files ok),cargo test -p xtask(11/11),git diff --checkclean,merge-treeclean againstmain.cargo clippy -p victory-shader --all-targets -- -D warnings(default &--all-features) andcargo clippy -p victory-gpu --lib -- -D warnings: 0 warnings.emit::lds, 24/24 in0.38s):exhaustive_byte_access_oracle_has_zero_false_accepts(48,212cases,0false accepts)exhaustive_mod_congruence_oracle_has_zero_false_disjoint_claims(35,721cases,0false disjoint claims)exhaustive_ranges_may_overlap_oracle_has_zero_false_disjoint_claims(72,000cases,0false disjoint claims)exhaustive_commutative_atomic_families_are_schedule_invariant(all 8 algebraic families across Wave64, hi-then-lo, reversed, and interleaved schedules)emit::wave64_tests, 32/32;lds_*7/7 HW + 7/7 WARP):35dispatches total on RTX 4070 SUPER, all assertinglowered.wave_size == Some(32)strictly withoutloose_lds/local_waves/widen+ bit-exact Wave64 parity): Refinement A disjoint ranges, Refinement B lane-private + returning atomic loop, Refinement C1 dynamicds_add_u32+ds_sub_u32histogram loop, Refinement C3 multi-family dynamic stride-8ds_max_u32+ds_min_u32, and mixed B+C private scratch + shared counter.VICTORY_LDS_WRITE_ONLY_OK=1opt-in verified).victory-shader&shader_cache: Fullvictory-shaderHW suite (356 passed; 0 failed; 4 ignored),victory-gpu --lib shader_cache(4/4).@TaynanGT on GitHub · 2026-11-27 13:48 UTC · original
@Vladimir-Human The important correctness checks are partial workgroups, aliased dwords and atomics that return a value. Keep the negative cases next to the new accepted cases so the analyzer proves why each Wave32 lowering is safe. The hardware comparison should use complete readbacks on the same inputs.
@Vladimir-Human on GitHub · 2026-11-27 13:52 UTC · original
@TaynanGT CI is now green across Clippy, Default tests, Diagnostics tests, and
check. Here are the paired accepted/negative checks and full-readback hardware tests on disk for each area:n = 33..63):crates/victory-shader/src/emit/lds.rs:4709(partial_workgroup_byte_alias_is_refused) pairs the aliasing negative case ([0, n)byte write vs uniform read atn - 1-> refused, Wave64) next to the disjoint accepted case (read atn-> Wave32) forn = 32, 33, 63, 64(including end-to-endn = 33, 63lowering).lds.rs:4772(exhaustive_byte_access_oracle_has_zero_false_accepts) sweeps48,212(n = 32..=65, stride, initial, r)combinations with0false accepts.<4-byte enclosing-dword & range/stride overlap):lds.rs:3599(overlapping_constant_offsets_refuse_wave32),lds.rs:3610(wide_b128_disjoint_and_overlap_checks), andlds.rs:3644(uniform_base_shared_disjoint_and_mismatch_refused, including unalignedds_write_b8+ds_read_b32enclosing-dword refusal) sit alongsidelds.rs:3980(exhaustive_ranges_may_overlap_oracle_has_zero_false_disjoint_claims,72,000checks).lds.rs:3759(commutative_non_returning_atomics_recover_exact_wave32) pairs accepted stride-8ds_max_u32+ds_min_u32directly next to colliding stride-4, cross-family, plain-write, and overlapping private+counter negative controls, backed bylds.rs:3894(exhaustive_mod_congruence_oracle_has_zero_false_disjoint_claims,35,721cases).lds.rs:4825(refinement_a_requires_uniform_write_data) andlds.rs:4924(unproven_write_only_regions_refused_by_default_and_gated_by_opt_in) pair lane-varying stores and unresolved cross-branch/cyclic write-only negative cases next to uniform-data positive controls.ds_*_rtn*):lds.rs:3707(returning_and_non_commutative_atomics_require_lane_privacy) pairs refused sharedds_add_rtn_u32,ds_cmpst_rtn_b32,ds_rsub_u32,ds_cmpst_b32, andds_min_f32(64) directly next to accepted lane-privateds_add_rtn_u32attid * 4(32).lds.rs:4539(write_only_ok_flag_handles_returning_atomics_and_four_kernels) andcrates/victory-shader/src/emit/wave64_tests.rs:1717(lds_shared_returning_atomic_stays_wave64) verify shared returning atomics stay Wave64 by default (and remain Wave64 on mixed read+atomic or non-32-lane hosts even under opt-inVICTORY_LDS_WRITE_ONLY_OK=1).crates/victory-shader/src/emit/wave64_tests.rs)::1717lds_shared_returning_atomic_stays_wave64,:1743lds_unresolved_dynamic_waw_and_varying_store_stay_wave64) sit directly ahead of the 5 Wave32 hardware parity tests (:1877lds_disjoint_constant_ranges_wave32_hw_parity— all128dwords;:1939lds_lane_private_and_rtn_atomic_loop_wave32_hw_parity— all128dwords;:2015lds_commutative_dynamic_histogram_wave32_hw_parity— all8bins;:2090lds_commutative_multifamily_mod_stride_wave32_hw_parity— all16min/max dwords;:2161lds_mixed_private_and_commutative_counter_wave32_hw_parity— all65private+counter dwords). Every dispatch checks the full readback buffer bit-for-bit against the exact Wave64 reference across the same boundary lane-count inputs (0, 1, 31, 32, 33, 63, 64+ loop counts;35dispatches total underVICTORY_D3D12_DEBUG=1).@TaynanGT on GitHub · 2026-11-27 14:11 UTC · original
@Vladimir-Human The 33/63-lane checks and full readbacks on the returning-atomic cases cover the boundaries I wanted to see. Keep
VICTORY_LDS_WRITE_ONLY_OKoff for the first comparison and give0bb3acdits own cache directory. #258 and #287 also declare translator version 10.@Aniseto on GitHub · 2026-11-27 18:01 UTC · original
Ran the new Wave32 LDS unit tests on an NVIDIA Blackwell part at
0bb3acd:Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 19.44.35230, DXC 1.9.2609.5, debug build.
The filter covers the analyzer's accepted and negative cases, including the exhaustive byte-access, ModCong and ranges-may-overlap oracles. The thread already has CI plus the owner's checks; this adds a Blackwell host on a newer driver and Windows build. These are CPU-side analyzer tests, so they do not by themselves show execution of the recovered Wave32 programs on hardware.
Not tested: hardware D3D12 execution of these programs, native wave64, AMD and Intel adapters, Wine, release profile, retail titles.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR head in a detached worktree, ran the command above and wrote this report; no game data was used.
@TaynanGT on GitHub · 2026-11-27 18:05 UTC · original
@Aniseto All 24 CPU-side cases are accounted for at
0bb3acd, including the byte-range and ModCong oracles. That gives us an analyzer pass on Windows 11 26200. The complementary check is a complete D3D12 readback for the newly accepted cases, especially the ones involving returning atomics.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.