Repository navigation
Recompiler: flatten direct DXIL root-UAV loads for compute - #2368
Draft
coolpersonnn wants to merge 1 commit into
Draft
coolpersonnn wants to merge 1 commit into
coolpersonnn wants to merge 1 commit into
Conversation
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)
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.
Part of #2088. Replace per-load
switch i32CFGs across the 4 root-UAV memory windows (u2..u5) in direct DXIL (XCL_DIRECT_DXIL=1,XCL_HEAP_WINDOWS=0) with branchless straight-linerawBufferLoad+selecton non-graphics stages (self.gfx.is_none()).In direct DXIL root-UAV mode, every scalar, buffer, or flat load previously branched through
with_mem_many_tys, emitting a per-load 5-armswitchand mergephinodes. Compute shaders with hundreds of loads generated thousands of basic blocks and forced heavy NVIDIA driver compile times and commit memory. Flattening read-only loads resolves the effective windoww_eff = sel(guard, w, n)once, comparesw_eff == kfor windows0..n, reads offset0on unselected windows/lanes, and selects the result — preserving#1693out-of-range (0) and inactive-lane (0) semantics while issuing only valid offset-0 reads on bound windows.Scope and relationship to other work
with_mem_many_tys, PR Recompiler: guard direct DXIL window stores with bit tests #2288),bvh_intersect,XCL_HEAP_WINDOWS=1(PR Recompiler: heap memory windows without a guard (min + null view), and the 64-bit atomics check #1695), and the HLSL path (PR Recompiler: big compute programs read their memory windows without a switch #1380 / PR Recompiler: pick root-UAV memory windows with bit tests, not a switch #2191) are untouched.VS/PS,self.gfx.is_some()) keep theswitchpath. Measuringps-200-loadson0829441showed that flattening root-UAV loads on Pixel Shaders regressed NVIDIA cold compile time 5.64x (1,632 -> 9,203 msstraight-line,2,224 -> 2,592 mslooped). On3f4495a, both non-coherent (#2346) andGLC-coherent compute shaders speed up consistently with zero regression, while PS DXIL stays byte-identical (dxil_hash=98a91ac649117912,132,508 B).bind.rs(u2..u5, filteringv != 0) andrunner::dispatch_withalways bind valid non-null buffers for all 4 root-UAV window slots so unselected offset-0 reads never hit GPU VA0.What is in it
crates/xcl/src/gpu/dxil/lower_mem.rs: addwith_mem_raw_loadsandmem_ld_chunks, routing direct DXIL read-only raw loads (mem_ld,mem_ld_n,ld_raw_guarded,ld_raw_u32_guarded,s_buffer_load,s_load, single-componentBufKind::FormatLoad) through branchless offset-0 loads +selectwhenself.heap_mem.is_none() && self.gfx.is_none().crates/xcl/src/hle/d3d12x/bind.rs: filterv != 0when populatingu2..u5so an unpopulated(0, 0)UMA_BUFFERslot falls back tofirst.crates/xcl/src/gpu/recomp/runner.rs: bind root UAVsu2..u5indispatch_with(previously onlyu2was bound).crates/xcl/src/gpu/dxil/core_tests.rs: addraw_loads_in_root_windows_are_branchless(IR shape across wave32, split-wave64, native-wave64, heap windows, stores/atomics, and PS exclusion) andraw_loads_in_root_windows_respect_exec_and_bounds(GPU readback over 4 windows, offset-0 canaries, window bounds,hi == 0-> w0, 64-bit carry across windows, maskedEXEC, and unaligned format loads).Tested
3f4495a->58bb1f5(including PR Recompiler: emit globallycoherent on compute memory windows only when needed #2346 non-coherent compute windows; 3 paired interleaved trials per spec using isolatedXCL_DXIL_CACHE, fresh per-run.execopies, and distinct unused root-constant layout keys; same-layout immediate warm replays took2.46–5.40 ms; 0 errors, 0 device removals):3f4495a)58bb1f5)cs-500-raw-w32(non-coherent)cs-500-raw-w32-glc(coherent)cs-1000-raw-w32(non-coherent)cs-1000-raw-w32-glc(coherent)cs-1000-raw-w64(split wave64)cs-1000-w32(w/ 33% FormatLoad, non-coherent)cs-1000-w32-glc(w/ 33% FormatLoad, coherent)cs-200-flat/cs-200-flat-glc, 1 paired trial on3f4495a):71.2 -> 77.6 msand71.3 -> 73.9 ms(blocks916 -> 6, switches183 -> 1).3f4495a->58bb1f5(3 paired interleaved trials, 128 root-window loads/lane across 4 windows, 128 groups x 128 timed dispatches after 8 warmups, 100% readback dwords verified, 0 device removals):uniform wave32:10.560 -> 3.296 us(3.20x faster)uniform split-wave64:9.696 -> 5.280 us(1.84x faster)mixed wave32:22.608 -> 4.832 us(4.68x faster)mixed split-wave64:21.408 -> 6.688 us(3.20x faster)58bb1f5(with an isolated freshXCL_DXIL_CACHE):XCL_ADAPTER=5090cargo build --workspace --locked --offline -j 8: passed.XCL_ADAPTER=5090cargo test -p xcl --lib --locked --offline -j 8 raw_loads_in_root_windows -- --nocapture: 2 passed, 0 failed, 0 ignored, 0SKIPPED.XCL_ADAPTER=5090cargo test -p xcl --lib --locked --offline -j 8 compute_globallycoherent_only_when_needed -- --nocapture: 1 passed, 0 failed, 0 ignored.XCL_ADAPTER=5090cargo test -p xcl --lib --locked --offline -j 8 gpu_compute_coherent_and_cached_loads -- --nocapture: 1 passed, 0 failed, 0 ignored, 0SKIPPED.XCL_ADAPTER=5090cargo test --workspace --locked --offline -j 8 --no-fail-fast -- --test-threads=4 --nocapture: 1,273 passed, 4 failed, 46 ignored, 26SKIPPEDnotices across 23 test binaries (xcl --lib: 1,204 passed, 4 failed, 26 ignored; the 4 failures are pre-existing RTX 5090gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3seeds 70, 545, 1019, 1507 hittingCreateComputePipelineState: 0x8007000E, identical to cleanmain).XCL_ADAPTER=warpcargo test -p xcl --lib --locked --offline -j 8 -- --test-threads=4 --nocapture: 1,208 passed, 0 failed, 26 ignored, 322SKIPPEDnotices.Regression run
Pending: no retail title folder was available in this session, so paired
scripts/smoke.ps1runs comparing3f4495aagainst58bb1f5have not been run yet. Opened as a draft until the retail smoke pair and retail shader pack measurements are attached.Not tested
scripts/smoke.ps1regression run (XCL_DIRECT_DXIL=1,XCL_HEAP_WINDOWS=0).shaders.rpf) cold PSO timings and steady-state retail GPU frame times.58bb1f5(earlier focusedraw_loads_in_root_windowspass on a Radeon iGPU passed 2/0 before addingself.gfx.is_some()and rebasing onto3f4495a, and was not repeated afterward).AI use
T3 Code (Antigravity harness, gemini-pro-orchestrator-neon) designed and implemented the direct DXIL flattening change and tests, measured the synthetic RTX 5090 cold PSO and GPU timings, ran the test suite, and drafted this PR description.