Repository navigation
Conversation
The NVIDIA driver maps its shader cache file of a process (AppData\LocalNVIDIA\DXCache\<id>.nvph) whole and reads all of it at start. For a retail title on an RTX 3060 Ti the file had grown to 4 GiB: 3.9 GB of xcl.exe's working set from the first second (sampled from outside with QueryWorkingSetEx), on a 32 GB machine the title fills until Windows has under 1 GB left. XCL keeps the driver's pipeline blobs in its own cache, so the file holds them a second time. With XCL_DRIVER_SHADER_CACHE=0 the driver's opens of such a file fail with access denied. Off by default. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
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 1. The mapping and the size, from earlier days on this machine (no switch)
2. Four runs today, driver cache of
So 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. |
|
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 AI use: Claude Code (Claude Opus 5.5) wrote this reply; Prime posted it. |
|
I found one path boundary to tighten before using I added only the regression below to an otherwise exact copy of this PR's Regression-only diff@@ -1291,6 +1291,7 @@ mod tests {
assert!(!is_driver_shader_cache(r"C:\Games\Title\data\cache.nvph"), "a title's own file of that type");
+ assert!(!is_driver_shader_cache(r"G:\assets\NVIDIA\DXCache\title.nvph"), "a title path can contain the driver's directory names");
assert!(!is_driver_shader_cache(r"C:\ProgramData\NVIDIA Corporation\Drs\nvdrssel.bin"), "the driver's settings");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. |
is_driver_shader_cache took any path that contained \NVIDIA\DXCache\ and ended in .nvph, so with XCL_DRIVER_SHADER_CACHE=0 a title's own file such as G:\assets\NVIDIA\DXCache\title.nvph was refused too (found in review on xcl-dev#3048). Now only a .nvph file directly in NVIDIA\DXCache of this user's AppData\Local (LOCALAPPDATA) or of the LocalLow folder beside it counts, with or without \?\. The test has the review's path, a file in a subfolder and another user's folder among its negative cases. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, confirmed and fixed in 7cd6697: only a AI use: Claude Code (Claude Opus 5.5) wrote the fix and this reply; Prime posted it. |
|
I checked the revised cache-root matcher on head For
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. |
|
Follow-up to andrewDoing’s redirected-folder check on head 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 Candidate diff against 7cd6697diff --git a/crates/xcl/Cargo.toml b/crates/xcl/Cargo.toml
index 238591b1..0cd1bee3 100644
--- a/crates/xcl/Cargo.toml
+++ b/crates/xcl/Cargo.toml
@@ -68,5 +68,6 @@ features = [
"Win32_Globalization",
"Win32_UI_Controls",
"Win32_UI_Controls_Dialogs",
+ "Win32_UI_Shell",
"Win32_UI_WindowsAndMessaging",
]
diff --git a/crates/xcl/src/vfs_hooks.rs b/crates/xcl/src/vfs_hooks.rs
index 365807bc..480fefd7 100644
--- a/crates/xcl/src/vfs_hooks.rs
+++ b/crates/xcl/src/vfs_hooks.rs
@@ -82,34 +82,44 @@ fn log_open(api: &str, path: &str, flags: u32) {
}
}
-/// Whether `path` is the NVIDIA driver's shader cache file of a process: a `.nvph` file directly
-/// in `NVIDIA\DXCache` of this user's `AppData\Local` (`LOCALAPPDATA`) or of the `LocalLow`
-/// folder beside it, where the driver keeps them. A title's own file in folders of those names
-/// elsewhere is not one.
+static DRIVER_CACHE_ROOTS: std::sync::OnceLock<Vec<String>> = std::sync::OnceLock::new();
+
+/// Whether `path` is a direct `.nvph` child of this user's actual NVIDIA cache folders.
fn is_driver_shader_cache(path: &str) -> bool {
- static ROOTS: std::sync::OnceLock<Vec<String>> = std::sync::OnceLock::new();
- let roots = ROOTS.get_or_init(|| driver_cache_roots(&std::env::var("LOCALAPPDATA").unwrap_or_default()));
- is_driver_cache_in(path, roots)
+ DRIVER_CACHE_ROOTS.get().is_some_and(|roots| is_driver_cache_in(path, roots))
}
-/// The folders the driver keeps its shader cache files in for the user's `AppData\Local` folder
-/// `local`, in lowercase: `<local>\nvidia\dxcache\` and `<local>\..\locallow\nvidia\dxcache\`.
-fn driver_cache_roots(local: &str) -> Vec<String> {
- let local = local.trim().replace('/', "\\").trim_end_matches('\\').to_ascii_lowercase();
- if local.is_empty() {
- return Vec::new();
- }
- let mut roots = vec![format!(r"{local}\nvidia\dxcache\")];
- if let Some((parent, _)) = local.rsplit_once('\\') {
- roots.push(format!(r"{parent}\locallow\nvidia\dxcache\"));
+/// Resolve LocalLow independently: redirected Local and LocalLow need not be siblings.
+fn local_low_dir() -> Option<String> {
+ use windows_sys::Win32::System::Com::CoTaskMemFree;
+ use windows_sys::Win32::UI::Shell::{FOLDERID_LocalAppDataLow, KF_FLAG_DONT_VERIFY, SHGetKnownFolderPath};
+ let mut path = std::ptr::null_mut();
+ let hr = unsafe { SHGetKnownFolderPath(&FOLDERID_LocalAppDataLow, KF_FLAG_DONT_VERIFY as u32, std::ptr::null_mut(), &mut path) };
+ let result = if hr >= 0 { unsafe { from_wide_ptr(path) } } else { None };
+ unsafe { CoTaskMemFree(path.cast()) };
+ result
+}
+
+fn normalize_driver_cache_path(path: &str) -> String {
+ let lower = path.replace('/', "\\").to_ascii_lowercase();
+ if let Some(rest) = lower.strip_prefix(r"\\?\unc\") {
+ format!(r"\\{rest}")
+ } else {
+ lower.strip_prefix(r"\\?\").unwrap_or(&lower).to_owned()
}
- roots
+}
+
+fn driver_cache_roots(local: Option<&str>, low: Option<&str>) -> Vec<String> {
+ [local, low].into_iter().flatten().filter_map(|path| {
+ let root = normalize_driver_cache_path(path);
+ let root = root.trim_end_matches('\\');
+ std::path::Path::new(root).is_absolute().then(|| format!(r"{root}\nvidia\dxcache\"))
+ }).collect()
}
/// Whether `path` (with or without `\\?\`) is a `.nvph` file directly in one of `roots`.
fn is_driver_cache_in(path: &str, roots: &[String]) -> bool {
- let lower = path.replace('/', "\\").to_ascii_lowercase();
- let plain = lower.strip_prefix(r"\\?\").unwrap_or(&lower);
+ let plain = normalize_driver_cache_path(path);
roots.iter().any(|root| {
plain.strip_prefix(root.as_str()).is_some_and(|name| name.len() > ".nvph".len() && name.ends_with(".nvph") && !name.contains('\\'))
})
@@ -1247,6 +1257,13 @@ unsafe extern "system" fn hk_find_close(h: HANDLE) -> i32 {
// ---------------------------------------------------------------------------------------
pub fn install() -> Result<(), String> {
+ if std::env::var("XCL_DRIVER_SHADER_CACHE").is_ok_and(|v| v.trim() == "0") {
+ DRIVER_CACHE_ROOTS.get_or_init(|| {
+ let local = std::env::var("LOCALAPPDATA").ok();
+ let low = local_low_dir();
+ driver_cache_roots(local.as_deref(), low.as_deref())
+ });
+ }
let kb = "kernelbase.dll";
let list: &[(&str, usize, &AtomicUsize)] = &[
("CreateFileW", hk_create_file_w as usize, &O_CREATE_FILE_W),
@@ -1313,20 +1330,24 @@ mod tests {
#[test]
fn only_the_drivers_shader_cache_files_are_recognised() {
- let roots = driver_cache_roots(r"C:\Users\a\AppData\Local");
+ let roots = driver_cache_roots(Some(r"D:\Redirected\Local"), Some(r"C:\Users\a\AppData\LocalLow"));
let is = |path: &str| is_driver_cache_in(path, &roots);
- assert!(is(r"C:\Users\a\AppData\Local\NVIDIA\DXCache\32e6a9dbc29925ed.nvph"));
+ assert!(is(r"D:\Redirected\Local\NVIDIA\DXCache\32e6a9dbc29925ed.nvph"));
assert!(is(r"\\?\c:\users\a\appdata\locallow\nvidia\dxcache\0002A9DBC29925ED.NVPH"));
- assert!(!is(r"C:\Users\a\AppData\Local\NVIDIA\DXCache\"), "the folder itself");
+ assert!(!is(r"D:\Redirected\LocalLow\NVIDIA\DXCache\wrong.nvph"), "the guessed sibling is not LocalLow");
+ assert!(!is(r"D:\Redirected\Local\NVIDIA\DXCache\"), "the folder itself");
assert!(!is(r"C:\Games\Title\data\cache.nvph"), "a title's own file of that type");
assert!(!is(r"G:\assets\NVIDIA\DXCache\title.nvph"), "a title's path with the driver's folder names");
- assert!(!is(r"C:\Users\a\AppData\Local\NVIDIA\DXCache\sub\title.nvph"), "not directly in the driver's folder");
+ assert!(!is(r"D:\Redirected\Local\NVIDIA\DXCache\sub\title.nvph"), "not directly in the driver's folder");
assert!(!is(r"C:\Users\b\AppData\Local\NVIDIA\DXCache\32e6a9dbc29925ed.nvph"), "another user's");
assert!(!is(r"C:\ProgramData\NVIDIA Corporation\Drs\nvdrssel.bin"), "the driver's settings");
- // this process's own folder, as the driver opens it
- if let Ok(local) = std::env::var("LOCALAPPDATA") {
- assert!(is_driver_shader_cache(&format!(r"{local}\NVIDIA\DXCache\32e6a9dbc29925ed.nvph")));
- assert!(!is_driver_shader_cache(r"G:\assets\NVIDIA\DXCache\title.nvph"));
+ assert!(is_driver_cache_in(r"D:\Redirected\Local\NVIDIA\DXCache\a.nvph", &driver_cache_roots(Some(r"D:\Redirected\Local"), None)));
+ assert!(is_driver_cache_in(r"C:\Users\a\AppData\LocalLow\NVIDIA\DXCache\a.nvph", &driver_cache_roots(None, Some(r"C:\Users\a\AppData\LocalLow"))));
+ let unc = driver_cache_roots(Some(r"\\server\profile\Local"), None);
+ assert!(is_driver_cache_in(r"\\?\UNC\server\profile\Local\NVIDIA\DXCache\a.nvph", &unc));
+ if let Some(low) = local_low_dir() {
+ let roots = driver_cache_roots(None, Some(&low));
+ assert!(is_driver_cache_in(&format!(r"{low}\NVIDIA\DXCache\a.nvph"), &roots));
}
}AI use: Codex (GPT-6.2 Sol) wrote and tested the candidate; Codex (GPT-6.2 Astra) checked the folder and hook-order design. |
Requested by Prime · project thread
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(D3D12.X: XCL_TEXTURE_SYSMEM puts streamed texture levels in system memory #3039 and D3D12.X: make shadowed textures active again when a draw samples them #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 D3D12.X: XCL_TEXTURE_SYSMEM puts streamed texture levels in system memory #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