Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion crates/xcl/src/hle/d3d12x/gfx_records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
73 changes: 65 additions & 8 deletions crates/xcl/src/hle/d3d12x/pso_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,17 +848,52 @@ pub(crate) fn shaders_of(key: u64, shaders: Vec<u64>) {
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<bool>, 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<u64> {
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<u64> {
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
Expand Down Expand Up @@ -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());
Expand All @@ -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)) }
Expand Down Expand Up @@ -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<Arc<Pending>> {
Expand Down
34 changes: 28 additions & 6 deletions crates/xcl/src/shaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -2100,7 +2106,11 @@ fn precompile(input: &Input, limit: usize, windows: u32, split: Option<bool>, on
let errors: Mutex<Vec<String>> = 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;
Expand Down Expand Up @@ -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};

Expand Down
Loading