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
37 changes: 24 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,30 @@ Fill the reusable DXIL cache ahead of a run with the read-only package wrapper.
<details>
<summary><b>Switches, caches, logs and the files XCL writes</b></summary>

- When a game folder contains a `shaders.rpf` shader pack or loose `.dxbc` files under
`shaders/`, XCL shows shader preparation in the game window before executing title code.
The same window then presents the game. The percentage counts
processed records. The timer counts seconds since one finished (or preparation started);
five seconds without progress counts as a stall, and the window shows when the last one ended.
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
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
the cause. Null-renderer runs skip shader preparation. With presentation disabled, the gate runs without a window.
- XCL uses the game window to show preparation progress before executing title code. It prepares
supported shader packs, supported loose shaders under `shaders/`, recorded graphics history and
staged pipeline recipes. Closing the window cancels launch. A failed staged recipe stops launch.
With presentation disabled, preparation runs without a window. A staged corpus still gates
launch when the null renderer is selected. For an unstaged title set `XCL_PREPARE=0`
to skip startup preparation, or `XCL_PREPARE_GRAPHICS=0` to skip optional graphics history.
Native recipes validated on this adapter and driver reuse their verified blobs across
rebuilds. Changes to translation, pipeline layout, settings or cache files trigger validation.
- To prepare known graphics, two-pass mesh and compute recipes offline, use a local
[archive layout profile](scripts/pso_corpus/archive-profile.md) with the following commands.
The staging command accepts several journals and deduplicates their recipes.

```powershell
python scripts/pso_corpus/pso_archive.py profile.json archive.bin pipelines.bin
python scripts/pso_corpus/stage.py --title <title-folder> pipelines.bin
xcl shaders <title-folder> --prepare-corpus --threads 8
```

The offline command accepts up to 32 workers. Normal launch also prepares the staged corpus.
When a shader pack or local history overlaps the corpus, XCL prepares each exact match once.
Use the same adapter and memory-window
configuration for offline preparation and play so the driver can reuse the results.
Graphics state combinations absent from the supplied recipes and local history can still
require a first-use compile during play.
- For compute shaders that XCL can split, the runtime first tries the saved driver blob for
the whole shader. A usable blob lets the GPU run it in one dispatch. If the blob is missing
or the driver rejects it, XCL builds the split pieces.
Expand Down
36 changes: 36 additions & 0 deletions crates/xcl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,41 @@ fn direct_sources(dir: &Path, out: &mut Vec<PathBuf>) {
mod source_hash;
use source_hash::{add, add_source};

// Bump when the native builder (including the D3D12.X glue in real.rs) changes the
// mapping from a journal recipe to driver descriptors or blob acceptance. Shader
// translator/toolchain, driver, adapter, settings and per-file stamps are keyed separately.
const NATIVE_PREPARATION_ABI: &[u8] = b"xcl-native-preparation-v1";
const PREPARATION_LAYOUT_SOURCES: &[&str] = &[
"src/gpu/recomp/pso.rs", // root signatures, translation glue, split pipeline layout
"src/hle/d3d12x/real/two_pass_identity.rs", // driver-blob identities for both mesh passes
"src/hle/d3d12x/gfx_records.rs", // normalized recipe fields and reconstruction
];

fn preparation_source_id(root: &Path) -> u64 {
let mut id = 0xcbf2_9ce4_8422_2325u64;
add(&mut id, NATIVE_PREPARATION_ABI);
for &relative in PREPARATION_LAYOUT_SOURCES {
println!("cargo:rerun-if-changed={relative}");
add(&mut id, relative.as_bytes());
add(&mut id, &[0]);
add_source(&mut id, &std::fs::read(root.join(relative)).expect("read pipeline layout input"));
add(&mut id, &[0]);
}
for name in ["TARGET", "PROFILE", "CARGO_ENCODED_RUSTFLAGS", "OPT_LEVEL", "DEBUG"] {
add(&mut id, name.as_bytes());
add(&mut id, std::env::var(name).unwrap_or_default().as_bytes());
add(&mut id, &[0]);
}
let rustc = std::process::Command::new(std::env::var_os("RUSTC").expect("rustc"))
.arg("-vV").output().expect("read compiler identity");
assert!(rustc.status.success());
add_source(&mut id, &rustc.stdout);
let mut features: Vec<_> = std::env::vars().filter(|(name,_)| name.starts_with("CARGO_FEATURE_")).collect();
features.sort();
for (name, value) in features { add(&mut id, name.as_bytes()); add(&mut id, value.as_bytes()); add(&mut id, &[0]); }
id
}

fn main() {
// xcl.exe without high-entropy ASLR: the title's memory then lies under 2^40, which a
// retail title's BVH builder requires of its GPU addresses (#585, PR #631)
Expand All @@ -59,6 +94,7 @@ fn main() {
_ => {}
}
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
println!("cargo:rustc-env=XCL_NATIVE_PREPARATION_ID={:016x}", preparation_source_id(root));
let mut h = 0xcbf2_9ce4_8422_2325u64;
add(&mut h, b"xcl-translator-source-v1\0");
add(&mut h, TRANSLATION_GLUE_REVISION.as_bytes());
Expand Down
2 changes: 1 addition & 1 deletion crates/xcl/src/gpu/recomp/dxc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ fn cache_key_for_toolchain(src: &str, entry: &str, profile: &str, toolchain: &st
h
}

fn cache_key(src: &str, entry: &str, profile: &str) -> u64 {
pub(crate) fn cache_key(src: &str, entry: &str, profile: &str) -> u64 {
cache_key_for_toolchain(src, entry, profile, toolchain_identity())
}

Expand Down
4 changes: 3 additions & 1 deletion crates/xcl/src/gpu/recomp/pso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ pub fn console_to_dxil_in(blob: &[u8], stage: Stage, sampler_base: u32, split_wa
/// each at every start. Keyed by two hashes and the length of the bytes, the stage and the
/// translation parameters; translator sources and the DXC toolchain identify compatible builds.
/// `XCL_TRANSLATED_CACHE=0` turns it off.
pub(crate) fn translation_cache_identity() -> u64 { translated::identity() }

mod translated {
use super::{Compiled, Stage};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -268,7 +270,7 @@ mod translated {

/// Translation semantics and the DXC DLLs, independent of link metadata and build profile.
/// Zero means the disk cache is disabled.
fn identity() -> u64 {
pub(super) fn identity() -> u64 {
static I: OnceLock<u64> = OnceLock::new();
*I.get_or_init(|| {
if std::env::var("XCL_TRANSLATED_CACHE").is_ok_and(|v| v == "0") {
Expand Down
Loading
Loading