Repository navigation
Recompiler: eliminate redundant split-wave64 compute barriers and share exchange helpers - #3655
Conversation
Single-wave 2D/3D native wave32 compute groups (y * z > 1, total <= 32) no longer allocate @xcl_wt or emit the wave-index atomic and barriers, since tid equals WaveGetLaneIndex(). Multi-wave 2D/3D groups also skip the trailing barrier unless sharing xcl_lds[8191]. Extend direct DXIL compute dispatch splitting to all full-wave native wave32 threadgroup shapes without guest LDS (total >= 32, total % 32 == 0): size per-group scratch by total threads, preserve @xcl_wt only as the wave-ID prefix for multi-wave 2D/3D groups while gating the wave64 exchange state machine on xcl_xs, select FlattenedThreadIdInGroup() for multi-wave 1D groups, and recompute Feature::WaveOps per piece so pieces without wave ops validate. Part of xcl-dev#1269, xcl-dev#2088. Assisted-by: Antigravity (Gemini 4 Neon)
Use the workgroup's flat logical thread ID for the continuation of each wave32 half. Keep each counter signal with its peer wait, and transfer the per-half arrival counters and double-buffered exchange slots at a group-wide rendezvous between pieces. Wave allocation starts afresh in each piece. Leave guest LDS and partial guest waves on the whole path. Exercise four wave64s with different exchange epochs across repeated cuts and compare every output word to the whole shader and a CPU oracle. Assisted-by: OpenAI Codex (GPT-6) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adopt WebIdentity1's four-wave fixture. Two guest waves return at different points while the other waves keep exchanging. Compare the whole shader and the dispatch chain to the CPU oracle across a 3D grid. Source: xcl-dev#2097 (comment) Assisted-by: OpenAI Codex (GPT-6) Co-authored-by: WebIdentity1 <212448219+WebIdentity1@users.noreply.github.com>
The dispatch-chain splitter kept every program with guest LDS whole: its mutable-global check refused xcl_lds, and its scan refused LDS loads, stores and atomics and guest barriers. Now the LDS (with the split form's exchange words at its top) is copied to the per-group scratch at each piece exit and back at the next piece's start, like the exchange slots of several split waves. Geps into it can cross a cut as their index. In the split form the lane counter lives in the LDS too, so a piece meets once more before restoring over it. One console wave follows the guest's scalar control flow, so any cut keeps its guest barriers paired. A group of several waves can branch and return apart: a piece of such a program starts only at a component every thread enters exactly once (no earlier edge jumps past it, no earlier block returns), and a loop that reads the LDS (a load or an atomic), which could poll for another wave's write past a cut, keeps the program whole.
Large direct DXIL compute shaders with guest LDS stayed whole when a single native wave32 was laid out across multiple group dimensions, or when a full guest wave64 used two hardware wave32 halves. Admit native wave32 LDS groups by their 32-thread count. Pass the flat split lane ID for a 64-thread LDS group so each piece can replay lane allocation before restoring LDS. Exercise three wave32 shapes and an 8x4x2 split wave64 group, and reject a two-wave native LDS group. Earlier measurements on an RTX 3060 with cold caches compared whole pipeline builds with pieces built in parallel: 219287eb2f6021fe 217.2 s -> 9.2 s 7b468aa4210b1810 74.9 s -> 5.9 s df45a39c275d0db5 65.7 s -> 4.0 s Assisted-by: OpenAI Codex (GPT-6.2 Sol) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rier A program of several hardware waves whose guest s_barrier became the early-exit-safe barrier (`Lw::safe_barrier_sync`: groupshared `xcl_bar`, a live-wave count and an arrival/generation word, polled with atomics) stayed whole: the planner refused the `xcl_bar` global, its atomics and fences. A retail title's 253 KB mesh producer (128 threads, split wave64, no LDS) had no other blocker. The planner now lets the barrier through. Its two words are saved and restored at each cut like the LDS, and a GEP into it is transported by its index. Its group syncs are allowed only in `Block(0)` (its set-up), where every thread starts; its polls use TGSM fences only. Cuts need not be where the whole group passes: pieces follow the program's flow (components in topological order) and keep a loop whole, so a wave polling at a barrier in a piece waits only for waves that reach that barrier in that piece or have already arrived. Test: four hardware waves, three barriers between wave-divergent loops and branches, cut into 14 pieces where the waves do not pass together; results and the barrier words (four waves alive, generation 3) match the whole program on an RTX 5070 Ti. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The compute pass of a two-pass mesh pipeline (the console mesh program writing one record per group) was always one compute pipeline. A retail title's 253 KB foliage producer took the NVIDIA driver 6.7 s cold, the longest compile of the pipelines its world needs. The direct translator now plans a chain for an `Entry::Mesh` (split wave64, a multiple of 64 threads, no LDS but a single wave's) as it does for a compute program, and the translation keeps it (`TwoPass::cs_chain`). `finish_two_pass` builds the pieces with `dispatch_chain::build` when the whole form is not ready from a cache (memory, disk or pipeline library); a library being built keeps the whole. A direct DispatchMesh runs the chain; an ExecuteIndirect runs the chain's whole form (`whole_ready`; skipped while it is still being built), and XCL_TWO_PASS_BATCH=2 does not defer a chain. Measured on an RTX 5070 Ti, 8 cold graphics/mesh recipes replayed with `xcl shaders --graphics-records --threads 8`, translation warm, driver cache off: wall 6.99 / 7.09 / 7.09 s before, 6.13 / 6.12 / 6.18 s after; peak commit 1.07 - 1.13 GB before, 0.93 - 0.96 GB after. The foliage producer's 6.65 - 6.76 s became four pieces of 71 - 113 KB (longest 1.73 - 1.84 s), a 123 KB depth producer's 2.53 s two pieces (longest 1.17 - 1.26 s). The batch is now bound by its 300 KB graphics pipelines (4.8 - 6.0 s). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A forward s_cbranch_execz over per-lane work reads each half's own word of EXEC, so the compare behind it is not exchanged (gpu/dxil/idioms.rs, the conditions in docs/wave64-on-wave32.md, "Idioms"); s_or_b64 exec, exec, s at its target gives the saved EXEC without asking for EXEC whole. XCL_WAVE64_IDIOMS=0 turns it off and tags the translated cache and the warm pipeline library's settings. Kernel::exchange_sites counts where the halves meet in a translation. On a retail pack's 9 442 distinct wave64 compute and mesh programs (retail_wave64_compute_exchange_census): 157 393 exchanged compares before, 114 214 with the votes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… value v_readfirstlane of a value every lane of EXEC holds (scalar arithmetic the compiler does in a VGPR) is the same in each half's first running lane of EXEC: the halves exchange it only when one of them has no such lane (idioms::uniform_reads, Lw::read_first_lane_uniform; the rule in docs/wave64-on-wave32.md). Kernel::exchange_sites leaves that exchange out. A lane mask an instruction reads (v_cndmask_b32's, a carry in, v_div_fmas' VCC) has to have one bit for all of EXEC's lanes, and the destination an accumulator or a 16-bit result keeps part of counts as an operand. In the same pack's programs 38 702 of 57 884 v_readfirstlane are such reads. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
s_movk_i32, s_cmovk_i32, s_addk_i32, s_mulk_i32 and s_cmpk_* read and write the registers they name, s_waitcnt_*cnt and s_version none; s_cmpk_* and s_addk_i32 replace SCC. The split form's mask demand took every SOPK instruction for one that may read any register, so a compare before any of them was exchanged: 114 214 exchanged compares in the pack's wave64 compute and mesh programs, 90 743 without that. Under XCL_WAVE64_IDIOMS as the other idioms. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Emit one internal DXIL helper per shader for the split-wave64 spin-exchange rendezvous (@xcl.spin.wait: participation check, both TGSM fences, leader election, counter signal/poll/timeout CAS, and wave broadcast with latched sign-bit status) and one for the early-exit-safe workgroup barrier arrival loop (@xcl.barrier.arrive). Compute own/peer slot bases and counter pointers once per compute entry instead of per exchange. Because each rendezvous is now a single indivisible call, dispatch-chain planning no longer needs spin_regions tracking; it charges both helper bodies against piece budgets and keeps WaveOps in piece features whenever @xcl.spin.wait is called. Assisted-by: Codex (GPT-6) Assisted-by: Gemini 4 Neon
…hanges Build on xcl-dev#3563's split-wave64 idioms to eliminate redundant inter-half spin exchanges and startup barriers in direct DXIL compute shaders (all gated under XCL_WAVE64_IDIOMS): - Local EXEC skips (S_CBRANCH_EXECZ/NZ) on each half's own EXEC word, including s_endpgm tails, LDS compute programs (with explicit LDS store ordering), all *_SAVEEXEC_B64 forms, scalar-only compares, half-overwritten pairs, and xcl-dev#3563's s_or_b64 exec restore joins. - Lazy meets: ballots and v_readlane/v_readfirstlane defer until the first whole read and batch stale pairs and lane values into one rendezvous. - Local lowering for one-value VGPR first-lane reads, thread-0 EXEC first-lane reads, and lane-number equality compares. - Deferred cross-half wave reductions (or/and/xor/add/min/max) folded when the halves next meet. - Hardware waves that need nothing of one another run apart without the startup atomic or group barrier (for programs up to 256 guest instructions without LDS). - Local loop exits when a half has no active lane left in an s_andn2_b64 loop mask. Assisted-by: Codex (GPT-6) Assisted-by: Gemini 4 Neon
|
One integration point if #3652 lands before this PR. When rebasing, please carry its exit-bit early exit and shorter spin cap into 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. |
|
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:
AI use: Antigravity ( |
|
Review (head 685008d, diff read, not a merge-check):
Fine (by reading): the two helpers keep the old meaning (sign-bit failure latch replaces AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
|
Diff review (head Strong work on the wave64 barrier/exchange reduction architecture and the
AI use: Antigravity (Gemini 4 Neon) audited the full diff against |
…e tracing Cut CPU overhead and allocations in the direct-DXIL optimizer and frontend: - Reuse instruction definitions, compact scoped CSE bucket chains, hash value-numbering keys a word at a time, filter hoist candidates before cloning operands, and stop optimizer iterations once passes no longer expose late phis, guarded selects, flat-read rewrites, or CFG changes. - Fold unsigned integer comparisons at operand bit-width endpoints (e.g. x <u 0, x <=u MAX), which simplifies emitted DXIL while preserving program semantics. - Reuse successor storage across DXIL CFG walks (including split.rs uniform-cut planning after xcl-dev#3655), borrow operands while tracing signature inputs once per output component, and scan VGPR bounds only when relative vector indexing is present. - Add a GS-phase LDS store to split_epilogue_clamps_lds_to_lds_top_and_validates so its emitted vertex loop stays live after folding `k <u 0 -> false`. Co-Authored-By: Codex (GPT-6) <noreply@openai.com> Co-Authored-By: Antigravity (Gemini 4 Neon) <noreply@google.com>
Rebase helper outlining directly onto main (reusing xcl-dev#3655's HelperBody representation) and outline repeated direct-DXIL helper sequences into shared internal functions with inherited BLOCKINFO function abbreviations: - Heap raw buffer loads: xcl.sbuf.word, xcl.sbuf.word2, xcl.sbuf.word4, and xcl.raw.word4, reusing private alloca output slots for multi-word results in whole-entry dispatches. - Dynamic buffer format decode: xcl.fmt.decode (leaving fmt_encode, scalar_flat_read, and f16 RNE rounding inline). - Arithmetic and address helpers: xcl.mul.legacy, xcl.fmad.words, and xcl.read.carry. - Optimizer and dispatch-splitter accounting: treat all four heap-load helpers as DCE-removable and raw-load flagged, infer ResourceHeapIndexing for them across split pieces, and charge every outlined HelperBody against dispatch_block_cost. - Opt-out switch: XCL_DXIL_OUTLINE=0 keeps all outlined helpers inline and appends xcl-dxil-outline-0 to the translator cache tag. Co-Authored-By: Codex (GPT-6) Co-Authored-By: Antigravity (Gemini 4 Neon)
Since xcl-dev#3655 a split-wave64 compute program calls two internal DXIL functions, xcl.spin.wait and xcl.barrier.arrive, which take groupshared pointers. vkd3d-proton's dxil-spirv cannot give a pointer parameter a SPIR-V type: it logs "Cannot reliably convert LLVM pointer type, we cannot differentiate between Function and Private" and calls std::terminate() (dxil_converter.cpp, get_type_id). Under Wine every title whose compute shaders use them ends a few seconds after start, while a pipeline is built ahead (status 0x3), on any GPU; on an RX 7800 XT with RADV main 5eaadb5 and d71578f end at ~3.5 s, df0cfef before xcl-dev#3655 runs. DXC never writes internal functions in a non-library shader either. Module::inline_helpers copies each helper's body into its caller right before the bitcode is written: the calling block is cut at the call, the helper's blocks follow it, and the rest of the block (with its terminator) goes on in a new block that the phis of its successors now name. Planning, optimisation and dispatch-chain cuts still see one indivisible call, as xcl-dev#3655 has them; only the written module changes. The two tests that looked for the calls now check that none is left, and a new one validates a split program with the rendezvous and the group barrier inside a loop.
…ry, not as functions Since xcl-dev#3655 the split-wave helpers are DXIL functions with groupshared pointer parameters, which dxil-spirv cannot type (it terminates): titles end a few seconds in under Wine. xcl-dev#3707 writes the bodies into the entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Compact emitted direct-DXIL bitcode tables, prune unused types before writing BLOCK_TYPE, and reuse interned scalar types, small integer constants, and matching dx.op.* declarations: - Prune dead types across entry instructions, globals, constants, metadata, and live xcl-dev#3655 internal HelperBody functions, and intern Ptr(f.ty, 0) lazily only for live Value::Func operands so value_ty and read-only scans never panic on un-interned function values. - Group live constants by (nesting depth, remapped type) so CST_CODE_SETTYPE is emitted once per live type. - Add LLVM 3.7 ArrayChar6 encoding, abbreviate MODULE_CODE_FUNCTION (including helper proto/linkage and FnAttrs::MAX_INDEX width), BLOCK_TYPE, BLOCK_METADATA, and VALUE_SYMTAB records, and fit val_rel_w and bb_w across both entry and live helper bodies. - Check fixed-field widths and abbrev IDs at runtime in BitWriter (surfacing overflow via try_finish / Module::try_to_bitcode) rather than relying on debug_assert!. - Add scalar_types, small_words, and dx_ops interning caches and non-interning int_width/float_width queries. Co-Authored-By: Codex (GPT-6) Co-Authored-By: Antigravity (Gemini 4 Neon)
Compact emitted direct-DXIL bitcode tables, prune unused types before writing BLOCK_TYPE, and reuse interned scalar types, small integer constants, and matching dx.op.* declarations: - Prune dead types across entry instructions, globals, constants, metadata, and live xcl-dev#3655 internal HelperBody functions. Cache each function's address-space-0 pointer type on FuncDecl in declare() (matching GlobalDef::ptr) so value_ty is total and O(1) across optimize(), scans, and emission while live_types prunes unused function pointer types from BLOCK_TYPE. - Group live constants by (nesting depth, remapped type) so CST_CODE_SETTYPE is emitted once per live type. - Add LLVM 3.7 ArrayChar6 encoding, abbreviate MODULE_CODE_FUNCTION (including helper proto/linkage and FnAttrs::MAX_INDEX width), BLOCK_TYPE, BLOCK_METADATA, and VALUE_SYMTAB records, and fit val_rel_w and bb_w across both entry and live helper bodies. - Check fixed-field widths, abbrev IDs, and ArrayChar6 operands at runtime in BitWriter (surfacing errors via try_finish / Module::try_to_bitcode) rather than relying on debug_assert!. - Add scalar_types, small_words, and dx_ops interning caches and non-interning int_width/float_width queries. Co-Authored-By: Codex (GPT-6) Co-Authored-By: Antigravity (Gemini 4 Neon)
Compact emitted direct-DXIL bitcode tables, prune unused types before writing BLOCK_TYPE, and reuse interned scalar types, small integer constants, and matching dx.op.* declarations: - Prune dead types across entry instructions, globals, constants, metadata, and live xcl-dev#3655 internal HelperBody functions. Cache each function's address-space-0 pointer type on FuncDecl in declare() (matching GlobalDef::ptr) so value_ty is total and O(1) across optimize(), scans, and emission while live_types prunes unused function pointer types from BLOCK_TYPE. - Group live constants by (nesting depth, remapped type) so CST_CODE_SETTYPE is emitted once per live type, and reject non-constant Value::Inst elements in Module::aggregate() via fail(). - Add LLVM 3.7 ArrayChar6 encoding, abbreviate MODULE_CODE_FUNCTION (including helper proto/linkage and FnAttrs::MAX_INDEX width), BLOCK_TYPE, BLOCK_METADATA, and VALUE_SYMTAB records, and fit val_rel_w and bb_w across both entry and live helper bodies. - Check fixed-field widths, abbrev IDs, and ArrayChar6 operands at runtime in BitWriter (surfacing errors via try_finish / Module::try_to_bitcode) rather than relying on debug_assert!. - Add scalar_types, small_words, and dx_ops interning caches and non-interning int_width/float_width queries. Co-Authored-By: Codex (GPT-6) Co-Authored-By: Antigravity (Gemini 4 Neon)
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.