VFS: XCL's shader cache on a drive a console mount names stays where it is

With XCL_DXIL_CACHE (or %LOCALAPPDATA%) on the PC's D: drive, the title's
process took the cache's paths for the console's D:\ (the game folder): it
wrote its DXIL and translations into the title's overlay and read them from
there. The folder that was named was neither read nor written, so a cache
filled outside the title (xcl shaders --precompile, no mounts there) was
not found.

Vfs::own_folder names a folder of XCL's own besides the title's data; the
host passes the shader cache folder.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
imnicho
2026-11-23 21:15:46 +01:00
committed by nicho
parent 85bdf2193e
commit 603cdd395c
2 changed files with 51 additions and 4 deletions
+2 -1
View File
@@ -115,7 +115,8 @@ pub fn host_main(boot_path: &Path) -> i32 {
crate::resolver::set_search_dirs(dirs);
let mounts: Vec<(String, String)> = boot.config.mounts.iter().map(|(k, v)| (k.clone(), boot.expand(v))).collect();
crate::vfs::init(crate::vfs::Vfs::new(&boot.game_root, &boot.data_dir, mounts));
// (the shader cache is XCL's too: on a drive a console mount names it must stay where it is)
crate::vfs::init(crate::vfs::Vfs::new(&boot.game_root, &boot.data_dir, mounts).own_folder(&crate::gpu::recomp::dxc::cache_dir()));
let _ = std::fs::create_dir_all(boot.data_dir.join("temp"));
if let Err(e) = crate::vfs_hooks::install() {
+49 -3
View File
@@ -71,6 +71,8 @@ pub struct Vfs {
data_root_lc: String,
pls_root: PathBuf,
pls_root_lc: String,
/// Other folders XCL itself reads and writes (`own_folder`), absolute and lower-case.
own_roots_lc: Vec<String>,
overlay: String,
mounts: Vec<(String, String)>,
whiteouts: Mutex<HashSet<String>>,
@@ -176,6 +178,7 @@ impl Vfs {
data_root_lc: trim_sep(&norm(&data_root)).to_lowercase(),
pls_root,
pls_root_lc,
own_roots_lc: Vec::new(),
game_root,
overlay: trim_sep(&norm(&overlay_dir.to_string_lossy())),
mounts,
@@ -187,6 +190,21 @@ impl Vfs {
}
}
/// `dir` is a folder of XCL's own outside the title's data folder – the shader cache, which
/// titles share. A console drive mount must not translate its paths either: with the cache on
/// the PC's D: drive ("D:" is the console's game drive) the title's process wrote its DXIL
/// into the overlay and looked for it in the game folder, so what `xcl shaders --precompile`
/// had put into the cache was never found and every run compiled again.
pub fn own_folder(mut self, dir: &Path) -> Vfs {
let dir = dir.to_string_lossy();
let dir = full_path(&dir).unwrap_or_else(|| dir.into_owned());
let dir = trim_sep(&strip_verbatim(&norm(&dir))).to_lowercase();
if !dir.is_empty() {
self.own_roots_lc.push(dir);
}
self
}
pub fn game_root(&self) -> &str {
&self.game_root
}
@@ -287,8 +305,9 @@ impl Vfs {
}
}
/// A path that already names the game folder or XCL's data folder on the PC. A console
/// drive mount ("D:") must not translate it when the PC has its folders on that drive.
/// A path that already names the game folder or one of XCL's own folders on the PC (the
/// title's data, `own_folder`). A console drive mount ("D:") must not translate it when the
/// PC has its folders on that drive.
/// Only a plain drive path counts: "<game>\GAME:\x" still names a console mount.
fn in_own_folders(&self, p: &str, full: impl Fn(&str) -> Option<String>) -> bool {
let b = p.as_bytes();
@@ -297,7 +316,7 @@ impl Vfs {
}
let Some(abs) = full(p) else { return false };
let lc = trim_sep(&strip_verbatim(&norm(&abs))).to_lowercase();
[&self.game_root_lc, &self.data_root_lc].iter().any(|root| {
[&self.game_root_lc, &self.data_root_lc].into_iter().chain(&self.own_roots_lc).any(|root| {
lc.strip_prefix(root.as_str()).is_some_and(|rest| rest.is_empty() || rest.starts_with('\\'))
})
}
@@ -748,6 +767,33 @@ mod tests {
let _ = std::fs::remove_dir_all(&dir);
}
/// The shader cache on the drive the console's "D:" mount names: without `own_folder` the
/// title's process writes it into the overlay (and reads the game folder) – a cache filled
/// outside the title, where no mount applies, is not the one it then uses.
#[test]
fn a_console_drive_mount_leaves_xcls_shader_cache_on_that_drive() {
let dir = std::env::temp_dir().join(format!("xcl_vfs_cache_{}", std::process::id()));
let game_s = full_path(&dir.join("game").to_string_lossy()).unwrap();
let drive = game_s[..2].to_string();
let cache = full_path(&dir.join("shader cache").join("dxil").to_string_lossy()).unwrap();
let file = format!("{cache}\\0123456789abcdef.dxil");
let mounts = || vec![(drive.clone(), game_s.clone())];
let before = Vfs::new(Path::new(&game_s), &dir.join("xcldata"), mounts());
// (the mount's target is the game folder: the cache file is taken for a game file)
assert_eq!(before.classify(&file), Target::Game { rel: file[3..].to_string() });
let v = Vfs::new(Path::new(&game_s), &dir.join("xcldata"), mounts()).own_folder(Path::new(&cache));
assert_eq!(v.classify(&file), Target::Pass);
assert_eq!(v.classify(&cache), Target::Pass);
assert_eq!(v.classify(&format!("{cache}\\translated\\0_Compute_0_4_1.bin")), Target::Pass);
// the folder's name is not a prefix of other names, and the rest of the drive is the console's
assert_eq!(v.classify(&format!("{cache}2\\x.dxil")), Target::Game { rel: format!("{}2\\x.dxil", &cache[3..]) });
assert_eq!(v.classify(&format!("{drive}\\data\\hello.txt")), Target::Game { rel: "data\\hello.txt".into() });
// a verbatim path (`std::fs::canonicalize`, which the DXIL cache uses for its folder)
assert_eq!(v.classify(&format!("\\\\?\\{file}")), Target::Pass);
}
#[test]
fn reads_never_touch_and_writes_copy_on_write() {
let f = Fixture::new("cow");