Skip to content

D3D12.X: persist graphics PSO blobs to disk even when GRAPHICS_BLOBS is full - #2910

Closed
real-alponzo wants to merge 1 commit into
xcl-dev:mainfrom
real-alponzo:fix/2884-graphics-blob-disk-persist
Closed

real-alponzo wants to merge 1 commit into
xcl-dev:mainfrom
real-alponzo:fix/2884-graphics-blob-disk-persist

Conversation

@real-alponzo

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

Copy link
Copy Markdown
Contributor

Ensure slow graphics PSO blobs in translated_graphics_pso_once continue persisting to driver_cache on disk even after GRAPHICS_BLOBS reaches its 256 MiB in-memory cap, matching finish_two_pass's mesh pass.

Fixes #2884.

What is in it

  • Updated keep_graphics_blob in crates/xcl/src/hle/d3d12x/real.rs to delegate directly to keep_graphics_blob_with, returning Option<Arc<Vec<u8>>> directly (and extracting blobs when slow || dxil_len >= COMPUTE_BLOB_MIN_DXIL || keep_fixtures), while still enforcing GRAPHICS_BLOBS_MAX inside remember_graphics_blob_into.
  • Updated translated_graphics_pso_once to gate slow on disk.is_some() && driver_cache::worth_keeping(build.in_driver) and pass the returned blob directly to driver_cache::keep instead of re-querying graphics_blob(gkey).
  • Added unit tests graphics_blob_cache_tests::keep_graphics_blob_returns_blob_for_disk_even_when_ram_cache_is_full and graphics_blob_cache_tests::keep_graphics_blob_skips_fast_small_pso exercising the production keep_graphics_blob_with path with an explicit keep_fixtures flag.

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 (2481b11f):

xcl-smoke v1
commit: 2481b11fca656627cb0350c0f9ed7c1accd664ed
gpu: AMD Radeon RX 6800
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1505 (PresentX 1505)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15165 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 graphics_blob_cache_tests -- --nocapture: 2 passed; 0 failed; 0 ignored; 1345 filtered out.
  • .\scripts\smoke.ps1 -Game "C:\VIctory-SSD-test\game" -Seconds 60 on 8b957bec and 2481b11f (blocks above).

Not tested

  • Extended retail world load filling the 256 MiB GRAPHICS_BLOBS cap live.

AI use

  • Antigravity (Gemini 4 Neon) implemented the keep_graphics_blob delegation and return-value fix, wrote the unit tests, ran the tests and paired smoke runs, and drafted this PR description.

@akimfomin

Copy link
Copy Markdown
Contributor

The new slow-small-PSO path still extracts a driver blob when XCL_PSO_DISK_CACHE=0. I traced the call at 3d34505: graphics_path returns None, but slow still bypasses the DXIL size floor before the disk path is checked. That adds a potential GetCachedBlob call and byte copy in the opt-out case. The baseline skipped extraction for that small shader.

Consider let slow = disk.is_some() && driver_cache::worth_keeping(build.in_driver); for the new exception to the size floor. One paired regression: for a slow small graphics PSO with a full RAM cache, expect a saved blob when enabled and no extra extraction when disabled. A fresh-process hit against a blank-directory control would also establish reuse. Related two-process control in Continued. PortBridge · AI-assisted source comparison, no latency measurement.

@fromthemoonx

fromthemoonx commented Nov 26, 2026 •

Copy link
Copy Markdown

Rerun on the new head 2481b11: passes on NVIDIA, and the new test now covers the shipped path: keep_graphics_blob calls keep_graphics_blob_with, and with main's behaviour put back there the test fails.

result
cargo test --workspace --no-fail-fast -- --test-threads=4, 2481b11 (base = main 8b957be, so head = merged) 1448 passed, 0 failed, 47 ignored; 25 SKIPPED lines
scratch: keep_graphics_blob_with returns None when remember_graphics_blob_into did not keep the blob (as on main) keep_graphics_blob_returns_blob_for_disk_even_when_ram_cache_is_full fails 3 of 3 (left: None); keep_graphics_blob_skips_fast_small_pso passes (it guards the other branch)
the first new test alone, 40 runs; hle::d3d12x::real:: (65 tests), --test-threads=8, 30 runs 40 of 40; 30 of 30
e2e test_title_draws_with_a_root_signature_under_the_debug_layer the same messages as main 8b957be: 3× error id 93, 1× error id 1046, 1× warning id 820, 8× id 0 at exit

From reading: keep_graphics_blob now holds the GRAPHICS_BLOBS lock while read_pso_cached_blob calls the driver's GetCachedBlob, which main did outside it. So other threads looking up a graphics blob wait for that copy. I did not measure whether this matters.


First run, on 3d34505: Full suite on NVIDIA (listed under Not tested): passes. But the new tests exercise keep_graphics_blob_with, a #[cfg(test)] copy of the logic, not the shipped keep_graphics_blob: with the old behaviour put back in the real function, both tests still pass.

Tested: 3d34505 (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, Graphics Tools (D3D12 debug layer) installed.

result
cargo test --workspace --no-fail-fast -- --test-threads=4 (all test binaries, which the PR lists under Not tested) 1448 passed, 0 failed, 47 ignored; 25 SKIPPED lines (no wave64, refused per-lane forms)
scratch: real keep_graphics_blob ends with graphics_blob(key) instead of Some(blob) (a blob is returned only if the RAM cache kept it, as on main) graphics_blob_cache_tests still pass, 3 of 3
scratch: the same change in the test-only keep_graphics_blob_with keep_graphics_blob_returns_blob_for_disk_even_when_ram_cache_is_full fails 3 of 3
e2e test_title_draws_with_a_root_signature_under_the_debug_layer the same messages as main 8b957be: 3× error id 93, 1× error id 1046, 1× warning id 820, 8× id 0 at exit

So the disk-persistence fix has no test of its own. If keep_graphics_blob called one shared helper (for example the current keep_graphics_blob_with without #[cfg(test)], taking read_pso_cached_blob as the closure, with graphics_blob / remember_graphics_blob around it), the test would cover the shipped path.

Not tested: a title run that fills the 256 MiB GRAPHICS_BLOBS cap, AMD / Intel on this run.

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

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…m, pure std)

Upstream single-commit 7575f67 on 8b957be: 1 file shaders.rs +38/-2.
Helper + 2 direct_sweep call-site swaps + regression test, hunk bodies
identical (only line offset from linux-only helpers). xcl-dev#2909/xcl-dev#2910 SKIP
(hle/d3d12x/real.rs, Windows-only); xcl-dev#2906 SKIP (dev-stack tip, same
shape as xcl-dev#2886); xcl-dev#2889 re-pinned f334cc9 (force-push, still SKIP).
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026

@KOLESNiii KOLESNiii left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fix in translated_graphics_pso_once looks right to me: it uses the same blob-keeping rule as the mesh path in finish_two_pass, and the RAM cap is still enforced. One change is needed before merge: the tests don't exercise the function this PR fixes (inline comment).

Review written with Claude Code (Claude Opus 5.5); I checked each point against the diff.

}

#[cfg(test)]
fn keep_graphics_blob_with(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new tests call keep_graphics_blob_with, a #[cfg(test)] copy of the logic, while production runs the separate unsafe fn keep_graphics_blob. The two have already drifted (this one has the bytes.is_empty() check, production has the pso.is_null() check), and the tests would pass on main too, so they don't guard the fix (AGENTS.md: a bug fix comes with a test that fails without the fix).

Please have keep_graphics_blob delegate to this function: take the GRAPHICS_BLOBS lock, pass its map, total and GRAPHICS_BLOBS_MAX, and use || read_pso_cached_blob(pso) as read_blob, keeping the null check in the wrapper. Then drop the #[cfg(test)] gate so the tests cover the code that runs.

@KOLESNiii

Copy link
Copy Markdown
Contributor

Two more points, neither blocking on its own:

  • keep_graphics_blob_skips_fast_small_pso relies on the process-wide KEEP_FIXTURES flag being off. Today only tests/gpu_two_pass_cache_e2e.rs sets it, in a separate binary, so the test passes. But if a lib test ever calls force_driver_cache_fixture_retention(), this test panics in read_blob, depending on test order. Passing the fixture flag into the helper as a parameter (or asserting !driver_cache::keep_fixtures() up front) would make it deterministic.
  • Tested shows only the xcl lib suite; the integration test binaries were not run. CONTRIBUTING.md asks for the whole cargo test --workspace -- --test-threads=4 on a GPU, and CI has no GPU, so it doesn't cover this. The pre-existing DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #1905 failure stops the lib binary first; cargo test --workspace --no-fail-fast -- --test-threads=4 runs the rest. Please add those counts. The driver-cache integration tests (gpu_two_pass_cache_e2e) are the ones closest to this change.

Written with Claude Code (Claude Opus 5.5); checked against the PR head 3d345054.

…is full

translated_graphics_pso_once previously called keep_graphics_blob and then looked up graphics_blob(gkey) before writing to driver_cache. Once GRAPHICS_BLOBS hit its 256 MiB RAM cap, remember_graphics_blob rejected new entries and graphics_blob(gkey) returned None, skipping disk persistence for slow graphics PSOs.

Return the extracted blob directly from keep_graphics_blob (and extract slow builds even below COMPUTE_BLOB_MIN_DXIL, matching finish_two_pass's mesh pass) so driver_cache::keep still persists it to disk while respecting GRAPHICS_BLOBS_MAX in RAM.

Fixes #2884.

Assisted-by: Antigravity (Gemini 4 Neon)
@real-alponzo
real-alponzo force-pushed the fix/2884-graphics-blob-disk-persist branch from 3d34505 to 2481b11 Compare November 27, 2026 03:30
@real-alponzo

Copy link
Copy Markdown
Contributor Author

Thanks @KOLESNiii and @fromthemoonx! Addressed in 2481b11: \keep_graphics_blob\ now delegates directly to \keep_graphics_blob_with\ (dropping #[cfg(test)]), \keep_fixtures\ is passed explicitly to keep tests order-independent, and \slow\ is gated on \disk.is_some(). Re-ran unit tests and 60 s smoke.

@futurepro62

Copy link
Copy Markdown

NVIDIA and AMD full-suite run, to go with the reports above by fromthemoonx, since none of them covers AMD. Tested exact head 2481b11f (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: keep_graphics_blob_returns_blob_for_disk_even_when_ram_cache_is_full, keep_graphics_blob_skips_fast_small_pso.
  • 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.

@thehollowedone

Copy link
Copy Markdown
Contributor

Independent Windows/NVIDIA test of PR head 2481b11f on an RTX 3080 Ti (driver 621.35), Windows 11 build 26300, Rust 1.99.1 MSVC.

  • cargo test --offline --locked -p xcl --lib graphics_blob_cache_tests -- --test-threads=4: 2 passed, 0 failed, 0 ignored.
  • cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4: 1,448 passed, 0 failed, 47 ignored across 38 test binaries. The run printed 25 SKIPPED GPU notices (mostly unavailable wave64 paths, plus unsupported per-lane forms and one heap-window case); these are not GPU coverage. The driver-cache integration tests ran, and console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk passed in this run.

This verifies the synthetic suite on this adapter. I did not run a retail title or fill the 256 MiB graphics-blob cap in a live workload, and I did not measure the GetCachedBlob lock contention already noted in this PR.

AI use: Codex (GPT-6.2 Sol) reviewed the changed path, ran the tests, and drafted this report.

@LocranKing

Copy link
Copy Markdown

Tested PR #2910 (2481b11f) against main (8b957bec) on Windows 11 (26300), Ryzen 5 5500 (6C/12T), RTX 3060 Ti 8 GiB (driver 621.40), rustc 1.100.0, DXC 1.9.2602.17.

Unit Tests (cargo test --locked -p xcl)

  • Filter keep_graphics_blob: 2 passed, 0 failed (keep_graphics_blob_returns_blob_for_disk_even_when_ram_cache_is_full and keep_graphics_blob_skips_fast_small_pso).

Paired 180 s Retail Smoke (9cc6a39e, Series S lockhart, XCL_HEAP_WINDOWS=1, XCL_DIRECT_DXIL=all, XCL_DIRECT_SPLIT_INSTRUCTIONS=0, XCL_PSO_WAIT_MS=50)

Both runs started from identical pre-warmed DXIL/driver cache snapshots and reached the 3D world (~60 s in-world):

Build Guest entry / World load Frames shown World presents Peak commit Peak local / non-local VRAM Blobs kept on disk (xcl.log) Crashes / Removals
main (8b957bec) 67.2 s / 188.4 s 1240 14 (28 windows) 29,411 MB 14,281 / 2,241 MB 16 blobs logged (last: 253 ms, 41 KB) 0 / 0 (exit: 0x0)
PR #2910 (2481b11f) 66.0 s / 185.9 s 1225 19 (29 windows) 29,719 MB 14,379 / 2,227 MB 8 blobs logged (last: 5279 ms, 385 KB) 0 / 0 (exit: 0x0)

Both runs exited cleanly (0x0, 0 crashes, 0 device removals). Note regarding #2884: during this short 180 s (~60 s world) window on Series S (XCL_DIRECT_DXIL=all), only 8–16 slow driver blobs (~385–718 KB max logged) were saved on disk, so the 256 MiB GRAPHICS_BLOBS RAM cap was not reached within this run duration.

Not tested: Multi-hour / heavy graphics PSO runs reaching 256 MiB in GRAPHICS_BLOBS, or a second warm pass reusing the newly persisted blobs.

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 2481b11

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 2c717a0
head: 2481b11
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1468 passed, 0 failed, 47 ignored (26 SKIPPED lines); base alone: 1466 passed, 0 failed, 47 ignored
review: none blocking. keep_graphics_blob has one caller and it is updated. Open from the thread and not measured: GRAPHICS_BLOBS stays locked during GetCachedBlob and the copy, so other pipeline builds wait on it meanwhile (no draw path waits on it, no lock-order problem found). The new test fails on main's behaviour by reading the code.
performance: default path (the disk cache is on by default). Builds of 250 ms or more now get their blob extracted also under 16 KB of DXIL, and are written to disk once the 256 MiB RAM cap is full, so the files written in one run no longer have an upper bound (before, about 256 MiB). Writes stay on the thread that creates the pipeline and stay atomic. No per-frame cost; disk growth over a long session was not measured here.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 2481b11

Main already does this: 665f72f ("D3D12.X: persist slow driver blobs past the RAM cap", on main since the #2959 merge). In translated_graphics_pso_once and the other graphics paths, keep_driver_blob reads the blob and stores it on disk when the build was slow, even when GRAPHICS_BLOBS refuses it for RAM. That is what this PR adds. The PR's code no longer applies either: GRAPHICS_BLOBS is now a DriverBlobs with a 3-part key.
In the diff: keep_graphics_blob calls read_pso_cached_blob (the driver's GetCachedBlob) while it holds the GRAPHICS_BLOBS lock. It also lets slow pipelines under COMPUTE_BLOB_MIN_DXIL into the RAM cache, not only onto disk.
Recommendation: close (superseded by main commit 665f72f).

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

@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Closing as superseded: this change is already on main (665f72f). main keep_driver_blob_at writes the slow graphics blob to disk (to_disk) even when GRAPHICS_BLOBS admission refuses it (665f72f, adapted from #2574)

Two independent checks found this: Foniass's close list on #1607 and ours against current main. If something here is still missing on main, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.

@throny throny added the duplicate This issue or pull request already exists label Dec 1, 2026
@throny throny closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

Projects

None yet

Development

Successfully merging this pull request may close these issues.

D3D12.X: slow graphics PSO blobs are not saved to disk once GRAPHICS_BLOBS is full

9 participants