From 7cb20ff53cd274d41f0ff9814ae1a1c8b14bcc19 Mon Sep 17 00:00:00 2001 From: Normal1919 <517205163@qq.com> Date: Wed, 25 Nov 2026 11:53:34 +0800 Subject: [PATCH] VFS: exempt xcl.exe and host tool dirs from console drive mounts host_main previously registered only dxc::cache_dir() with Vfs::own_folder. When XCL_DXC_DIR, XCL_D3D12_DIR, XCL_OPUS_DIR, or xcl.exe's own folder lived on a drive mapped to a console mount (such as D: -> {game}), vfs_hooks rewrote attribute probes inside the host process into the game folder. Launcher preflight reported DXC as available, while every host shader compile failed with dxcompiler.dll not found. Exempt xcl.exe's directory and the configured tool DLL directories in host::build_vfs, and ignore bare drive roots in Vfs::own_folder so a misconfigured path cannot disable an entire console drive mount. Assisted-by: Antigravity (Gemini 4 Neon) --- crates/xcl/src/host.rs | 109 +++++++++++++++++++++++++++++++++++++++-- crates/xcl/src/vfs.rs | 13 ++--- 2 files changed, 113 insertions(+), 9 deletions(-) diff --git a/crates/xcl/src/host.rs b/crates/xcl/src/host.rs index 444333d891..a5c32fa63a 100644 --- a/crates/xcl/src/host.rs +++ b/crates/xcl/src/host.rs @@ -126,9 +126,13 @@ 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(); - // (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 mut extra_own: Vec = std::env::current_exe().ok().and_then(|p| p.parent().map(Path::to_path_buf)).into_iter().collect(); + for var in ["XCL_DXC_DIR", "XCL_D3D12_DIR", "XCL_OPUS_DIR"] { + if let Some(dir) = std::env::var_os(var).and_then(trim_dir) { + extra_own.push(dir); + } + } + crate::vfs::init(build_vfs(&boot, &crate::gpu::recomp::dxc::cache_dir(), &extra_own)); let _ = std::fs::create_dir_all(boot.data_dir.join("temp")); if let Err(e) = crate::vfs_hooks::install() { @@ -157,3 +161,102 @@ pub fn host_main(boot_path: &Path) -> i32 { crate::log::flush(); code as i32 } + +fn trim_dir(raw: std::ffi::OsString) -> Option { + match raw.to_str() { + Some(s) => { + let t = s.trim(); + (!t.is_empty()).then(|| std::path::PathBuf::from(t)) + } + None => Some(std::path::PathBuf::from(raw)), + } +} + +/// Build the host VFS, exempting XCL's own folders outside `boot.data_dir` (the shared shader +/// cache, `xcl.exe`'s directory, and configured host tool DLL folders) from console drive mounts. +fn build_vfs(boot: &Boot, cache_dir: &Path, extra_own: &[std::path::PathBuf]) -> crate::vfs::Vfs { + let mounts: Vec<(String, String)> = boot.config.mounts.iter().map(|(k, v)| (k.clone(), boot.expand(v))).collect(); + let mut vfs = crate::vfs::Vfs::new(&boot.game_root, &boot.data_dir, mounts).own_folder(cache_dir); + for dir in extra_own { + vfs = vfs.own_folder(dir); + } + vfs +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::config::Config; + use crate::vfs::Target; + use std::path::PathBuf; + + fn test_root(name: &str) -> PathBuf { + let dir = std::env::temp_dir().join(format!("xcl_host_{name}_{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + let canon = std::fs::canonicalize(&dir).unwrap(); + let s = canon.to_string_lossy(); + PathBuf::from(s.strip_prefix(r"\\?\").unwrap_or(&s)) + } + + #[test] + fn console_drive_mount_exempts_host_tool_and_exe_folders() { + let root = test_root("own_tools"); + let game = root.join("game"); + let data = root.join("xcldata"); + let cache = root.join("dxil_cache"); + let dxc = root.join("sdk").join("x64"); + let d3d12 = root.join("agility"); + let opus = root.join("opus"); + let exe_dir = root.join("bin"); + for d in [&game, &data, &cache, &dxc, &d3d12, &opus, &exe_dir] { + std::fs::create_dir_all(d).unwrap(); + } + let drive = root.to_string_lossy()[..2].to_string(); + let mut config = Config::default(); + config.mounts.insert(drive.clone(), "{game}".into()); + let boot = Boot { title: "test".into(), exe_path: game.join("test.exe"), game_root: game, data_dir: data, config }; + + let vfs = build_vfs(&boot, &cache, &[exe_dir.clone(), dxc.clone(), d3d12.clone(), opus.clone()]); + for own in [ + dxc.join("dxcompiler.dll"), + dxc.join("dxil.dll"), + d3d12.join("D3D12Core.dll"), + opus.join("opus.dll"), + exe_dir.join("dxcompiler.dll"), + cache.join("a.dxil"), + ] { + let s = own.to_string_lossy(); + assert_eq!(vfs.classify(&s), Target::Pass, "{s}"); + assert_eq!(vfs.classify(&format!(r"\\?\{s}")), Target::Pass, "verbatim {s}"); + } + assert_eq!(vfs.classify(&format!(r"{drive}\data\hello.txt")), Target::Game { rel: r"data\hello.txt".into() }); + let sibling = PathBuf::from(format!("{}2", dxc.display())).join("dxcompiler.dll"); + let sibling_rel = sibling.to_string_lossy()[3..].to_string(); + assert_eq!(vfs.classify(&sibling.to_string_lossy()), Target::Game { rel: sibling_rel }); + let _ = std::fs::remove_dir_all(&root); + } + + #[test] + fn drive_root_or_blank_own_dir_does_not_disable_console_mount() { + assert_eq!(trim_dir("".into()), None); + assert_eq!(trim_dir(" \t ".into()), None); + assert_eq!(trim_dir(r" D:\sdk\x64 ".into()), Some(PathBuf::from(r"D:\sdk\x64"))); + + let root = test_root("root_guard"); + let game = root.join("game"); + let data = root.join("xcldata"); + let cache = root.join("dxil_cache"); + for d in [&game, &data, &cache] { + std::fs::create_dir_all(d).unwrap(); + } + let drive = root.to_string_lossy()[..2].to_string(); + let mut config = Config::default(); + config.mounts.insert(drive.clone(), "{game}".into()); + let boot = Boot { title: "test".into(), exe_path: game.join("test.exe"), game_root: game, data_dir: data, config }; + + let vfs = build_vfs(&boot, &cache, &[PathBuf::from(format!(r"{drive}\")), PathBuf::from(format!(r"{drive}\sub\.."))]); + assert_eq!(vfs.classify(&format!(r"{drive}\data\hello.txt")), Target::Game { rel: r"data\hello.txt".into() }); + let _ = std::fs::remove_dir_all(&root); + } +} diff --git a/crates/xcl/src/vfs.rs b/crates/xcl/src/vfs.rs index dd02bcb67a..7e3d4e1bbc 100644 --- a/crates/xcl/src/vfs.rs +++ b/crates/xcl/src/vfs.rs @@ -190,16 +190,17 @@ 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. + /// `dir` is a folder of XCL's own outside the title's data folder – the shader cache, + /// `xcl.exe`'s directory, or configured host tool DLL folders (`XCL_DXC_DIR`, …). A console + /// drive mount must not translate its paths either: with the cache or DXC 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 or `dxcompiler.dll` in the game folder. Bare drive roots are ignored so an + /// empty or root path cannot disable a whole console drive mount. 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() { + if !dir.is_empty() && !(dir.len() == 2 && dir.as_bytes()[1] == b':') { self.own_roots_lc.push(dir); } self