VFS: XCL_DRIVER_SHADER_CACHE=0 refuses the driver its shader cache file #3048
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3048"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-27T17:54:16Z.
Requested by Prime
With
XCL_DRIVER_SHADER_CACHE=0the display driver's opens of its own shader cache file fail with access denied, so it runs without one. Off by default: it trades RAM for slower driver compiles, measured below.Part of #2688; the cache file's share of the working set is tiagonleal's finding on #1773.
Why
The NVIDIA driver maps its shader cache file for the process (
%LOCALAPPDATA%\NVIDIA\DXCache\<id>.nvph) whole. Forxcl.exeit had grown to 4 GiB, and 3.9 GB of it was in the working set 25 s after start, before any frame (sampled from outside withVirtualQueryEx/QueryWorkingSetEx). In a retail title driven into its world on an RTX 3060 Ti 8 GB with 32 GB of RAM, Series S profile, 420 s runs on a local branch ofnvidia-devwith the trial switches of #2688 work, the machine (32 GB, about 9.5 GB taken by other programs) ran out of RAM at about 225 s; with this switch on, 10.8 GB was still available at 222 s against 1.7 GB. The cost: the driver compiles from scratch. Compute pipelines' driver compiles took a median of 717 ms against 157 ms, p90 15.5 s against 253 ms, and 869 pipelines were built in 420 s against 2,401. By 420 s the process's own memory had grown to fill the RAM either way. XCL keeps the driver's pipeline blobs in its own cache (XCL_PSO_DISK_CACHE_MIN_MS), so that file holds them a second time. A second observation, not proven to be cause and effect: that day the file had stood at exactly 4 GiB, full, since about 09:51 local; of the 420 s runs made with it, 4 of 6 lost the device (0x887a0005, DRED page fault at GPU address 0) between 288 and 422 s, the one run with this switch on did not, and after the cache files were deleted 2 of 2 runs were clean. In the 60 s regression run below (switch off, the default) the title shows 1388 frames against the base's 1391.What is in it
crates/xcl/src/vfs_hooks.rs:is_driver_shader_cacheanddriver_cache_refused(the switch, read once, a line at powers of two), checked first in theCreateFileW/CreateFileA/CreateFile2hooks.vfs_hooks::tests::only_the_drivers_shader_cache_files_are_recognised..nvphfile directly inNVIDIA\DXCacheof this user'sAppData\Local(LOCALAPPDATA) or of theLocalLowfolder beside it counts (driver_cache_roots,is_driver_cache_in), with or without\\?\. The first commit took any path with those folder names, so a title's ownG:\assets\NVIDIA\DXCache\title.nvphwas refused too; the test now has that path, a file in a subfolder and another user's folder among its negative cases.Tested
cargo test --locked --workspace --no-fail-fast -- --test-threads=4withXCL_DXC_DIRset to DXC 1.9.2609.5: 1825 passed, 8 failed, 48 ignored. The 8 failures are the same tests that fail onnvidia-devd1be8103itself (1824passed,8failed,48ignored there, same command):async_compute_pso_registers_real_pso_and_not_standin,console_ms_in_as_slot_and_ms_with_as_are_refused_cleanly,hle::d3d12x::texture_upload::tests::gpu_parts_of_a_texture_go_up_and_the_rest_stays,hle::d3d12x::texture_upload::tests::pieces_hold_the_texels_of_their_levels,split_compute_prefers_the_offline_whole_pipeline,two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs.Build and test (Windows, no GPU)fails here, as it does on the other open pull requests againstnvidia-dev(#3039 and #2956 among them): on the runner's WARP device a sparse-window test loses the device (hle::d3d12x::sparse::tests::a_gpu_write_into_a_gpu_view_lands_in_its_cpu_viewon #3039) and the lib test process exits with 0x887a0020. The suite above passes that test on the card.Regression run
A commit of
main(b49be183, the last one before the shader preparation screen of #2555, which prepares every record before the title and so does not fit a 60 s run):The base of this PR,
nvidia-devd1be8103:This PR's head:
Not tested
LocalLowfolder moved away from the folder besideLOCALAPPDATA: the driver's files there are not recognised.AI use
Claude Code (Claude Fable 5.2 and Claude Opus 5.5) wrote the code, ran the suite and the regression runs on the hardware above, and wrote this description; Prime asked for it and owns the account. We coordinate the 8 GB work on the XCL Discord too: https://discord.gg/6B4TykyC4W
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by imnicho on 2026-11-27T19:15:46Z.
Measurements from a 16 GB machine: the mapping is the same here, the file gets far larger than 4 GiB, and with a small file the switch buys no RAM but costs frames
RTX 5080 16 GB (driver 610.47), i7-7700K, 16 GB RAM, Windows 10 22H2. Your commit
edc2b458cherry-picked (cleanly) onto a localnvidia-devtest tree (d1be8103plus other open nvidia-dev PRs and local test changes), release build, one binary for all four runs, a retail title driven into its world, Series S profile, 600 s limit, the switch the only difference, runs alternated.1. The mapping and the size, from earlier days on this machine (no switch)
xcl.exewere 4 GB and 2 GB; 3.2 GB of them were resident in the title's process at its start, and Windows had trimmed that to 0.1 GB once the world needed the RAM (file-backed pages, so they go first)..nvphfile, with 0.9 GB of RAM available while three workers compiled.xcl.exewas 34.6 GB in ten files (the largest 8 and 16 GB, all last written on 26 or 27 Nov), and the system drive was full in the middle of a run (#3058 adds a warning for that). I deleted the set afterwards, so the runs below start from a small one.2. Four runs today, driver cache of
xcl.exeat about 1 GBXCL_DRIVER_SHADER_CACHE=0XCL_DRIVER_SHADER_CACHE=00x887a0006at 543 s0x887a0006at 348 sSo here the case for the switch is the start-up and the preparation (the 7.8 GB above), not the world; and what would help a small machine more than refusing the file is keeping it small. I did not test either of those today.
Not tested: the switch with a large cache file, the preparation with the switch, AMD, the Series X profile.
AI use: Claude Code with Claude Fable 5.2 built the tree, ran the four runs and wrote this comment.
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-27T20:51:59Z.
Thanks, this is the comparison I couldn't make. With a 1 GB file on a 16 GB machine the switch buys no RAM in the world and costs frames (0.4-0.7 against 1.4-1.6 a second), so it stays off by default and stays a switch for start-up and preparation on machines short of RAM.
A data point from here that points the same way as your last paragraph: on the 3060 Ti machine the file for
xcl.exehad stood at exactly 4 GiB (full) since the morning. In the afternoon 4 of 6 runs with it lost the device (0x887a0005, a DRED page fault at address 0), the run with the switch on didn't, and after the cache group was deleted 2 of 2 runs were clean. That's not proven to be cause and effect, but keeping the file small, or starting it again when it's full, looks like the better fix than refusing it. That would be a separate change; I'll say here if we make one.AI use: Claude Code (Claude Opus 5.5) wrote this reply; Prime posted it.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-27T21:02:52Z.
I found one path boundary to tighten before using
XCL_DRIVER_SHADER_CACHE=0on titles with arbitrary file names. At headedc2b458,is_driver_shader_cacheaccepts any path containing\NVIDIA\DXCache\and ending in.nvph. A title-owned path such asG:\assets\NVIDIA\DXCache\title.nvphmatches, and the threeCreateFilehooks return access denied before title VFS routing.I added only the regression below to an otherwise exact copy of this PR's
vfs_hooks.rs.cargo test --locked -p xcl --lib only_the_drivers_shader_cache_files_are_recognised -- --nocapturefailed 0 passed / 1 failed at the new assertion. The existing positive paths show the intended Local and LocalLow cache locations. I suggest matching normalized absolute paths under the current user's actual Local/LocalLow NVIDIA cache roots, with a direct.nvphchild, rather than searching for the directory names anywhere in the path. Keep\\?\paths covered and add the guest-path negative case.Regression-only diff
This is a synthetic path test. I did not test a modified matcher or run a title with the switch enabled. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), rustc 1.99.1 MSVC. AI use: Codex (GPT-6.2 Sol) wrote and ran the regression; Codex (GPT-6.2 Astra) independently traced the hook path.
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-27T23:03:45Z.
Thanks, confirmed and fixed in
7cd66976: only a.nvphfile directly inNVIDIA\DXCacheunder this user'sAppData\Local(fromLOCALAPPDATA) or theLocalLowfolder beside it counts now, with or without\\?\.G:\assets\NVIDIA\DXCache\title.nvphand a file in a subfolder of the cache folder are among the negative cases ofonly_the_drivers_shader_cache_files_are_recognised, which fails on the old matcher. The suite and the smoke for the new head are in the description.AI use: Claude Code (Claude Opus 5.5) wrote the fix and this reply; Prime posted it.
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T04:40:45Z.
I checked the revised cache-root matcher on head
7cd66976with synthetic Windows paths and the exact production predicate. It appears to assume LocalLow is a sibling ofLOCALAPPDATA. Windows exposes Local and LocalLow as separate known folders, so they can have different locations.For
LOCALAPPDATA=D:\Redirected\Localand LocalLow atC:\Users\sample\AppData\LocalLow:D:\Redirected\LocalLow\NVIDIA\DXCache\a.nvphpath did match.This is a synthetic path-classification probe; I did not redirect known folders or open files on this machine. Resolving the LocalLow known folder independently, rather than deriving it from Local's parent, would address this layout. See the Windows known-folder IDs.
AI use: OpenAI Codex with GPT-6.2 Astra built and ran the probe; Codex reviewed and prepared this report.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-28T06:50:51Z.
Follow-up to andrewDoing’s redirected-folder check on head
7cd6697: I tested a small candidate that resolvesFOLDERID_LocalAppDataLowindependently ofLOCALAPPDATA. It obtains the known folder before installing the CreateFile hooks, then checks only a direct.nvphchild of either actual cache root. That avoids resolving a folder from inside an intercepted file open. The existingwindows-sysdependency needs its Shell feature enabled.The focused cache-path test passed (1/0/0), including redirected Local and LocalLow roots, the falsely guessed sibling, and an extended UNC path. The full
vfs_hooks::testsgroup passed (11/0/0), andcargo build --offline --locked -j 4 --workspacepassed. On Windows 11 build 26300, RTX 3080 Ti, the candidate'scargo test --offline --locked -j 4 --workspace -- --test-threads=4stopped at the library suite: 1,697 passed, 3 failed, 28 ignored, with 25 GPU skip notices. All three failures also reproduce on the untouched7cd6697head when filtered: twotexture_upload::testsfailures andconsole_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk. Later workspace test binaries were not run because Cargo stopped after the library failure. I did not run a title smoke on this uncommitted suggestion.Candidate diff against
7cd6697AI use: Codex (GPT-6.2 Sol) wrote and tested the candidate; Codex (GPT-6.2 Astra) checked the folder and hook-order design.
Imported from ivall/xcl. Originally posted by vasanex on 2026-11-29T04:23:15Z.
Edited 2026-11-29: verdict changed from "safe to merge"; see my follow-up below.
How this was run: the suite ran once on the 11 of your PRs that build on this base, merged together (#3047 #3048 #3049 #3091 #3092 #3103 #3104 #3105 #3107 #3123 #3125; a local tree, only #3125 needed a resolution in README and the
sparse.rstest module); the base alone gave 2608 passed, 0 failed, 49 ignored with the same 27SKIPPEDlines (21 no wave64, 3 refused per-lane f16/f32 forms, 2 heap windows opt-in, 1 driver cache needs Developer Mode). This PR alone was merged onto the base, built (cargo build --workspace, then release), its modules' lib tests run (debug), and smoke-run once for 60 s (scripts/smoke.ps1, retail title, front end,XCL_PREPARE=0). The smoke numbers are for my local merged tree, not a clean-head block for the description.AI use: Claude Code (Claude Opus 5.5 and Claude Fable 5.2) ran the builds, tests and title runs, reviewed the diff and wrote this; the code points cited were checked against the merged tree.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-29T06:09:53Z.
Source review of #3048 head
7cd66976: the cache switch can miss the preparation phase it is intended to cover. Host startup callsbefore_guestbeforevfs_hooks::install(). With preparation enabled,prepare_for_launchcan create a D3D12 device before those hooks exist. The default multiworker path also starts separatexcl shadersprocesses, which never run host VFS installation. An earlier driver cache open/mapping would persist after the host installs its hooks.The repair needs both startup paths: install the three cache-aware
CreateFile*hooks before the first preparation device in the host and in shader worker entry, while leaving guest VFS remapping inactive during preparation. Merely moving the currentinstall()call is insufficient: eachhk_create_file_*currently passes through whenvfs::get()is absent, before it checksdriver_cache_refused. The later full VFS installation must not hook those exports a second time. A focused regression should check cache denial before VFS initialization and non-cache pass-through; a preparation-enabled host/worker run withXCL_DRIVER_SHADER_CACHE=0should check the actual file-open/mapping behavior on NVIDIA.Local candidate and verification (same #3048 head). A small uncommitted patch installs only the three cache-aware
CreateFile*hooks before host shader preparation and at the start ofxcl shaders. The cache check runs beforevfs::get(); guest path mapping still waits for VFS initialization. A shared one-time installer prevents the later full VFS install from detouring those functions twice. It attempts the independentCreateFile2hook even if another hook fails.On Windows 11 build 26300, RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Rust 1.99.1 MSVC, DXC 1.8.2502.11:
cargo build --offline --locked -j 4 --workspace: passed.cargo test --offline --locked -j 4 -p xcl --test vfs_cache_early -- --test-threads=1: 1 passed, 0 failed, 0 ignored. The test exercises W, A and 2 before VFS exists, ordinary file pass-through, then guest VFS opens and cache denial after full installation.cargo test --offline --locked -j 4 -p xcl --lib vfs_hooks::tests:: -- --test-threads=1: 11 passed, 0 failed, 0 ignored.xcl shaderswith a synthetic nonexistent cache path: switch0returned access denied (OS error 5); switch unset returned path not found (OS error 3). This checks the real worker entry without creating a GPU device.cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4: 1,825 passed, 9 failed, 48 ignored; 26 GPU skip notices. The nine failure results represent seven distinct tests because two child processes reran failing tests. All seven (mesh cache, two texture upload, mesh stream, two compute e2e, two-pass cache) also failed on the untouched exact PR head. The first untouched-head suite additionally missed three e2e binaries because it ran beforecargo build --workspace; after that build, its focused e2e target passed 4/0/0.This establishes the hook ordering and synthetic API behavior, not the NVIDIA driver's actual cache mapping or memory reduction during shader preparation. The patch is uncommitted; no clean-commit paired smoke was run. The LocalLow path finding is separate.
Candidate patch and regression test (for adaptation)
AI use: Codex (GPT-6.2 Sol) wrote and ran the local candidate and tests and drafted this update; Codex (GPT-6.2 Astra) traced and reviewed the startup and hook lifecycle.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T22:38:28Z.
merge-check
base:
beeb81be4b(mergeable cleanly on current main)head:
7cd669763emerge: clean
build: cargo check -p xcl --all-targets -> ok
tests: non-GPU lib tests of touched module (vfs_hooks 11 passed). Full workspace suite and GPU tests not run.
review: none blocking. Opt-in via XCL_DRIVER_SHADER_CACHE=0; matches .nvph files directly in LOCALAPPDATA\NVIDIA\DXCache (and LocalLow sibling), tested against look-alike paths, runs only inside the VFS guard.
performance: off by default (one OnceLock read per CreateFile). Switch-on RAM vs compile-time tradeoff was not re-measured here. Tested in a combined 600 s retail run on main
beeb81be+ 13 PRs (warm cache, defaults) vs baseline: presents/2 s 3.27 vs 3.29, peak commit 35,016 vs 35,767 MB, local video memory 14.19-14.76 vs 14.32-14.95 GB, 0 pipeline waits >= 1 s vs 5, 0 device removals, 0 crashes. Combined result across all 13 PRs, not isolated to this PR.verdict: not yet: full workspace suite not run on its own merge.
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti, driver 32.0.16.1074, AMD Ryzen 9 9950X, Windows 11 Pro 26200 / Claude Code (claude-opus-5-5)
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-29T22:45:57Z.
Review: COMMENTED
Critical review of current head
7cd66976. Coverage gap in the opt-in behavior: host startup calls shader preparation beforevfs_hooks::install, and default multiworker preparation starts separatexcl shadersprocesses that do not install the host VFS hooks. Driver cache files opened there can remain mapped when the title starts, soXCL_DRIVER_SHADER_CACHE=0may miss the memory it is supposed to save. Install the filter in preparation workers before D3D12 device creation or explicitly scope/document the switch to the later title process; test a fresh prep-enabled launch. See the current-head source review. No local Windows run.Imported from ivall/xcl. Originally posted by vasanex on 2026-11-29T23:29:30Z.
Follow-up to my merge-check above (comment): @thehollowedone's source review (comment) and @bmjask's review of the same head show that the switch can miss the phase it is meant for, and I agree after reading it on this PR merged onto current
main(53e85fb1, merged tree5f0583c1):host.rscallspresent::preparation::before_guestat line 91 andvfs_hooks::install()only at line 281, its single call site;xcl shaders(main.rs→shaders::run) never installs the hooks –shaders.rsandshaders/do not refer tovfs_hooks;hk_create_file_*returns the original call whilevfs::get()is absent, beforedriver_cache_refusedis asked.Read only; I did not run a launch with preparation on. My merge-check did not exercise
XCL_DRIVER_SHADER_CACHE=0at all (it says so), so it could not have seen this.What my verdict covered and still does: with the switch off (the default) the change is inert – suite and smoke were unchanged. What it should not be read as: evidence that the switch does what the description says during shader preparation or in the worker processes. With that gap open I put it as "not yet" rather than "safe to merge", and have edited the verdict line of my merge-check to match.
AI use: Claude Code (Claude Fable 5.2) read the merged tree and wrote this; read and posted by me.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-12-01T01:30:14Z.
Follow-up to the preparation-coverage finding on unchanged head
7cd66976: a bounded way to cover it is to install only the three CreateFile detours early whenXCL_DRIVER_SHADER_CACHE=0.before_guest. Inshaders::run, do it after argument parsing and before the preparation/measurement paths dispatch;pso-precompilealso delegates toshaders::run. This covers the standalone worker processes that never initialize host VFS.hk_create_file_*wrapper, enter the recursion guard, decode the path, and apply the opt-in cache-file decision before asking forvfs::get(). If VFS is absent and the path is ordinary, call the original API. Keep the present VFS routing when it is available. Precompute the switch and cache roots before enabling the detours so their first driver-thread invocation does not initialize them.install()share once-per-process installation state.hooks::hookstores its trampoline before enabling and leaks the detour; calling it again on an already-detoured function, or treating a nonzero trampoline as proof of success, is unsafe. Surface any early installation failure instead of claiming the switch took effect.I would avoid moving the whole VFS installer before preparation: the existing
ReadFilehook has work outside thevfs::get()guard, so an early full install is not a transparent pass-through. A child-process regression with a syntheticLOCALAPPDATAcan call realCreateFileW,CreateFileA, andCreateFile2before VFS exists: only a direct.nvphin the selected cache root should returnINVALID_HANDLE_VALUE/access denied; ordinary and sibling files should open. Then initialize VFS, verify normal overlay routing, and call the later installer to check that no CreateFile detour is installed twice. Include a default-mode child where the synthetic cache file opens normally.This is a source-level implementation route; I did not build or test it or measure driver mapping. AI use: OpenAI Codex (GPT-6.2 Sol) traced the hook and startup paths; OpenAI Codex (GPT-6.2 Astra) independently checked installation lifetime and worker coverage.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:51:13Z.
Review (head
7cd66976, diff read, not a merge-check; draft, so not built or run):host.rs~91 runs shader preparation (creates a D3D12 device and builds pipelines,milestone.rs~245) beforevfs::init/vfs_hooks::install(~278 / ~281), and the hook also passes through whilevfs::get()is None. So the driver's opens of its cache during preparation aren't refused, and nothing shows whether the file then stays mapped while the title runs. Please say whether preparation ran in the 420 s measurement, or check the cache file's mapping after preparation.d1be8103(873 commits behind main) and its only CI run is from that base; please rebase onto main, squash the second commit into the first, and add the switch to README.\??\) paths won't match; that fails safe (the switch just does nothing).Fine: off by default with one
OnceLockread per open; only.nvphfiles directly in this user'sLocal/LocalLowNVIDIA\DXCachefolder are refused (case-insensitive, with or without the\?\prefix), and the test covers a title's ownNVIDIA\DXCachepath, subfolders and another user's folder; the last error code is preserved.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T17:35:34Z.
Test report (not a merge-check: draft)
base:
b2b1f109d2head:
7cd669763emerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2903 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: not repeated here; my review of this same head is at https://github.com/xcl-dev/xcl/pull/3048#issuecomment-7302207637, and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: no smoke run. The first run of this merge lost the lib test binary to the known driver-cache access violation (#1487); this is the rerun.
assessment: merges, builds and passes the whole suite on current main (0 failed); the findings in my review stand
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.