Repository navigation
Recompiler: emit globallycoherent on compute memory windows only when needed - #2346
Merged
Merged
Conversation
coolpersonnn
added a commit
to coolpersonnn/xcl
that referenced
this pull request
Nov 25, 2026
In direct DXIL root-UAV window mode (`XCL_DIRECT_DXIL=1`, `XCL_HEAP_WINDOWS=0`), every scalar/buffer/flat read previously went through `with_mem_many_tys`, emitting a per-load `switch i32` + guard CFG and `phi` nodes over all 4 root-UAV windows (`u2..u5`). Compute shaders with hundreds of loads grew thousands of basic blocks, triggering multi-second to multi-minute cold NVIDIA driver compiles and high compiler commit memory. Replace multi-window direct DXIL read-only raw loads on non-graphics stages (`self.gfx.is_none()`, `self.heap_mem.is_none()`) with branchless straight-line loads via `with_mem_raw_loads`: - Resolve the effective window `w_eff = sel(guard, w, n)` once and compare `w_eff == k` across windows `0..n`, reading offset `0` on unselected windows/lanes and merging with `select`. - Preserve `xcl-dev#1693` semantics: out-of-range window indices and inactive lanes select `0` while emitting only valid offset-0 reads on bound windows. - Ensure `bind.rs` (`u2..u5`, filtering `v != 0`) and `runner::dispatch_with` always bind valid non-null buffers for all 4 root-UAV window slots. - Exclude graphics stages (`VS`/`PS`, `self.gfx.is_some()`), where flattening root-UAV loads regressed straight-line PS cold NVIDIA compile time by 5.64x (1,632 -> 9,203 ms on `0829441`). - Keep stores/atomics (`xcl-dev#2288`), `bvh_intersect`, `XCL_HEAP_WINDOWS` (`xcl-dev#1695`), and HLSL emission (`xcl-dev#1380`/`xcl-dev#2191`) unchanged. Measured on RTX 5090 (driver 621.01, Windows 11, release) against `3f4495a` (including PR xcl-dev#2346 non-coherent compute windows, 3 paired interleaved trials per spec with cold root-signature keys and fresh exe copies): - `cs-500-raw-w32` (non-coherent / coherent): 5,133 -> 1,748 ms (2.94x) / 5,129 -> 1,751 ms (2.93x); peak commit 309 -> 191 MiB - `cs-1000-raw-w32` (non-coherent / coherent): 19,742 -> 5,156 ms (3.83x) / 19,767 -> 5,132 ms (3.85x); peak commit 993 -> 259 MiB (-73.9%) - `cs-1000-raw-w64` (split wave64): 19,709 -> 5,171 ms (3.81x); peak 994 -> 259 MiB - `cs-1000-w32` (mixed w/ 33% FormatLoad, non-coherent / coherent): 49,431 -> 17,977 ms (2.75x) / 49,944 -> 18,058 ms (2.77x); peak 1.34 GiB -> 464 MiB - Synthetic GPU dispatch (128 loads/lane, uniform & mixed, w32 & split w64): 1.84x to 4.68x faster (3.296-6.688 us vs 9.696-22.608 us), 100% readback match. Assisted-by: T3 Code (gemini-pro-orchestrator-neon) Assisted-by: Codex in T3 Code (gpt-6.2-sol)
This was referenced Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continues #1850 by @certified-retart, whose branch stopped merging into
mainafter #2054 and other changes (conflicts intests.rsandemit.rs). The author has not answered since, and people are waiting for this change, so it is opened here at their request. The commit is the author's, rebased ontomain0829441as83ad6a5, with their authorship and message; the change itself was not altered. If the author comes back they are welcome to take it over, and #1850 and this PR should not both be merged.Only emit
globallycoherenton compute shaders' flat memory windows (mem,mem1… andXCL_HEAP_WINDOWSheap views) when the RDNA2 program actually uses cross-workgroup flat-memory coherence (GLC/DLC/SLC, flat-memory atomics, or data cache invalidation). Part of #675 and #1269.Previously both the HLSL emitter and the direct DXIL translator marked every compute shader's flat memory UAVs
globallycoherentunconditionally so cross-workgroup algorithms (such as bottom-up BVH builds) would see other workgroups' writes. On NVIDIA D3D12 hardware,globallycoherentbypasses SM L1 for everyRWByteAddressBufferload—including uniformSMEMloads that all threads in a wave fetch from the same address—turning L1 broadcasts into serialized L2 traffic (and on imported host-memory heaps, multi-microsecond GPU-wide serialized loads).On RDNA2 hardware itself, a workgroup can span both CUs of a WGP (each with its own GL0 cache), so any console shader relying on cross-wave or cross-workgroup flat-memory visibility already emits
GLC/DLC/SLC, atomics, or cache invalidations. Plain compute shaders without any of those only access read-only or disjointly written memory within the dispatch and can safely keep L1 caching enabled.What is in it
crates/xcl/src/gpu/recomp/mod.rs: add sharedneeds_coherent_mem(insts: &[Decoded]) -> boolreturningtrueiff the program contains any flat-memory atomic (BUFFER_ATOMIC_*,GLOBAL_ATOMIC_*,FLAT_ATOMIC_*),GLC/DLC/SLConENC_SMEM/ENC_MUBUF/ENC_MTBUF/ENC_FLAT/ENC_FLAT_GLBL, or cache invalidation (S_DCACHE_INV,S_GL1_INV,BUFFER_GL0_INV,BUFFER_GL1_INV); setem.coherent_memintranslate().crates/xcl/src/gpu/recomp/emit.rs: emitgloballycoherenton rootmem/mem1… declarations andXCL_HEAP_WINDOWSaccessors (XCL_MW) only whenself.coherent_memis set.crates/xcl/src/gpu/dxil/kernel.rs&crates/xcl/src/gpu/recomp/lower_dxil.rs: passcs.is_some() && recomp::needs_coherent_mem(insts)tomem_windowsinLw::new(covering both direct DXIL andlower_dxil).crates/xcl/src/gpu/recomp/tests.rs: addcompute_globallycoherent_only_when_needed(HLSL root/switch/heap,Mode::Kernel, and Direct DXILannotateHandleIsGloballyCoherentbit checks across all triggers) andgpu_compute_coherent_and_cached_loads(real GPU execution of cached plain compute and multi-workgroup coherent atomic+GLC compute across both HLSL and Direct DXIL).Measured GPU impact (RTX 5070)
Load4, 320×180×1 groups of 8×8×1):6.140 ms(globallycoherent) →0.552 ms(cached) — 11.1× fasterXCL_HEAP_WINDOWS=1):6.975 ms→0.538 ms— 13.0× faster4.921 ms→2.297 ms(2.14× faster)5.514 ms→2.171 ms(2.54× faster)XCL_GPU_PROFILE=1,XCL_HEAP_WINDOWS=1):85.4 ms16×16×16 pass dropped to2.3 ms), allowing the title to advance through 10+ consecutive 3D world frames (~24k dispatches).What the rebase changed
crates/xcl/src/gpu/recomp/emit.rs: two conflicts of two changes adding next to each other.mainhad added theimg_writesfield ofEm(andimage_write_srsrcs) where this change addscoherent_mem; both fields are kept, and both initialisers in the constructor.crates/xcl/src/gpu/recomp/tests.rs: both tests appended at the end of the file are kept,main's resinfo one and this change'scompute_globallycoherent_only_when_neededandgpu_compute_coherent_and_cached_loads.Tested
CARGO_BUILD_JOBS=2.compute_globallycoherent_only_when_neededandgpu_compute_coherent_and_cached_loadspass; the GPU one ran, it was not skipped.cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4on83ad6a5: 1274 passed, 0 failed, 46 ignored. 27 SKIPPED, none on a path this change touches: 21 wave64 cases (no wave64 on this GPU), 3 per-lane f16 cases the per-lane form refuses, 1 "no heap windows", 2 for the D3D12 debug layer not being installed.Regression run
xcl-smokepair for this head yet: the machine used for the rebase runs out of memory when it runs the title, and two attempts of other runs were stopped by the system.PR checkswill flag it until someone runsscripts/smoke.ps1on83ad6a5; a run from a reviewer, on a card with more memory, is welcome.ecc9723(the same change onmaincbc296a, RTX 5070) is in Recompiler: emit globallycoherent on compute memory windows only when needed #1850: 1685 frames and 15 660 MB for the PR against 1682 and 15 030 MB formain, no device removal and no crash.Not tested
ecc9723.AI use
main, resolved the conflicts, ran the tests and wrote this description.