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 <noreply@anthropic.com>
|
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 <noreply@anthropic.com>
|
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. |
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 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. |
|
Source review of #3048 head The repair needs both startup paths: install the three cache-aware Local candidate and verification (same #3048 head). A small uncommitted patch installs only the three cache-aware On Windows 11 build 26300, RTX 3080 Ti (621.35), Ryzen 7 9800X3D, Rust 1.99.1 MSVC, DXC 1.8.2502.11:
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)diff --git a/crates/xcl/src/host.rs b/crates/xcl/src/host.rs
index 9904da06..7c117230 100644
--- a/crates/xcl/src/host.rs
+++ b/crates/xcl/src/host.rs
@@ -80,6 +80,10 @@ pub fn host_main(boot_path: &Path) -> i32 {
std::env::set_var("XCL_UMA_MB", boot.config.uma_mb.to_string());
}
crate::state::set_boot(boot.clone());
+ if let Err(e) = crate::vfs_hooks::install_driver_cache_early() {
+ crate::xlog_error!("Driver shader cache hook: {e}");
+ return 2;
+ }
if let Err(e) = crate::hle::d3d12x::present::preparation::before_guest(&boot) {
crate::xlog_error!("Shader preparation: {e}");
eprintln!("xcl: {e}");
diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs
index 67fb3e0d..4f3791bd 100644
--- a/crates/xcl/src/shaders.rs
+++ b/crates/xcl/src/shaders.rs
@@ -920,6 +920,10 @@ pub fn run(path: &Path, args: &[String]) -> i32 {
return 2;
}
};
+ if let Err(e) = crate::vfs_hooks::install_driver_cache_early() {
+ eprintln!("xcl shaders: driver shader cache hook: {e}");
+ return 2;
+ }
// the runtime's memory windows: as many as a run has (`XCL_UMA_WINDOWS`), from the
// descriptor heap with `XCL_HEAP_WINDOWS=1` (`pso::mem_windows`), as `--precompile`
let runtime_windows = {
diff --git a/crates/xcl/src/vfs_hooks.rs b/crates/xcl/src/vfs_hooks.rs
index 365807bc..69725b28 100644
--- a/crates/xcl/src/vfs_hooks.rs
+++ b/crates/xcl/src/vfs_hooks.rs
@@ -162,11 +162,12 @@ fn apply_open_decision(
unsafe extern "system" fn hk_create_file_w(n: *const u16, acc: u32, sh: u32, sa: *const c_void, disp: u32, fl: u32, t: HANDLE) -> HANDLE {
let orig = orig!(O_CREATE_FILE_W as FnCreateFileW);
- let (Some(_g), Some(v)) = (Guard::enter(), vfs::get()) else { return orig(n, acc, sh, sa, disp, fl, t) };
+ let Some(_g) = Guard::enter() else { return orig(n, acc, sh, sa, disp, fl, t) };
let Some(path) = from_wide_ptr(n) else { return orig(n, acc, sh, sa, disp, fl, t) };
if driver_cache_refused(&path) {
return INVALID_HANDLE_VALUE;
}
+ let Some(v) = vfs::get() else { return orig(n, acc, sh, sa, disp, fl, t) };
log_open("CreateFileW", &path, fl);
apply_open_decision(
v.open_decision(&path, acc, disp, fl),
@@ -178,11 +179,12 @@ unsafe extern "system" fn hk_create_file_w(n: *const u16, acc: u32, sh: u32, sa:
unsafe extern "system" fn hk_create_file_a(n: *const u8, acc: u32, sh: u32, sa: *const c_void, disp: u32, fl: u32, t: HANDLE) -> HANDLE {
let orig = orig!(O_CREATE_FILE_A as FnCreateFileA);
- let (Some(_g), Some(v)) = (Guard::enter(), vfs::get()) else { return orig(n, acc, sh, sa, disp, fl, t) };
+ let Some(_g) = Guard::enter() else { return orig(n, acc, sh, sa, disp, fl, t) };
let Some(path) = from_ansi_ptr(n) else { return orig(n, acc, sh, sa, disp, fl, t) };
if driver_cache_refused(&path) {
return INVALID_HANDLE_VALUE;
}
+ let Some(v) = vfs::get() else { return orig(n, acc, sh, sa, disp, fl, t) };
log_open("CreateFileA", &path, fl);
apply_open_decision(
v.open_decision(&path, acc, disp, fl),
@@ -194,13 +196,14 @@ unsafe extern "system" fn hk_create_file_a(n: *const u8, acc: u32, sh: u32, sa:
unsafe extern "system" fn hk_create_file_2(n: *const u16, acc: u32, sh: u32, disp: u32, params: *const c_void) -> HANDLE {
let orig = orig!(O_CREATE_FILE_2 as FnCreateFile2);
- let (Some(_g), Some(v)) = (Guard::enter(), vfs::get()) else { return orig(n, acc, sh, disp, params) };
+ let Some(_g) = Guard::enter() else { return orig(n, acc, sh, disp, params) };
let Some(path) = from_wide_ptr(n) else { return orig(n, acc, sh, disp, params) };
- // CREATEFILE2_EXTENDED_PARAMETERS { dwSize, dwFileAttributes, dwFileFlags, ... }
- let flags = if params.is_null() { 0 } else { *((params as *const u8).add(8) as *const u32) };
if driver_cache_refused(&path) {
return INVALID_HANDLE_VALUE;
}
+ let Some(v) = vfs::get() else { return orig(n, acc, sh, disp, params) };
+ // CREATEFILE2_EXTENDED_PARAMETERS { dwSize, dwFileAttributes, dwFileFlags, ... }
+ let flags = if params.is_null() { 0 } else { *((params as *const u8).add(8) as *const u32) };
log_open("CreateFile2", &path, flags);
apply_open_decision(
v.open_decision(&path, acc, disp, flags),
@@ -1246,12 +1249,40 @@ unsafe extern "system" fn hk_find_close(h: HANDLE) -> i32 {
// ---------------------------------------------------------------------------------------
+static CREATE_FILE_HOOKS: std::sync::OnceLock<Result<(), String>> = std::sync::OnceLock::new();
+
+fn install_create_file_hooks() -> Result<(), String> {
+ CREATE_FILE_HOOKS.get_or_init(|| {
+ let kb = "kernelbase.dll";
+ let mut errors = Vec::new();
+ match unsafe { hook(kb, "CreateFileW", hk_create_file_w as usize, &O_CREATE_FILE_W) } {
+ Ok(()) => {
+ if let Err(e) = unsafe { hook(kb, "CreateFileA", hk_create_file_a as usize, &O_CREATE_FILE_A) } {
+ errors.push(e);
+ }
+ }
+ Err(e) => errors.push(e),
+ }
+ if let Err(e) = unsafe { hook(kb, "CreateFile2", hk_create_file_2 as usize, &O_CREATE_FILE_2) } {
+ errors.push(e);
+ }
+ if errors.is_empty() { Ok(()) } else { Err(errors.join("; ")) }
+ }).clone()
+}
+
+/// Install the cache check before shader preparation can create a driver device.
+pub fn install_driver_cache_early() -> Result<(), String> {
+ if !std::env::var("XCL_DRIVER_SHADER_CACHE").is_ok_and(|v| v.trim() == "0") {
+ return Ok(());
+ }
+ // Resolve policy before enabling a detour that may observe this process's file opens.
+ let _ = driver_cache_refused("");
+ install_create_file_hooks()
+}
+
pub fn install() -> Result<(), String> {
let kb = "kernelbase.dll";
let list: &[(&str, usize, &AtomicUsize)] = &[
- ("CreateFileW", hk_create_file_w as usize, &O_CREATE_FILE_W),
- ("CreateFileA", hk_create_file_a as usize, &O_CREATE_FILE_A),
- ("CreateFile2", hk_create_file_2 as usize, &O_CREATE_FILE_2),
("GetFileAttributesW", hk_get_attr_w as usize, &O_GET_ATTR_W),
("GetFileAttributesA", hk_get_attr_a as usize, &O_GET_ATTR_A),
("GetFileAttributesExW", hk_get_attr_ex_w as usize, &O_GET_ATTR_EX_W),
@@ -1286,6 +1317,9 @@ pub fn install() -> Result<(), String> {
("MoveFileWithProgressA", hk_move_file_with_progress_a as usize, &O_MOVE_FILE_PROGRESS_A),
];
let mut errors = Vec::new();
+ if let Err(e) = install_create_file_hooks() {
+ errors.push(e);
+ }
for (module, list) in [(kb, list), ("kernel32.dll", k32)] {
for (name, det, slot) in list {
if let Err(e) = unsafe { hook(module, name, *det, slot) } {
@@ -1294,7 +1328,7 @@ pub fn install() -> Result<(), String> {
}
}
if errors.is_empty() {
- crate::xlog_info!("VFS: {} file hooks active", list.len() + k32.len());
+ crate::xlog_info!("VFS: {} file hooks active", list.len() + k32.len() + 3);
Ok(())
} else {
Err(errors.join("; "))
diff --git a/crates/xcl/tests/vfs_cache_early.rs b/crates/xcl/tests/vfs_cache_early.rs
new file mode 100644
--- /dev/null
+++ b/crates/xcl/tests/vfs_cache_early.rs
@@ -0,0 +1,70 @@
+//! Cache-file denial before the guest VFS exists, then full VFS installation.
+
+use std::ffi::CString;
+use std::fs;
+use std::path::{Path, PathBuf};
+use windows_sys::Win32::Foundation::{CloseHandle, GetLastError, GENERIC_READ, INVALID_HANDLE_VALUE};
+use windows_sys::Win32::Storage::FileSystem::{
+ CreateFile2, CreateFileA, CreateFileW, GetFileAttributesW, FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ, OPEN_EXISTING,
+};
+
+struct Temp(PathBuf);
+impl Drop for Temp {
+ fn drop(&mut self) { let _ = fs::remove_dir_all(&self.0); }
+}
+
+fn wide(path: &str) -> Vec<u16> {
+ path.encode_utf16().chain([0]).collect()
+}
+
+unsafe fn open_w(path: &Path) -> *mut std::ffi::c_void {
+ CreateFileW(wide(&path.to_string_lossy()).as_ptr(), GENERIC_READ, FILE_SHARE_READ, std::ptr::null(), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, std::ptr::null_mut())
+}
+
+#[test]
+fn cache_denial_precedes_vfs_and_full_install_does_not_double_hook() {
+ let root = Temp(std::env::temp_dir().join(format!("xcl_cache_early_{}", std::process::id())));
+ // An ASCII-only fake root keeps the ANSI probe independent of the test user's code page.
+ let local = PathBuf::from(format!(r"C:\xcl_cache_probe_{}", std::process::id()));
+ let cache = local.join("NVIDIA").join("DXCache").join("fixture.nvph");
+ let ordinary = root.0.join("ordinary.txt");
+ fs::create_dir_all(&root.0).unwrap();
+ fs::write(&ordinary, b"ordinary").unwrap();
+ std::env::set_var("LOCALAPPDATA", &local);
+ std::env::set_var("XCL_DRIVER_SHADER_CACHE", "0");
+ xcl::vfs_hooks::install_driver_cache_early().unwrap();
+
+ unsafe {
+ let c = CString::new(cache.to_string_lossy().as_bytes()).unwrap();
+ let cache_w = wide(&cache.to_string_lossy());
+ let w = open_w(&cache);
+ assert_eq!(w, INVALID_HANDLE_VALUE);
+ assert_eq!(GetLastError(), 5, "CreateFileW denial");
+ let a = CreateFileA(c.as_ptr().cast(), GENERIC_READ, FILE_SHARE_READ, std::ptr::null(), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, std::ptr::null_mut());
+ assert_eq!(a, INVALID_HANDLE_VALUE);
+ assert_eq!(GetLastError(), 5, "CreateFileA denial");
+ let two = CreateFile2(cache_w.as_ptr(), GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, std::ptr::null());
+ assert_eq!(two, INVALID_HANDLE_VALUE);
+ assert_eq!(GetLastError(), 5, "CreateFile2 denial");
+ let allowed = open_w(&ordinary);
+ assert_ne!(allowed, INVALID_HANDLE_VALUE, "ordinary file before VFS: {}", GetLastError());
+ CloseHandle(allowed);
+ }
+
+ let game = root.0.join("game");
+ fs::create_dir_all(&game).unwrap();
+ fs::write(game.join("title.bin"), b"title").unwrap();
+ let mounts = vec![("G:".to_string(), game.to_string_lossy().into_owned())];
+ xcl::vfs::init(xcl::vfs::Vfs::new(&game, &root.0.join("data"), mounts));
+ xcl::vfs_hooks::install().unwrap();
+ unsafe {
+ assert_ne!(GetFileAttributesW(wide("G:\\title.bin").as_ptr()), u32::MAX);
+ let guest = CreateFileW(wide("G:\\title.bin").as_ptr(), GENERIC_READ, FILE_SHARE_READ, std::ptr::null(), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, std::ptr::null_mut());
+ assert_ne!(guest, INVALID_HANDLE_VALUE, "guest VFS open: {}", GetLastError());
+ CloseHandle(guest);
+ assert_eq!(open_w(&cache), INVALID_HANDLE_VALUE);
+ assert_eq!(GetLastError(), 5, "cache denial after full VFS install");
+ }
+}
+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. |
|
merge-check |
bmjask
left a comment
There was a problem hiding this comment.
Critical review of current head 7cd66976. Coverage gap in the opt-in behavior: host startup calls shader preparation before vfs_hooks::install, and default multiworker preparation starts separate xcl shaders processes that do not install the host VFS hooks. Driver cache files opened there can remain mapped when the title starts, so XCL_DRIVER_SHADER_CACHE=0 may 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.
|
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
Read only; I did not run a launch with preparation on. My merge-check did not exercise 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. |
|
Follow-up to the preparation-coverage finding on unchanged head
I would avoid moving the whole VFS installer before preparation: the existing 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. |
|
Review (head 7cd6697, diff read, not a merge-check; draft, so not built or run):
Fine: off by default with one AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point. |
|
Test report (not a merge-check: draft) AI-written and posted by Foniass without a human check of each point. |
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(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