Recompiler: emit globallycoherent on compute memory windows only when needed #2346
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2346
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2346/head"
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?
@gefydev on GitHub · 2026-11-25 16:11 UTC · original
gefydev:globallycoherent-rebased→main· +181 −5 · 5 files · 1 commits · merged 2026-11-25 16:16 UTCContinues #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 #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.