Skip to content

Recompiler: guard direct DXIL window stores with bit tests - #2288

Draft
coolpersonnn wants to merge 1 commit into
xcl-dev:mainfrom
coolpersonnn:codex/direct-dxil-store-guards-refresh
Draft

coolpersonnn wants to merge 1 commit into
xcl-dev:mainfrom
coolpersonnn:codex/direct-dxil-store-guards-refresh

Conversation

@coolpersonnn

Copy link
Copy Markdown
Contributor

Part of #2088. Replace the dynamic direct DXIL raw-store switch with a one-hot guard per root UAV window. The mask clears for inactive lanes and out-of-range window indices.

What is in it

  • lower_mem.rs emits the window guards. core_tests.rs checks the DXIL and GPU readback in wave32 and wave64 across four windows, including inactive lanes and invalid indices.

Tested

  • Windows 11 build 26300, Ryzen 9 9950X3D, 93.6 GiB usable RAM, RTX 5090 32 GB (621.01), and Radeon iGPU (32.0.21045.29003) for the focused test. Rust 1.100.0 and Windows SDK DXC/DXIL 1.8.2502.11.
  • Release benchmarks on 426a5a7 → 5e502c5. Median first-use NVIDIA pipeline build time fell 5.0–33.6% on four of five records. The fifth rose 0.47%. The driver caches stayed enabled. Same-layout warm replays took 0.892–3.341 ms. GPU readback passed and synthetic dispatch time fell in both wave modes. Measurements and cache controls
  • cargo build --workspace --locked --offline -j 8 passed. cargo test --workspace --locked --offline -j 8 --no-fail-fast -- --test-threads=4 --nocapture on the RTX 5090 with XCL_SAMPLE_RPF and an isolated XCL_DXIL_CACHE gave 1,240 passed, 4 failed, 46 ignored and 25 GPU skip notices. The same four fuzz seeds (70, 545, 1019, 1507) failed with 0x8007000E on the clean base.
  • cargo test -p xcl --lib --locked --offline -j 8 raw_stores_in_root_windows_respect_exec_and_bounds -- --nocapture on the RTX 5090 and Radeon iGPU gave 1 passed, 0 failed, 0 ignored and 0 GPU skips on each.
  • cargo test -p xcl --lib --locked --offline -j 8 -- --test-threads=4 --nocapture on WARP gave 1,175 passed, 0 failed, 26 ignored and 311 GPU skip notices.

Regression run

After the push, both release builds ran ./scripts/smoke.ps1 -Game $RetailTitleFolder -Seconds 60 -Xcl $ReleaseExe -OutDir $SmokeArtifacts with XCL_ADAPTER=5090, XCL_DIRECT_DXIL=1, XCL_HEAP_WINDOWS=0, XCL_PSO_TRACE=1 and XCL_FRAME_DUMP=300. Each started with empty XCL caches. NVIDIA implicit caches stayed enabled.

Clean main

xcl-smoke v1
commit: 426a5a745db4d5e4b037449ede0b70cb342f5192
gpu: NVIDIA GeForce RTX 5090
title: a93b40d7
seconds: 60
exit: 0x0
frames shown: 845 (PresentX 845)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15364 MB

Clean head

xcl-smoke v1
commit: 5e502c50805e27fa1df1e833e413841f7f122503
gpu: NVIDIA GeForce RTX 5090
title: a93b40d7
seconds: 60
exit: 0x0
frames shown: 869 (PresentX 869)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15230 MB

Not tested

  • First-playable latency and steady-state retail GPU time. The retail smoke reached the account picker. GPU timing used the synthetic store fixture.
  • Retail smoke on AMD. macOS and Linux were not built or tested.

AI use

OpenAI Codex (GPT-6, exact variant unavailable) wrote the lowering and regression test, ran the benchmark, tests and smoke pair, and drafted this description.

Use one-hot window guards for dynamic raw stores through root UAVs.
Clear the mask for inactive lanes and out-of-range windows before
testing any bit.

Against main 426a5a7, three paired RTX 5090 trials per record reduced
median first-use driver build time by 5 to 34 percent on four of five
retail compute records. The fifth was within 0.5 percent. The GPU
readback passed in wave32 and split-wave64 on the RTX 5090, and the
store regression passed on Radeon. The four NVIDIA fuzz failures
reproduced on the clean base.

Part of xcl-dev#2088

Reapplies the lowering and test from local commit 29b9dcb.
Assisted-by: OpenAI Codex (GPT-6, exact variant unavailable)
@GustavoEllwanger

Copy link
Copy Markdown
Contributor

Independent dual-GPU Windows verification on exact PR head 5e502c50805e27fa1df1e833e413841f7f122503 (parent 426a5a7).

Tested

  • Host / toolchain: AMD Ryzen 7 7700, Windows 11, Rust 1.95.0 (59807616e 2026-04-14), DXC 1.8.2502.11, debug build.
  • NVIDIA GeForce RTX 5060 (driver 32.0.16.1088, Blackwell / wave32 + split-wave64):
    • XCL_ADAPTER=5060 cargo test -p xcl --lib gpu::dxil::core_tests::raw_stores_in_root_windows_respect_exec_and_bounds -- --nocapture: 1 passed, 0 failed, 0 ignored (0 skipped).
    • XCL_ADAPTER=5060 cargo test -p xcl --lib gpu::dxil:: -- --test-threads=4: 148 passed, 0 failed, 3 ignored (0 skipped).
    • XCL_ADAPTER=5060 cargo test --workspace -- --test-threads=4: 1244 passed, 0 failed, 46 ignored (27 runtime SKIPPED: 20 native-wave64 tests on wave32 NVIDIA, 3 per-lane #1426 refusals, 2 missing D3D12 debug layer, 1 Developer Mode cache-disable, 1 heap windows).
  • AMD Radeon(TM) Graphics (RDNA2 iGPU, driver 32.0.21042.62, native wave64):
    • XCL_ADAPTER=Radeon cargo test -p xcl --lib gpu::dxil::core_tests::raw_stores_in_root_windows_respect_exec_and_bounds -- --nocapture: 1 passed, 0 failed, 0 ignored (0 skipped; verifies both wave32 and native wave64 paths).
    • XCL_ADAPTER=Radeon cargo test --workspace --no-fail-fast -- --test-threads=4: 1242 passed, 2 failed, 46 ignored (17 runtime SKIPPED: 7 no mesh shaders, 6 per-lane #1426 refusals, 2 missing D3D12 debug layer, 1 Developer Mode cache-disable, 1 heap windows). Both AMD failures are unrelated to this PR:
      1. gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 540: res[833] = 0x7, CPU 0x6) — independently reproduced identically on clean origin/main (1a0bbe3) on this AMD driver.
      2. gpu::recomp::tests::gpu_image_get_resinfo_past_last_level — this PR's parent 426a5a7 predates ea088a5 (Recompiler: image_get_resinfo past the last level gives 0 sizes on AMD too); independently confirmed passing (1/1) on origin/main (1a0bbe3) on this AMD adapter.

Not tested

  • Retail title run (scripts/smoke.ps1), Intel GPUs, non-Windows hosts.

AI use

  • Antigravity (Google Gemini): checked out PR head 5e502c5, ran the focused and full workspace suites on both GPUs, verified the two AMD baseline failures against origin/main (1a0bbe3), and drafted this comment from the raw logs.

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent Windows/RX 6800M check of exact PR head 5e502c50805e27fa1df1e833e413841f7f122503 against its base 426a5a745db4d5e4b037449ede0b70cb342f5192.

Environment: Windows 11 build 26200; Ryzen 9 5980HX; Radeon RX 6800M driver 30.0.13002.13003; Rust 1.99.0 MSVC; DXC/DXIL 1.9.2609.5. XCL_ADAPTER=6800M, XCL_DIRECT_DXIL=1, and isolated Cargo targets. Both production worktrees are clean. No game data was copied or attached.

Focused test: cargo test --locked -p xcl --lib -j 2 raw_stores_in_root_windows_respect_exec_and_bounds -- --test-threads=1 --show-output, with XCL_REQUIRE_GPU=wave64, exited 0xC0000005 twice on the PR head before the test harness recorded a pass/fail. In a temporary test-only diagnostic run, the process reached wave32 before dispatch and crashed inside the first runner::run_in_arena; it never reached wave64. Windows Application Error events name amdxc64.dll version 30.0.13002.13003, fault offset 0x43801, in all three runs. The integrated Radeon on this laptop could not serve as a control: this fixture reported no wave32 there under XCL_REQUIRE_GPU=wave64.

Base control: I copied only the PR's 48-line fixture to a detached 426a5a7 tree and disabled its two PR-specific DXIL-shape assertions so it could reach the same dispatch with the base's original lowering. It also exited 0xC0000005; Windows logged the same amdxc64.dll and 0x43801 fault. This establishes that the crash is present with the base production code on this driver. I restored both test-only edits afterward. It does not establish correct GPU readback on either revision.

Release and owned-title regression run: cargo build --locked --workspace --release -j 2 passed on the clean PR head. Both runs used XCL_ADAPTER=6800M, XCL_DIRECT_DXIL=1, XCL_HEAP_WINDOWS=0, default smoke script, the same owned title, separate fresh data/cache directories, and a 12-second duration. Neither hit my external process/memory guard.

Base:

xcl-smoke v1
commit: 426a5a745db4d5e4b037449ede0b70cb342f5192
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 12
exit: 0x0
frames shown: 108 (PresentX 108)
presents per 2 s (last 3): 0 47 60
device removals: 0
crashes: 0
peak commit: 8213 MB

PR head:

xcl-smoke v1
commit: 5e502c50805e27fa1df1e833e413841f7f122503
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 12
exit: 0x0
frames shown: 110 (PresentX 110)
presents per 2 s (last 3): 0 49 60
device removals: 0
crashes: 0
peak commit: 8196 MB

Limits: The focused GPU fixture is blocked by this driver's pre-existing compiler crash, so I cannot confirm its value readback on this card. The brief title run does not show whether it exercised the changed root-window store path; frame counts are not a performance comparison. I did not run the full workspace suite on this head.

AI use: OpenAI Codex (GPT-6; exact variant not exposed in this session) ran the native Windows tests, inspected the Windows fault events, constructed and restored the test-only base control, monitored the paired title runs, and drafted this report. No game files were uploaded.

@bielfreedom

Copy link
Copy Markdown

AMD Windows driver timing for #2288: on the RX 9070 XT, the direct-DXIL window-store guards are neutral in AMD's CreateComputePipelineState (−0.7 %, within noise). That differs from #2191, the HLSL-path version of the same idea, which made the AMD driver 1.56× slower on this card (data).

Setup

  • GPU: RX 9070 XT 16 GB (RDNA4, native wave64), AMD driver 32.0.32029.2010.
  • CPU and memory: Ryzen 7 7700 (16 threads), 32 GB RAM, Windows 11, release.
  • Builds:
    • this PR's parent 426a5a7;
    • this PR at 5e502c5.
  • Both builds carry a local patch that logs per-program DXIL size, record hash (fnv64) and per-CreateComputePipelineState time.

Method

  • XCL_DIRECT_DXIL=1, XCL_HEAP_WINDOWS=0 (root windows, the form this PR changes), XCL_PIPELINE_THREADS=1.
  • XCL_PSO_DISK_CACHE=0 and a fresh exe name per run, because the AMD driver cache is keyed on the exe file name.
  • 26 retail compute programs, 6 KB to 1.0 MB of direct DXIL, including 84eee477d68b6fdf (CS_RaytracingResolve) and 620491641aa9bad6.
  • 2 rounds, interleaved.

Results (means of 2 rounds; all 104 builds succeeded, 0 refused)

426a5a7 #2288 change
direct DXIL, total 8,407,272 B 8,436,636 B +0.35 %
programs changed 20 of 26
driver, sum (r1 / r2) 321.2 / 321.4 s 318.0 / 320.3 s −0.7 %
driver run, process peak private 4.08–4.09 GB 4.09 GB same
  • Per program, the driver time is within ±5 % for 21 of the 26. The other five:
    • 84eee477d68b6fdf: 63.0 → 60.1 s (−5 %);
    • 620491641aa9bad6: 19.9 → 18.6 s (−7 %);
    • three small programs under 1 s (−14 to +15 %, a few tens of ms).
  • The DXIL grows by up to 4.6 % on small programs and by under 0.1 % on the large ones.
  • On the HLSL path, by contrast, Recompiler: pick root-UAV memory windows with bit tests, not a switch #2191 grew the same programs' DXIL by 15 %.

Tests on this card (XCL_REQUIRE_GPU=1, XCL_ADAPTER=9070)

  • raw_stores_in_root_windows_respect_exec_and_bounds: 1 passed, 0 failed, no SKIPPED notice. This is the native wave64 discrete-GPU run of it.

Read / inference

Not tested

  • GPU output of the retail programs.
  • XCL_HEAP_WINDOWS=1.
  • A title run.
  • RDNA2 and RDNA3.

AI use: Claude Code (Claude Opus 5.5) ran the measurements and drafted this. Counts and timings only, no game data.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

coolpersonnn added a commit to coolpersonnn/xcl that referenced this pull request Nov 25, 2026
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)
Assisted-by: Codex in T3 Code (gpt-6.2-sol)
@Prime1997 Prime1997 mentioned this pull request Nov 26, 2026
@github-actions

Copy link
Copy Markdown

Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

@github-actions github-actions Bot added the stale No activity for 3 days; closed 4 days later unless something happens label Nov 29, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 5e502c5

No open or merged PR makes the same change. Main's with_mem_many_tys in gpu/dxil/lower_mem.rs still dispatches multi-window accesses with a switch. #3283 (NaN handling in float min/max memory atomics) and #1439 (window switches in the HLSL path, recomp/emit.rs) change other code. The new path handles only out_tys.is_empty() (stores and atomics that return nothing). It applies the w < n check before testing the one-hot bits, so out-of-range windows cannot alias a valid bit. No problems found in the diff.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale No activity for 3 days; closed 4 days later unless something happens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants