Skip to content

Recompiler: eliminate redundant split-wave64 compute barriers and share exchange helpers - #3655

Merged
Prime1997 merged 16 commits into
xcl-dev:mainfrom
Kalmarv:pr/wave64-barriers-exchange
Dec 2, 2026
Merged

Prime1997 merged 16 commits into
xcl-dev:mainfrom
Kalmarv:pr/wave64-barriers-exchange

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Stacked on #3504 and #3563 (builds on @Royalflamejlh's wave64 idioms in #3563 and #3504's dispatch chains; supersedes #2343; will rebase onto main once those merge).

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/-281 across 12 files, of which ~750 lines are new unit and GPU tests in mask_exchange.rs); #3504 and @Royalflamejlh's #3563 commits are preserved intact underneath. All new compute exchange-elimination passes remain gated under #3563's XCL_WAVE64_IDIOMS=0 switch.

What is in it

  • Commit 1 (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):
    • Emit one internal DXIL helper per shader for the split-wave64 spin-exchange rendezvous (@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).
    • Precompute own/peer slot bases and counter pointers once per compute entry (Lw::spin_bases) instead of rebuilding them at each exchange.
    • Because each rendezvous is now a single indivisible call, dispatch-chain planning (module/split.rs) drops spin_regions, charges helper bodies against piece budgets, preserves the multi-wave LDS-polling restriction for @xcl.barrier.arrive, and retains Feature::WaveOps on pieces calling @xcl.spin.wait.
  • Commit 2 (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):
    • Reconciles cleanly with @Royalflamejlh's #3563 (idioms.rs): keeps #3563's XCL_WAVE64_IDIOMS=0 gate, plain_sopk + SCC kills (adding S_SETREG_IMM32_B32), s_or_b64 exec, exec, s restore joins, Kernel::exchange_sites, and uniform_reads fallback for mesh and eager v_readfirstlane sites.
    • Generalizes local EXEC skips (S_CBRANCH_EXECZ/NZ on each half's own EXEC word, including s_endpgm tails, compute LDS programs with explicit Lw::lds_store_order, all *_SAVEEXEC_B64 forms, scalar-only compares, and half-overwritten pairs).
    • Lazy meets (mask_exchange::lazy_meets, Lw::meet_at, Lw::keep_lane): ballots and v_readlane/v_readfirstlane defer until the first whole read and batch stale pairs and lane reads into one rendezvous.
    • Local lowering (How::OwnFirst, How::LaneBit) for one-value VGPR first-lane reads, thread-0 EXEC first-lane reads, and lane-number equality compares.
    • Deferred cross-half wave reductions (Item::Reduce, How::Folded) for or/and/xor/add/min/max folded when the halves next meet.
    • Hardware waves that need nothing of one another run apart (Plan::apart, Lw::apart, up to 256 guest instructions without LDS), removing even the startup atomic and group barrier.
    • Local loop exits (Plan::own_scc, mask_exchange::leave_is_local) when a half has no active lane left in an s_andn2_b64 loop mask.
    • Includes comprehensive unit and GPU execution tests in mask_exchange.rs (plus updated #3563 test expectations in idioms.rs reflecting lazy batching 6 -> 2 meets on six_first_lanes and half-overwritten VCC pairs).

Measured impact (vs #3504 + #3563 base 460cd800f, DXC 1.9.2609.5 validated)

  • 6 profiled hot split-wave64 compute shaders (460cd800f → 685008d1e):
    • Spin-exchange rendezvous sites: 179 → 15 (-91.6%) (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).
    • Effective runtime barriers / atomics across the 6 shaders: 364 → 33 barriers (-90.9%), 545 → 50 atomics (-90.8%).
    • Static IR barriers / atomics (combining elimination + @xcl.spin.wait helper sharing): 364 → 9 barriers (-97.5%), 545 → 14 atomics (-97.4%).
    • Total DXIL size across the 6 shaders: 181,408 B → 120,728 B (-60,680 B / -33.4%).
  • 329-shader offline direct-DXIL validation sweep (--sample 400 --seed 1 --validate --split 1 --windows 4, 460cd800f → 685008d1e):
    • 329/335 translated (6 unsupported), 0 validation errors, 0 panics, 0 timeouts.
    • Total DXIL size: 10,989,548 B → 10,354,264 B (-635,284 B / -5.8%, avg 33,402.9 B → 31,471.9 B).
    • Median translation time (p50): 19.88 ms → 17.92 ms (-9.9%).
  • 60 s title smoke (RTX 5070 Ti, 685008d1e vs main 1c8b55147): 1423 vs 1387 frames shown (+2.6%), 60 60 60 presents per 2 s, peak commit 15087 MB vs 17480 MB (-2393 MB / -13.7%), 0 device removals, 0 crashes.

Tested

  • Hardware & toolchain: NVIDIA GeForce RTX 5070 Ti (driver 610.74), AMD Ryzen 9 9950X 16-Core, Windows 11 Pro 10.0.26200.0, rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.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: 22 no wave64, 2 no heap windows).
  • cargo build --release -p xcl: clean (39 warnings, 0 new vs main and #3504+#3563).
  • Offline DXC 1.9.2609.5 validation sweep: 329/335 translated, 0 validation errors, 0 panics.

Regression run

Baseline (main):

xcl-smoke v1
commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1387 (PresentX 1387)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17480 MB

PR head:

xcl-smoke v1
commit: 685008d1e9a55eb744e1a8fe613af74600d2dfef
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1423 (PresentX 1423)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15087 MB

Not tested

  • AMD and Intel GPUs, including native wave64 hardware paths (22 wave64 GPU tests skipped on RTX 5070 Ti).
  • Opt-in XCL_HEAP_WINDOWS=1 GPU tests (2 skipped under default scripts/test.ps1).
  • Legacy HLSL recompiler (crates/xcl/src/gpu/recomp/ was not modified).

AI use

  • Built on @Royalflamejlh's #3563 wave64 idioms and #3504 dispatch-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's idioms.rs and #3504's module/split.rs (including preserving Feature::WaveOps on split pieces calling @xcl.spin.wait and keeping XCL_WAVE64_IDIOMS=0 gating), ran the base-vs-PR offline A/B measurements, scripts/test.ps1, and the 60 s smoke test, and drafted this description.

saintwolf and others added 16 commits December 1, 2026 22:29
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
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 2, 2026
@pvfreis

pvfreis commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

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 into xcl.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.

@Kalmarv

Kalmarv commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

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 (Gemini 4 Neon) checked #3652's diff and drafted this reply.

@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Review (head 685008d, diff read, not a merge-check):

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 by skip_is_local / leave_is_local contain 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.

@Decodere

Decodere commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Diff review (head 685008d1e, read-only code review — not a test report):

Strong work on the wave64 barrier/exchange reduction architecture and the VAR_XDEAD sign-bit latch in xcl.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:

  1. [CRITICAL] Unsound uniform-VGPR tracking in mask_exchange.rs::known_step and vgprs_alive can silently miscompile V_READFIRSTLANE_B32 as How::OwnFirst (skipping cross-half exchange) and mis-fire fold() (crates/xcl/src/gpu/dxil/mask_exchange.rs:505-518, :691-699):
    rdna2::vgpr_uses (crates/xcl/src/gpu/rdna2.rs:607-609) only adds VDST to vr for V_FMAC_F32, V_MAC_F32, and V_FMAC_LEGACY_F32. Unlike idioms.rs:203-207 (which explicitly guards these cases), known_step (mask_exchange.rs:514-518) misses four non-uniformity sources:

    • 16-bit partial-width writes (V_CVT_F16_F32, V_ADD_F16, V_MUL_F16, V_MOV_B16, V_FMA_MIXLO_F16, V_FMA_MIXHI_F16, etc. where VDST has o.size < 32): preserve per-lane high bits [31:16], yet vr omits VDST, so known_step marks VDST as uniform (k.all).
    • Unlisted accumulators (V_DOT2C_F32_F16, V_DOT4C_I32_I8, V_PK_FMAC_F16, V_FMAC_F16): accumulate into per-lane VDST, yet vr omits VDST -> falsely marked uniform (k.all).
    • VOP3 carry-in with SDST == NULL (125) and per-lane carry mask in SRC2 (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 out 125, leaving touch.1 == 0, and touch.0 & (VCC | EXEC) == 0 because SRC2 is an OPR_SREG pair rather than VCC -> falsely marked uniform (k.all).
    • Non-GLC BUFFER_LOAD_DWORD* (mask_exchange.rs:516): marks uniform-address vector buffer loads as uniform across both asynchronously scheduled wave32 halves, directly contradicting docs/wave64-on-wave32.md:199-200 in this same PR ("nor a memory load: another wave may write that memory between the halves' loads").
    • The same partial-write / accumulator omission in vgprs_alive (mask_exchange.rs:696-698: let kills = valu(d) && known[i].is_some_and(|k| k.ones)) falsely kills live VGPRs before fold().
      Applying the same guards used in idioms.rs:203-207 (include vw in vr for o.size < 32 / MAC / DOT*C, check OPR_SREG carry-in inputs, and drop BUFFER_LOAD_DWORD* from same) fixes all five cases.
  2. [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:346 disables batching (batch = !lds at :358) with the comment "With LDS, larger slots would cut into the guest LDS (no batches)", yet still passes lazy = compute (true) when lds == true. In lazy mode, mask_exchange.rs:1184 grows p.words up to MEET_WORDS = 16, and lanes.rs:40-42 carves 4 * xslot * waves dwords out of the fixed 32 KiB (8192 dwords) xcl_lds array. 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. Capping xslot to 1 (or disabling multi-word meets) when lds == true keeps the guest LDS budget intact.

  3. [Scope / Stacking] Size (+4352/-348, 20 files) & overlap with #3652 and #3654:
    This PR bundles several independent changes (idioms.rs, lazy meets/reductions/apart, shared xcl.spin.wait/xcl.barrier.arrive helpers, and multi-wave/LDS/safe-barrier/two-pass-mesh dispatch_chain splitting). Splitting it along those natural boundaries will make review and bisecting much cleaner and ease coordination with #3652 (xcl.spin.wait peer-exit handling) and #3654 (which also introduces internal helper functions in module.rs).

AI use: Antigravity (Gemini 4 Neon) audited the full diff against main and drafted this review.

Kalmarv added a commit to Kalmarv/xcl that referenced this pull request Dec 2, 2026
…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>
Kalmarv added a commit to Kalmarv/xcl that referenced this pull request Dec 2, 2026
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)
Royalflamejlh pushed a commit to Royalflamejlh/xcl that referenced this pull request Dec 2, 2026
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.
Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Dec 2, 2026
…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>
Kalmarv added a commit to Kalmarv/xcl that referenced this pull request Dec 2, 2026
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)
Kalmarv added a commit to Kalmarv/xcl that referenced this pull request Dec 2, 2026
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)
Kalmarv added a commit to Kalmarv/xcl that referenced this pull request Dec 2, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants