From 0982250a73970b79076f0f5fd39a9f31be32a2ce 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 | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/crates/xcl/src/shaders.rs b/crates/xcl/src/shaders.rs index 019e948564..5be64c95ea 100644 --- a/crates/xcl/src/shaders.rs +++ b/crates/xcl/src/shaders.rs @@ -1210,6 +1210,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 process is already building elsewhere: AtomicUsize, split_programs: AtomicUsize, @@ -1230,6 +1232,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, @@ -1780,6 +1801,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), @@ -1949,11 +1971,17 @@ 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(), &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 { - driver_cache::write(path, unsafe { std::slice::from_raw_parts(bytes, len) }); + !bytes.is_null() && len != 0 + && driver_cache::write(path, unsafe { std::slice::from_raw_parts(bytes, len) }) + } 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()); } } } @@ -2216,6 +2244,10 @@ fn precompile(input: &Input, limit: usize, windows: u32, split: Option, on if let Some(p) = pipelines { println!("pipelines made on the GPU {}, refused {}", p.made.load(Ordering::Relaxed), p.refused.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}");