Skip to content

Recompiler: flatten direct DXIL root-UAV loads for compute - #2368

Draft
coolpersonnn wants to merge 1 commit into
xcl-dev:mainfrom
coolpersonnn:direct-dxil-flat-loads
Draft

coolpersonnn wants to merge 1 commit into
xcl-dev:mainfrom
coolpersonnn:direct-dxil-flat-loads

Conversation

@coolpersonnn

Copy link
Copy Markdown

Part of #2088. Replace per-load switch i32 CFGs across the 4 root-UAV memory windows (u2..u5) in direct DXIL (XCL_DIRECT_DXIL=1, XCL_HEAP_WINDOWS=0) with branchless straight-line rawBufferLoad + select on 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-arm switch and merge phi nodes. 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 window w_eff = sel(guard, w, n) once, compares w_eff == k for windows 0..n, reads offset 0 on unselected windows/lanes, and selects the result — preserving #1693 out-of-range (0) and inactive-lane (0) semantics while issuing only valid offset-0 reads on bound windows.

Scope and relationship to other work

What is in it

  • crates/xcl/src/gpu/dxil/lower_mem.rs: add with_mem_raw_loads and mem_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-component BufKind::FormatLoad) through branchless offset-0 loads + select when self.heap_mem.is_none() && self.gfx.is_none().
  • crates/xcl/src/hle/d3d12x/bind.rs: filter v != 0 when populating u2..u5 so an unpopulated (0, 0) UMA_BUFFER slot falls back to first.
  • crates/xcl/src/gpu/recomp/runner.rs: bind root UAVs u2..u5 in dispatch_with (previously only u2 was bound).
  • crates/xcl/src/gpu/dxil/core_tests.rs: add raw_loads_in_root_windows_are_branchless (IR shape across wave32, split-wave64, native-wave64, heap windows, stores/atomics, and PS exclusion) and raw_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, masked EXEC, and unaligned format loads).

Tested

  • Host / toolchain: Windows 11 build 26300, AMD Ryzen 9 9950X3D, 93.6 GiB usable RAM, NVIDIA GeForce RTX 5090 32 GB (driver 621.01), Rust 1.100.0 MSVC, Windows SDK DXC/DXIL 1.8.2502.11.
  • Synthetic RTX 5090 cold PSO release benchmarks on 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 isolated XCL_DXIL_CACHE, fresh per-run .exe copies, and distinct unused root-constant layout keys; same-layout immediate warm replays took 2.46–5.40 ms; 0 errors, 0 device removals):
Synthetic compute spec Base (3f4495a) PR (58bb1f5) Speedup Peak commit IR blocks / switches
cs-500-raw-w32 (non-coherent) 5,133.0 ms 1,748.1 ms 2.94x (-65.9%) 309.0 -> 191.1 MiB 2,051 -> 16 / 410 -> 3
cs-500-raw-w32-glc (coherent) 5,128.6 ms 1,751.0 ms 2.93x (-65.9%) 309.2 -> 190.7 MiB 2,051 -> 16 / 410 -> 3
cs-1000-raw-w32 (non-coherent) 19,741.5 ms 5,155.6 ms 3.83x (-73.9%) 993.4 -> 259.1 MiB 3,926 -> 16 / 785 -> 3
cs-1000-raw-w32-glc (coherent) 19,766.8 ms 5,132.0 ms 3.85x (-74.0%) 992.1 -> 258.7 MiB 3,926 -> 16 / 785 -> 3
cs-1000-raw-w64 (split wave64) 19,709.1 ms 5,170.6 ms 3.81x (-73.8%) 994.0 -> 258.6 MiB 3,926 -> 16 / 785 -> 3
cs-1000-w32 (w/ 33% FormatLoad, non-coherent) 49,431.4 ms 17,976.7 ms 2.75x (-63.6%) 1,341.3 -> 463.9 MiB 4,494 -> 9 / 898 -> 1
cs-1000-w32-glc (w/ 33% FormatLoad, coherent) 49,944.2 ms 18,057.9 ms 2.77x (-63.8%) 1,339.5 -> 464.7 MiB 4,494 -> 9 / 898 -> 1
  • Small straight-line compute diagnostic (cs-200-flat / cs-200-flat-glc, 1 paired trial on 3f4495a): 71.2 -> 77.6 ms and 71.3 -> 73.9 ms (blocks 916 -> 6, switches 183 -> 1).
  • Synthetic RTX 5090 GPU dispatch timing on 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)
  • Workspace & focused checks on 58bb1f5 (with an isolated fresh XCL_DXIL_CACHE):
    • XCL_ADAPTER=5090 cargo build --workspace --locked --offline -j 8: passed.
    • XCL_ADAPTER=5090 cargo test -p xcl --lib --locked --offline -j 8 raw_loads_in_root_windows -- --nocapture: 2 passed, 0 failed, 0 ignored, 0 SKIPPED.
    • XCL_ADAPTER=5090 cargo test -p xcl --lib --locked --offline -j 8 compute_globallycoherent_only_when_needed -- --nocapture: 1 passed, 0 failed, 0 ignored.
    • XCL_ADAPTER=5090 cargo test -p xcl --lib --locked --offline -j 8 gpu_compute_coherent_and_cached_loads -- --nocapture: 1 passed, 0 failed, 0 ignored, 0 SKIPPED.
    • XCL_ADAPTER=5090 cargo test --workspace --locked --offline -j 8 --no-fail-fast -- --test-threads=4 --nocapture: 1,273 passed, 4 failed, 46 ignored, 26 SKIPPED notices across 23 test binaries (xcl --lib: 1,204 passed, 4 failed, 26 ignored; the 4 failures are pre-existing RTX 5090 gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 seeds 70, 545, 1019, 1507 hitting CreateComputePipelineState: 0x8007000E, identical to clean main).
    • XCL_ADAPTER=warp cargo test -p xcl --lib --locked --offline -j 8 -- --test-threads=4 --nocapture: 1,208 passed, 0 failed, 26 ignored, 322 SKIPPED notices.

Regression run

Pending: no retail title folder was available in this session, so paired scripts/smoke.ps1 runs comparing 3f4495a against 58bb1f5 have not been run yet. Opened as a draft until the retail smoke pair and retail shader pack measurements are attached.

Not tested

  • Paired retail title scripts/smoke.ps1 regression run (XCL_DIRECT_DXIL=1, XCL_HEAP_WINDOWS=0).
  • Retail shader pack (shaders.rpf) cold PSO timings and steady-state retail GPU frame times.
  • AMD and Intel GPUs on 58bb1f5 (earlier focused raw_loads_in_root_windows pass on a Radeon iGPU passed 2/0 before adding self.gfx.is_some() and rebasing onto 3f4495a, and was not repeated afterward).
  • macOS and Linux (not built or tested).

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.

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant