D3D12.X: persist slow driver blobs past the RAM cache cap (#1833) #2564

Closed
razormontana wants to merge 1 commit from upstream-pr/2574 into main
razormontana commented 2026-11-25 23:19:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by razormontana on 2026-11-25T23:19:36Z.


Part of #1833. A slow translated pipeline could fail to leave a driver blob for the next run when XCL's in-memory blob cache was full. Save eligible blobs to disk independently of RAM admission so later sessions can reuse them.

What is in it

  • real.rs uses one captured blob for the RAM and disk paths covering translated compute, translated graphics and the compute pass of two-pass pipelines. It still uses the existing keys, memory limits, minimum DXIL size and disk-write eligibility. README.md documents that disk saves can continue when the RAM budget is full.
  • A synthetic test fills a small cache, verifies that its retained entries stay within budget, and reads the later blob from the disk path. A second test checks the existing size and time thresholds and empty or unreadable blobs.
  • Recheck the key under the cache lock before charging RAM. Concurrent same-key builds keep the first resident blob and charge the key once. This covers the shared helper used by translated compute, graphics and two-pass compute. The compute accounting overlaps #826 and #2740. #2515 covers cache key identity and #2426 covers driver errors that invalidate cached blobs.

Tested

  • Windows 11 Pro build 22631, Core i7-10700K, RTX 3070 8 GB (driver 617.42), Rust 1.100.0 MSVC.
  • Seven hle::d3d12x::real::driver_cache::tests passed. The new regression failed before the fix when the same key was charged twice and prevented an unrelated blob from fitting. The saturated-cache test still checks disk persistence.
  • Debug workspace build passed. On c00f3476, cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --show-output reported 1,445 passed, 0 failed and 47 ignored. The pass count includes 26 explicit GPU skip notices.
  • cargo build --offline --locked --release -p xcl succeeded.

Regression run

Both release builds ran the same retail title offline for 60 seconds on the RTX 3070. Both used the Series S profile, direct DXIL and copies of the same starting cache. This pair uses e120925, the preceding main commit. At 8b957be, smoke reached its startup deadline during #2555 shader preparation. The PR merges cleanly into 8b957be; the combined retail run remains unverified. The initial pair showed 703 frames on main and 408 on the PR. For this repeat, both started from copies of the cache left by the first main run, after builds completed.

Main

xcl-smoke v1
commit: e120925e3abc9956a8b9bae631969d32e8ccd43c
gpu: NVIDIA GeForce RTX 3070
title: 80ea98f7
seconds: 60
exit: 0x0
frames shown: 445 (PresentX 446)
presents per 2 s (last 3): 18 18 18
device removals: 0
crashes: 0
peak commit: 17596 MB

PR head

xcl-smoke v1
commit: c00f3476dff7702dc076a783206f289d1f6a720e
gpu: NVIDIA GeForce RTX 3070
title: 80ea98f7
seconds: 60
exit: 0x0
frames shown: 434 (PresentX 435)
presents per 2 s (last 3): 16 16 17
device removals: 0
crashes: 0
peak commit: 17600 MB

Not tested

Retail cache saturation, cold compile times and other GPU vendors remain unmeasured. The isolated cache tests control the size and timing inputs.

AI use

Codex GPT-6.2 wrote and reviewed the code and tests, rebased the branch, ran the checks, and updated this description.

<!-- greyfinch-sync:ivall/xcl:issue:5500875301 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2574). Originally posted by [razormontana](https://github.com/razormontana) on 2026-11-25T23:19:36Z. --- Part of #1833. A slow translated pipeline could fail to leave a driver blob for the next run when XCL's in-memory blob cache was full. Save eligible blobs to disk independently of RAM admission so later sessions can reuse them. **What is in it** - `real.rs` uses one captured blob for the RAM and disk paths covering translated compute, translated graphics and the compute pass of two-pass pipelines. It still uses the existing keys, memory limits, minimum DXIL size and disk-write eligibility. `README.md` documents that disk saves can continue when the RAM budget is full. - A synthetic test fills a small cache, verifies that its retained entries stay within budget, and reads the later blob from the disk path. A second test checks the existing size and time thresholds and empty or unreadable blobs. - Recheck the key under the cache lock before charging RAM. Concurrent same-key builds keep the first resident blob and charge the key once. This covers the shared helper used by translated compute, graphics and two-pass compute. The compute accounting overlaps #826 and #2740. #2515 covers cache key identity and #2426 covers driver errors that invalidate cached blobs. **Tested** - Windows 11 Pro build 22631, Core i7-10700K, RTX 3070 8 GB (driver 617.42), Rust 1.100.0 MSVC. - Seven `hle::d3d12x::real::driver_cache::tests` passed. The new regression failed before the fix when the same key was charged twice and prevented an unrelated blob from fitting. The saturated-cache test still checks disk persistence. - Debug workspace build passed. On `c00f3476`, `cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --show-output` reported 1,445 passed, 0 failed and 47 ignored. The pass count includes 26 explicit GPU skip notices. - `cargo build --offline --locked --release -p xcl` succeeded. **Regression run** Both release builds ran the same retail title offline for 60 seconds on the RTX 3070. Both used the Series S profile, direct DXIL and copies of the same starting cache. This pair uses `e120925`, the preceding main commit. At `8b957be`, smoke reached its startup deadline during #2555 shader preparation. The PR merges cleanly into `8b957be`; the combined retail run remains unverified. The initial pair showed 703 frames on main and 408 on the PR. For this repeat, both started from copies of the cache left by the first main run, after builds completed. Main ``` xcl-smoke v1 commit: e120925e3abc9956a8b9bae631969d32e8ccd43c gpu: NVIDIA GeForce RTX 3070 title: 80ea98f7 seconds: 60 exit: 0x0 frames shown: 445 (PresentX 446) presents per 2 s (last 3): 18 18 18 device removals: 0 crashes: 0 peak commit: 17596 MB ``` PR head ``` xcl-smoke v1 commit: c00f3476dff7702dc076a783206f289d1f6a720e gpu: NVIDIA GeForce RTX 3070 title: 80ea98f7 seconds: 60 exit: 0x0 frames shown: 434 (PresentX 435) presents per 2 s (last 3): 16 16 17 device removals: 0 crashes: 0 peak commit: 17600 MB ``` **Not tested** Retail cache saturation, cold compile times and other GPU vendors remain unmeasured. The isolated cache tests control the size and timing inputs. **AI use** Codex GPT-6.2 wrote and reviewed the code and tests, rebased the branch, ran the checks, and updated this description.
DavidM1911 commented 2026-11-26 00:05:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T23:45:31Z.


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

  • cargo test -p xcl --lib: all passed, 0 failed, 26 ignored.

Thanks!

— Devin

<!-- greyfinch-sync:ivall/xcl:comment:7178008001 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2574#issuecomment-7178008001). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T23:45:31Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 26 ignored. Thanks! — Devin
xpatfussy69x commented 2026-11-26 00:05:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by xpatfussy69x on 2026-11-26T00:01:57Z.


Test run on exact head e2aae0e (e2aae0e87df1499ddc393bec6b7b3d39adb24006, on its base e1d84b7), clean tree.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (driver 32.0.16.2124, 32-lane waves only), AMD Ryzen 5 7500F, Windows 11, Rust 1.100.0; debug build for the tests, release for the smoke runs
  • cargo test --workspace -- --test-threads=4: 1425 passed, 0 failed, 46 ignored
  • SKIPPED (25): 21 × no wave64; 1 × no heap windows; 3 × per-lane form refused V_MUL_F16 / V_PK_MUL_F16 / V_CVT_F16_F32 (on main too)
  • cargo test -p xcl --lib a_slow_pipeline_is_saved: 1 passed, 0 failed
  • This PR's new tests in the workspace run:
    • a_slow_pipeline_is_saved_for_the_next_run_after_the_memory_cache_fills: ok
    • storing_a_pipeline_still_observes_the_size_and_time_thresholds: ok

Regression run (60 s, default settings, a retail title)

main:

xcl-smoke v1
commit: 08db8020d323bf478964fcc586152cce54959cfc
gpu: NVIDIA GeForce RTX 3060
title: c3f791f3
seconds: 60
exit: 0x0
frames shown: 1571 (PresentX 1571)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14042 MB

this PR:

xcl-smoke v1
commit: e2aae0e87df1499ddc393bec6b7b3d39adb24006
gpu: NVIDIA GeForce RTX 3060
title: c3f791f3
seconds: 60
exit: 0x0
frames shown: 1582 (PresentX 1582)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14012 MB

No crash or device removal; frames 101 % of main's, peak commit 100 %. The main run is on current main (08db802), newer than this PR's base.

Not tested

  • Whether the RAM cache cap was reached in this 60 s run, and the second-run startup time: a regression check only
  • The PR merged into current main (tested on its own base; it merges into 08db802 without conflicts)
  • AMD / native wave64

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and both smoke runs on the machine above and wrote this report.
<!-- greyfinch-sync:ivall/xcl:comment:7178319804 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2574#issuecomment-7178319804). Originally posted by [xpatfussy69x](https://github.com/xpatfussy69x) on 2026-11-26T00:01:57Z. --- Test run on exact head `e2aae0e` (`e2aae0e87df1499ddc393bec6b7b3d39adb24006`, on its base `e1d84b7`), clean tree. **Tested** - NVIDIA GeForce RTX 3060 12 GB (driver 32.0.16.2124, 32-lane waves only), AMD Ryzen 5 7500F, Windows 11, Rust 1.100.0; debug build for the tests, release for the smoke runs - `cargo test --workspace -- --test-threads=4`: 1425 passed, 0 failed, 46 ignored - SKIPPED (25): 21 × no wave64; 1 × no heap windows; 3 × per-lane form refused `V_MUL_F16` / `V_PK_MUL_F16` / `V_CVT_F16_F32` (on `main` too) - `cargo test -p xcl --lib a_slow_pipeline_is_saved`: 1 passed, 0 failed - This PR's new tests in the workspace run: - `a_slow_pipeline_is_saved_for_the_next_run_after_the_memory_cache_fills`: ok - `storing_a_pipeline_still_observes_the_size_and_time_thresholds`: ok **Regression run** (60 s, default settings, a retail title) main: ``` xcl-smoke v1 commit: 08db8020d323bf478964fcc586152cce54959cfc gpu: NVIDIA GeForce RTX 3060 title: c3f791f3 seconds: 60 exit: 0x0 frames shown: 1571 (PresentX 1571) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14042 MB ``` this PR: ``` xcl-smoke v1 commit: e2aae0e87df1499ddc393bec6b7b3d39adb24006 gpu: NVIDIA GeForce RTX 3060 title: c3f791f3 seconds: 60 exit: 0x0 frames shown: 1582 (PresentX 1582) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14012 MB ``` No crash or device removal; frames 101 % of `main`'s, peak commit 100 %. The `main` run is on current `main` (`08db802`), newer than this PR's base. **Not tested** - Whether the RAM cache cap was reached in this 60 s run, and the second-run startup time: a regression check only - The PR merged into current `main` (tested on its own base; it merges into `08db802` without conflicts) - AMD / native wave64 **AI use** - Claude Code (Claude Opus 5.5) ran the tests and both smoke runs on the machine above and wrote this report.
ramon-victor commented 2026-11-26 00:05:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ramon-victor on 2026-11-26T00:05:26Z.


Independent NVIDIA (wave32) full-suite + retail smoke test report on exact PR head e2aae0e87df1499ddc393bec6b7b3d39adb24006 (clean detached checkout, no local changes).

Tested

  • Hardware & toolchain: NVIDIA GeForce RTX 3070 8 GiB (wave32, driver 621.24), AMD Ryzen 7 5700X, 32 GiB RAM, Windows 11 Pro (build 26300), Rust 1.99.0 (x86_64-pc-windows-msvc), DXC/DXIL 1.8.2502.11 (Windows SDK 10.0.26100.0); debug tests, release smoke.
  • Targeted PR tests (cargo test -p xcl --lib driver_cache::tests): 6 passed, 0 failed (including the 2 new tests a_slow_pipeline_is_saved_for_the_next_run_after_the_memory_cache_fills and storing_a_pipeline_still_observes_the_size_and_time_thresholds).
  • Full workspace (.\scripts\test.ps1): 1425 passed, 0 failed, 46 ignored (25 GPU skips expected on this wave32 adapter: 21 no wave64, 1 no heap windows, 3 wave32 per-lane refused for #1426 f16/f32 semantics).
  • Release build (cargo build --release -p xcl) and 60 s retail smoke run (XCL_NETWORK=0, compared against main @ 08db802 baseline on the same machine today: 1605 frames, 15009 MB peak commit, 0 crashes, 0 device removals):

Regression run

xcl-smoke v1
commit: e2aae0e87df1499ddc393bec6b7b3d39adb24006
gpu: NVIDIA GeForce RTX 3070
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1624 (PresentX 1625)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14972 MB

Not tested

  • AMD / Intel GPUs and wave64-only GPU tests (skipped on RTX 3070); XCL_SAMPLE_* tests (unset).

AI use

  • Antigravity (Gemini 4 Neon) ran the build, test suite, and smoke run and drafted this report.
<!-- greyfinch-sync:ivall/xcl:comment:7178383463 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2574#issuecomment-7178383463). Originally posted by [ramon-victor](https://github.com/ramon-victor) on 2026-11-26T00:05:26Z. --- Independent NVIDIA (wave32) full-suite + retail smoke test report on exact PR head `e2aae0e87df1499ddc393bec6b7b3d39adb24006` (clean detached checkout, no local changes). **Tested** - Hardware & toolchain: NVIDIA GeForce RTX 3070 8 GiB (wave32, driver 621.24), AMD Ryzen 7 5700X, 32 GiB RAM, Windows 11 Pro (build 26300), Rust 1.99.0 (`x86_64-pc-windows-msvc`), DXC/DXIL 1.8.2502.11 (Windows SDK 10.0.26100.0); debug tests, release smoke. - Targeted PR tests (`cargo test -p xcl --lib driver_cache::tests`): **6 passed, 0 failed** (including the 2 new tests `a_slow_pipeline_is_saved_for_the_next_run_after_the_memory_cache_fills` and `storing_a_pipeline_still_observes_the_size_and_time_thresholds`). - Full workspace (`.\scripts\test.ps1`): **1425 passed, 0 failed, 46 ignored** (25 GPU skips expected on this wave32 adapter: 21 `no wave64`, 1 `no heap windows`, 3 wave32 per-lane refused for `#1426` f16/f32 semantics). - Release build (`cargo build --release -p xcl`) and 60 s retail smoke run (`XCL_NETWORK=0`, compared against `main @ 08db802` baseline on the same machine today: `1605` frames, `15009 MB` peak commit, `0` crashes, `0` device removals): **Regression run** ``` xcl-smoke v1 commit: e2aae0e87df1499ddc393bec6b7b3d39adb24006 gpu: NVIDIA GeForce RTX 3070 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1624 (PresentX 1625) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14972 MB ``` **Not tested** - AMD / Intel GPUs and wave64-only GPU tests (skipped on RTX 3070); `XCL_SAMPLE_*` tests (unset). **AI use** - Antigravity (Gemini 4 Neon) ran the build, test suite, and smoke run and drafted this report.
pickles976 commented 2026-11-26 05:05:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by pickles976 on 2026-11-26T04:42:55Z.


Wine/NVIDIA cross-check of the focused tests — all pass. Head e2aae0e87df1499ddc393bec6b7b3d39adb24006, Linux + Wine 11.0, vkd3d-proton 3.2.0 (2576c0b4adfae4a), NVIDIA 590.48.1, RTX 4060 Laptop GPU 8 GiB, --locked --target x86_64-pc-windows-msvc, one test thread, fresh Compiling xcl .../xcl-pr2574/... provenance, DXVK_CONFIG='dxgi.hideNvidiaGpu = False'.

cargo test --locked --target x86_64-pc-windows-msvc -p xcl --lib hle::d3d12x::real::driver_cache::tests:: -- --nocapture --test-threads=1 → 6/6 pass on the real adapter, including the new a_slow_pipeline_is_saved_for_the_next_run_after_the_memory_cache_fills (the log shows the late blob recovered through the disk path after the RAM map is dropped: "2 driver blobs kept on disk for the next run (this one: 250 ms…)") and the unchanged a_kept_blob_is_read_back_and_a_refused_one_is_dropped (its kept-on-disk reload and the refused-foreign-adapter branch both behave). The four pre-existing tests pass unmodified.

Scope: synthetic fixtures with a small cache and controlled timing inputs — no retail cache saturation or cold-compile timing measured here, and no title run. On this 16 GiB host the change is relevant exactly as scoped: a saturated RAM blob cache no longer silently loses slow translated pipelines between sessions.

Log: .compat-xcl/logs/verify-pr2574-wine-blob-cache.log (local). AI-assisted verification and report (OpenAI Codex).

<!-- greyfinch-sync:ivall/xcl:comment:7182837721 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2574#issuecomment-7182837721). Originally posted by [pickles976](https://github.com/pickles976) on 2026-11-26T04:42:55Z. --- **Wine/NVIDIA cross-check of the focused tests — all pass.** Head `e2aae0e87df1499ddc393bec6b7b3d39adb24006`, Linux + Wine 11.0, vkd3d-proton 3.2.0 (`2576c0b4adfae4a`), NVIDIA 590.48.1, RTX 4060 Laptop GPU 8 GiB, `--locked --target x86_64-pc-windows-msvc`, one test thread, fresh `Compiling xcl .../xcl-pr2574/...` provenance, `DXVK_CONFIG='dxgi.hideNvidiaGpu = False'`. `cargo test --locked --target x86_64-pc-windows-msvc -p xcl --lib hle::d3d12x::real::driver_cache::tests:: -- --nocapture --test-threads=1` → **6/6 pass** on the real adapter, including the new `a_slow_pipeline_is_saved_for_the_next_run_after_the_memory_cache_fills` (the log shows the late blob recovered through the disk path after the RAM map is dropped: "2 driver blobs kept on disk for the next run (this one: 250 ms…)") and the unchanged `a_kept_blob_is_read_back_and_a_refused_one_is_dropped` (its kept-on-disk reload and the refused-foreign-adapter branch both behave). The four pre-existing tests pass unmodified. Scope: synthetic fixtures with a small cache and controlled timing inputs — no retail cache saturation or cold-compile timing measured here, and no title run. On this 16 GiB host the change is relevant exactly as scoped: a saturated RAM blob cache no longer silently loses slow translated pipelines between sessions. Log: `.compat-xcl/logs/verify-pr2574-wine-blob-cache.log` (local). AI-assisted verification and report (OpenAI Codex).
throny commented 2026-11-26 14:03:07 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-26T13:38:27Z.


Two contributors checked independently and found that #2740 solves the same problem (for #1833) in a different way: #1607, group D127. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

<!-- greyfinch-sync:ivall/xcl:comment:7193630985 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2574#issuecomment-7193630985). Originally posted by [throny](https://github.com/throny) on 2026-11-26T13:38:27Z. --- <!-- xcl-1607-hint:D127 --> Two contributors checked independently and found that #2740 solves the same problem (for #1833) in a different way: #1607, group D127. You may want to compare them with the other author and agree on one, or say in the PR why both are needed. This is a hint from the community triage in #1607, not a maintainer decision. AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
gut0to commented 2026-11-26 15:50:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-11-26T15:50:55Z.

Review: COMMENTED


AI-assisted review (OpenAI GPT-6). I inspected the changed cache path and verified the lock sequence; I did not run tests.

<!-- greyfinch-sync:ivall/xcl:review:6077053835 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2574#pullrequestreview-6077053835). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-26T15:50:55Z. **Review:** COMMENTED --- AI-assisted review (OpenAI GPT-6). I inspected the changed cache path and verified the lock sequence; I did not run tests.
gut0to commented 2026-11-26 16:06:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-11-26T15:50:55Z.

Code review location: crates/xcl/src/hle/d3d12x/real.rs; line 4786

@@ -4730,25 +4764,39 @@ unsafe fn read_pso_cached_blob(pso: *mut c_void) -> Option<Vec<u8>> {
     (!bytes.is_empty()).then_some(bytes)
 }
 
-/// The driver's blob of the PSO just built (works on both adopted title PSOs and raw PC compute
-/// passes owned by `TwoPassPso`).
-unsafe fn keep_compute_blob(key: (u64, usize, i32), pso: *mut c_void, dxil_len: usize) {
-    if dxil_len < COMPUTE_BLOB_MIN_DXIL || pso.is_null() || compute_blob(key).is_some() {
+type DriverBlobs<K> = Mutex<Option<(HashMap<K, std::sync::Arc<Vec<u8>>>, usize)>>;
+
+/// Keep a driver's blob within the process budget and offer slow builds to the disk cache.
+fn keep_driver_blob<K: Eq + std::hash::Hash>(
+    cache: &DriverBlobs<K>, limit: usize, key: K, dxil_len: usize,
+    disk: Option<&std::path::Path>, took: std::time::Duration, read: impl FnOnce() -> Option<Vec<u8>>,
+) {
+    if dxil_len < COMPUTE_BLOB_MIN_DXIL {
         return;
     }
-    let Some(bytes) = read_pso_cached_blob(pso) else { return };
-    let mut g = COMPUTE_BLOBS.lock().unwrap();
-    let (m, total) = g.get_or_insert_with(|| (HashMap::new(), 0));
-    if bytes.is_empty() || *total + bytes.len() > COMPUTE_BLOBS_MAX {
-        return;
+    let existing = cache.lock().unwrap().as_ref().and_then(|(map, _)| map.get(&key).cloned());
+    let blob = match existing {
+        Some(blob) => blob,
+        None => {
+            let Some(bytes) = read().filter(|b| !b.is_empty()) else { return };
+            let blob = std::sync::Arc::new(bytes);
+            let mut guard = cache.lock().unwrap();
+            let (map, total) = guard.get_or_insert_with(|| (HashMap::new(), 0));
+            if blob.len() <= limit.saturating_sub(*total) {
+                *total += blob.len();

Could this recheck map.get(&key) while holding guard before incrementing total? Two concurrent builds for the same cache key can both observe existing == None at line 4777, read their blobs, then serialize here and each add its length even though the second insert replaces the first entry. That overcounts the RAM budget and can reject unrelated blobs before the cache actually reaches its limit. I traced both lock scopes; I did not run tests. AI-assisted review (OpenAI GPT-6).

<!-- greyfinch-sync:ivall/xcl:review-comment:4710691142 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2574#discussion_r4710691142). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-26T15:50:55Z. **Code review location:** `crates/xcl/src/hle/d3d12x/real.rs`; line 4786 ~~~~diff @@ -4730,25 +4764,39 @@ unsafe fn read_pso_cached_blob(pso: *mut c_void) -> Option<Vec<u8>> { (!bytes.is_empty()).then_some(bytes) } -/// The driver's blob of the PSO just built (works on both adopted title PSOs and raw PC compute -/// passes owned by `TwoPassPso`). -unsafe fn keep_compute_blob(key: (u64, usize, i32), pso: *mut c_void, dxil_len: usize) { - if dxil_len < COMPUTE_BLOB_MIN_DXIL || pso.is_null() || compute_blob(key).is_some() { +type DriverBlobs<K> = Mutex<Option<(HashMap<K, std::sync::Arc<Vec<u8>>>, usize)>>; + +/// Keep a driver's blob within the process budget and offer slow builds to the disk cache. +fn keep_driver_blob<K: Eq + std::hash::Hash>( + cache: &DriverBlobs<K>, limit: usize, key: K, dxil_len: usize, + disk: Option<&std::path::Path>, took: std::time::Duration, read: impl FnOnce() -> Option<Vec<u8>>, +) { + if dxil_len < COMPUTE_BLOB_MIN_DXIL { return; } - let Some(bytes) = read_pso_cached_blob(pso) else { return }; - let mut g = COMPUTE_BLOBS.lock().unwrap(); - let (m, total) = g.get_or_insert_with(|| (HashMap::new(), 0)); - if bytes.is_empty() || *total + bytes.len() > COMPUTE_BLOBS_MAX { - return; + let existing = cache.lock().unwrap().as_ref().and_then(|(map, _)| map.get(&key).cloned()); + let blob = match existing { + Some(blob) => blob, + None => { + let Some(bytes) = read().filter(|b| !b.is_empty()) else { return }; + let blob = std::sync::Arc::new(bytes); + let mut guard = cache.lock().unwrap(); + let (map, total) = guard.get_or_insert_with(|| (HashMap::new(), 0)); + if blob.len() <= limit.saturating_sub(*total) { + *total += blob.len(); ~~~~ --- Could this recheck `map.get(&key)` while holding `guard` before incrementing `total`? Two concurrent builds for the same cache key can both observe `existing == None` at line 4777, read their blobs, then serialize here and each add its length even though the second `insert` replaces the first entry. That overcounts the RAM budget and can reject unrelated blobs before the cache actually reaches its limit. I traced both lock scopes; I did not run tests. AI-assisted review (OpenAI GPT-6).
Decodere commented 2026-11-26 22:33:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T22:33:38Z.


Independent desktop NVIDIA verification of PR #2574 at head c00f3476dff7702dc076a783206f289d1f6a720e (1 commit; exact parent & merge-base: e120925e3abc9956a8b9bae631969d32e8ccd43c, pre-#2555 ancestor of main).

Environment

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted release tests & build (c00f3476)

Command Result
cargo test --release -p xcl --lib a_slow_pipeline_is_saved_for_the_next_run_after_the_memory_cache_fills -- --nocapture 1 passed; 0 failed; 0 ignored; 1344 filtered out (0.00s)
cargo test --release -p xcl --lib overlapping_builds_charge_a_driver_blob_only_once -- --nocapture 1 passed; 0 failed; 0 ignored; 1344 filtered out (0.00s)
cargo test --release -p xcl --lib storing_a_pipeline_still_observes_the_size_and_time_thresholds -- --nocapture 1 passed; 0 failed; 0 ignored; 1344 filtered out (0.00s)
cargo test --release -p xcl --lib hle::d3d12x::real:: (3 consecutive runs) 66 passed; 0 failed; 0 ignored; 1279 filtered out × 3 (0.39s, 0.36s, 0.36s)
cargo build --release -p xcl --bin xcl Clean build (1m 12s, exit 0)

Paired quiet 60 s retail smoke (title: 29640639)

Exact parent & merge-base (e120925e3abc9956a8b9bae631969d32e8ccd43c, cached baseline on the same machine):

xcl-smoke v1
commit: e120925e3abc9956a8b9bae631969d32e8ccd43c
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1602 (PresentX 1602)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13979 MB

PR #2574 (c00f3476dff7702dc076a783206f289d1f6a720e):

xcl-smoke v1
commit: c00f3476dff7702dc076a783206f289d1f6a720e
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1603 (PresentX 1603)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14010 MB

Runtime log observations (xcl.log)

  • 9221 log lines, 0 [ERROR] / device-removal / panic lines.
  • Disk driver-blob reuse observed live: D3D12.X: 1 pipelines made from the driver's blob of an earlier run (kept on disk).
  • Final draw/memory telemetry in log: 19471 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample 14009 MB committed by the process; video memory 6116 MB local, 4683 MB non-local.

Limits of coverage

  • Full-RAM-cache disk persistence, overlapping-build single charging, and size/time thresholds were verified through the 3 new driver_cache::tests and 3× hle::d3d12x::real:: runs (66/0/0).
  • The 60 s retail smoke ran on the warm shader/driver cache and did not saturate the in-memory driver-blob cache cap (XCL_DRIVER_CACHE_MB), so it serves as an end-to-end non-regression check on title: 29640639 rather than a cold cache-overflow stress test.

AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).

<!-- greyfinch-sync:ivall/xcl:comment:7204787240 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2574#issuecomment-7204787240). Originally posted by [Decodere](https://github.com/Decodere) on 2026-11-26T22:33:38Z. --- Independent desktop NVIDIA verification of **PR #2574** at head `c00f3476dff7702dc076a783206f289d1f6a720e` (`1` commit; exact parent & merge-base: `e120925e3abc9956a8b9bae631969d32e8ccd43c`, pre-`#2555` ancestor of `main`). ### Environment - **GPU:** NVIDIA GeForce RTX 4060 (8 GB / `7956 MiB` reported by D3D12), driver `32.0.16.2114` (NVIDIA `621.14`, WDDM 3.2) - **CPU / RAM / OS:** Intel Core i5-11400F (6C / 12T), 32 GB RAM (`31.9 GiB` usable), Windows 11 Home `26200` (Developer Mode off) - **Toolchain:** `rustc 1.100.0 (0ef1bc386 2026-11-09)` MSVC, DXC `1.9.2609.5`, `--release` ### Targeted release tests & build (`c00f3476`) | Command | Result | | --- | --- | | `cargo test --release -p xcl --lib a_slow_pipeline_is_saved_for_the_next_run_after_the_memory_cache_fills -- --nocapture` | `1 passed; 0 failed; 0 ignored; 1344 filtered out` (`0.00s`) | | `cargo test --release -p xcl --lib overlapping_builds_charge_a_driver_blob_only_once -- --nocapture` | `1 passed; 0 failed; 0 ignored; 1344 filtered out` (`0.00s`) | | `cargo test --release -p xcl --lib storing_a_pipeline_still_observes_the_size_and_time_thresholds -- --nocapture` | `1 passed; 0 failed; 0 ignored; 1344 filtered out` (`0.00s`) | | `cargo test --release -p xcl --lib hle::d3d12x::real::` (3 consecutive runs) | `66 passed; 0 failed; 0 ignored; 1279 filtered out` × 3 (`0.39s`, `0.36s`, `0.36s`) | | `cargo build --release -p xcl --bin xcl` | Clean build (`1m 12s`, exit `0`) | ### Paired quiet 60 s retail smoke (`title: 29640639`) Exact parent & merge-base (`e120925e3abc9956a8b9bae631969d32e8ccd43c`, cached baseline on the same machine): ``` xcl-smoke v1 commit: e120925e3abc9956a8b9bae631969d32e8ccd43c gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1602 (PresentX 1602) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13979 MB ``` PR #2574 (`c00f3476dff7702dc076a783206f289d1f6a720e`): ``` xcl-smoke v1 commit: c00f3476dff7702dc076a783206f289d1f6a720e gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1603 (PresentX 1603) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 14010 MB ``` ### Runtime log observations (`xcl.log`) - `9221` log lines, `0` `[ERROR]` / device-removal / panic lines. - Disk driver-blob reuse observed live: `D3D12.X: 1 pipelines made from the driver's blob of an earlier run (kept on disk)`. - Final draw/memory telemetry in log: `19471 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped)`; last memory sample `14009 MB committed by the process; video memory 6116 MB local, 4683 MB non-local`. ### Limits of coverage - Full-RAM-cache disk persistence, overlapping-build single charging, and size/time thresholds were verified through the 3 new `driver_cache::tests` and 3× `hle::d3d12x::real::` runs (`66/0/0`). - The 60 s retail smoke ran on the warm shader/driver cache and did not saturate the in-memory driver-blob cache cap (`XCL_DRIVER_CACHE_MB`), so it serves as an end-to-end non-regression check on `title: 29640639` rather than a cold cache-overflow stress test. *AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).*
github-actions[bot] commented 2026-12-01 02:36:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:36:05Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7298792019 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2574#issuecomment-7298792019). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-12-01T02:36:05Z. --- 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.
Foniass commented 2026-12-01 08:24:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:24:12Z.


Triage (#1607) – head c00f347

This change is already on main: 665f72f ("D3D12.X: persist slow driver blobs past the RAM cap", adapted from this PR) makes keep_driver_blob write a slow build's blob to the disk cache even when the RAM cache refuses it, for compute, two-pass and graphics pipelines, and adds the README line. #2740 (same problem, compute only) is covered by the same commit.
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.

<!-- greyfinch-sync:ivall/xcl:comment:7305270241 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2574#issuecomment-7305270241). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T08:24:12Z. --- **Triage (#1607)** – head c00f347 This change is already on main: 665f72f ("D3D12.X: persist slow driver blobs past the RAM cap", adapted from this PR) makes `keep_driver_blob` write a slow build's blob to the disk cache even when the RAM cache refuses it, for compute, two-pass and graphics pipelines, and adds the README line. #2740 (same problem, compute only) is covered by the same commit. 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 commented 2026-12-01 12:54:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:54:12Z.


Closing as superseded: this change is already on main (665f72fc). main real.rs persists slow driver blobs past the RAM cap (665f72fc adapted from #2574); same behaviour as the PR (compute and graphics), README line included

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.

<!-- greyfinch-sync:ivall/xcl:comment:7311815755 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2574#issuecomment-7311815755). Originally posted by [throny](https://github.com/throny) on 2026-12-01T12:54:12Z. --- Closing as superseded: this change is already on `main` (665f72fc). main real.rs persists slow driver blobs past the RAM cap (665f72fc adapted from #2574); same behaviour as the PR (compute and graphics), README line included 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.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!2564
No description provided.