d3d12-shader: Wave64 loop convergence, lane provenance, and wide/sub-dword paired LDS (D3D12-SHADER-PAIRED-WAVE64-EXACTNESS) #2662
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2662"
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 ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-30T00:09:06Z.
Claimed in the coordination issue as: D3D12-SHADER-PAIRED-WAVE64-EXACTNESS (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7250778009, https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7264381245)
What and why
Fixes
D3D12-SHADER-PAIRED-WAVE64-EXACTNESSacrossd3d12/crates/leonida-shader/src/emit/{mod.rs, wave.rs, paired.rs, lower.rs, paired_tests.rs, wave64_tests.rs}:LEONIDA_LOOPS_WAVE=1), partial-grouphost_widemasking + dead-half-wave exit, and fixpoint loop-region tracking:loops_wavedefaulted to0whenLEONIDA_LOOPS_WAVEwas unset, leaving threads that exited per-lane loops on earlier iterations in independent sub-warps on 32-lane hosts (NVIDIA), which corrupted post-loopwaveActiveBallot/exchange_halves/v_readfirstlane/v_mbcnttile appends (CS_TransmissionVolumetrics_GenerateTiles1aa247ed3653b616and boundary tile classifiers).loops_wavenow defaults to1for Wave64 compute programs on 32-lane hosts while keepingLEONIDA_LOOPS_WAVE=0as an explicit opt-out (aftertrustno1-coder/VIctory-NVIDIA64d4931, GPL-3.0).Lower::wave_wide, thehost_widebranch now masksminebyself.partial_active(And(mine, a)forany,Or(mine, Xor(a, true))for!any) and combines withwaveAnyTrue(a)when an entire 32-lane host half-wave is unlaunched (waveAnyTrue(a) == false) so dead half-waves exit on iteration 1 and reach post-loop barriers cleanly instead of spinning toLOOP_LIMIT.lower::lane_regions(all_lane_blocks,branches_around) treated per-lane loop exit,continue, or guarded-breakblocks as wave-converged whenever post-dominated across later iterations.lane_regionsnow intersects each retreating edge's backward walk fromlatchwith forward reachability fromhead(keeping exact natural loops on reducible CFGs and exact loop SCCs on irreducible CFGs without leaking into entry block0), merges loop bodies sharinghead, and closes the non-post-dominated walk to a fixpoint overfull_by_headwhenever a per-lane branch reachesheador exitsfull_bodydirectly or through intermediate blocks (while keeping diamondif/elsejoins and nested loops inside uniform outer loops unexpanded).Sym::Own(Value, u32)&Shape::Lane(Value, u32)):wave.rstracked initial lane values asSym::Own(Value)without their source lane index0..wave, miscompiling fixed-lane broadcasts inside whole-wave sections (s_or_saveexec_b64 -1..v_readlane_b32 s_dst, v_src, <lane>) into per-lane identity reads (Shape::Value(v_src)).Sym::Own(Value, u32)andShape::Lane(Value, u32)now preserve the exact source console lane0..63, lowered across both halves inpaired_shapeand throughconsole_lane_read(with half-wave refusal and cachedevery_lane_blockfull-wave convergence checks) inLower::shape(afteredsuuu/VI-BR-PORTcf3394bandTaynanGT/Vice-Tay5e588e8, GPL-3.0).paired_crossv_readlane_b32withLower::valu:paired_instinterceptedv_readlane_b32beforeLower::valu, bypassingResources::restored_lanesand post-sectionSection::reads.paired_crossnow lowers both across lower and upper paired halves (self.both/put_lanes) before general lane shuffles and appliesmemory_guardinv_readfirstlane_b32andds_bpermute_b32.paired.rsalongside_rtnatomics,ds_cmpst_rtn_b32, andds_subCAS loops:supports_paired_ldsandpaired_ldstods_read_b64/_b96/_b128,ds_write_b64/_b96/_b128,ds_read2_b64,ds_write2_b64,ds_read2st64_b32/_b64,ds_write2st64_b32/_b64, and sub-dwordds_read_{u8,i8,u16,i16}/ds_write_{b8,b16}(plus_d16and_d16_hi), using atomicRmw::And+Rmw::Orfor sub-dword writes so lower and upper console lanes sharing an LDS dword never clobber each other, preserving multi-wavebarriers_on_every_way,_rtninteger atomics,ds_cmpst_rtn_b32, andLower::lds_int_subcompare-exchange loops fords_sub_u32/ds_sub_rtn_u32/0 - xadds, and guarding every dword access byindex < dwordsso out-of-bounds reads/returns yield0and out-of-bounds writes drop cleanly (afterTaynanGT/Vice-Tay5e588e8,fxceless/victory-fork, andvoidopcode/vilocityadd4873/5c8149f, GPL-3.0).USER_DISPATCH_THREADS_X) Wave64 compute programs and 1-DBeforeWiderescue inpaired:spill::is_spilledrefusal inemit::pairedand decouples theBeforeWidepairedfallback from the 2-Dtilecheck (while keepingwiden()'s barrier-heavy fallback gated ontileunlessLEONIDA_WAVE_WIDE_LAST=all) so refused 1-D[64, 1, 1]groups with divergent cross-half LDS regions translate cleanly.partial_activemasks inLower::run(counted = true)against console group widthcs.threads[0]without early-exiting host threads needed at LDS barriers, swapspartial_activeinLaneState/swap_lanes, and applies per-halfpartial_active/launchedacrossmask_dword,scc_some,wave_wide, andpaired_f64_constant_sum.Tested
origin/main):all_lane_blocksleft per-lane loop latches, shared-latch / directcontinueloop bodies, and guarded-breakblockstrue;whole_wave_section_fixed_lane_broadcast_preserves_lane_provenancereturned0x12340000 + tinstead of0x12340000 + lane; unmaskedhost_wideloops in partial thread-countedhalves/exchangedispatches spun toLOOP_LIMIT; andpaired_readlane_after_whole_wave_section_and_restored_parked_scalar,paired_lds_wide_strided_and_subdword_accesses_across_halves,the_lds_operations_the_paired_form_takes, andpaired_partial_thread_counted_dispatch_masks_both_halves_and_keeps_barriersfailed withUnsupported/ assertion errors.cargo test --manifest-path d3d12/Cargo.toml -p leonida-shader --lib paired_tests -- --test-threads=4(default &--features host) ->22/22passed (GenerateTiles64-group post-loop append + 1-D refused group rescue, multi-wavebarriers_on_every_way, fixed-lane whole-wave broadcasts acrosslane in [0, 19, 31, 32, 37, 63]andstart in [0, 16, 40],Section::reads+restored_lanes,ds_read_b64/_b96/_b128+ OOB +2st64_b32/_b64+ concurrentb8/u8/i8/b16/u16/i16+_d16/_d16_hi+ds_sub_rtn_u32CAS loop +ds_cmpst_rtn_b32+ OOB return0, spilled partial thread-counted[2, 1, 1]dispatches in bothpairedandhost_widehalves/exchangemodes including iteration-1 dead-half-wave exit proof, and direct/trampolined/shared-latchcontinue, guardedbreak, irreducible 2-entry loop, and diamond/nested-loop non-expansion CFG checks).cargo test --manifest-path d3d12/Cargo.toml -p leonida-shader --lib wave64_tests -- --test-threads=4(default &--features host) ->30/30passed;lds_subtracts(--features host) ->2/2passed;emit::tests->23/23passed.cargo clippy --manifest-path d3d12/Cargo.toml -p leonida-shader --all-targets(default &--features host) ->0warnings on touched code.python -I scripts/check_no_game_data.py->0issues.GPUs tested: NVIDIA GeForce RTX 3090 (driver 610.88) and Microsoft WARP, Windows 11 Pro (26200)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a:d3d12/crates/leonida-shaderDXIL backend;docs/design.mdcoverstools/rdna2spirv.py)Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-30T00:47:17Z.
Native D3D12 Wave64 verification on RTX 4090 (NVIDIA 616.64, Windows 11 build 26300, MSVC, Rust 1.98.1, SDK 26100 DXIL validator). I merged
ab78da371ontob8bd37111(tree9be32c2d3).cargo test --locked -p leonida-shader --features host --lib:paired_tests22/22,wave64_tests30/30,lds_subtracts2/2. These filters mix CPU and GPU assertions.b8bd37111under the same toolchain and driver.Synthetic inputs only. AI-assisted with OpenAI Codex (GPT-6.2 Sol).
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T00:50:51Z.
Independent Wave64 verification on Wine and RADV. I merged
ab78da371intomainb8bd37111(tree9be32c2d3) and built the Win64leonida-shadertests with--features host. Wine 11.22 and VKD3D-Proton71cae091, RTX 4070 SUPER (620.73.04) and Radeon Raphael (RADV 26.3.1).paired_testsand 30wave64_testspassed on each GPU. Thewave64_teststotal includes three optional native-Wave64 hardware paths that loggednot runon NVIDIA and one 32-lane-only flag-dispatch path skipped on RADV.mainand the merged tree.Synthetic fixtures only. AI-assisted with OpenAI Codex.