Skip to content

Shaders: cache normalized DXIL cache dir and passthrough DXIL in RAM - #2915

Open
real-alponzo wants to merge 1 commit into
xcl-dev:mainfrom
real-alponzo:fix/2885-cache-passthrough-and-dir
Open

real-alponzo wants to merge 1 commit into
xcl-dev:mainfrom
real-alponzo:fix/2885-cache-passthrough-and-dir

Conversation

@real-alponzo

@real-alponzo real-alponzo commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Cache canonicalized DXIL cache directories in dxc::normalized_cache_dir and cache compiled passthrough DXIL (ms_6_6 / gs_6_6) in RAM for finish_two_pass_compiled, console_geometry, and rect_list_gs.

Fixes #2885.

What is in it

  • Cached existing canonicalized cache directories in crates/xcl/src/gpu/recomp/dxc.rs (normalized_cache_dir_in / normalized_cache_dir, capped at 64 entries), keyed by std::path::absolute(dir) so relative XCL_DXIL_CACHE paths still resolve cleanly across working directory changes (mid-process symlink/junction re-pointing is documented as not handled; non-existent paths are not cached until they exist).
  • Added an in-memory passthrough DXIL cache (compile_passthrough_cached_in / compile_passthrough_cached, capped at 256 entries, keyed by (normalized_cache_dir, profile, hlsl), never caching errors or deferred misses, and recording DXIL cache hits via dxc::record_cache_hit()) in crates/xcl/src/gpu/recomp/pso.rs and wired it into finish_two_pass_compiled, console_geometry, and rect_list_gs.
  • Added unit tests normalized_cache_dir_caches_existing_dir_and_retries_missing and passthrough_ram_cache_reuses_compiled_dxil_and_does_not_cache_errors.

Regression run

Base (main):

xcl-smoke v1
commit: 8b957bec6f82495aec940944c6bf47faa02db590
gpu: AMD Radeon RX 6800
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1525 (PresentX 1525)
presents per 2 s (last 3): 60 61 59
device removals: 0
crashes: 0
peak commit: 14867 MB

PR head (dd437650):

xcl-smoke v1
commit: dd43765097194ab84e82b811de3990bd70241387
gpu: AMD Radeon RX 6800
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1532 (PresentX 1533)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15321 MB

Tested

  • Hardware: Windows 11 Pro for Workstations x64 (Build 26300), Intel Core i9-9900K, 32 GB RAM, AMD Radeon RX 6800 (Driver 32.0.21045.29003), rustc 1.100.0, DXC 1.9.2602.17.
  • cargo test -p xcl --lib normalized_cache_dir_caches_existing_dir -- --nocapture: 1 passed; 0 failed; 0 ignored; 1346 filtered out.
  • cargo test -p xcl --lib passthrough_ram_cache_reuses_compiled_dxil -- --nocapture: 1 passed; 0 failed; 0 ignored; 1346 filtered out.
  • .\scripts\smoke.ps1 -Game "C:\VIctory-SSD-test\game" -Seconds 60 on 8b957bec and dd437650 (blocks above).

Not tested

  • Extended world-load CPU profiling of passthrough rebuild frequency beyond the 60 s smoke run.

AI use

  • Antigravity (Gemini 4 Neon) implemented the normalized_cache_dir and passthrough DXIL RAM caches, addressed review feedback, wrote the unit tests, ran the tests and paired smoke runs, and drafted this PR description.

@fromthemoonx

fromthemoonx commented Nov 27, 2026 •

Copy link
Copy Markdown

Rerun on the new head dd43765: still passes on NVIDIA, both RAM caches are still hit by the suite's real calls, and both tests still fail with the lookups disabled.

result
cargo test --workspace --no-fail-fast -- --test-threads=4, dd43765 (base = main 8b957be, so head = merged) 1448 passed, 0 failed, 47 ignored; 25 SKIPPED lines
scratch eprintln! in the shipped normalized_cache_dir / compile_passthrough_cached (unit tests' own _in calls left out), cargo test -p xcl --lib normalized_cache_dir: 84 calls, 38 hits; passthrough: 4 hits, 1 miss (ms_6_6)
same, --test d3d12_mesh_stream --test gpu_compute_e2e normalized_cache_dir: 5 calls, 2 hits; no passthrough calls
scratch: both get(...) lookups replaced by None, each test alone normalized_cache_dir_caches_existing_dir_and_retries_missing and passthrough_ram_cache_reuses_compiled_dxil_and_does_not_cache_errors fail 3 of 3

The test checks the hit count through its own on_hit closure, so dropping dxc::record_cache_hit from compile_passthrough_cached would not fail any test.


First run, on 6f7f998: Full suite on NVIDIA (listed under Not tested): passes. Both RAM caches are hit by the suite's real calls, and both new tests fail with the lookups disabled.

Tested: 6f7f998 (its base is current main 8b957be, so head = merged). RTX 3060 12 GB (driver 610.88), Ryzen 7 5700X, Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug, DXC 1.9.2602.17.

result
cargo test --workspace --no-fail-fast -- --test-threads=4 1448 passed, 0 failed, 47 ignored; 25 SKIPPED lines (no wave64, refused per-lane forms)
scratch eprintln! on each hit / miss, cargo test -p xcl --lib + --test d3d12_mesh_stream --test gpu_compute_e2e (the new unit tests' own calls subtracted) passthrough: 4 hits, 1 miss (ms_6_6); normalized_cache_dir: 34 hits, 50 misses; all tests pass
scratch: both get(...) lookups replaced by None passthrough_ram_cache_reuses_compiled_dxil_and_does_not_cache_errors and normalized_cache_dir_caches_existing_dir_and_retries_missing fail 3 of 3; unchanged they pass 3 of 3

compile_passthrough_cached and normalized_cache_dir call the tested _in helpers directly, so the tests cover the shipped path.

Not tested: a title run (no time saved was measured), AMD / Intel on this run.

AI use: Claude Code (Claude Opus 5.5) ran the tests and the scratch checks and wrote this report.

@JJAutoCompare

Copy link
Copy Markdown

Tested: 6f7f998963b1339a1d8282ae9e92211e2c93d635 on Windows 11 build 26200, Ryzen 7 3800X, Rust 1.100.0 MSVC, debug, DXC 1.9.2602.17. Ran the built library test executable with --test-threads=1 --nocapture for normalization, alias deduplication, cache statistics, passthrough RAM reuse, key context and mesh compute caching. Six passed, 0 failed, ignored or skipped. Repeated the mesh test in a separate process with a second fresh cache root: 1 passed, 0 failed, ignored or skipped. Each root held four files, and their SHA-256 inventories matched.

Not tested: Same-process cache-root switching, GPU execution, performance, full suite, and retail smoke.

AI use: T3 Code / Codex (gpt-6.2-sol) ran and reran the checks and wrote this report.

@KOLESNiii KOLESNiii left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Requesting changes for two points, marked blocking inline:

  1. The passthrough RAM cache (pso.rs) short-circuits dxc::compile_cached, so it ignores the DXIL cache directory and its counters.
  2. The normalized-dir cache (dxc.rs) is keyed on the path as given, so relative paths and re-pointed links can return a stale canonical path.

The other inline comments are non-blocking.

Scope: this PR has three changes: the passthrough DXIL RAM cache (pso.rs), the canonical-path cache for the DXIL cache dir (dxc.rs), and the console_geometry refactor onto finish_two_pass_compiled. CONTRIBUTING.md asks for one logical change per PR. Please split the dxc.rs path cache into its own PR. The console_geometry dedup can go with the pso.rs cache or stand alone.

This review was written from the diff at 6f7f998. I did not build this PR or run its tests.

Review assisted by Claude Code (Claude Opus 5.5); I checked each point before posting.

) -> Result<Vec<u8>, String> {
let key = (crate::gpu::shader::fnv64(hlsl.as_bytes()), hlsl.len(), profile);
if let Some(hit) = cache.lock().unwrap_or_else(|e| e.into_inner()).get(&key).cloned() {
return Ok(hit);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking. A RAM hit returns before dxc::compile_cached runs, so after the first compile of a passthrough MS/GS shader:

  • the DXIL cache counters (cache_counters() hits/compilations, which feed XCL_ACTIVITY and the report stats) stop counting these shaders;
  • the key doesn't include cache_dir(). If XCL_DXIL_CACHE changes inside the process, the new directory never gets the ms_6_6/gs_6_6 passthrough .dxil. gpu_compute_e2e.rs and gpu_pso_e2e.rs both point XCL_DXIL_CACHE at a cold dir in-process, so a cold-cache test can miss shaders it expects to find written.

Please either key the RAM cache on the resolved cache dir as well (and count a RAM hit as a DXIL cache hit), or move this cache under compile_cached so the disk-cache bookkeeping still runs.

Comment thread crates/xcl/src/gpu/recomp/pso.rs Outdated
profile: &'static str,
compile: impl FnOnce() -> Result<Vec<u8>, String>,
) -> Result<Vec<u8>, String> {
let key = (crate::gpu::shader::fnv64(hlsl.as_bytes()), hlsl.len(), profile);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: the key is only (fnv64(hlsl), len, profile), and a hit is returned without comparing the source. If two passthrough sources of the same length collide on FNV-64, the wrong DXIL comes back with no check, and you get mismatched output signatures and garbage geometry. The disk cache also mixes in the toolchain identity and entry point. The passthrough sources are small, so storing the HLSL in the entry (or using it as the key) and comparing it on a hit costs little.

) -> PathBuf {
if let Some(hit) = cache.lock().unwrap_or_else(|e| e.into_inner()).get(dir).cloned() {
return hit;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking. The cache is keyed on dir as given, so a stale result can come back in two cases:

  • a relative XCL_DXIL_CACHE (e.g. .\dxil) keeps its first canonical result after the current directory changes;
  • a directory later replaced by a junction/symlink keeps its old target, while an alias of it canonicalizes to the new one.

In both cases cache_mutex_name and the flight key no longer match where the files are actually written. Unifying those is the reason normalized_cache_dir exists. At least key the cache on std::path::absolute(dir) (and only cache absolute inputs), and document that links swapped mid-process are not handled.

Comment thread crates/xcl/src/gpu/recomp/dxc.rs Outdated
let calls = std::sync::atomic::AtomicUsize::new(0);
let first = normalized_cache_dir_in(&cache, &dir, |p| {
calls.fetch_add(1, Ordering::Relaxed);
Ok(PathBuf::from(r"\\?\C:\fake\cache").join(p.file_name().unwrap_or_default()))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking, test: the fake canonicalize joins the file name onto \\?\C:\fake\cache, so the cached value is ...\cache\cache. It works, but it isn't a plausible canonical path and hides what the test means. Returning the fixed path would be clearer. Also, the missing-dir half asserts >= 1 calls and never calls a second time, so it doesn't test the "retries" in the name: a regression that caches the ancestor fallback for a missing dir would still pass. Call normalized_cache_dir_in twice for missing and assert that canonicalize runs again.

@andrewDoing

Copy link
Copy Markdown

Confirmed the relative-directory concern with a Windows public-API probe using the same relative cache path dxil throughout. Both a/dxil and b/dxil existed and started empty. The test compiled source 1 under working directory a, changed to b, then compiled source 1, source 2, and source 2 again; the sources had distinct keys.

Revision Source 1 under b Source 2 first / repeat under b DXIL files in a / b
Main 8b957bec Miss Miss / hit 1 / 2
PR 6f7f9989 Hit Miss / hit 2 / 0

The PR reused the old directory for both a cache hit and a new write. The stale canonical path constructs the target filename upstream of locking, so this affects file placement even without concurrent writers. Both revisions used the identical test-only overlay and were explicitly rebuilt from their respective checkouts. Junction retargeting and retail performance were not tested.

AI use: OpenAI Codex with GPT-6.2 Astra wrote and ran the synthetic probe and checked the build roots; Codex coordinated and prepared this report.

@oni-swr

oni-swr commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Tested (AMD): clean 6f7f998963b1339a1d8282ae9e92211e2c93d635 (base = main 8b957bec). Windows 11 26200, Ryzen 7 5700X3D, AMD Radeon RX 7800 XT (driver 32.0.31035.1003), Rust 1.100.0 MSVC, DXC 1.8.2502.11 (Windows SDK 10.0.26100), debug.

  • cargo test -j 4 -p xcl --no-fail-fast -- --test-threads=4 then cargo build --workspace + cargo test -p xcl --test e2e: the e2e tests need the workspace-built test title, so the first run failed 3 of them for lack of it and the rerun passed 4 of 4. Lib/other targets: 1 failed, 7 SKIPPED lines (no heap windows, refused V_CVT_F16_F32 / V_MUL_F16 / VOP3-modifier forms), 47 ignored. The one failure, gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 722: res[30] = 0x1, CPU 0x7fffffff), also fails on main 8b957be with the same seed on this GPU, so it is not from the PR.
  • Totals: 1447 passed, 1 failed (baseline fuzz seed 722, fails on main too), 47 ignored.
  • PR's own tests: normalized_cache_dir_caches_existing_dir_and_retries_missing and passthrough_ram_cache_reuses_compiled_dxil_and_does_not_cache_errors pass.

Review (by reading, no bugs found): the passthrough RAM key (fnv64(hlsl), len, profile) matches what the disk key hashes for these fixed-entry (main), toolchain-process-static compiles; errors and cached-only deferrals are not cached (pso.rs:1074-1090). Both caches stop inserting at 64 / 256 entries (dxc.rs:829, pso.rs:1086) with no eviction, so overflow only costs the old behaviour. Concurrent workers can at worst compile the same HLSL twice; DXC compiles stay coalesced by the disk-cache flight. Minor: the key is a 64-bit hash + length with no source comparison.

Not tested: retail smoke. The scripts/smoke.ps1 run starts with a cold-cache precompile of about 26k shaders, which did not fit this session's time budget, so I did not produce a base/head xcl-smoke pair. No runtime hit-rate or timing was measured either.

AI use: Claude Code (Claude Sonnet 5.5) ran the checks and wrote this.

dxc::compile_cached_in_observed previously called std::fs::canonicalize via normalized_cache_dir on every shader lookup, and finish_two_pass_compiled / rect_list_gs re-read and re-validated passthrough DXIL from disk on every two-pass MS/GS or rect-list PSO build.

Cache canonicalized existing cache directories in dxc.rs and cache compiled passthrough DXIL (ms_6_6 / gs_6_6) in RAM in pso.rs.

Fixes xcl-dev#2885.

Assisted-by: Antigravity (Gemini 4 Neon)
@real-alponzo
real-alponzo force-pushed the fix/2885-cache-passthrough-and-dir branch from 6f7f998 to dd43765 Compare November 27, 2026 03:30
@real-alponzo

Copy link
Copy Markdown
Contributor Author

Thanks @KOLESNiii and @andrewDoing! Addressed all points in dd43765:
ormalized_cache_dir_in\ now keys on \std::path::absolute(dir)\ (documenting mid-process link swaps and testing missing-dir retries twice), and \compile_passthrough_cached\ keys on (normalized_cache_dir, profile, hlsl)\ while recording DXIL cache hits via \dxc::record_cache_hit(). Re-ran unit tests and 60 s smoke.

@ettehn

ettehn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Tested: The relative DXIL cache path regression is fixed on dd43765097194ab84e82b811de3990bd70241387. A Windows CPU-only Rust probe built each revision’s unchanged dxc.rs and called dxc::compile_cached with two synthetic ps_6_6 shaders. Each revision ran once in a fresh process with two empty cache directories. With XCL_DXIL_CACHE=dxil throughout, the process compiled red in A, changed to B, compiled red and then green twice, and returned to A to compile red again.

Revision B/red B/green first / repeat A/red on return DXIL files A / B
main 8b957bec Miss Miss / hit Hit 1 / 2
previous head 6f7f9989 Hit Miss / hit Hit 2 / 0
revised head dd437650 Miss Miss / hit Hit 1 / 2

All three probes exited 0 with their expected results. Windows 11 build 26200, Rust 1.97.1 MSVC, DXC 1.8.2502.11.

Not tested: Passthrough RAM cache, junction retargeting, GPU execution, retail smoke, and the full workspace suite.

AI use: OpenAI Codex (GPT-6) wrote and ran the probe and prepared this report.

@futurepro62

Copy link
Copy Markdown

NVIDIA and AMD full-suite run, to go with the reports above by ettehn, fromthemoonx, since none of them covers AMD. Tested exact head dd437650 (on its base 8b957be).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace --no-fail-fast -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 1436 passed, 0 failed, 45 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, dispatch_chain_native_wave64_builds_whole, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: normalized_cache_dir_caches_existing_dir_and_retries_missing, passthrough_ram_cache_reuses_compiled_dxil_and_does_not_cache_errors.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace --no-fail-fast -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 1447 passed, 0 failed, 47 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main c2ee10e4 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests, const_and_null_mask_operands_agree_with_hlsl_on_the_gpu and mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

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.

Shaders: two-pass passthrough DXIL and the cache dir canonicalization are redone on every PSO build (verification help wanted)

8 participants