Repository navigation
Recompiler: emit globallycoherent on compute memory windows only when needed - #2346
Merged
Merged
Conversation
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.