From 3c4891dd4cf7d249d7f818aec05c7150a347504a Mon Sep 17 00:00:00 2001 From: joeypercia Date: Thu, 26 Nov 2026 05:07:56 -0800 Subject: [PATCH] Shaders: a title's preparation workers build split programs' whole forms The workers that build a title's compute pipelines before it starts (pipelines_in_workers) run precompile without a startup state, and only with one does it build a split program's whole form. The title then built each whole form at the program's first ExecuteIndirect, on its own thread (Chain::whole): 15 - 25 s a program cold, 750 KB - 1.1 MB of DXIL. A retail title froze in its world load for minutes on them (RTX 5090, RTX 4070 Ti; KDenKC's finding and change, #2624). precompile now builds the whole form in a preparation worker too (XCL_PRECOMPILE_PARENT set). The first preparation takes longer; the title then finds the whole forms in the driver cache. Assisted-by: Claude Code (Claude Opus 5.5) --- crates/xcl/src/shaders.rs | 5 ++- crates/xcl/tests/gpu_compute_e2e.rs | 53 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs index 67fb3e0dcb..3d7feb2479 100644 --- a/crates/xcl/src/shaders.rs +++ b/crates/xcl/src/shaders.rs @@ -2169,7 +2169,10 @@ fn precompile(input: &Input, limit: usize, windows: u32, split: Option, on Ok(c) => { if let Some(p) = pipelines { p.make(&c); - if startup.is_some() && c.dispatch_chain.as_ref().is_some_and(|plan| plan.pieces.len() >= 2) { + // (a title's preparation worker too: the title would otherwise + // build a split program's whole form at its first ExecuteIndirect, + // on its own thread, 15 – 25 s a program cold) + if (startup.is_some() || std::env::var_os("XCL_PRECOMPILE_PARENT").is_some()) && c.dispatch_chain.as_ref().is_some_and(|plan| plan.pieces.len() >= 2) { p.make_one(&c.dxil, &c.samplers, true, None); } } diff --git a/crates/xcl/tests/gpu_compute_e2e.rs b/crates/xcl/tests/gpu_compute_e2e.rs index 5ffa519a96..5a61afc076 100644 --- a/crates/xcl/tests/gpu_compute_e2e.rs +++ b/crates/xcl/tests/gpu_compute_e2e.rs @@ -306,6 +306,59 @@ fn offline_split_compute_pipeline_is_reused_by_a_second_process() { let _ = fs::remove_dir_all(&dir); } +/// A title's preparation worker (`XCL_PRECOMPILE_PARENT`) leaves the whole form of a split +/// program in the driver cache besides its pieces: the title needs it at a split program's first +/// ExecuteIndirect, and builds it there itself when it is missing. +#[test] +fn a_preparation_worker_also_builds_a_split_programs_whole_form() { + use std::{fs, process::Command}; + let _serial = SERIAL.lock().unwrap_or_else(|e| e.into_inner()); + if xcl::gpu::recomp::dxc::location().is_err() { + runner::skip_test("no DXC"); + return; + } + if !runner::wave32_supported().unwrap_or(false) { + runner::skip_test("no wave32 GPU"); + return; + } + let nonce = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos(); + let dir = std::env::temp_dir().join(format!("xcl-worker-whole-{}-{nonce}", std::process::id())); + let input = dir.join("input"); + let cache = dir.join("cache"); + fs::create_dir_all(&input).unwrap(); + fs::write(input.join("split.bin"), console_cs(&split_program(), 2 << 1 | 1 << 7, [32, 1, 1])).unwrap(); + let out = Command::new(env!("CARGO_BIN_EXE_xcl")) + .arg("shaders") + .arg(&input) + .args(["--precompile", "--pipelines", "--windows", "1"]) + .env("XCL_DXIL_CACHE", &cache) + .env("XCL_DIRECT_DXIL", "1") + .env("XCL_DIRECT_SPLIT_INSTRUCTIONS", "12") + .env("XCL_PSO_DISK_CACHE", "1") + // as `pipelines_in_workers` starts it: this test is its parent + .env("XCL_PRECOMPILE_PARENT", std::process::id().to_string()) + .output() + .unwrap(); + let text = String::from_utf8_lossy(&out.stdout).into_owned(); + assert!(out.status.success(), "{text} +{}", String::from_utf8_lossy(&out.stderr)); + let files: Vec<_> = fs::read_dir(cache.join("driver")).unwrap().flatten().map(|e| e.path()).collect(); + // the split program's pieces, as the precompile counts them ("split compute programs: 1 (N + // pieces)"); the whole form is one more pipeline, its blob kept beside theirs + let pieces: usize = text + .split("split compute programs: 1 (") + .nth(1) + .and_then(|t| t.split(' ').next()) + .and_then(|n| n.parse().ok()) + .unwrap_or_else(|| panic!("no split program: {text}")); + assert!(pieces >= 2, "{text}"); + assert!(text.contains(&format!("pipelines made on the GPU {}, refused 0", pieces + 1)), "the whole form was not built: {text}"); + assert_eq!(files.len(), pieces + 1, "a blob for each piece and the whole form: {files:?} +{text}"); + assert!(files.iter().all(|p| p.metadata().unwrap().len() > 0)); + let _ = fs::remove_dir_all(&dir); +} + /// 16×8 threads per group (two wave64s), s[0:1] = output base and row width, TGID_X/Y in /// s2/s3, thread ids in v0/v1: each thread writes its global (x, y), and through LDS + /// s_barrier the (x, y) of the thread at the mirrored index, which is in the other wave.