From d36718ca18c07d8d4697b6b055dd614cd4997205 Mon Sep 17 00:00:00 2001 From: bmjask <> Date: Thu, 26 Nov 2026 01:25:24 -0800 Subject: [PATCH] Shaders: report driver-cache write failures A successful offline driver compile could silently fail to persist its blob and repeat the same expensive work on the next run. Count attempted persistence failures, warn once with the affected path, and include the total in the preparation summary without changing completion semantics. Assisted-by: Codex (GPT-5.6-sol) --- crates/xcl/src/shaders.rs | 41 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs index 62120aa2fd..506e50c12b 100644 --- a/crates/xcl/src/shaders.rs +++ b/crates/xcl/src/shaders.rs @@ -1328,6 +1328,8 @@ struct Pipelines { made: AtomicUsize, refused: AtomicUsize, reused: AtomicUsize, + /// pipelines made successfully whose driver blob could not be persisted + write_failures: AtomicUsize, /// pipelines an OS-backed claim proves another preparation process is already building elsewhere: AtomicUsize, split_programs: AtomicUsize, @@ -1348,6 +1350,25 @@ struct Pipelines { cache_dir: Option, } +fn record_driver_blob_write(wrote: bool, failures: &AtomicUsize) -> Option { + (!wrote).then(|| failures.fetch_add(1, Ordering::Relaxed) + 1) +} + +#[cfg(test)] +mod pipeline_write_tests { + use super::record_driver_blob_write; + use std::sync::atomic::{AtomicUsize, Ordering}; + + #[test] + fn only_failed_driver_blob_writes_are_counted() { + let failures = AtomicUsize::new(0); + assert_eq!(record_driver_blob_write(true, &failures), None); + assert_eq!(record_driver_blob_write(false, &failures), Some(1)); + assert_eq!(record_driver_blob_write(false, &failures), Some(2)); + assert_eq!(failures.load(Ordering::Relaxed), 2); + } +} + #[derive(Clone, Debug, Eq, Hash, PartialEq)] struct PipelineCacheIdentity { dxil_len: usize, @@ -1926,6 +1947,7 @@ impl Pipelines { made: AtomicUsize::new(0), refused: AtomicUsize::new(0), reused: AtomicUsize::new(0), + write_failures: AtomicUsize::new(0), elsewhere: AtomicUsize::new(0), split_programs: AtomicUsize::new(0), split_pieces: AtomicUsize::new(0), @@ -2136,14 +2158,25 @@ impl Pipelines { desc.CachedPSO = D3D12_CACHED_PIPELINE_STATE::default(); let pso = unsafe { self.dev.CreateComputePipelineState::(&desc) }; if let (Some(path), Ok(pso)) = (path.as_deref().filter(|_| _claim.is_some() || cached.is_some()), &pso) { - if let Ok(blob) = unsafe { pso.GetCachedBlob() } { + let wrote = if let Ok(blob) = unsafe { pso.GetCachedBlob() } { let bytes = unsafe { blob.GetBufferPointer() }.cast::(); let len = unsafe { blob.GetBufferSize() }; if !bytes.is_null() && len != 0 { let bytes = unsafe { std::slice::from_raw_parts(bytes, len) }; - if driver_cache::write(path, bytes) { + let wrote = driver_cache::write(path, bytes); + if wrote { if let Some(((book, layout), _)) = receipt { book.record(warm_blobs::stamp(path, layout, bytes)); } } + wrote + } else { + false + } + } else { + false + }; + if let Some(failures) = record_driver_blob_write(wrote, &self.write_failures) { + if failures == 1 { + crate::xlog_warn!("Shader preparation: failed to persist driver blob {}; this pipeline will be rebuilt on the next run", path.display()); } } } @@ -3261,6 +3294,10 @@ fn precompile(input: &Input, limit: usize, windows: u32, split: Option, on println!("previously verified native compute pipelines {}", p.verified.load(Ordering::Relaxed)); } println!("pipelines loaded from the driver cache {}", p.reused.load(Ordering::Relaxed)); + let write_failures = p.write_failures.load(Ordering::Relaxed); + if write_failures != 0 { + println!("pipeline driver-cache writes failed {write_failures}"); + } let elsewhere = p.elsewhere.load(Ordering::Relaxed); if elsewhere != 0 { println!("pipelines left to another preparation process {elsewhere}");