Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
88bc67d
xcl run: a pack's compute pipelines are prepared by worker processes
theaustinayers Nov 26, 2026
5584a82
xcl run: the preparation screen counts each pass by itself, and every…
theaustinayers Nov 26, 2026
ad1ff9a
xcl run: the preparation takes the shaders earlier runs used, or none
theaustinayers Nov 26, 2026
f985c1c
xcl run: one preparation worker builds a pipeline, the others leave it
theaustinayers Nov 26, 2026
53c1d28
D3D12.X: record the graphics pipelines a run uses with their state
theaustinayers Nov 26, 2026
192374e
xcl run: the memory line and a device removal give the system's commit
theaustinayers Nov 25, 2026
8f90648
xcl run: build the graphics pipelines earlier runs used before the title
theaustinayers Nov 26, 2026
0a79e6c
Shaders: replay compatible two-pass mesh pipelines at startup
CryingLaughing Nov 26, 2026
4d78a9b
Shaders: discover and stage pipeline recipes from offline archives
bmjask Nov 26, 2026
7b39214
Shaders: prepare known native pipelines before releasing the game window
bmjask Nov 26, 2026
0600e86
Shaders: stream staged graphics jobs and preserve mesh cache identities
bmjask Nov 26, 2026
f383079
Shaders: prepare exact pack and history overlaps once at startup
bmjask Nov 26, 2026
02c66ca
Shaders: keep the launch owner responsible for the whole input
bmjask Nov 26, 2026
7659b88
Shaders: recover usable graphics history after an interrupted append
bmjask Nov 26, 2026
2d473dc
Shaders: retain verified native preparations across rebuilds
bmjask Nov 26, 2026
0d97736
Shaders: share verification between launch and offline workers
bmjask Nov 26, 2026
b64e486
Shaders: preserve inactive-stage cache identities on main
bmjask Nov 27, 2026
62c6bda
Shaders: prove native pipeline library round trips
bmjask Nov 27, 2026
b83c3f0
Shaders: pass null for empty pipeline libraries
bmjask Nov 27, 2026
0d84fb5
Shaders: publish semantic corpus identities
bmjask Nov 27, 2026
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: 25 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,31 @@ xcl rpf D:\data\shaders.rpf --extract NAME --out folder
<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 that need state supplied by the
title are created during play. 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_PREPARE=0` leaves the preparation out: the game starts at once and builds the shaders it
uses as it goes (it stands still while they build).
- 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, deduplicates their recipes and atomically publishes
a content identity for later preparation receipts.

```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
42 changes: 42 additions & 0 deletions crates/xcl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,45 @@ 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_layout_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]);
}
id
}

fn preparation_source_id(mut id: u64) -> u64 {
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 +98,9 @@ fn main() {
_ => {}
}
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let layout = preparation_layout_id(root);
println!("cargo:rustc-env=XCL_PIPELINE_LAYOUT_ID={layout:016x}");
println!("cargo:rustc-env=XCL_NATIVE_PREPARATION_ID={:016x}", preparation_source_id(layout));
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 @@ -691,7 +691,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
27 changes: 25 additions & 2 deletions crates/xcl/src/gpu/recomp/pso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,29 @@ pub fn fspx(blob: &[u8]) -> Option<Fspx<'_>> {
/// Memory windows of the title's unified memory (1 without it), with `HEAP_WINDOWS` when
/// shaders take them from the descriptor heap (`heap_windows`).
pub fn mem_windows() -> u32 {
let title = TITLE_WINDOWS.load(std::sync::atomic::Ordering::Relaxed);
if title != 0 {
return windows_for(title & !super::HEAP_WINDOWS, title & super::HEAP_WINDOWS != 0 && !SWITCH_FORM.with(|s| s.get()));
}
let n = crate::gpu::uma::get().map_or(1, |u| u.shader_windows() as u32);
if n > 1 && heap_windows() && !SWITCH_FORM.with(|s| s.get()) {
windows_for(n, heap_windows() && !SWITCH_FORM.with(|s| s.get()))
}

/// The title's windows (`mem_windows` with `HEAP_WINDOWS`) for a process without its memory: a
/// shader preparation worker builds the title's pipelines with them (0: none given).
static TITLE_WINDOWS: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);

/// `mem_windows` is `windows` from here on (a preparation worker: `uma::leave_out`).
pub fn set_title_windows(windows: u32) {
TITLE_WINDOWS.store(windows, std::sync::atomic::Ordering::Relaxed);
}

/// `n` windows as shaders take them: from the descriptor heap (`heap`), or in the switch form
/// over the root UAVs – of which there are `MAX_WINDOWS`, so never more there (the HLSL path
/// refused a wider switch, and DXIL quietly made it 4: a 16-window run whose heap views could
/// not be made, or a pipeline the driver refused with them, lost every shader on HLSL).
fn windows_for(n: u32, heap: bool) -> u32 {
if n > 1 && heap {
n | super::HEAP_WINDOWS
} else {
n
Expand Down Expand Up @@ -178,6 +199,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 @@ -245,7 +268,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
7 changes: 7 additions & 0 deletions crates/xcl/src/gpu/uma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,13 @@ impl Arena {

static GLOBAL: OnceLock<Option<Uma>> = OnceLock::new();

/// A process that holds no title memory (a shader preparation worker): `get` is None from here
/// on, and nothing is reserved or committed for it (a run's region commits its coherent window).
/// Before any `get`.
pub fn leave_out() {
let _ = GLOBAL.set(None);
}

/// The title's graphics memory XCL places in the coherent window (`note_coherent_need`) is
/// known only once it asks for it, and the window is committed when it is made: its size is
/// what the title asked for in its last run (`<data>/cache/uma_coherent.txt`) and XCL's own
Expand Down
Loading
Loading