From fb573832d32d4c1c1e99a0370cd4f1cebbf1b8d7 Mon Sep 17 00:00:00 2001 From: Prime <215761102+Prime1997@users.noreply.github.com> Date: Sat, 28 Nov 2026 04:27:15 -0800 Subject: [PATCH 1/2] Shaders: prepare whole split fallbacks in the offline CLI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adapt xcl-dev/xcl#2551 (3567b2efdc94617de71e50be77e107991a6bd41c) by Rene / DTsordas to nvidia-dev integration. The ordinary offline pass omitted whole chain forms, leaving the runtime to compile them synchronously when needed. Reuse the existing chain root signature and driver-cache path, and remove the startup-only duplicate call. Preserve WholeSource and earlier memory repairs. Extend synthetic cache reuse and cap coverage; native tests are delegated to the integration owner and have not yet run for this commit. Co-authored-by: René <153442863+DTsordas@users.noreply.github.com> Assisted-by: Codex (GPT-6) --- README.md | 3 +++ crates/xcl/src/shaders.rs | 41 ++++++++++++++++++----------- crates/xcl/tests/gpu_compute_e2e.rs | 13 ++++----- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 978c73b613..80126e889d 100644 --- a/README.md +++ b/README.md @@ -256,6 +256,9 @@ Fill the reusable DXIL cache ahead of a run with the read-only package wrapper. - 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. +- **Offline compute preparation**: `--precompile --pipelines` prepares both split pieces and their + whole fallback, using the same root signature and driver-cache names as runtime indirect dispatch. + Startup workers use the same preparation path. - **`--pipelines` size cap**: a compute program whose DXIL is over 8 MiB and that has no saved blob is left to the runtime instead of being compiled in the pass — those compiles take tens of minutes and gigabytes and stopped the pass on the biggest programs. `XCL_PIPELINE_MAX_KB` diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs index 798a632a46..154c9bb743 100644 --- a/crates/xcl/src/shaders.rs +++ b/crates/xcl/src/shaders.rs @@ -1376,30 +1376,32 @@ mod pipeline_cap_tests { samplers: vec![], }; - pipelines.max_dxil = max_piece; + pipelines.max_dxil = max_piece.max(whole.len()); pipelines.make(&compiled); let p0_path = scratch.0.join(driver_cache::name_for(&piece0, 0, true)); let p1_path = scratch.0.join(driver_cache::name_for(&piece1, 0, true)); let whole_path = scratch.0.join(driver_cache::name_for(&whole, 0, false)); + let whole_chain_path = scratch.0.join(driver_cache::name_for(&whole, 0, true)); assert_eq!(pipelines.split_programs.load(Ordering::Relaxed), 1); assert_eq!(pipelines.split_pieces.load(Ordering::Relaxed), 2); - assert_eq!(pipelines.made.load(Ordering::Relaxed), 2); + assert_eq!(pipelines.made.load(Ordering::Relaxed), 3); assert_eq!(pipelines.refused.load(Ordering::Relaxed), 0); assert_eq!(pipelines.reused.load(Ordering::Relaxed), 0); assert_eq!(pipelines.capped.load(Ordering::Relaxed), 0); assert!(p0_path.is_file() && p0_path.metadata().unwrap().len() > 0, "piece 0 .chain.pso missing"); assert!(p1_path.is_file() && p1_path.metadata().unwrap().len() > 0, "piece 1 .chain.pso missing"); + assert!(whole_chain_path.is_file() && whole_chain_path.metadata().unwrap().len() > 0, "whole form .chain.pso missing"); assert!(!whole_path.exists(), "unsplit whole .pso should not be written for a split compute program"); - // Second pass reuses both cached piece blobs. + // Second pass reuses both pieces and the whole fallback. pipelines.make(&compiled); - assert_eq!(pipelines.reused.load(Ordering::Relaxed), 2); - assert_eq!(pipelines.made.load(Ordering::Relaxed), 4); + assert_eq!(pipelines.reused.load(Ordering::Relaxed), 3); + assert_eq!(pipelines.made.load(Ordering::Relaxed), 6); assert_eq!(pipelines.refused.load(Ordering::Relaxed), 0); // Runtime-side check: the dispatch-chain root signature accepts each cached .chain.pso blob. let chain_rs = recomp::pso::dispatch_chain_root_signature(&pipelines.dev, &[]).expect("dispatch chain RS"); - for (dxil, path) in [(&piece0, &p0_path), (&piece1, &p1_path)] { + for (dxil, path) in [(&piece0, &p0_path), (&piece1, &p1_path), (&whole, &whole_chain_path)] { let blob = std::fs::read(path).expect("read cached .chain.pso"); let desc = D3D12_COMPUTE_PIPELINE_STATE_DESC { pRootSignature: std::mem::ManuallyDrop::new(Some(chain_rs.clone())), @@ -1421,9 +1423,19 @@ mod pipeline_cap_tests { pipelines.make(&compiled); assert!(!p1_path.exists(), "rejected over-cap .chain.pso should be removed"); assert_eq!(pipelines.capped.load(Ordering::Relaxed), 1); - if piece0.len() <= pipelines.max_dxil { - assert_eq!(pipelines.reused.load(Ordering::Relaxed), reused_before + 1); - } + // Valid cached blobs stay reusable even when they exceed the cold-build cap. + assert_eq!(pipelines.reused.load(Ordering::Relaxed), reused_before + 2); + + // A missing whole form obeys the cap too; the two pieces remain independently usable. + assert!(whole.len() > max_piece, "fixture whole form must exceed its pieces"); + std::fs::remove_file(&whole_chain_path).unwrap(); + pipelines.max_dxil = max_piece; + let capped_before = pipelines.capped.load(Ordering::Relaxed); + let made_before = pipelines.made.load(Ordering::Relaxed); + pipelines.make(&compiled); + assert!(!whole_chain_path.exists(), "over-cap cold whole form must not be built"); + assert_eq!(pipelines.capped.load(Ordering::Relaxed), capped_before + 1); + assert_eq!(pipelines.made.load(Ordering::Relaxed), made_before + 2); } } @@ -1471,7 +1483,9 @@ impl Pipelines { /// The compute pipeline of `c` (made and released). When direct translation split the program /// into a dispatch chain of at least two pieces, each piece is built and cached under the /// dispatch-chain root signature (`.chain.pso`) as the runtime does (`dispatch_chain::build`), - /// instead of the unsplit whole container. + /// and so is the whole program: the runtime needs it under that signature when an indirect + /// dispatch cannot run the pieces. Ordinary CLI preparation must cover the same forms as + /// a launch worker (xcl-dev/xcl#2551). fn make(&self, c: &recomp::pso::Compiled) { self.make_with_cache_path(c, None); } @@ -1498,6 +1512,7 @@ impl Pipelines { } }); } + self.make_one(&c.dxil, &c.samplers, true, None); return; } } @@ -2185,12 +2200,6 @@ fn precompile(input: &Input, limit: usize, windows: u32, split: Option, on Ok(c) => { if let Some(p) = pipelines { p.make(&c); - // (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); - } } compiled.fetch_add(1, Ordering::Relaxed) } diff --git a/crates/xcl/tests/gpu_compute_e2e.rs b/crates/xcl/tests/gpu_compute_e2e.rs index 84210f3b33..fb9fc60d30 100644 --- a/crates/xcl/tests/gpu_compute_e2e.rs +++ b/crates/xcl/tests/gpu_compute_e2e.rs @@ -286,24 +286,25 @@ fn offline_split_compute_pipeline_is_reused_by_a_second_process() { let cold = run(); let mut files: Vec<_> = fs::read_dir(cache.join("driver")).unwrap().flatten().map(|e| e.path()).collect(); files.sort(); - let pieces = files.len(); - assert!(pieces >= 2, "expected >= 2 split piece blobs in driver cache, got {files:?}\n{cold}"); + let blobs = files.len(); + assert!(blobs >= 3, "expected >= 2 split piece blobs and a whole fallback, got {files:?}\n{cold}"); + let pieces = blobs - 1; assert!( files.iter().all(|p| p.file_name().and_then(|n| n.to_str()).is_some_and(|n| n.ends_with(".chain.pso"))), "split compute precompile must write only .chain.pso files, got {files:?}" ); assert!(files.iter().all(|p| p.metadata().unwrap().len() > 0)); - assert!(cold.contains(&format!("pipelines made on the GPU {pieces}, refused 0")), "{cold}"); + assert!(cold.contains(&format!("pipelines made on the GPU {blobs}, refused 0")), "{cold}"); assert!(cold.contains(&format!("split compute programs: 1 ({pieces} pieces)")), "{cold}"); let warm = run(); - assert!(warm.contains(&format!("pipelines loaded from the driver cache {pieces}")), "{warm}"); + assert!(warm.contains(&format!("pipelines loaded from the driver cache {blobs}")), "{warm}"); // A corrupt .chain.pso is rejected and rebuilt cleanly while sibling pieces stay reused. fs::write(&files[0], b"invalid cached chain pipeline").unwrap(); let recovered = run(); - assert!(recovered.contains(&format!("pipelines made on the GPU {pieces}, refused 0")), "{recovered}"); - assert!(recovered.contains(&format!("pipelines loaded from the driver cache {}", pieces - 1)), "{recovered}"); + assert!(recovered.contains(&format!("pipelines made on the GPU {blobs}, refused 0")), "{recovered}"); + assert!(recovered.contains(&format!("pipelines loaded from the driver cache {}", blobs - 1)), "{recovered}"); assert!(files[0].metadata().unwrap().len() > b"invalid cached chain pipeline".len() as u64); let _ = fs::remove_dir_all(&dir); } From 73872c0d487c6f7b001a78424e5e49ad819b9fef Mon Sep 17 00:00:00 2001 From: Prime <215761102+Prime1997@users.noreply.github.com> Date: Sat, 28 Nov 2026 05:02:42 -0800 Subject: [PATCH 2/2] Tests: make whole pipeline cap coverage independent of DXIL size The Windows CI compiler emitted a whole fixture no larger than its pieces, so the size-order assertion failed before the cold whole cache-cap check. Rebuild the previously rejected piece first, then remove only the whole cache entry and cap it at its own DXIL length minus one. Assert both cached pieces are reused and the missing whole is capped independently of compiler size ordering. Fixture only; runtime behavior unchanged. Reviewed the fixture and diff; git diff --check passes. Native execution is deferred to the integration owner after gameplay ends. Assisted-by: Codex (GPT-6) --- crates/xcl/src/shaders.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs index 154c9bb743..2419337f31 100644 --- a/crates/xcl/src/shaders.rs +++ b/crates/xcl/src/shaders.rs @@ -1353,8 +1353,8 @@ mod pipeline_cap_tests { &[], ) .expect("piece1 DXC compile"); - // Larger than both pieces so a cap between piece size and whole size proves each piece - // is capped individually rather than against the unsplit whole container. + // A distinct whole form exercises its own cache entry and cold-build cap. Its DXIL + // size relative to either piece depends on the compiler version. let whole = recomp::dxc::compile( "RWByteAddressBuffer mem : register(u2); \ [numthreads(1,1,1)] void main() { \ @@ -1426,16 +1426,28 @@ mod pipeline_cap_tests { // Valid cached blobs stay reusable even when they exceed the cold-build cap. assert_eq!(pipelines.reused.load(Ordering::Relaxed), reused_before + 2); - // A missing whole form obeys the cap too; the two pieces remain independently usable. - assert!(whole.len() > max_piece, "fixture whole form must exceed its pieces"); + // Restore the rejected piece before testing a cold whole with both pieces cached. + pipelines.max_dxil = max_piece.max(whole.len()); + let reused_before = pipelines.reused.load(Ordering::Relaxed); + let made_before = pipelines.made.load(Ordering::Relaxed); + pipelines.make(&compiled); + assert!(p0_path.is_file() && p0_path.metadata().unwrap().len() > 0, "piece 0 .chain.pso missing"); + assert!(p1_path.is_file() && p1_path.metadata().unwrap().len() > 0, "restored piece 1 .chain.pso missing"); + assert_eq!(pipelines.reused.load(Ordering::Relaxed), reused_before + 2); + assert_eq!(pipelines.made.load(Ordering::Relaxed), made_before + 3); + assert_eq!(pipelines.refused.load(Ordering::Relaxed), 0); + + // A missing whole form obeys its cap regardless of how large the cached pieces are. std::fs::remove_file(&whole_chain_path).unwrap(); - pipelines.max_dxil = max_piece; + pipelines.max_dxil = whole.len() - 1; let capped_before = pipelines.capped.load(Ordering::Relaxed); let made_before = pipelines.made.load(Ordering::Relaxed); + let reused_before = pipelines.reused.load(Ordering::Relaxed); pipelines.make(&compiled); assert!(!whole_chain_path.exists(), "over-cap cold whole form must not be built"); assert_eq!(pipelines.capped.load(Ordering::Relaxed), capped_before + 1); assert_eq!(pipelines.made.load(Ordering::Relaxed), made_before + 2); + assert_eq!(pipelines.reused.load(Ordering::Relaxed), reused_before + 2); } }