From 5a21f6d3f3fd20ce9e4e64f09f995a96f27e6a69 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 11 Nov 2026 01:36:25 -0800 Subject: [PATCH] METAL2VULKAN_LOG_PASSES: a default-off log of the render passes that name a watched texture A diagnostic to find which pass draws the white at a widget's glass edges in the 27.0.1 guest: the runtime sees every pass's attachments, which the consumer's own logs cannot name. The switch's value is the textures to watch, a comma-separated list of FORMAT:WIDTHxHEIGHT (the format as the notices print it or as Metal names it, `*` for any format or size). At the end of each render encoder that renders into a watched texture, binds one to its fragment stage or makes one resident, the device logs one line (id name metal2vulkan-passes, Info): the render area, its Vulkan render pass instances and draw calls, each attachment (format, size, object ID, label, whether it took its storage form, level, slice, load and store actions as the pass ends, its stand-in and cause), the depth/stencil aspects' actions, the pipeline states its draws drew with, the textures bound to the fragment stage at a draw, the watched resident textures with their stages, and what it watched. A line the same as one printed before is not printed again; a process prints at most 256. Off (unset, empty or 0, or a value it cannot read, said once on stderr), an encoder notes nothing; no behaviour reads it. - crates/metal2vulkan/src/env_vars.rs: the registry row and `log_passes()`, the raw value. - crates/metal2vulkan-runtime/src/pass_log.rs: the filter, the notes, the line and its bound. - render.rs: an encoder's notes, made where the log is on, noted at each draw call, logged at the pass's end once its store actions are settled. - texture.rs: `Texture::took_storage_form`, which the line names. - docs/API.md and the artifact test's list of the runtime's variables name it. Verified: cargo fmt; the build, clippy and the tests run on potluck after this commit (tests::pass_log: the filter's parse and refusals, an entry's match, the once-and-bound rule). --- crates/metal2vulkan-runtime/src/lib.rs | 1 + crates/metal2vulkan-runtime/src/pass_log.rs | 329 ++++++++++++++++++ crates/metal2vulkan-runtime/src/render.rs | 13 + crates/metal2vulkan-runtime/src/tests/mod.rs | 1 + .../src/tests/pass_log.rs | 120 +++++++ crates/metal2vulkan-runtime/src/texture.rs | 6 + .../src/candidate/engine/artifact/tests.rs | 2 +- crates/metal2vulkan/src/env_vars.rs | 21 ++ docs/API.md | 12 + 9 files changed, 504 insertions(+), 1 deletion(-) create mode 100644 crates/metal2vulkan-runtime/src/pass_log.rs create mode 100644 crates/metal2vulkan-runtime/src/tests/pass_log.rs diff --git a/crates/metal2vulkan-runtime/src/lib.rs b/crates/metal2vulkan-runtime/src/lib.rs index 9e216b6af..cb0f18cf0 100644 --- a/crates/metal2vulkan-runtime/src/lib.rs +++ b/crates/metal2vulkan-runtime/src/lib.rs @@ -174,6 +174,7 @@ mod nan_clear; mod neutral; mod noted_apart; mod owned_kernel; +mod pass_log; mod pass_runs; mod pending_audit; mod pending_dispatch; diff --git a/crates/metal2vulkan-runtime/src/pass_log.rs b/crates/metal2vulkan-runtime/src/pass_log.rs new file mode 100644 index 000000000..e337afbd5 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/pass_log.rs @@ -0,0 +1,329 @@ +//! The pass log: a default-off diagnostic, `METAL2VULKAN_LOG_PASSES` (`metal2vulkan::env_vars`), +//! that names each render pass that renders into a texture it watches, binds one to its fragment +//! stage or makes one resident: what such a pass does with its attachments, and what its draws +//! read. +//! +//! - **What it watches.** The switch's value: a comma-separated list of `FORMAT:WIDTHxHEIGHT`, +//! for example `RGBA16Float:128x128,BGRA8Unorm:224x128`. `FORMAT` is a pixel format's name as +//! the notices print it (`RGBA16Float`, `BGRA8UnormSRGB`) or as Metal names it +//! (`MTLPixelFormatRGBA16Float`, `BGRA8Unorm_sRGB`); `*` stands for any format, and a size of +//! `*` for any size. Unset, empty or `0`, the log is off; a value it cannot read turns it off +//! and says why once, on stderr. +//! - **What it prints.** At the end of a render encoder that names a watched texture, one line +//! through the device's message sink at `Info` severity (id name `metal2vulkan-passes`), else +//! on stderr: the render area, its Vulkan render pass instances (more than one where the pass +//! split) and its draw calls; each color attachment (index, format, size, object ID and label, +//! whether its texture took its storage form, level and slice, load and store actions as the +//! pass ends, and the stand-in it renders through, with its cause); the depth/stencil +//! attachment with each aspect's actions; the pipeline states its draws drew with (label and +//! functions); the textures bound to the fragment stage at a draw (index, format, size, object +//! ID and label); the count of textures it made resident and the watched ones among them, with +//! their stages; and what it watched. A line lists at most [`KEPT`] states and fragment +//! textures, each once. +//! - **Its volume.** A line the same as one the process printed before is not printed again, so +//! a pass a frame repeats prints once; and the process prints at most [`LINES`] lines, the last +//! saying so. +//! - **Off, it costs nothing.** The switch is read once; an encoder notes nothing and no line is +//! formatted. On, every render encoder notes its draws' states and fragment textures, and one +//! that names a watched texture formats its line. + +use super::device::lock; +use super::driver_facts::inform_through; +use super::render_pass::{AspectTarget, PassLayout}; +use super::residency::Residency; +use super::{Device, RenderPipelineState, Texture}; +use metal2vulkan::metal::{PixelFormat, RenderStages}; +use std::collections::{BTreeMap, BTreeSet}; +use std::hash::{DefaultHasher, Hash, Hasher}; +use std::sync::{Mutex, OnceLock}; + +/// The id name of the log's messages. +const ID_NAME: &str = "metal2vulkan-passes"; + +/// The most lines a process prints. +pub(crate) const LINES: usize = 256; + +/// The most pipeline states, and the most fragment textures, a pass's line lists. +const KEPT: usize = 32; + +/// A texture the log watches: of `format` and `size`, `None` for any. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub(crate) struct Watched { + pub(crate) format: Option, + pub(crate) size: Option<[u64; 2]>, +} + +impl Watched { + /// Whether it watches a texture of `format`, `width` by `height`. + pub(crate) fn watches(&self, format: PixelFormat, [width, height]: [u64; 2]) -> bool { + self.format.is_none_or(|watched| watched == format) + && self.size.is_none_or(|size| size == [width, height]) + } +} + +/// The textures `value` watches (the module docs), or why it names none. +pub(crate) fn parse(value: &str) -> Result, String> { + value.split(',').map(str::trim).map(entry).collect() +} + +/// The texture one entry of the switch's list watches. +fn entry(entry: &str) -> Result { + let (format, size) = entry + .split_once(':') + .ok_or_else(|| format!("`{entry}` is not FORMAT:WIDTHxHEIGHT"))?; + let format = match format { + "*" => None, + name => { + Some(format_named(name).ok_or_else(|| format!("`{entry}`: no pixel format `{name}`"))?) + } + }; + let size = match size { + "*" => None, + size => { + let side = |side: &str| side.parse::().ok().filter(|&side| side > 0); + let parsed = size + .split_once('x') + .and_then(|(width, height)| Some([side(width)?, side(height)?])); + Some(parsed.ok_or_else(|| format!("`{entry}`: `{size}` is not WIDTHxHEIGHT"))?) + } + }; + Ok(Watched { format, size }) +} + +/// The pixel format named `name`: as the notices print it (its `Debug` name), or as Metal names +/// it, with or without its `MTLPixelFormat` prefix. +fn format_named(name: &str) -> Option { + PixelFormat::ALL + .iter() + .copied() + .find(|&format| { + format!("{format:?}") == name + || format.name().strip_prefix("MTLPixelFormat") == Some(name) + }) + .or_else(|| PixelFormat::from_name(name)) +} + +/// The textures the log watches, read once: none while it is off. +fn watched() -> &'static [Watched] { + static WATCHED: OnceLock> = OnceLock::new(); + WATCHED.get_or_init(|| { + let Some(value) = metal2vulkan::env_vars::log_passes() else { + return Vec::new(); + }; + let value = value.to_string_lossy(); + if value.is_empty() || value == "0" { + return Vec::new(); + } + parse(&value).unwrap_or_else(|why| { + eprintln!("metal2vulkan: METAL2VULKAN_LOG_PASSES={value}: {why}; the pass log is off"); + Vec::new() + }) + }) +} + +/// Whether the log is on. +pub(crate) fn enabled() -> bool { + !watched().is_empty() +} + +/// Whether the log watches `texture`. +fn watches(texture: &Texture) -> bool { + let size = [texture.width(), texture.height()]; + (watched().iter()).any(|watched| watched.watches(texture.pixel_format(), size)) +} + +/// What a render encoder's draws named, for its line at its end, while the log is on. +#[derive(Default)] +pub(crate) struct PassNotes { + /// Its draw calls. + draws: u64, + /// Each pipeline state its draws drew with, once, in the order they first did. + states: Vec, + /// Each texture bound to the fragment stage at a draw, once by index and texture. + fragment: Vec<(u32, Texture)>, +} + +impl PassNotes { + /// Note a draw call with `state`, `fragment` bound to its fragment stage by index. + pub(crate) fn drew( + &mut self, + state: Option<&RenderPipelineState>, + fragment: &BTreeMap, + ) { + self.draws += 1; + if let Some(state) = state { + if self.states.len() < KEPT && !self.states.contains(state) { + self.states.push(state.clone()); + } + } + for (&index, texture) in fragment { + let id = texture.object_id(); + let noted = (self.fragment.iter()).any(|(i, t)| *i == index && t.object_id() == id); + if !noted && self.fragment.len() < KEPT { + self.fragment.push((index, texture.clone())); + } + } + } +} + +/// A texture as a line names it: its format, size, object ID and label, and whether its own +/// image took its storage form (`texture/storage_form.rs`). +fn named(texture: &Texture) -> String { + let label = texture + .label() + .map_or_else(String::new, |label| format!(" {label:?}")); + let storage = match texture.took_storage_form() { + true => ", its storage form", + false => "", + }; + format!( + "{:?} {}x{} object {}{label}{storage}", + texture.pixel_format(), + texture.width(), + texture.height(), + texture.object_id().get(), + ) +} + +/// A pipeline state as a line names it: its label and its functions' names. +fn state_named(state: &RenderPipelineState) -> String { + let label = state + .label() + .map_or_else(String::new, |label| format!("{label:?} ")); + format!("{label}({})", state.function_names().join(", ")) +} + +/// At the end of a render encoder whose draws `notes` noted, rendering into `layout` in +/// `instances` Vulkan render pass instances with `residency` made resident: its line, where it +/// names a watched texture and the process printed no line the same (the module docs). +pub(crate) fn ended( + device: &Device, + notes: &PassNotes, + layout: &PassLayout, + instances: usize, + residency: &Residency, +) { + let mut seen = Vec::new(); + let mut colors = Vec::new(); + for (index, color) in layout.colors.iter().enumerate() { + let Some(color) = color else { + continue; + }; + let target = &color.target; + if watches(&target.texture) { + seen.push(format!("color {index}")); + } + let stand_in = color + .stand_in + .as_ref() + .map_or_else(String::new, |stand_in| { + format!(", through a stand-in ({:?})", stand_in.cause) + }); + colors.push(format!( + "{index}: {} level {} slice {}, load {:?}, store {:?}{stand_in}", + named(&target.texture), + target.level, + target.layer, + color.load, + color.store, + )); + } + let depth_stencil = match layout.depth_stencil.as_ref().filter(|ds| !ds.hidden) { + Some(ds) => { + if watches(&ds.target.texture) { + seen.push("the depth/stencil attachment".to_owned()); + } + let aspect = |name: &str, aspect: Option<&AspectTarget>| { + aspect.map_or_else(String::new, |aspect| { + format!(", {name} load {:?} store {:?}", aspect.load, aspect.store) + }) + }; + format!( + "{}{}{}", + named(&ds.target.texture), + aspect("depth", ds.depth.as_ref()), + aspect("stencil", ds.stencil.as_ref()), + ) + } + None => "none".to_owned(), + }; + let mut fragment = Vec::new(); + for (index, texture) in ¬es.fragment { + if watches(texture) { + seen.push(format!("fragment texture {index}")); + } + fragment.push(format!("{index}: {}", named(texture))); + } + let mut resident = 0; + let mut resident_watched = Vec::new(); + for (texture, stages) in residency.textures_made_in() { + resident += 1; + if watches(texture) { + resident_watched.push(format!("{} in {}", named(texture), stages_named(stages))); + } + } + if !resident_watched.is_empty() { + seen.push(format!("{} resident texture(s)", resident_watched.len())); + } + if seen.is_empty() { + return; + } + let states: Vec = notes.states.iter().map(state_named).collect(); + let [width, height] = layout.extent; + let mut text = format!( + "metal2vulkan: pass: {width}x{height} in {instances} Vulkan render pass instance(s), {} \ + draw call(s); colors [{}]; depth/stencil {depth_stencil}; states [{}]; fragment \ + textures [{}]; {resident} texture(s) resident, watched among them [{}]; it watched {}", + notes.draws, + colors.join("; "), + states.join(", "), + fragment.join("; "), + resident_watched.join("; "), + seen.join(", "), + ); + if fresh(&mut text) { + inform_through(device.shared().instance.sink(), ID_NAME, text); + } +} + +/// The render stages `stages` holds, by name. +fn stages_named(stages: RenderStages) -> String { + let names = [ + (RenderStages::VERTEX, "vertex"), + (RenderStages::FRAGMENT, "fragment"), + (RenderStages::TILE, "tile"), + (RenderStages::OBJECT, "object"), + (RenderStages::MESH, "mesh"), + ]; + let named: Vec<&str> = (names.iter()) + .filter(|(stage, _)| stages.contains(*stage)) + .map(|&(_, name)| name) + .collect(); + match named.is_empty() { + true => "no stage".to_owned(), + false => named.join(" and "), + } +} + +/// Whether to print `text`: the process printed no line the same and fewer than [`LINES`]; the +/// last line it prints says so (the module docs). +fn fresh(text: &mut String) -> bool { + static PRINTED: Mutex> = Mutex::new(BTreeSet::new()); + fresh_in(&PRINTED, text) +} + +/// [`fresh`] against the lines `printed` holds, by hash. +pub(crate) fn fresh_in(printed: &Mutex>, text: &mut String) -> bool { + let mut hasher = DefaultHasher::new(); + text.hash(&mut hasher); + let mut printed = lock(printed); + if printed.len() >= LINES || !printed.insert(hasher.finish()) { + return false; + } + if printed.len() == LINES { + text.push_str(&format!( + "; the pass log's last line (it prints at most {LINES})" + )); + } + true +} diff --git a/crates/metal2vulkan-runtime/src/render.rs b/crates/metal2vulkan-runtime/src/render.rs index c068e8f47..bdff98be6 100644 --- a/crates/metal2vulkan-runtime/src/render.rs +++ b/crates/metal2vulkan-runtime/src/render.rs @@ -308,6 +308,7 @@ use super::linear_merge::{LinearMerge, MERGE_STAGES}; use super::live_bind::{Emptied, LiveBind, Reshape, SettledHere}; use super::nan_clear::{keeps_nan_sign, NanDepthWrite}; use super::owned_kernel::OwnedModule; +use super::pass_log; use super::pass_runs::{Joined, Joining, RunHeld, RunKey, RunMerge, RunWork}; use super::pipeline::Settled; use super::pipeline::{BufferForms, DrawPipeline}; @@ -1710,6 +1711,9 @@ pub(crate) struct RenderLowering { /// A stand-in or the hidden depth and stencil arrived after a pin: no later draw pins /// (`render/snapshot.rs`). pins_frozen: bool, + /// What its draws named, for the pass log's line at its end, while that log is on + /// (`pass_log.rs`). + pass_notes: Option>, } /// What a render encoder's draws retained of their own (their pipeline states, their variants' @@ -2345,6 +2349,7 @@ impl RenderLowering { grouped, pinned_through: 0, pins_frozen: false, + pass_notes: pass_log::enabled().then(Box::default), }, ); Lowering::starting_from(lowering, start) @@ -4363,6 +4368,7 @@ impl RenderLowering { bind_memo, pass_start, pinned_through, + pass_notes, .. } = *self; // The views and sampler descriptions its binds made or found, which the device's next @@ -4445,6 +4451,10 @@ impl RenderLowering { own.texture.degrade_kept_signs(); } } + // The pass's line, where the pass log is on and the pass names a texture it watches. + if let Some(notes) = pass_notes { + pass_log::ended(core.device(), ¬es, &layout, instances.len(), &residency); + } if grouped.is_none() && untouched::changes_nothing(&layout, called, &instances) { core.device().shared().counts.untouched_pass_skipped(); let targets: Vec = (layout.colors.iter().flatten()) @@ -7910,6 +7920,9 @@ impl RenderLowering { empty: bool, ) -> Result<(), Error> { self.sync_heaps(); + if let Some(notes) = self.pass_notes.as_mut() { + notes.drew(self.pipeline.as_ref(), &self.fragment.textures); + } // The encoder's kept draw again, which no call came between: its Vulkan draw alone // (`render/draw_again.rs`), the pipeline state's own where the last draw drew through // another. Any other draw keeps itself in its place where it can, and forgets every diff --git a/crates/metal2vulkan-runtime/src/tests/mod.rs b/crates/metal2vulkan-runtime/src/tests/mod.rs index f0e830b3a..ed285f1a2 100644 --- a/crates/metal2vulkan-runtime/src/tests/mod.rs +++ b/crates/metal2vulkan-runtime/src/tests/mod.rs @@ -355,6 +355,7 @@ mod owned_pushes; mod padding_unobserved; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod pass_end_tiles; +mod pass_log; #[cfg(any(m2v_gpu, m2v_cpu_icd))] mod passing_holds; mod pending_audit; diff --git a/crates/metal2vulkan-runtime/src/tests/pass_log.rs b/crates/metal2vulkan-runtime/src/tests/pass_log.rs new file mode 100644 index 000000000..1fc3abe02 --- /dev/null +++ b/crates/metal2vulkan-runtime/src/tests/pass_log.rs @@ -0,0 +1,120 @@ +//! The pass log's filter and its volume (`pass_log.rs`). + +use crate::pass_log::{fresh_in, parse, Watched, LINES}; +use metal2vulkan::metal::PixelFormat; +use std::collections::BTreeSet; +use std::sync::Mutex; + +/// The textures a value watches: each entry's format and size, a name as the notices print it or +/// as Metal names it, `*` for any; spaces around an entry are left out. +#[test] +fn the_filter_reads_formats_and_sizes() { + let watched = |format, size| Watched { format, size }; + let rgba16f = Some(PixelFormat::RGBA16Float); + assert_eq!( + parse("RGBA16Float:128x128"), + Ok(vec![watched(rgba16f, Some([128, 128]))]) + ); + assert_eq!( + parse("RGBA16Float:128x128, BGRA8Unorm:224x128"), + Ok(vec![ + watched(rgba16f, Some([128, 128])), + watched(Some(PixelFormat::BGRA8Unorm), Some([224, 128])), + ]) + ); + for name in ["MTLPixelFormatRGBA16Float", "RGBA16Float"] { + assert_eq!( + parse(&format!("{name}:1920x1080")), + Ok(vec![watched(rgba16f, Some([1920, 1080]))]), + "{name}" + ); + } + let srgb = Some(PixelFormat::BGRA8UnormSRGB); + for name in [ + "BGRA8UnormSRGB", + "BGRA8Unorm_sRGB", + "MTLPixelFormatBGRA8Unorm_sRGB", + ] { + assert_eq!( + parse(&format!("{name}:*")), + Ok(vec![watched(srgb, None)]), + "{name}" + ); + } + assert_eq!( + parse("*:224x128"), + Ok(vec![watched(None, Some([224, 128]))]) + ); + assert_eq!(parse("*:*"), Ok(vec![watched(None, None)])); +} + +/// A value the log cannot read names what it lacks: no `:`, a format of no name, a size that is +/// not two nonzero sides, an empty entry. +#[test] +fn the_filter_refuses_what_it_cannot_read() { + for (value, why) in [ + ("RGBA16Float", "`RGBA16Float` is not FORMAT:WIDTHxHEIGHT"), + ( + "RGBA16:128x128", + "`RGBA16:128x128`: no pixel format `RGBA16`", + ), + ( + "RGBA16Float:128", + "`RGBA16Float:128`: `128` is not WIDTHxHEIGHT", + ), + ( + "RGBA16Float:0x128", + "`RGBA16Float:0x128`: `0x128` is not WIDTHxHEIGHT", + ), + ( + "RGBA16Float:128x", + "`RGBA16Float:128x`: `128x` is not WIDTHxHEIGHT", + ), + ("RGBA16Float:128x128,", "`` is not FORMAT:WIDTHxHEIGHT"), + ] { + assert_eq!(parse(value), Err(why.to_owned()), "{value}"); + } +} + +/// An entry watches the textures of its format and size, either part any where it is `*`. +#[test] +fn an_entry_watches_its_format_and_size() { + let [entry] = parse("RGBA16Float:128x128").unwrap()[..] else { + panic!("one entry"); + }; + assert!(entry.watches(PixelFormat::RGBA16Float, [128, 128])); + assert!(!entry.watches(PixelFormat::RGBA16Float, [128, 64])); + assert!(!entry.watches(PixelFormat::RGBA16Float, [64, 128])); + assert!(!entry.watches(PixelFormat::BGRA8Unorm, [128, 128])); + let [any_format] = parse("*:128x128").unwrap()[..] else { + panic!("one entry"); + }; + assert!(any_format.watches(PixelFormat::BGRA8Unorm, [128, 128])); + assert!(!any_format.watches(PixelFormat::BGRA8Unorm, [128, 129])); + let [any_size] = parse("BGRA8Unorm:*").unwrap()[..] else { + panic!("one entry"); + }; + assert!(any_size.watches(PixelFormat::BGRA8Unorm, [1, 4096])); + assert!(!any_size.watches(PixelFormat::RGBA8Unorm, [1, 4096])); +} + +/// A line the same as one printed before is not printed again, and no more than [`LINES`] are, +/// the last saying so. +#[test] +fn the_log_prints_each_line_once_and_at_most_its_bound() { + let printed = Mutex::new(BTreeSet::new()); + let mut first = "a pass".to_owned(); + assert!(fresh_in(&printed, &mut first)); + assert_eq!(first, "a pass"); + assert!(!fresh_in(&printed, &mut "a pass".to_owned())); + for n in 1..LINES - 1 { + assert!(fresh_in(&printed, &mut format!("pass {n}")), "line {n}"); + } + let mut last = "the last pass".to_owned(); + assert!(fresh_in(&printed, &mut last)); + assert_eq!( + last, + format!("the last pass; the pass log's last line (it prints at most {LINES})") + ); + assert!(!fresh_in(&printed, &mut "one more".to_owned())); +} diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index 430288cfd..3e1898ee1 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -5207,6 +5207,12 @@ impl Texture { } } + /// Whether the texture's image took its storage form (`texture/storage_form.rs`): what the + /// pass log names (`pass_log.rs`). A texture buffer, which has no image, took none. + pub(crate) fn took_storage_form(&self) -> bool { + self.image().is_ok_and(|image| image.form.plan().is_some()) + } + /// The buffer's bytes a texture buffer is, or `None` for a texture with an image. pub(super) fn texels(&self) -> Option<&Texels> { match self.storage() { diff --git a/crates/metal2vulkan-validation/src/candidate/engine/artifact/tests.rs b/crates/metal2vulkan-validation/src/candidate/engine/artifact/tests.rs index a0dd939ac..37acf544d 100644 --- a/crates/metal2vulkan-validation/src/candidate/engine/artifact/tests.rs +++ b/crates/metal2vulkan-validation/src/candidate/engine/artifact/tests.rs @@ -145,7 +145,7 @@ fn the_runtime_sources_are_the_committed_ones() { ("metal2vulkan-air/src/lib.rs", compile), ("metal2vulkan/src/cache/digest.rs", "the content digest, which defines the artifact rather than acting on it"), ("metal2vulkan/src/cache/mod.rs", "the plan's specialization and variant keys, whose values the plan digest holds, and RUNTIME_VERSION itself, which cannot be among the sources it versions"), - ("metal2vulkan/src/env_vars.rs", "the operational variables' accessors: the runtime reads only METAL2VULKAN_LOG_PIPELINES, METAL2VULKAN_LOG_MEMORY, METAL2VULKAN_LOG_SHADOWS and METAL2VULKAN_PENDING_AUDIT, default-off diagnostics that print and change no run"), + ("metal2vulkan/src/env_vars.rs", "the operational variables' accessors: the runtime reads only METAL2VULKAN_LOG_PIPELINES, METAL2VULKAN_LOG_MEMORY, METAL2VULKAN_LOG_SHADOWS, METAL2VULKAN_LOG_PASSES and METAL2VULKAN_PENDING_AUDIT, default-off diagnostics that print and change no run"), ("metal2vulkan/src/error/mod.rs", "the error vocabulary: the runtime's code decides which error a run reports, and a record keeps the error as reported"), ("metal2vulkan/src/library/mod.rs", compile), ("metal2vulkan/src/lower/access/imageblock.rs", compile), diff --git a/crates/metal2vulkan/src/env_vars.rs b/crates/metal2vulkan/src/env_vars.rs index 2e614c337..ec37c916f 100644 --- a/crates/metal2vulkan/src/env_vars.rs +++ b/crates/metal2vulkan/src/env_vars.rs @@ -87,6 +87,20 @@ pub const REGISTRY: &[EnvVar] = &[ the texels' offset and row pitch, or its own image), and what made it a \ shadow; set to anything but empty or 0", }, + EnvVar { + name: "METAL2VULKAN_LOG_PASSES", + default: "unset (off)", + effect: "metal2vulkan-runtime's diagnostics: the textures to watch, a comma-separated \ + list of FORMAT:WIDTHxHEIGHT (FORMAT as the notices print it or as Metal names \ + it; `*` for any format or any size), for example RGBA16Float:128x128; at the \ + end of each render pass that renders into a watched texture, binds one to its \ + fragment stage or makes one resident, one line through the device's message \ + sink or on stderr: the pass's attachments (format, size, level, slice, object \ + ID and label, load and store actions, stand-in, storage form), its Vulkan \ + render pass instances and draws, its draws' pipeline states and the textures \ + bound to their fragment stage, and what it watched; a line the same as one \ + printed before is not printed again, and at most 256 are; empty or 0 is off", + }, ]; /// Multi-line `--help` block listing every registry var. @@ -137,6 +151,13 @@ pub fn log_shadows() -> bool { .is_some_and(|value| !value.is_empty() && value != "0") } +/// The textures metal2vulkan-runtime's pass log watches, as set (`REGISTRY`): a comma-separated +/// list of `FORMAT:WIDTHxHEIGHT` the runtime parses, empty or `0` for none. A default-off +/// diagnostic: it changes no pass, only what is printed. +pub fn log_passes() -> Option { + std::env::var_os("METAL2VULKAN_LOG_PASSES") +} + /// Whether each metal2vulkan-runtime device runs its pending audit (`REGISTRY`): set, and neither /// empty nor `0`. A default-off diagnostic: it reads timelines and prints, and changes no work. pub fn pending_audit() -> bool { diff --git a/docs/API.md b/docs/API.md index adecaa418..c0a6284f8 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1641,6 +1641,18 @@ texture's image of its stored frame and its twin, a two-plane extended-range tex depth or stencil texture's tiled twin over a surface plane, and a YCbCr texture's converted image and render shadow. A heap texture's shadow, a view's shadow of an image and a texture buffer's staging are not logged. +With `METAL2VULKAN_LOG_PASSES` set to a comma-separated list of `FORMAT:WIDTHxHEIGHT` (the format +as the notices print it or as Metal names it, `*` for any format or any size, for example +`RGBA16Float:128x128`), a device logs a line at the end of each render pass that renders into a +texture of the list, binds one to its fragment stage or makes one resident (id name +`metal2vulkan-passes`, `Info` severity): its render area, Vulkan render pass instances and draw +calls; each attachment's format, size, object ID, label, level, slice, load and store actions, +whether its texture took its storage form, and the stand-in it renders through with its cause; +the pipeline states its draws drew with (label and functions); the textures bound to the fragment +stage at a draw; the watched textures among those it made resident, with their stages; and what +it watched. A line the same as one printed before is not printed again, and a process prints at +most 256. Empty or `0` is off; a value the runtime cannot read turns the log off and says why on +stderr. With `METAL2VULKAN_PENDING_AUDIT` set (or `DeviceOptions::pending_audit`), a device checks, at each `vkBeginCommandBuffer`, each `vkResetCommandPool` of a spare command pool, each command pool given back to its spares and each submission of a command buffer submitted before (one not begun for