diff --git a/crates/metal2vulkan-rt/src/counters.rs b/crates/metal2vulkan-rt/src/counters.rs index cfdc2e821..36c289ab6 100644 --- a/crates/metal2vulkan-rt/src/counters.rs +++ b/crates/metal2vulkan-rt/src/counters.rs @@ -203,6 +203,8 @@ pub(crate) enum Gauge { Shadows, /// [`Gauges::shadow_bytes`]. ShadowBytes, + /// [`Gauges::textures_copied_over`]. + TexturesCopiedOver, /// [`Gauges::timestamp_pools`]. TimestampPools, /// [`Gauges::imports`]. @@ -327,6 +329,7 @@ struct Atomics { pipeline_cache_bytes: AtomicU64, shadows: AtomicU64, shadow_bytes: AtomicU64, + textures_copied_over: AtomicU64, timestamp_pools: AtomicU64, imports: AtomicU64, /// Segment ends whose barrier reaches the host, for the tests. @@ -680,6 +683,7 @@ impl Counters { Gauge::PipelineCacheBytes => &a.pipeline_cache_bytes, Gauge::Shadows => &a.shadows, Gauge::ShadowBytes => &a.shadow_bytes, + Gauge::TexturesCopiedOver => &a.textures_copied_over, Gauge::TimestampPools => &a.timestamp_pools, Gauge::Imports => &a.imports, } @@ -808,6 +812,7 @@ impl Counters { pipeline_cache_bytes: a.pipeline_cache_bytes.load(Relaxed), shadows: a.shadows.load(Relaxed), shadow_bytes: a.shadow_bytes.load(Relaxed), + textures_copied_over: a.textures_copied_over.load(Relaxed), timestamp_pools: a.timestamp_pools.load(Relaxed), imports: a.imports.load(Relaxed), } @@ -987,6 +992,7 @@ pub struct Metrics { /// and its image of its own ([`Buffer::new_texture`](crate::Buffer::new_texture)): the /// buffer's bytes into the image, in the upload that leads a submission or after a command /// wrote the buffer, and the image back into the buffer after a command wrote the texture. + /// The textures held so are [`Gauges::textures_copied_over`]. pub over_copies: u64, /// The bytes of those copies, which count in [`bytes_copied`](Self::bytes_copied) too. pub over_copy_bytes: u64, @@ -1214,6 +1220,12 @@ pub struct Gauges { pub shadows: u64, /// The bytes of the shadows' memory. pub shadow_bytes: u64, + /// Textures over a buffer the runtime holds in an image of their own, where the device's + /// linear image does not take the texture or the buffer's bytes are imported + /// ([`Buffer::new_texture`](crate::Buffer::new_texture)): the copies between them and their + /// buffers are [`Metrics::over_copies`]. A view is its texture's. The rest of the textures over + /// buffers are in place. + pub textures_copied_over: u64, /// The device's timestamp query pools, each of 4096 queries, a pair for each command buffer /// from its first record until its times are read at its completion: made as command buffers /// need them, and kept until the device drops. diff --git a/crates/metal2vulkan-rt/src/tests/copy_over.rs b/crates/metal2vulkan-rt/src/tests/copy_over.rs index f7f8f8a24..2a61ce46f 100644 --- a/crates/metal2vulkan-rt/src/tests/copy_over.rs +++ b/crates/metal2vulkan-rt/src/tests/copy_over.rs @@ -163,12 +163,15 @@ mod on_device { .unwrap_or_else(|e| panic!("{name}: {e}")); let mut now: Vec = (0..LEN).map(|i| (i % 251) as u8).collect(); write(&buffer, &now); + let held = || device.counters().gauges().textures_copied_over; + let before = held(); let texture = (buffer.new_texture(&descriptor(), None, 0, pitch)) .unwrap_or_else(|e| panic!("{name}: {e}")); assert!( texture.copied_over().is_some(), "{name}: an image of its own" ); + assert_eq!(held(), before + 1, "{name}: the gauge counts it"); let scratch = plain(name, &device, &texels(0)); let queue = device.new_command_queue(4).expect("a queue"); for round in 0..3 { diff --git a/crates/metal2vulkan-rt/src/texture.rs b/crates/metal2vulkan-rt/src/texture.rs index 81b034d80..63acc196a 100644 --- a/crates/metal2vulkan-rt/src/texture.rs +++ b/crates/metal2vulkan-rt/src/texture.rs @@ -602,6 +602,7 @@ impl Drop for TextureInner { // A view's id and image are its parent's, which it keeps. if self.view.is_none() { if let Some(named) = (self.named.as_ref()).filter(|named| named.form == Form::Copied) { + core.counters.fall(Gauge::TexturesCopiedOver); match named.buffer.held().1 { // Its buffer keeps its image where a copy back is owed // (`crate::over::ManagedOvers`). @@ -1204,6 +1205,9 @@ impl Device { // Over a buffer of no device copy, the commands track what they write while it lives // (`crate::over`). let copied = (inner.named.as_ref()).filter(|named| named.form == Form::Copied); + if copied.is_some() { + core.counters.rise(Gauge::TexturesCopiedOver); + } if copied.is_some_and(|named| named.buffer.held().1.is_none()) { core.copied_overs.fetch_add(1, Ordering::Relaxed); } diff --git a/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs b/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs index 6a75fb290..6a6d15d01 100644 --- a/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs +++ b/crates/metal2vulkan-validation/src/replay/new_runtime/mod.rs @@ -350,6 +350,9 @@ pub struct NewRuntime { host_alignment: Option, /// The no-copy buffers by how they play, and the recorded ranges of the stream's blocks. no_copies: imports::NoCopies, + /// The textures over buffers made (not substituted): in place, and held in an image of their + /// own (`rt::Gauges::textures_copied_over` rose across the making). + textures_over: [u64; 2], } /// The objects `values` name, lists included. @@ -656,6 +659,7 @@ fn named(gauges: rt::Gauges) -> Vec<(&'static str, u64)> { ("pipeline_cache_bytes", gauges.pipeline_cache_bytes), ("shadows", gauges.shadows), ("shadow_bytes", gauges.shadow_bytes), + ("textures_copied_over", gauges.textures_copied_over), ("timestamp_pools", gauges.timestamp_pools), ] } @@ -681,6 +685,7 @@ impl NewRuntime { places: Places::new(device.clone()), host_alignment: imports::host_alignment(&device), no_copies: imports::NoCopies::default(), + textures_over: [0; 2], device, objects: HashMap::new(), indices: indices::Indices::default(), @@ -1126,6 +1131,12 @@ impl NewRuntime { addressed(buffer, place) } + /// The runtime's live textures over buffers in an image of their own. A copied texture freed + /// on another thread between two reads moves it too, so a making counts by it nearly always. + fn copied_over(&self) -> u64 { + self.device.counters().gauges().textures_copied_over + } + /// A texture of `descriptor`, at an index where shaders reach it: the next of its class's /// sequence, or for a texture `outside` the program's IDs one outside it. fn new_texture( @@ -1868,7 +1879,12 @@ impl NewRuntime { } let (offset, bytes_per_row) = (uint(call, 1)?, uint(call, 2)?); let make = |index| buffer.new_texture(&descriptor, index, offset, bytes_per_row); - self.texture_or_substitute(call, descriptor.usage, &descriptor, make) + let (gaps, copied) = (self.substitutes.gaps, self.copied_over()); + let made = self.texture_or_substitute(call, descriptor.usage, &descriptor, make)?; + if self.substitutes.gaps == gaps { + self.textures_over[usize::from(self.copied_over() > copied)] += 1; + } + Ok(made) } "newTiledTextureWithDescriptor:offset:bytesPerRow:" => { let descriptor = self.texture_descriptor(call, 0)?; @@ -2430,6 +2446,7 @@ impl Backend for NewRuntime { ("imports", gauges.imports), ("buffers", gauges.buffers), ("textures", gauges.textures), + ("textures_copied_over", gauges.textures_copied_over), ("pipelines", gauges.pipelines), ("kernels", gauges.kernels), ("command_buffers", gauges.command_buffers), @@ -2510,6 +2527,12 @@ impl Backend for NewRuntime { lines.push(self.seconds.line()); } lines.push(self.no_copies.line()); + let [in_place, copied] = self.textures_over; + lines.push(format!( + "textures over buffers {}: {in_place} in place, {copied} in an image of their own, \ + copied at use (the runtime's gauge rose across the making)", + in_place + copied + )); lines.push(self.asides.line()); lines.push(self.places.line()); lines.push(self.unwritten.line()); diff --git a/crates/metal2vulkan-validation/src/runtime_lane/rt_replay.rs b/crates/metal2vulkan-validation/src/runtime_lane/rt_replay.rs index 63e2d1052..8a1fa0fba 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/rt_replay.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/rt_replay.rs @@ -1135,6 +1135,9 @@ fn a_no_copy_buffer_is_an_import_and_a_texture_over_it_the_counted_copy() { kinds.is_some_and(|line| line.starts_with(counted) && line.contains("; bytes-form 1 (")), "{lines:?}" ); + // The texture over the import is held in an image of its own. + let over = "textures over buffers 1: 0 in place, 1 in an image of their own"; + assert!(lines.iter().any(|line| line.starts_with(over)), "{lines:?}"); // The texture's bytes into its image of its own, once. let executed = &report.total.executed; assert_eq!(executed["over_copies"], 1, "{executed:?}"); diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 1e547eb23..af0fd878a 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -2338,6 +2338,7 @@ field metal2vulkan-rt::Gauges.stage_entries pub stage_entries: u64 field metal2vulkan-rt::Gauges.stage_entry_bytes pub stage_entry_bytes: u64 field metal2vulkan-rt::Gauges.staging_bytes pub staging_bytes: u64 field metal2vulkan-rt::Gauges.textures pub textures: u64 +field metal2vulkan-rt::Gauges.textures_copied_over pub textures_copied_over: u64 field metal2vulkan-rt::Gauges.threads pub threads: [u64; THREADS] field metal2vulkan-rt::Gauges.timestamp_pools pub timestamp_pools: u64 field metal2vulkan-rt::HeapRange.block pub block: BlockId