Skip to content

PSO: xcl pso-precompile builds a title's compute pipelines before its run - #1871

Open
bmjask wants to merge 2 commits into
xcl-dev:mainfrom
bmjask:perf/pso-aot
Open

bmjask wants to merge 2 commits into
xcl-dev:mainfrom
bmjask:perf/pso-aot

Conversation

@bmjask

@bmjask bmjask commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

A retail title's world load creates hundreds of compute pipelines, several of them 0.3 – 1.6 MB of DXIL that take NVIDIA's compiler 15 – 170 s each. Compiled cold during the run, the title's binds wait for them or run without them, and its loading never finishes. xcl pso-precompile builds them before the run. It translates the title's compute programs from its shader package and has the driver compile each pipeline the way the runtime does (same DXIL, XCL ABI root signature with the program's static samplers, flags). It writes the blob to the driver_cache file the runtime reads, so the run loads it instead of compiling.

What is in it

  • xcl pso-precompile <game folder | shaders.rpf> [--threads N] [--records FILE] [--used]: shaders --precompile --pipelines of the folder's shaders.rpf.
  • Pipelines are made after all programs are translated. The ones an earlier run used (used-pipelines.txt) go first, and within each group the biggest go first, so the longest compiles don't start last.
  • Driver compiles at once: --threads, XCL_PIPELINE_THREADS, or one per core but at most one per 2 GB of RAM (was 4).
  • --records FILE (record hashes as the runtime's "driver compile start … record H" lines name them, or pipeline keys) and --used restrict the pass to those programs. A whole retail pack is 26,503 records. The set the load needs is a few hundred.
  • Resumable: a pipeline whose blob is on disk is only loaded. Progress lines show the count, cache hits and every compile of 10 s or more. The summary gives driver time by DXIL size and the 10 slowest.
  • XCL_DIRECT_DXIL / XCL_HEAP_WINDOWS change the translation keys, so the warm-up must run with the same values as the game.
  • Unit tests: job order, thread default, used-pipelines.txt parsing, shader package lookup, record / key selection.

Numbers (RTX 4090, 24 driver compiles at once, XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1)

  • Load set: every record a run compiled cold, gathered over runs (70), plus the pipelines an earlier run used. That is 867 compute programs in the pack.
  • Cold warm-up: translation 31 s, then 667 driver compiles in 1,301 s wall (29,554 s of driver time) and 200 loaded from the cache. Warm rerun: 12 s, all 867 from the cache.
  • The 24-way contention is heavy: the 714 KB resolve program takes 65 s at 24 at once, against 15 s alone. A lower --threads is probably better and is not measured yet.
  • Title run after a cold compile of only the 29 records first seen: 42 cold compiles during the load, the run flatlines at 102 s and the watchdog aborts.
  • Title run after the full load set: 0 cold compiles during the load, 287 pipelines from the warmed blobs. The load gets further (the loading screen fades out at about 120 s), then the GPU hangs: the queues stop completing, and the device is removed (0x887a0006) at 117 s / 137 s in two runs. That hang is a separate issue and is not addressed here.

Tested

  • RTX 4090, release; cargo test --release -p xcl --lib pipeline_tests: 5 passed.

Regression run
XCL_PRESS_AT=2:B,4:B,6:B,8:B, XCL_PRESS_A_AT=10,20,…,60

main:

xcl-smoke v1
commit: c4d37bec1bb4286eb373aea963404a23f13401fa
gpu: NVIDIA GeForce RTX 4090
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1475 (PresentX 1475)
presents per 2 s (last 3): 37 51 24
device removals: 0
crashes: 0
peak commit: 22202 MB

PR:

xcl-smoke v1
commit: 27362a08509c7dd79f7eebdf39c4ad29e98e4d6f
gpu: NVIDIA GeForce RTX 4090
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1489 (PresentX 1490)
presents per 2 s (last 3): 42 55 32
device removals: 0
crashes: 0
peak commit: 21084 MB

Not tested

  • The full cargo test --workspace suite. Whole-pack warm-up time (26,503 records). AMD / Intel GPUs. The HLSL path's warm-up for the full load set (its translations are far slower).

AI use

  • Claude Code (Claude Opus 5.5) wrote the change, ran the warm-ups and title runs, and wrote this description.

🤖 Generated with Claude Code

bmjask and others added 2 commits November 24, 2026 16:17
Translates a title's compute programs from its shader package and has the
driver compile their pipelines ahead of the run, writing the same driver
blobs (same DXIL, root signature, flags) the runtime looks up. Pipelines an
earlier run used go first, each group biggest first, on one driver compile
a core (bounded by memory, --threads N). --records FILE / --used restrict
it to given record hashes / pipeline keys; cached pipelines only load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thehollowedone

thehollowedone commented Nov 24, 2026 •

Copy link
Copy Markdown

Independent check of 27362a0 on an RTX 3080 Ti (621.35), Windows 11 build 26300, Rust 1.99.1 MSVC debug.

I generated a two-record synthetic shader package and ran xcl pso-precompile <folder> --threads 1 --records <file> in fresh processes with XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1. A nonmatching hash made zero pipelines. Selecting one record with an empty XCL cache built one pipeline and saved a 1,530-byte driver blob. The warm run loaded one pipeline from that blob, compiled zero in the driver, and left the blob byte-for-byte unchanged. Zero refusals across the three runs.

cargo build --offline --locked -p xcl succeeded. cargo test --offline --locked -p xcl --lib shaders::pipeline_tests:: -- --nocapture --test-threads=1 passed 5/5, with zero skips. This report covers record selection and reuse by the precompile command itself.

AI-assisted. Codex (GPT-6 family, exact variant unavailable) generated the synthetic fixture, ran the checks, and drafted this report.

Runtime cache check

On the same revision and hardware, I also passed a synthetic compute shader through the runtime's public CreateComputePipelineState hook in two fresh processes. The empty-cache control created the translated PSO without a blob. After xcl pso-precompile <folder> --threads 1 --records <file> seeded a separate cache, the runtime supplied the blob on its first attempt, recorded one disk-cache hit and made the translated PSO without a retry. The driver blob stayed byte-for-byte unchanged. Both runs used split wave64 and four descriptor-heap memory windows.

The scratch test scratch_precompile_to_runtime_compute_pso, built with cargo test --offline --locked -p xcl --lib, passed 1/1 in each process with zero skips. The check covered pipeline creation.

AI-assisted. Codex (GPT-6 family, exact variant unavailable) wrote and ran the scratch test and drafted this update.

Selection coverage check

Following Kalmarv’s report, I tested a synthetic pack with three requested keys. Two keys referred to the same compute shader, and one key had no match. The current PR head built one pipeline and exited successfully without reporting the unmatched key. A local test build counted 2 of 3 keys matched for --records, 1 of 2 for --used, and 2 of 3 when combined. All three runs still made one pipeline. Filtering out compute with --only PS gave 0 of 3 matches and made zero pipelines.

Same Windows 11 and RTX 3080 Ti setup. cargo test --offline --locked -p xcl --lib shaders::pipeline_tests:: -- --nocapture --test-threads=1 passed 5/5. The CLI runs used xcl pso-precompile <folder> --threads 1 with the selectors above. Synthetic inputs only.

AI-assisted. Codex (GPT-6 family, exact variant unavailable) wrote the local change, ran the tests, and drafted this update.

@WebIdentity1

Copy link
Copy Markdown
Contributor

RTX 3090 full-suite check and a small --records operand fix for exact head 27362a08509c7dd79f7eebdf39c4ad29e98e4d6f. Windows 10 19045, driver 591.74, Rust 1.98.1 MSVC; XCL_ADAPTER=3090, direct-DXIL and REQUIRE_GPU unset. Synthetic fixture only.

Tested

  • cargo build --locked --workspace: exit 0 on the exact head and on the head plus the local patch.
  • cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output: exact head 963 passed / 1 failed / 43 ignored, candidate 964 / 1 / 43, across 20 targets, 25 explicit SKIPPED lines on each. The only failure on both was the known gpu_clamp_and_omod_per_instruction on this adapter; no candidate-only failure.
  • New CLI regression pso_precompile_rejects_records_without_a_file: 0/1/0 with the head's runtime, 1/0/0 with the local fix. An empty 64-byte synthetic RPF header made this safe: bare --records exits 0 on the head and falls through to the unrestricted selector (precompiling 0 shaders for this empty fixture). With real records that would select the whole pack. The fix reuses the existing required("--records") check, rejecting bare --records and --records --used with exit 2 and a missing-value error.

The three 303-file source snapshots matched their SHA-256 manifests before and after native Windows runs. This PR head is still behind current main 689f2db; the paired suite above is head versus head+patch, not a current-main integration test. No code commit or competing PR from me; this patch is for the author to incorporate:

Two-file patch (28 insertions, one deletion)
diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs
index 4c308f3..c95bea6 100644
--- a/crates/xcl/src/shaders.rs
+++ b/crates/xcl/src/shaders.rs
@@ -913,6 +913,13 @@ pub fn run(path: &Path, args: &[String]) -> i32 {
         );
     }
     if args.iter().any(|a| a == "--precompile") {
+        let record_file = match required("--records") {
+            Ok(f) => f,
+            Err(e) => {
+                eprintln!("{e}");
+                return 2;
+            }
+        };
         let only = args.iter().position(|a| a == "--only").and_then(|i| args.get(i + 1)).map(|s| s.to_ascii_lowercase());
         let pipelines = args.iter().any(|a| a == "--pipelines");
         if let Some(n) = opt("--threads") {
@@ -923,7 +930,7 @@ pub fn run(path: &Path, args: &[String]) -> i32 {
         // `--records FILE` (record hashes or pipeline keys, a hexadecimal one a line) and / or
         // `--used` (the pipelines an earlier run used): only those programs
         let mut select: Option<std::collections::HashSet<u64>> = None;
-        if let Some(f) = args.iter().position(|a| a == "--records").and_then(|i| args.get(i + 1)) {
+        if let Some(f) = record_file {
             match std::fs::read_to_string(f) {
                 Ok(t) => select.get_or_insert_with(Default::default).extend(parse_used(&t)),
                 Err(e) => {
diff --git a/crates/xcl/tests/shaders_e2e.rs b/crates/xcl/tests/shaders_e2e.rs
index caac3a0..be77532 100644
--- a/crates/xcl/tests/shaders_e2e.rs
+++ b/crates/xcl/tests/shaders_e2e.rs
@@ -154,6 +154,26 @@ fn run_shaders(target: &Path, extra: &[&str]) -> Output {
         .expect("spawn xcl shaders")
 }
 
+#[test]
+fn pso_precompile_rejects_records_without_a_file() {
+    let dir = TempDir::new("pso-records-operand");
+    let pack = dir.path().join("shaders.rpf");
+    let mut bytes = b"9FPR".to_vec();
+    bytes.resize(0x40, 0);
+    std::fs::write(&pack, bytes).unwrap();
+
+    for tail in [&["--records"][..], &["--records", "--used"][..]] {
+        let out = Command::new(env!("CARGO_BIN_EXE_xcl"))
+            .arg("pso-precompile")
+            .arg(&pack)
+            .args(tail)
+            .output()
+            .expect("spawn xcl pso-precompile");
+        assert_eq!(out.status.code(), Some(2), "{out:?}");
+        assert!(String::from_utf8_lossy(&out.stderr).contains("--records needs a value"), "{out:?}");
+    }
+}
+
 #[test]
 fn shaders_single_file_reports_text_top_json_recomp_and_dxc_compile() {
     let dir = TempDir::new("single");

Not tested: retail smoke, whole-pack precompile time or memory, runtime cache reuse, and gameplay. This is a bounded CLI regression, not merge readiness.

AI use: Codex desktop (GPT-6) wrote the test and local patch, ran the Windows checks and drafted this report; results are from retained raw logs.

@Alm0stSurely

Copy link
Copy Markdown

Tested on Proton Experimental with the HLSL backend. The title reused the offline blobs when paired with #1368. Both runs reached illustrated loading and showed black at 105 and 240 s.

I applied the three-file diff from this PR at 27362a08509c7dd79f7eebdf39c4ad29e98e4d6f to main 689f2db477c3c062cf162649781640ef8a977c18 to keep the shader translator identical between preparation and playback. The comparison used the same diagnostic runtime on main, first as-is, then with #1368 at 0074749a9678a697455c48a95f7c4f746ccd602e. EndeavourOS, Ryzen 9 9950X3D, 60 GiB usable RAM, RTX 5080 / NVIDIA 620.73.04, Proton Experimental, vkd3d-proton 4522cc1 / dxil-spirv 53aac418 with the local dominance-performance patch, DXC 1.9.2609.5.

  • Preparation: xcl pso-precompile <shader-package> --records records.txt --threads 4. The file contained 262 unique compute records previously observed without a driver blob. XCL_DIRECT_DXIL=0 XCL_COMPACT_CS=auto, four memory windows, split wave64. Translation reported 247 compute jobs and zero errors. I stopped preparation after more than 10 minutes. Of 245 distinct matching translations in the fresh cache namespace, 244 had a nonempty driver blob. The 29,215,780-byte DXIL program still had none.
  • Playback: xcl <title-exe>, same backend, driver, 45-key preload history and XCL_RUN_SECONDS=240, independent copies of the same partially warmed XCL/vkd3d/NVIDIA caches. On main, 204 selected records had a supplied blob refused and 18 had none. With D3D12.X: translated compute pipelines are made with node mask 0 #1368, 242 selected records completed with a supplied blob and no cold retry, and 18 had none. For all 203 records supplied in both runs, refusal changed to acceptance. The precompiled and runtime-rewritten blobs checked had the same filename and different compute state hashes consistent with NodeMask 0 versus 1 at flags 0.
  • Cache migration is visible too: 58 records outside the selected set accepted a supplied blob on main and retried without it with D3D12.X: translated compute pipelines are made with node mask 0 #1368. Seventeen other out-of-set records accepted blobs in both runs. A cache populated under the old runtime can therefore give a different first-run result from a freshly prepared cache.

One playback per configuration. This measures blob acceptance and the observed screen; full-pack preparation, linked adapters, and native Windows were outside this test. Investigation, log analysis and report assisted by OpenAI Codex (GPT-6.2 Astra).

@Kalmarv

Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

A test note from a run on an RTX 5070 Ti (NVIDIA), of our own precompile pass (the same approach, not this PR's code). It concerns which programs a shaders.rpf-only input can cover.

In a 300 s title run after a pass over 1,957 compute programs, 60 compute programs the title created had no translation and no driver blob:

  • 31 are not in shaders.rpf at all. They are DXBC containers inside the title's XboxBvhBuilder.dll (it holds 52; the run created 31). pso-precompile reads only shaders.rpf, so it cannot cover them, and with --used their keys appear in used-pipelines.txt but no record matches. Cold, on their own, they took a median of 119 ms and at most 7.0 s each, 20 s in all. That is small, but they are still compiled during the load.
  • 29 are in shaders.rpf (27 CS_…Classified0…26_…_Wrapped records of one effect plus two CS_RaytracingResolve_…_Wrapped). Our pass missed them only because its input list came from an older inventory. A whole-pack pso-precompile would include them, and so would --used after a run that created them. They include the two slowest programs of the load (1.14 MB and 1.21 MB of DXIL: 14.6 s and 24.2 s cold).

A suggestion: also take the DXBC containers of the title's DLLs (or of XCL_DUMP_SHADERS dumps), or at least report the --used keys that matched no record, so a warm-up that looks complete isn't missing programs without saying so.

Tested: RTX 5070 Ti, Windows 11 26200, DXC 1.7.2308 (Windows Kits), XCL_HEAP_WINDOWS=1; one title run plus a precompile of the 60 from the run's cache records.

AI use: Claude Code (Claude Opus 5.5) ran the pass and the title run on our machine and wrote this.

@Filip722

Copy link
Copy Markdown

The selective precompile worked across separate Proton processes on an RTX 5060 Laptop GPU (8 GiB), NVIDIA 615.78.08, Bazzite 44 and Proton Experimental 11.0-20261112. I used the record selector from this PR ported to main 689f2db, one compiler, and a custom vkd3d-proton build based on 4522cc1. Both offline passes used pipeline_library_app_cache.

The seven selected compute pipelines took 120.4 s in the cold driver stage. The warm stage took 0.3 s, with seven cache hits and zero refusals. All seven blobs contained both inline SPIR-V and Vulkan cache data (18,011,104 bytes total). This exercised the underlying record selector on seven private inputs. Six were also found in the shader archive.

A separate offline title run using the same app-cache mode and the saved blobs on a composite XCL build reached six of those records before the host froze. Their six logged driver calls completed in 1–120 ms. That title run ended with a manual power cycle during loading. Gameplay and the cause of the freeze remain unverified. Only the offline cold/warm timings above are a matched comparison.

OpenAI Codex assisted with these tests and the report.

anoyarou pushed a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
…-dev#1871)

Translates a title's compute programs from its shader package and has the
driver compile their pipelines ahead of the run, writing the same driver
blobs (same DXIL, root signature, flags) the runtime looks up. Pipelines an
earlier run used go first, each group biggest first, on one driver compile
a core (bounded by memory, --threads N). --records FILE / --used restrict
it to given record hashes / pipeline keys; cached pipelines only load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
…ripts

- docs/linux.md: documents native Linux MSVC cross-compilation via cargo-xwin
  (including the CFLAGS=-FIstring.h workaround for libudis86-sys under clang-cl),
  MinGW fallback, Proton/vkd3d-proton environment variables, tuning switches
  (XCL_PSO_WAIT_MS, XCL_PSO_FRAME_WAIT_MS, XCL_COHERENT_HEAPS/MB, XCL_DRED),
  offline compute PSO precompilation, and amdgpu troubleshooting.
- scripts/linux/build-xwin.sh: portable cargo-xwin workspace build & optional
  --deploy script targeting x86_64-pc-windows-msvc.
- scripts/linux/precompile-pso.sh: portable Proton/Wine wrapper for
  xcl.exe pso-precompile (xcl-dev#1871).

Assisted-by: Antigravity (Gemini 4)
anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
)

Brings main to full parity with upstream/main (de36462):
- xcl-dev#1969: official upstream merge of 64-bit icmp 32-bit lowering and MIMG heap guards
- xcl-dev#1774: size-based commit headroom admission for big driver compiles and
  XCL_PIPELINE_MAX_KB cap for offline --pipelines precompile

Conflicts resolved by keeping HEAD's already-merged xcl-dev#1969 emit.rs (with heap_index),
combining xcl-dev#1996 + xcl-dev#1774 comments in real.rs, and combining xcl-dev#1871 + xcl-dev#1774 in shaders.rs.

Assisted-by: Antigravity (Gemini 4)
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

@JJAutoCompare

Copy link
Copy Markdown

PR #1871 compatibility verification

Tested detached head 27362a08509c7dd79f7eebdf39c4ad29e98e4d6f on STOR-WINLAB. The offline compute cache integration test passed on Arc. The workspace suite had 19 failures, and the new subcommand's --help invocation exited 2.

Environment

Windows 11 Enterprise Evaluation build 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 16 GiB (driver 32.0.101.9175, wave range 8–32, DoublePrecisionFloatShaderOps=0). DXC/DXIL 1.9.2609.5, rustc 1.100.0 (0ef1bc386 2026-11-09), dev/test profiles without debug info, XCL_ADAPTER=A770.

Tested

  • cargo build --workspace and cargo test --workspace --no-run succeeded.
  • cargo test -p xcl pipeline_tests -- --nocapture passed all 5 new tests, covering package lookup, record and pipeline key selection, used-key parsing, job order, and thread limits.
  • cargo test -p xcl --test gpu_compute_e2e offline_compute_pipeline_is_reused_by_a_second_process -- --nocapture passed (1 passed, 0 skipped) under the Arc lock. The synthetic shader exercised the shared shaders --precompile --pipelines path: cache write, reuse in a second process, and rebuild after cache corruption.
  • Global xcl --help exited 0 and listed the new command and options. xcl pso-precompile --help treated the flag as a path and printed no shaders.rpf in --help.
  • One locked cargo test --workspace --no-fail-fast -- --test-threads=4 exited 101. Across 20 result blocks, libtest reported 945 passed, 19 failed, 43 ignored. The log contains 22 SKIPPED lines, which represent no coverage for the skipped paths. All 6 focused tests passed again.

Failures and skips

  • 14 compute PSO creation failures returned 0x80070057, including FP64 cases. Four other GPU assertions failed on fused FMA, sampling LOD, the FP16 high half, and pixel-wave reductions. The test title failed the dynamic depth-bias check.
  • Skips comprised 17 wave64 cases, 3 wave32 forms refused by the translator, 1 heap-window case, and 1 cache-disabled timing case.

Not tested

Retail shaders.rpf through the new subcommand, retail title smoke or startup timing, main baseline, other adapters, and the D3D12 debug layer (d3d12SDKLayers.dll absent). XCL_SAMPLE_* inputs were unset.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1871-suite.log and published this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants