Recompiler: eliminate redundant split-wave64 compute barriers and share exchange helpers #3655
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3655"
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 ivall/xcl. Originally posted by Kalmarv on 2026-12-02T04:08:28Z.
Eliminates redundant split-wave64 compute spin exchanges and startup barriers, and shares the remaining spin-exchange rendezvous and safe-barrier arrival loops as internal DXIL helpers (
crates/xcl/src/gpu/dxil/only; legacy HLSL untouched). Only the top 2 commits (b995046b6,685008d1e) belong to this PR (+2417/-281across 12 files, of which ~750 lines are new unit and GPU tests inmask_exchange.rs);#3504and @Royalflamejlh's#3563commits are preserved intact underneath. All new compute exchange-elimination passes remain gated under #3563'sXCL_WAVE64_IDIOMS=0switch.What is in it
b995046b6) — Share split-wave exchange and barrier loops as DXIL helpers (module.rs,module/opt.rs,module/split.rs,lanes.rs,lower.rs,kernel.rs,core_tests.rs,robustness_tests.rs):@xcl.spin.wait: participation/latched-failure check in the sign bit, both TGSM fences, leader election, counter signal/poll/timeout CAS, and wave broadcast) and one for the early-exit-safe workgroup barrier arrival loop (@xcl.barrier.arrive).Lw::spin_bases) instead of rebuilding them at each exchange.module/split.rs) dropsspin_regions, charges helper bodies against piece budgets, preserves the multi-wave LDS-polling restriction for@xcl.barrier.arrive, and retainsFeature::WaveOpson pieces calling@xcl.spin.wait.685008d1e) — Eliminate redundant split-wave64 compute barriers and exchanges (mask_exchange.rs,idioms.rs,lanes.rs,lower.rs,lower_valu.rs,kernel.rs,compact.rs,core_tests.rs):#3563(idioms.rs): keeps#3563'sXCL_WAVE64_IDIOMS=0gate,plain_sopk+ SCC kills (addingS_SETREG_IMM32_B32),s_or_b64 exec, exec, srestore joins,Kernel::exchange_sites, anduniform_readsfallback for mesh and eagerv_readfirstlanesites.S_CBRANCH_EXECZ/NZon each half's own EXEC word, includings_endpgmtails, compute LDS programs with explicitLw::lds_store_order, all*_SAVEEXEC_B64forms, scalar-only compares, and half-overwritten pairs).mask_exchange::lazy_meets,Lw::meet_at,Lw::keep_lane): ballots andv_readlane/v_readfirstlanedefer until the first whole read and batch stale pairs and lane reads into one rendezvous.How::OwnFirst,How::LaneBit) for one-value VGPR first-lane reads, thread-0 EXEC first-lane reads, and lane-number equality compares.Item::Reduce,How::Folded) foror/and/xor/add/min/maxfolded when the halves next meet.Plan::apart,Lw::apart, up to 256 guest instructions without LDS), removing even the startup atomic and group barrier.Plan::own_scc,mask_exchange::leave_is_local) when a half has no active lane left in ans_andn2_b64loop mask.mask_exchange.rs(plus updated#3563test expectations inidioms.rsreflecting lazy batching6 -> 2meets onsix_first_lanesand half-overwritten VCC pairs).Measured impact (vs
#3504+#3563base460cd800f, DXC1.9.2609.5validated)460cd800f→685008d1e):3→0,16→4,1→0,24→4,135→7,0→0); 3 of 6 shaders run completely apart with 0 barriers and 0 atomics (startup sync and atomic eliminated).@xcl.spin.waithelper sharing): 364 → 9 barriers (-97.5%), 545 → 14 atomics (-97.4%).--sample 400 --seed 1 --validate --split 1 --windows 4,460cd800f→685008d1e):6unsupported), 0 validation errors, 0 panics, 0 timeouts.p50): 19.88 ms → 17.92 ms (-9.9%).685008d1evsmain 1c8b55147): 1423 vs 1387 frames shown (+2.6%),60 60 60presents per 2 s, peak commit 15087 MB vs 17480 MB (-2393 MB / -13.7%), 0 device removals, 0 crashes.Tested
610.74), AMD Ryzen 9 9950X 16-Core, Windows 11 Pro10.0.26200.0,rustc 1.99.0 (b940084d7 2026-09-28), DXC1.9.2609.5(debug + release).scripts/test.ps1(cargo build --workspace,cargo bench -p xcl --bench '*' -- --test,cargo test --workspace -- --test-threads=4): 2954 passed, 0 failed, 52 ignored across 43 test targets (24 SKIPPED GPU tests on this adapter: 22no wave64, 2no heap windows).cargo build --release -p xcl: clean (39 warnings, 0 new vsmainand#3504+#3563).1.9.2609.5validation sweep: 329/335 translated, 0 validation errors, 0 panics.Regression run
Baseline (
main):PR head:
Not tested
XCL_HEAP_WINDOWS=1GPU tests (2 skipped under defaultscripts/test.ps1).crates/xcl/src/gpu/recomp/was not modified).AI use
#3563wave64 idioms and#3504dispatch-chain foundation.Codex (GPT-6)wrote the split-wave helper sharing and compute barrier/exchange elimination passes and tests during the offline optimization loops.Antigravity (Gemini 4 Neon)cherry-picked, reconciled the passes with#3563'sidioms.rsand#3504'smodule/split.rs(including preservingFeature::WaveOpson split pieces calling@xcl.spin.waitand keepingXCL_WAVE64_IDIOMS=0gating), ran the base-vs-PR offline A/B measurements,scripts/test.ps1, and the 60 s smoke test, and drafted this description.Imported from ivall/xcl. Originally posted by pvfreis on 2026-12-02T04:56:07Z.
One integration point if #3652 lands before this PR. When rebasing, please carry its exit-bit early exit and shorter spin cap into
xcl.spin.wait, and its shorter workgroup-barrier cap intoxcl.barrier.arrive.The GPU regression in #3652 covers a partner half that has already exited and a completed exchange followed immediately by exit. Keeping both cases matters because the completed exchange must still win when the peer exit bit is already set.
AI use: Codex (GPT-6) checked the overlap and drafted this note. Claude Code (Claude Fable 5.2) reviewed it against excerpts from the pinned commits.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T04:59:17Z.
Thanks for flagging this, @pvfreis — noted! If #3652 lands before this PR, we will carry all of its changes directly into the shared helpers on rebase:
xcl.spin.wait: checkHI2(0xC000_0000) on bounds, maskarrived = c & 0x3FFF_FFFFand testarrived >= need(andactual & 0x3FFF_FFFF >= needin the CAS race path) before inspecting the0x4000_0000peer-exit bit so a completed exchange followed immediately by exit still wins, bail early on peer exit or #3652's shorter spin cap, and keepspin_exchange_exit(reusingspin_bases's counter pointer when present).xcl.barrier.arrive: carry #3652's shorter workgroup-barrier cap.AI use: Antigravity (
Gemini 4 Neon) checked #3652's diff and drafted this reply.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T08:35:59Z.
Review (head
685008d1, diff read, not a merge-check):hle/d3d12x/bind.rs,real.rs,real/dispatch_chain.rs,gpu/recomp/pso.rs,shaders.rsandREADME.mdcome from them, so merging this one merges both unreviewed. This PR's own part is +2417/-281, and685008d1alone is +2064/-53 (about 700 lines tests), holding six separate changes: local EXEC skips, planning compute programs with LDS (with the extra store ordering), lazy meets, reduction folds, waves that run apart, and local loop exits. Over ~800 lines CONTRIBUTING asks for a reason; the description gives none. Possible split: (1) theHelperBodyinternal-function code inmodule.rs(shared with #3654); (2)b995046b(the helpers, about +350); (3)685008d1cut along its six parts, each with its tests, stacked on #3504 and #3563 once those merge.XCL_WAVE64_IDIOMS=0does not turn the new behaviour off. The description says the new passes stay behind this switch, but: theuses()changes ingpu/dxil/mask_exchange.rs~126-148 apply to mesh programs and the eager plan too (all*_SAVEEXEC_B64forms andDS_*other than (b)permute are no longer opaque; SDWA/DPP no longer read EXEC and SCC whole; a pair with one word overwritten no longer counts as a read of the other word); andgpu/dxil/kernel.rs~350/371 now plans compute programs that use LDS (main skipped the plan for any LDS program) and turns onlds_store_order. With the switch off, LDS compute and mesh programs still get the new analysis, so it is neither a clean A/B nor a fallback if a title regresses. Put these behind the switch or correct the description.kernel.rs~361 /mask_exchange::apartlooks only at the instructions. In that formlanes.rs~105 takes the thread index straight from the group with no remap, whilecompute_init(kernel.rs~1231) still derives the TG_SIZE wave index astid / 64. On NVIDIA the hardware waves of 2-D/3-D groups (e.g. 8x8x4) are formed from non-consecutive thread indices (as the design doc notes), so one hardware wave can hold lanes of two console waves and this "scalar" differs between its lanes.known()treats a VGPR moved from any SGPR as uniform, so aHow::OwnFirstv_readfirstlaneof it gives one console wave's index to the other wave's lanes. Narrow (TG_SIZE, no LDS, 2-D/3-D group, at most 256 instructions), but excludingcs.tg_sizefrom the apart form would close it.HelperBodystruct,helper_bodyfield, internal function emission and used-function marking ingpu/dxil/module.rs; the two PRs conflict there and inmodule/split.rsandkernel.rs. This should be one preparation PR both build on.@xcl.spin.wait/@xcl.barrier.arrive(conflicts inlanes.rs,lower.rs,kernel.rs,core_tests.rs); whichever lands second must re-implement the other's behaviour, and #3652's exit regression test should then run against the helpers. #3643 also changes howmask_exchange::uses/plantreat the EXEC read ofv_readfirstlane. Textual conflicts also with #3633, #3645, #3656, #3663, #3668, #3669.Fine (by reading): the two helpers keep the old meaning (sign-bit failure latch replaces
VAR_XDEAD; same 2^20 poll limit and compare-exchange on timeout); dispatch-chain planning still refuses to cut a polling loop on the LDS (split.rs~181); the regions skipped byskip_is_local/leave_is_localcontain no meet, LDS access or lane read; the apart form rejects meets, LDS, MBCNT, DPP/SDWA and lane-number compares and is never cut into a dispatch chain.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T08:49:10Z.
Diff review (head
685008d1e, read-only code review — not a test report):Strong work on the wave64 barrier/exchange reduction architecture and the
VAR_XDEADsign-bit latch inxcl.spin.wait. A full line-by-line audit of all 20 files found two high-impact soundness/memory bugs in the new lazy-form compute pass, plus scope/stacking concerns:[CRITICAL] Unsound uniform-VGPR tracking in
mask_exchange.rs::known_stepandvgprs_alivecan silently miscompileV_READFIRSTLANE_B32asHow::OwnFirst(skipping cross-half exchange) and mis-firefold()(crates/xcl/src/gpu/dxil/mask_exchange.rs:505-518,:691-699):rdna2::vgpr_uses(crates/xcl/src/gpu/rdna2.rs:607-609) only addsVDSTtovrforV_FMAC_F32,V_MAC_F32, andV_FMAC_LEGACY_F32. Unlikeidioms.rs:203-207(which explicitly guards these cases),known_step(mask_exchange.rs:514-518) misses four non-uniformity sources:V_CVT_F16_F32,V_ADD_F16,V_MUL_F16,V_MOV_B16,V_FMA_MIXLO_F16,V_FMA_MIXHI_F16, etc. whereVDSThaso.size < 32): preserve per-lane high bits[31:16], yetvromitsVDST, soknown_stepmarksVDSTas uniform (k.all).V_DOT2C_F32_F16,V_DOT4C_I32_I8,V_PK_FMAC_F16,V_FMAC_F16): accumulate into per-laneVDST, yetvromitsVDST-> falsely marked uniform (k.all).SDST == NULL (125)and per-lane carry mask inSRC2(V_ADD_CO_CI_U32 v1, null, s0, s1, s[4:5],V_SUB_CO_CI_U32,V_SUBREV_CO_CI_U32):touches(mask_exchange.rs:213) filters out125, leavingtouch.1 == 0, andtouch.0 & (VCC | EXEC) == 0becauseSRC2is anOPR_SREGpair rather thanVCC-> falsely marked uniform (k.all).BUFFER_LOAD_DWORD*(mask_exchange.rs:516): marks uniform-address vector buffer loads as uniform across both asynchronously scheduled wave32 halves, directly contradictingdocs/wave64-on-wave32.md:199-200in this same PR ("nor a memory load: another wave may write that memory between the halves' loads").vgprs_alive(mask_exchange.rs:696-698:let kills = valu(d) && known[i].is_some_and(|k| k.ones)) falsely kills live VGPRs beforefold().Applying the same guards used in
idioms.rs:203-207(includevwinvrforo.size < 32/MAC/DOT*C, checkOPR_SREGcarry-in inputs, and dropBUFFER_LOAD_DWORD*fromsame) fixes all five cases.[HIGH] Guest LDS budget blowup when
compute && lds(crates/xcl/src/gpu/dxil/kernel.rs:346-358,crates/xcl/src/gpu/dxil/mask_exchange.rs:92,:1184,crates/xcl/src/gpu/dxil/lanes.rs:40-42):kernel.rs:346disables batching (batch = !ldsat:358) with the comment "With LDS, larger slots would cut into the guest LDS (no batches)", yet still passeslazy = compute(true) whenlds == true. In lazy mode,mask_exchange.rs:1184growsp.wordsup toMEET_WORDS = 16, andlanes.rs:40-42carves4 * xslot * wavesdwords out of the fixed 32 KiB (8192dwords)xcl_ldsarray. For a 1024-thread group (waves = 16,xslot = 16), that silently steals 1,024 dwords (4 KiB = 12.5%) of guest LDS (vs 256 B previously), clamping/corrupting shaders using >27.8 KiB of guest LDS. Cappingxslotto1(or disabling multi-word meets) whenlds == truekeeps the guest LDS budget intact.[Scope / Stacking] Size (
+4352/-348, 20 files) & overlap with#3652and#3654:This PR bundles several independent changes (
idioms.rs, lazy meets/reductions/apart, sharedxcl.spin.wait/xcl.barrier.arrivehelpers, and multi-wave/LDS/safe-barrier/two-pass-meshdispatch_chainsplitting). Splitting it along those natural boundaries will make review and bisecting much cleaner and ease coordination with#3652(xcl.spin.waitpeer-exit handling) and#3654(which also introduces internal helper functions inmodule.rs).AI use: Antigravity (Gemini 4 Neon) audited the full diff against
mainand drafted this review.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T11:16:05Z.
merge-check
base:
1c8b551475head:
685008d1e9merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2954 passed, 0 failed, 52 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3655#issuecomment-7339668864 and its findings stand. Most serious: +4352 lines, 14 of its 16 commits are copies of open #3504 and #3563, and the switch off doesn't turn the new analysis off.
performance: 60 s smoke of a retail title, main
1c8b5514vs this merge (685008d1): 1652 -> 1588 frames shown (96 %; last presents per 2 s: 60 60 60), peak commit 18228 -> 15994 MB, 0 device removals, 0 crashes.verdict: not yet: +4352 lines, 14 of its 16 commits are copies of open #3504 and #3563, and the switch off doesn't turn the new analysis off (see the review)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by AAsobu on 2026-12-03T06:12:05Z.
GPU hang (
0x887a0006) on an RTX 3090 (wave32), retail title, currentmain— report with a bisect.What is seen:
D3D12 device removed: 0x887a0006, 155–261 s into the run, with DREDpage fault at GPU VA 0x0; allocations there: [].Where DRED puts it:
vs 505022186d7aeaa4 ps c1cffdc3f13a4f2fbound; 4 of those at exactly the same place (8897 of 11147 operations done), on different builds.cs b2901c3a82a606c1twice,cs 7b0c2ac0ea62b4d4once).Starts with the page fault, per build (360 s each):
1c8b5514df0cfef6(+#3566)d71578f8(+#3655)5eaadb545ad98adb078358a0(+#3652)078358a0+ #2349So it starts with #3655 (none in 18 starts before it). #3652 may make it rarer (about 1 in 3 starts before, 2 in 13 after) but does not remove it. Twice it hit two starts in a row.
Separate, once: on
df0cfef6one start ended at 182 s withqueue.Wait ... did not complete within 5000 msbetween q1 and q4 (each waiting for the other's 0x7a3), then the watchdog stopped the title and the device was removed during the drain, with no DRED page fault. Not seen in any other start listed above.hardware / tool and model: RTX 3090 24 GB (driver 621.24), i5-10600K, 32 GB, Windows 11 26300 / Claude Code (Claude Opus 5.5)