diff --git a/README.md b/README.md index 973a027e86..b1be21ef7d 100644 --- a/README.md +++ b/README.md @@ -248,7 +248,7 @@ Fill the reusable DXIL cache ahead of a run with the read-only package wrapper. XCL prepares supported shader stages and compute pipelines, including split pieces and their whole fallback. Graphics pipelines are created during play the first time; the ones a run used are recorded with their state (`used-graphics-pipelines.bin` beside - the shader cache, at most `XCL_GFX_RECORDS_MB`, default 64) and built before the title starts + the shader cache, or `-lockhart` variants under Series S `lockhart`, at most `XCL_GFX_RECORDS_MB`, default 64) and built before the title starts on the next launch, with their driver blobs kept, so the title makes them from those in milliseconds. `XCL_PREPARE_GRAPHICS=0` leaves that pass out. Later launches reuse matching cache entries. Closing the window cancels the launch. A compiler or driver failure stops it and reports diff --git a/crates/xcl/src/hle/d3d12x/gfx_records.rs b/crates/xcl/src/hle/d3d12x/gfx_records.rs index cb4b872354..dfd8b953f9 100644 --- a/crates/xcl/src/hle/d3d12x/gfx_records.rs +++ b/crates/xcl/src/hle/d3d12x/gfx_records.rs @@ -42,7 +42,8 @@ const SHADER: u8 = 2; /// The records of this cache (beside the DXIL cache, as `used-pipelines.txt`). pub(crate) fn path() -> PathBuf { - crate::gpu::recomp::dxc::cache_dir().join("used-graphics-pipelines.bin") + let name = super::pso_async::used_file_name("used-graphics-pipelines", "bin", super::pso_async::profile_is_series_s()); + crate::gpu::recomp::dxc::cache_dir().join(name) } /// `XCL_GFX_RECORDS_MB`: the most the records may take on disk (64 MB: ~300 000 pipelines). diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs index 51e0453f17..55d829dda8 100644 --- a/crates/xcl/src/hle/d3d12x/pso_async.rs +++ b/crates/xcl/src/hle/d3d12x/pso_async.rs @@ -848,17 +848,52 @@ pub(crate) fn shaders_of(key: u64, shaders: Vec) { used::parts(key, shaders); } +/// Whether the active console profile is Xbox Series S (`lockhart`): checks `state::boot()` +/// first (already folded with `xcl.toml` and `XCL_DEVICE_TYPE` in the host process), then falls +/// back to `XCL_DEVICE_TYPE` for standalone `xcl shaders --used-only` and preparation workers +/// where no boot record is loaded. +pub(crate) fn profile_is_series_s() -> bool { + profile_is_series_s_from( + crate::state::boot().map(|b| b.config.is_series_s()), + std::env::var("XCL_DEVICE_TYPE").ok().as_deref(), + ) +} + +fn profile_is_series_s_from(boot_series_s: Option, env_device_type: Option<&str>) -> bool { + if let Some(series_s) = boot_series_s { + return series_s; + } + env_device_type.and_then(crate::config::parse_device_type) == Some("lockhart") +} + +/// File name for a per-profile usage or replay manifest beside the DXIL cache: Series X +/// (`anaconda`, default) keeps `{stem}.{ext}` unchanged; Series S (`lockhart`) uses +/// `{stem}-lockhart.{ext}` so switching profiles does not cross-pollinate startup preparation +/// or runtime preload lists. +pub(crate) fn used_file_name(stem: &str, ext: &str, series_s: bool) -> String { + if series_s { format!("{stem}-lockhart.{ext}") } else { format!("{stem}.{ext}") } +} + +pub(crate) fn used_pipelines_name() -> String { + used_file_name("used-pipelines", "txt", profile_is_series_s()) +} + +pub(crate) fn used_shaders_name() -> String { + used_file_name("used-shaders", "txt", profile_is_series_s()) +} + /// The shaders of the pipelines earlier runs used, each by its own key (`used-shaders.txt` -/// beside the DXIL cache): what a title's shader preparation translates. Empty before a run -/// with this list has used a pipeline. +/// or `used-shaders-lockhart.txt` beside the DXIL cache): what a title's shader preparation +/// translates. Empty before a run with this list has used a pipeline. pub fn earlier_used_shaders() -> std::collections::HashSet { - used::parse(&std::fs::read_to_string(crate::gpu::recomp::dxc::cache_dir().join("used-shaders.txt")).unwrap_or_default()) + used::parse(&std::fs::read_to_string(crate::gpu::recomp::dxc::cache_dir().join(used_shaders_name())).unwrap_or_default()) } -/// The keys of the pipelines earlier runs used (`used-pipelines.txt` beside the DXIL cache): -/// what `xcl shaders --precompile --used-only` builds. +/// The keys of the pipelines earlier runs used (`used-pipelines.txt` or +/// `used-pipelines-lockhart.txt` beside the DXIL cache): what +/// `xcl shaders --precompile --used-only` builds. pub fn earlier_used_keys() -> std::collections::HashSet { - used::parse(&std::fs::read_to_string(crate::gpu::recomp::dxc::cache_dir().join("used-pipelines.txt")).unwrap_or_default()) + used::parse(&std::fs::read_to_string(crate::gpu::recomp::dxc::cache_dir().join(used_pipelines_name())).unwrap_or_default()) } /// The pipelines a title used, by a hash of their shaders, kept between runs @@ -896,7 +931,7 @@ mod used { if cfg!(test) { return Used { earlier: RwLock::new(HashSet::new()), now: Mutex::new((HashSet::new(), None)), parts: Default::default(), shaders: Mutex::new((HashSet::new(), None)) }; } - let path = crate::gpu::recomp::dxc::cache_dir().join("used-pipelines.txt"); + let path = crate::gpu::recomp::dxc::cache_dir().join(super::used_pipelines_name()); let earlier = parse(&std::fs::read_to_string(&path).unwrap_or_default()); if !earlier.is_empty() { crate::xlog_info!("D3D12.X: the pipelines of {} shader sets an earlier run used are built ahead of their first use", earlier.len()); @@ -905,7 +940,7 @@ mod used { let _ = std::fs::create_dir_all(dir); } let file = std::fs::OpenOptions::new().create(true).append(true).open(&path).ok(); - let shaders_path = path.with_file_name("used-shaders.txt"); + let shaders_path = path.with_file_name(super::used_shaders_name()); let shaders = parse(&std::fs::read_to_string(&shaders_path).unwrap_or_default()); let shaders_file = std::fs::OpenOptions::new().create(true).append(true).open(&shaders_path).ok(); Used { now: Mutex::new((earlier.clone(), file)), earlier: RwLock::new(earlier), parts: Default::default(), shaders: Mutex::new((shaders, shaders_file)) } @@ -2362,6 +2397,28 @@ mod used_tests { let _ = released(standin); } } + + #[test] + fn used_manifests_separate_series_s_from_series_x() { + assert_eq!(used_file_name("used-pipelines", "txt", false), "used-pipelines.txt"); + assert_eq!(used_file_name("used-shaders", "txt", false), "used-shaders.txt"); + assert_eq!(used_file_name("used-graphics-pipelines", "bin", false), "used-graphics-pipelines.bin"); + assert_eq!(used_file_name("used-pipelines", "txt", true), "used-pipelines-lockhart.txt"); + assert_eq!(used_file_name("used-shaders", "txt", true), "used-shaders-lockhart.txt"); + assert_eq!(used_file_name("used-graphics-pipelines", "bin", true), "used-graphics-pipelines-lockhart.bin"); + + // Host boot config takes precedence over environment variables. + assert!(profile_is_series_s_from(Some(true), Some("anaconda"))); + assert!(!profile_is_series_s_from(Some(false), Some("lockhart"))); + // Standalone CLI / preparation workers without a boot record fall back to XCL_DEVICE_TYPE. + for raw in ["lockhart", "Series S", "series_s", "xss", "S"] { + assert!(profile_is_series_s_from(None, Some(raw)), "{raw}"); + } + for raw in ["anaconda", "Series X", "xsx", "X", "", "unknown"] { + assert!(!profile_is_series_s_from(None, Some(raw)), "{raw}"); + } + assert!(!profile_is_series_s_from(None, None)); + } } fn entry(pso: usize) -> Option> { diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs index 67fb3e0dcb..33dea47ba6 100644 --- a/crates/xcl/src/shaders.rs +++ b/crates/xcl/src/shaders.rs @@ -1803,17 +1803,23 @@ mod claim_tests { /// when that list exists (the title builds another when it first uses it). Their records count /// into `progress`. A worker that fails is noted and the title starts all the same: it builds /// what is missing itself. +fn pipeline_worker_command(me: &Path, pack: &Path, windows: u32, used_only: bool, slice: &str, series_s: bool) -> std::process::Command { + let mut c = worker_command(me); + c.arg("shaders").arg(pack).args(["--precompile", "--only", "cs", "--pipelines", "--windows"]).arg((windows & !recomp::HEAP_WINDOWS).to_string()); + if used_only { c.arg("--used-only"); } + c.env("XCL_PRECOMPILE_SLICE", slice); + c.env("XCL_DEVICE_TYPE", if series_s { "lockhart" } else { "anaconda" }); + c +} + fn pipelines_in_workers(pack: &Path, windows: u32, workers: usize, records: usize, progress: &LaunchPreparation) -> Result<(), String> { let me = std::env::current_exe().map_err(|e| e.to_string())?; + let series_s = crate::hle::d3d12x::pso_async::profile_is_series_s(); let used_only = !crate::hle::d3d12x::pso_async::earlier_used_keys().is_empty(); let t0 = std::time::Instant::now(); crate::xlog_info!("Shader preparation: compute pipelines in {workers} worker processes{}", if used_only { ", those an earlier run used" } else { "" }); let (cancelled, failed, _) = in_workers(workers, records, progress, |i| { - let mut c = worker_command(&me); - c.arg("shaders").arg(pack).args(["--precompile", "--only", "cs", "--pipelines", "--windows"]).arg((windows & !recomp::HEAP_WINDOWS).to_string()); - if used_only { c.arg("--used-only"); } - c.env("XCL_PRECOMPILE_SLICE", format!("{i}/{workers}")); - c + pipeline_worker_command(&me, pack, windows, used_only, &format!("{i}/{workers}"), series_s) }); if cancelled { return Err("Shader preparation cancelled".into()); } crate::xlog_info!("Shader preparation: compute pipelines done in {:.0} s ({failed} of {workers} workers failed)", t0.elapsed().as_secs_f64()); @@ -2100,7 +2106,11 @@ fn precompile(input: &Input, limit: usize, windows: u32, split: Option, on let errors: Mutex> = Mutex::new(Vec::new()); let unused = AtomicUsize::new(0); if let Some(u) = used { - println!("--used-only: {} pipelines earlier runs used (used-pipelines.txt); compute programs of other pipelines are passed over", u.len()); + println!( + "--used-only: {} pipelines earlier runs used ({}); compute programs of other pipelines are passed over", + u.len(), + crate::hle::d3d12x::pso_async::used_pipelines_name() + ); } // the compiles run on the DXC pool; these threads translate and keep it fed let threads = recomp::dxc::compile_threads() + 2; @@ -2682,6 +2692,18 @@ mod tests { assert!(super::used_compute(&b, &keys)); } + #[test] + fn pipeline_worker_command_forwards_console_profile() { + let dev_env = |series_s| { + let cmd = super::pipeline_worker_command(Path::new("xcl.exe"), Path::new("shaders.rpf"), 4, true, "0/2", series_s); + cmd.get_envs() + .find_map(|(k, v)| (k == std::ffi::OsStr::new("XCL_DEVICE_TYPE")).then(|| v.map(|s| s.to_string_lossy().into_owned()))) + .flatten() + }; + assert_eq!(dev_env(true).as_deref(), Some("lockhart")); + assert_eq!(dev_env(false).as_deref(), Some("anaconda")); + } + use super::*; use crate::gpu::xbox::tests::{fssm, sample, CODE};