From 0eca412a4673f12d28a40b5ed7e9ffefca90454e Mon Sep 17 00:00:00 2001 From: FIocker <4461558+FIocker@users.noreply.github.com> Date: Tue, 24 Nov 2026 01:12:41 +0100 Subject: [PATCH] GPU diagnostics: skip pipelines by shader hash Co-authored-by: Claude Opus 5.5 --- README.md | 1 + crates/victory-gpu/src/draw.rs | 16 ++++++++ crates/victory-gpu/src/pipeline.rs | 65 +++++++++++++++++++++++++++--- 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 81eedb3..304ea8d 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,7 @@ cargo build --profile diag -p victory --features diagnostics # target\diag\vic | `VICTORY_D3D12_DEBUG=1` | host debug layer | | `VICTORY_D3D12_GBV=1` | with the above, GPU-based validation (bad descriptor use reported, not faulted; slow) | | `VICTORY_D3D12_DRED=1` | on a GPU failure, the allocation hit and the commands in flight | +| `VICTORY_SKIP_PIPELINES=,...` | omit draws and dispatches, including indirect ones, whose pipeline contains a listed 16-digit shader hash | | `VICTORY_GPU_TIMING=1` | with the above, each list of a submission run and timed on its own; slow lists logged with their slowest commands | | `VICTORY_D3D12_WARP=1` | host device on the software adapter (slow; cannot reset the driver) | | `VICTORY_AUDIO_CAPTURE=` | records what the title plays (our process only) | diff --git a/crates/victory-gpu/src/draw.rs b/crates/victory-gpu/src/draw.rs index af6ad04..5f1f034 100644 --- a/crates/victory-gpu/src/draw.rs +++ b/crates/victory-gpu/src/draw.rs @@ -333,6 +333,10 @@ impl State { /// As [`State::prepare`], for draws (`mesh` false) or mesh dispatches. fn prepare_for(&mut self, list: &HostList, indexed: bool, mesh: bool) -> bool { + #[cfg(feature = "diagnostics")] + if crate::pipeline::is_skipped(self.pipeline as This) { + return false; + } let Some(p) = crate::pipeline::host_pipeline(self.pipeline as This) else { return false; }; @@ -489,6 +493,12 @@ impl State { /// Runs a dispatch on the host. pub(crate) fn dispatch(&mut self, list: &HostList, x: u32, y: u32, z: u32) { + #[cfg(feature = "diagnostics")] + if crate::pipeline::is_skipped(self.pipeline as This) { + DROPPED.fetch_add(1, Ordering::Relaxed); + crate::pipeline::note_drop(self.pipeline as This); + return; + } let Some(p) = crate::pipeline::host_pipeline(self.pipeline as This) else { once!( pipeline = format_args!("{:#x}", self.pipeline), @@ -935,6 +945,12 @@ impl State { let why = |what: &str| crate::pipeline::note_why(format!("indirect kind {kind}: {what}")); #[cfg(not(feature = "diagnostics"))] let why = |_: &str| {}; + // Skip before the argument clamp can mutate the indirect buffer. + #[cfg(feature = "diagnostics")] + if crate::pipeline::is_skipped(self.pipeline as This) { + crate::pipeline::note_drop(self.pipeline as This); + return false; + } let len = u64::from(stride) * u64::from(max.max(1)); let Some(args) = crate::shadow::find(arguments, len) else { why("arguments outside title buffers"); diff --git a/crates/victory-gpu/src/pipeline.rs b/crates/victory-gpu/src/pipeline.rs index f351c9a..d488d03 100644 --- a/crates/victory-gpu/src/pipeline.rs +++ b/crates/victory-gpu/src/pipeline.rs @@ -207,19 +207,64 @@ pub(crate) fn making() -> u64 { make::waiting() } -/// Draws and dispatches dropped since the last [`take_drops`], by why their -/// pipeline has no host pipeline (diagnostics). +/// Draws and dispatches dropped since the last [`take_drops`], by reason +/// (diagnostics). #[cfg(all(windows, feature = "diagnostics"))] static DROPS: Mutex>> = Mutex::new(None); -/// Counts a draw or dispatch of `this` dropped for want of a host pipeline -/// (diagnostics). +/// Shader hashes as printed in the pipeline diagnostics. +#[cfg(all(windows, feature = "diagnostics"))] +fn parse_skip_hashes(value: &str) -> Vec { + value + .split(',') + .map(str::trim) + .filter(|hash| !hash.is_empty()) + .filter_map(|hash| { + if hash.len() == 16 && hash.bytes().all(|byte| byte.is_ascii_hexdigit()) { + Some(hash.to_ascii_lowercase()) + } else { + tracing::warn!( + hash, + "VICTORY_SKIP_PIPELINES expects 16-digit shader hashes" + ); + None + } + }) + .collect() +} + +#[cfg(all(windows, feature = "diagnostics"))] +fn skipped_shader(p: &Pipeline) -> Option<&str> { + static HASHES: OnceLock> = OnceLock::new(); + let hashes = HASHES.get_or_init(|| { + let value = std::env::var("VICTORY_SKIP_PIPELINES").unwrap_or_default(); + parse_skip_hashes(&value) + }); + if hashes.is_empty() { + return None; + } + p.shaders + .iter() + .find(|shader| hashes.contains(&shader.hash)) + .map(|shader| shader.hash.as_str()) +} + +#[cfg(all(windows, feature = "diagnostics"))] +pub(crate) fn is_skipped(this: This) -> bool { + !this.is_null() && skipped_shader(pipeline(this)).is_some() +} + +/// Counts a draw or dispatch of `this` intentionally skipped or dropped +/// for want of a host pipeline (diagnostics). #[cfg(all(windows, feature = "diagnostics"))] pub(crate) fn note_drop(this: This) { let why = if this.is_null() { Some("no pipeline set".to_owned()) } else { - make::missing(&pipeline(this).host) + let p = pipeline(this); + skipped_shader(p) + .map(|hash| format!("skipped shader {hash}")) + .or_else(|| make::missing(&p.host)) }; if let Some(why) = why { note_why(why); @@ -458,6 +503,16 @@ pub fn save_pipeline_cache() { #[cfg(test)] mod tests { + #[cfg(all(windows, feature = "diagnostics"))] + #[test] + fn skip_hashes_accepts_full_hashes_only() { + assert!(super::parse_skip_hashes(" , ").is_empty()); + assert_eq!( + super::parse_skip_hashes(" 0123456789ABCDEF, 0123456789abcde, xyz, 0011223344556677,"), + ["0123456789abcdef", "0011223344556677"] + ); + } + use super::*; use crate::object::{S_OK, slot};