diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs index 0cd2ed7b3a..45091eb2be 100644 --- a/crates/xcl/src/shaders.rs +++ b/crates/xcl/src/shaders.rs @@ -1356,30 +1356,35 @@ mod pipeline_cap_tests { samplers: vec![], }; - pipelines.max_dxil = max_piece; + // a cap that lets every piece and the whole form through + 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); + // both pieces and the whole form, all under the dispatch-chain root signature: the runtime + // builds the whole form there too (`Chain::whole`, `.chain.pso`) + 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 all three cached blobs. 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())), @@ -1398,12 +1403,13 @@ mod pipeline_cap_tests { std::fs::write(&p1_path, b"corrupt chain blob").expect("corrupt piece1 blob"); pipelines.max_dxil = piece1.len() - 1; let reused_before = pipelines.reused.load(Ordering::Relaxed); + let capped_before = pipelines.capped.load(Ordering::Relaxed); 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); - } + assert_eq!(pipelines.capped.load(Ordering::Relaxed), capped_before + 1); + // the whole form's blob is good: reused, cap or not + let piece0_reused = usize::from(piece0.len() <= pipelines.max_dxil); + assert_eq!(pipelines.reused.load(Ordering::Relaxed), reused_before + piece0_reused + 1); } } @@ -1443,7 +1449,8 @@ 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 builds it under that root signature too + /// (`Chain::whole`), on the title's thread, for what the pieces cannot run (an ExecuteIndirect). fn make(&self, c: &recomp::pso::Compiled) { self.make_with_cache_path(c, None); } @@ -1470,6 +1477,7 @@ impl Pipelines { } }); } + self.make_one(&c.dxil, &c.samplers, true, None); return; } } diff --git a/crates/xcl/tests/gpu_compute_e2e.rs b/crates/xcl/tests/gpu_compute_e2e.rs index ce77d502e0..0eed97494b 100644 --- a/crates/xcl/tests/gpu_compute_e2e.rs +++ b/crates/xcl/tests/gpu_compute_e2e.rs @@ -198,24 +198,26 @@ 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}"); + // every piece and the whole form (what the runtime builds for an ExecuteIndirect) + let blobs = files.len(); + let pieces = blobs - 1; + assert!(pieces >= 2, "expected >= 2 split piece blobs and the whole form's in driver cache, got {files:?}\n{cold}"); 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); }