Repository navigation
Recompiler: emit globallycoherent on compute memory windows only when needed - #1850
certified-retart wants to merge 1 commit into
Conversation
|
Tested On I also ran a separate HLSL microbenchmark that varied only Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, Rust 1.99.1 MSVC debug, DXC 1.8.2502.11. Not tested The timings isolate the qualifier on an HLSL compute shader. This does not measure retail frame time or descriptor-heap dispatch performance. AI-assisted. Codex (GPT-6 family, exact variant unavailable) wrote and ran the timing fixture and drafted this report. Descriptor-heap retest on the same revision I ran the cached-load and atomic-ticket fixtures with two distinct 4 KiB descriptor-heap views on the same RTX 3080 Ti setup. The shader addressed window 1 for its input, output, and atomic counter. Window 0 held sentinels at the same offsets. HLSL, per-instruction DXIL, and per-lane DXIL each returned all 128 expected load results and all 512 atomic tickets, with a final counter of 512. All 1,024 sentinel words in window 0 stayed intact in both cases. Each backend was compiled and dispatched directly.
|
|
On Ampere: RTX 3070 8 GB (32-lane waves), driver 616.56, Windows 11, debug. Merge with
* AI-assisted (Claude Code). Synthetic tests only. |
|
Tested (RTX 3090, 32-lane waves so the split wave64 form, I applied the HLSL-path part of this PR ( 1. The rule removes the worst dispatches here
2. Why it is seconds here and milliseconds in the description: the imported host-memory heap The cost is not only the L1 bypass. It depends on what backs the memory window. Micro-benchmark, one heap view, 1 024 dependent loads per thread, ns per load per wave:
So a coherent load from the committed window is about 30 times more expensive than the same load from video memory, and other groups wait for it. That is what turned loops over a constant buffer into 8 s dispatches. 3. What remains with the rule: programs kept for one atomic About 23 % of the pack's compute programs keep the qualifier under this rule. In a world frame they now carry almost all the GPU time, about 5 s per frame on the main queue:
Every one of these is kept because of a Setup (edited in: the exact stack)
Not tested
AI use: Claude Code (Claude Fable 5.2) ran the measurements and drafted this report. |
…to ethans-superbuild - dxil/kernel.rs: needs_coherent_mem in Lw::new; TRANSLATOR_VERSION stays 9. - recomp/mod.rs: needs_coherent_mem beside the compact backend; prepare sets Em::coherent_mem for both backends. - recomp/tests.rs: both new tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Title runs with both parts of Tree: 1. The program from #1766's example,
2. The GPU wait stalls (#1452) over the whole run:
The two runs with this PR that ended early, at 213 s and 225 s, are the title reading through garbage pointers (the #1164 family), not GPU waits. Not tested: this PR's own head (only the port); its tests on this base; AMD. AI use: Claude Code (Claude Opus 5.5) ported the change, ran the runs and wrote this. |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
0861c8c to
dc7565d
Compare
|
Rebased cleanly onto \main\ (\3da2abb, new head \dc7565d) to resolve the \dxil/kernel.rs\ and |
dc7565d to
e878d28
Compare
|
@CharlyRien I ran a quick follow-up microbenchmark on an RTX 5070 (Blackwell, Agility SDK v614, DXC 1.9.2602.17) backed by a 1 MiB host-memory buffer imported via \OpenExistingHeapFromAddress\ (64 groups × 32 threads, 512 dependent loads/thread, D3D12 timestamp queries, median of 3 measured dispatches after warmup) to test splitting plain loads and \globallycoherent\ atomics/stores in the same compute shader:
A same-thread hazard check (plain \Load\ → coherent \Store\ → plain \Load\ → coherent \InterlockedAdd\ → plain \Load) also showed \ |
e878d28 to
ecc9723
Compare
|
RTX 5080: a retail dispatch that does not finish with Measured tonight before I knew of this PR, so this is not a run of your code: it is the same change made by hand in one program. It supports what you measured, from a card with 32-lane waves where that dispatch ends the run. Setup. RTX 5080 16 GB (driver 610.47), i7-7700K, Windows 10 22H2; the retail title of #675 (my own copy), In the title. Every run on this card ends in
Synthetic, same card (my own shader in a local test:
So here too the flag costs 4 - 8x on loads every thread repeats; the heap form's handle per access doubles that once more (taking the four handles once at the start of Not tested
AI use: Claude Code with Claude Fable 5.2 ran the title and the tests and wrote this. |
|
@certified-retart thanks for running that – it matches what we measured here, and here is the follow-up I promised above: the per-instruction form implemented in the translator and what it does to the programs this PR's rule keeps coherent. Setup
Micro-benchmark (one shader with both views of the same imported host heap, 1 024 dependent loads per thread; ns per load per wave)
Atomics cost the same through either view (1 423 ns per wave), stores too (37 ns). 64 groups, whole dispatch: plain 0.085 ms, coherent 373 ms, split 0.161 ms. Results exact in every run (65 536 of 65 536 tickets distinct, counter exact, stores visible to the CPU). The DXIL has one On the pack
Not tested yet
I can post the diff ( AI use: Claude Code (Claude Fable 5.2 coordinating, Claude Opus 5.5 for the implementation and the benchmark) did this and drafted the report. |
PR #1850 qualifier testTested
& 'C:\Users\ljensen\.cargo\bin\cargo.exe' test -p xcl --lib gpu::recomp::tests::compute_globallycoherent_only_when_needed -- --exact --nocapture --test-threads=1
Not tested
AI use
|
Conflicts: - the translator's version is one of its own (its output differs from main's: globallycoherent windows only where a program needs them, xcl-dev#1850); - compute and graphics driver blobs reach the disk cache also when the store in memory is full (main's read_pso_cached_blob and graphics blobs, our return of the blob); - sparse: our copies back with main's lock_state and wait notes; - title textures: our uploads on the title's queue in main's batches (256 textures, 32 MiB); - DirectStorage: a page list is read again at execution (xcl-dev#1405) through main's read_own (xcl-dev#509); - list_x / bind: our diagnostics and the ExecuteIndirect guard kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Tested RTX 5060 Ti 16 GB (driver 610.88), Ryzen 9 9900X, Windows 11 build 26300, DXC 1.9.2609.5.
Before this PR, on Not tested
AI use: Claude Code (Claude Opus 5.5) built the head, ran the runs and drafted this report. |
|
RTX 5080 16 GB, the title on this PR's rule (the follow-up I promised above): the dispatch that hung takes 7 ms; what is left are the programs the rule keeps coherent Setup. As in my comment above (RTX 5080 16 GB, driver 610.47, 32-lane waves; i7-7700K, 16 GB RAM; Windows 10 22H2; the retail title of #675, my own copy; 1. The program of my first table ( 2. The device is still removed, later (imported host memory behind the committed window, the default on this card). Seven runs: 3. Where the GPU time is now (one run with
"Kept coherent" is from each program's translated source. Later in that run single calls reached 3.0 s ( 4. With the committed window in video memory ( 5. Instruction by instruction. That is #2067 now. I had made the direct-path part of the same idea locally before I saw it, and measured it in this title: the frame's console GPU time falls by about a third without the shadow, five of the six coherent programs above take 2.4 to more than 10 times less a call, the sixth ( Not tested
AI use: Claude Code with Claude Fable 5.2 ran the title and the tests and wrote this. |
|
AMD RDNA4 offline numbers for #1850: AMD driver time −2.3 % (repeats in both rounds), but DXC's DXIL grows 6.9 %. That is on the HLSL path, 24 retail compute programs; 21 of the 24 lose Setup
Method
Totals (round 1 / round 2; 0 refused in all runs)
Per program (mean of 2 rounds)
Read / inference
Not tested
AI use: Claude Code (Claude Opus 5.5) ran the measurement and drafted this. Counts and timings only, no game data. |
|
Please rebase onto |
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).Tested
XCL_D3D12_DIRAgility SDK v614, DXC 1.9.2602.17.maincbc296a(ecc9723):cargo test -p xcl --lib compute_globallycoherent_only_when_needed -- --nocapture: 1 passed, 0 failed (HLSL & Direct DXIL).XCL_DIRECT_DXIL=1 cargo test -p xcl --lib gpu_compute_coherent_and_cached_loads -- --nocapture: 1 passed, 0 failed.cargo test --workspace -- --test-threads=4passed with 0 failures on prior rebase (3da2abb); targeted unit and real-GPU tests plus 60 s smoke re-verified onecc9723.SKIPPEDGPU tests on this host:gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask(no wave64),gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware(no wave64),shaders::tests::pso_measurement_compiles_an_exact_synthetic_record(cannot disable the driver cache),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).Regression run
main:
PR:
Not tested
AI use