diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 8569895df..d89a0a061 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -2290,7 +2290,13 @@ while the driver's exit handler waited on a lock, with every runtime thread alre waited, each with its count, time and longest: `first_use_variant_waits` (a kernel's pipeline for a new workgroup size, threadgroup memory lengths or tiles), `first_use_line_waits` (a render content's line-class pipeline) and `first_use_point_waits` (its point-class pipeline). - No dispatch lowers a function. + No dispatch lowers a function. `Counters::variant_makes(from)` answers the kept makes of + kernels' `VkPipeline`s numbered `from` or later, the last 256 to end on the device, each a + `VariantMake`: its key (the `DispatchVariant` its dispatches answer), who started it + (`VariantStart`: the state's creation, a `prepare_dispatch` call, or a dispatch's first use), + when it began and ended in `host_time`, whether it made the pipeline, and the first-use waits + that waited for it, with when the earliest began. A wait on a make another thread started + found that make in flight. Neither type has a Metal counterpart. - `ComputePipelineState::prepare_dispatch(Dispatch, threads_per_threadgroup, threadgroup_memory_lengths)` has no Metal counterpart: it is a hook for a consumer's pre-pass. Metal compiles a compute state whole when the state is made, and so does the state's creation diff --git a/crates/metal2vulkan-runtime/src/counters.rs b/crates/metal2vulkan-runtime/src/counters.rs index c310c5da9..549e9dfa8 100644 --- a/crates/metal2vulkan-runtime/src/counters.rs +++ b/crates/metal2vulkan-runtime/src/counters.rs @@ -1,7 +1,10 @@ //! The device's counters: cumulative metrics and live gauges, as relaxed atomics that are always -//! on, and each timed part's longest call under a lock taken only when a call passes it. Each part -//! of the runtime adds to its own; nothing turns them on or off. +//! on, each timed part's longest call under a lock taken only when a call passes it, and the last +//! variant makes of compute kernels under a lock taken once a make. Each part of the runtime adds +//! to its own; nothing turns them on or off. +use crate::pipeline::DispatchVariant; +use std::collections::VecDeque; use std::sync::atomic::{AtomicU64, Ordering::Relaxed}; use std::sync::{Arc, Mutex, PoisonError}; @@ -102,6 +105,61 @@ pub(crate) enum FirstUse { Points, } +/// The variant makes [`Counters::variant_makes`] keeps: the last this many to end. +pub(crate) const VARIANT_MAKES: usize = 256; + +/// No Metal counterpart: who started a make of a compute kernel's `VkPipeline` for one +/// [`DispatchVariant`] ([`VariantMake::start`]). +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum VariantStart { + /// The state's creation, at a size it knows: a tiling kernel's tiles, an image-only kernel's + /// square workgroups, or an observing kernel's `requiredThreadsPerThreadgroup`. + State, + /// A [`prepare_dispatch`](crate::ComputePipelineState::prepare_dispatch) call, ahead of the + /// dispatches that run it. + Ahead, + /// A dispatch's encoding that found it neither made nor being made, which waited for it: a + /// first-use wait ([`Metrics::first_use_variant_waits`]). + FirstUse, +} + +/// No Metal counterpart: one ended make of a compute kernel's `VkPipeline` +/// ([`Counters::variant_makes`]): the key it was made for, who started it, when it began and +/// ended, and the first-use waits that waited for it. Times are [`host_time`](crate::host_time)'s. +#[non_exhaustive] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct VariantMake { + /// Its number among the device's variant makes, from 0, in the order they ended. + pub number: u64, + /// The key of the dispatches that run it, as + /// [`dispatch_variant`](crate::ComputePipelineState::dispatch_variant) answers them; the + /// states of one content share it. + pub variant: DispatchVariant, + /// Who started it. + pub start: VariantStart, + /// When it began: when it was entered as being made, before its `vkCreateComputePipelines` + /// call. + pub began: u64, + /// When it ended, made or failed. + pub ended: u64, + /// Whether it made the `VkPipeline`. A make that failed is made again by the next call or + /// dispatch that needs it, a make of its own. + pub made: bool, + /// The first-use waits that waited for it: the dispatch that started it where + /// [`start`](Self::start) is [`VariantStart::FirstUse`], and each dispatch that found it being + /// made, a make already in flight. + pub waits: u32, + /// When the earliest of those waits began; 0 where none waited. + pub first_wait: u64, +} + +/// The last [`VARIANT_MAKES`] variant makes to end, oldest first, and the number of the next. +#[derive(Default)] +struct VariantMakes { + next: u64, + kept: VecDeque, +} + /// A [`Part`]'s longest call: its nanoseconds, its bytes, and whether it made an allocation of /// its own ([`Timed::longest_made`]); a [`Site`]'s longest allocation, its nanoseconds and bytes /// ([`SiteAllocations::longest_bytes`]). @@ -472,6 +530,8 @@ struct Atomics { first_use_sites: [[AtomicU64; 3]; 3], /// The makes ahead of a dispatch: their count and total nanoseconds. made_ahead: [AtomicU64; 2], + /// [`Counters::variant_makes`]. + variant_makes: Mutex, blocks_made: AtomicU64, block_bytes_made: AtomicU64, consumer_allocations: AtomicU64, @@ -714,6 +774,29 @@ impl Counters { total.fetch_add(nanos, Relaxed); } + /// One more ended variant make, `make` of its number: kept, and the oldest kept dropped past + /// [`VARIANT_MAKES`]. + pub(crate) fn variant_made(&self, make: impl FnOnce(u64) -> VariantMake) { + let mut makes = (self.atomics.variant_makes.lock()).unwrap_or_else(PoisonError::into_inner); + if makes.kept.len() == VARIANT_MAKES { + makes.kept.pop_front(); + } + let number = makes.next; + makes.next += 1; + makes.kept.push_back(make(number)); + } + + /// No Metal counterpart: the kept variant makes numbered `from` or later, oldest first. The + /// device keeps the last 256 to end, so a reader that passes one past the last number it read + /// gets each make once, and a number missing at the front was dropped before the read. + pub fn variant_makes(&self, from: u64) -> Vec { + let makes = (self.atomics.variant_makes.lock()).unwrap_or_else(PoisonError::into_inner); + (makes.kept.iter()) + .filter(|make| make.number >= from) + .copied() + .collect() + } + /// One more surface wait ([`Metrics::surface_waits`]): `nanos` nanoseconds, for `submissions` /// of the runtime's submissions. pub(crate) fn surface_wait(&self, nanos: u64, submissions: u64) { diff --git a/crates/metal2vulkan-runtime/src/encoder.rs b/crates/metal2vulkan-runtime/src/encoder.rs index 41a3bb190..0d6d2d76c 100644 --- a/crates/metal2vulkan-runtime/src/encoder.rs +++ b/crates/metal2vulkan-runtime/src/encoder.rs @@ -1032,7 +1032,7 @@ impl ComputeCommandEncoder { _ => { let (set, max) = (&self.threadgroup_lengths, limits.max_shared_memory); let lengths = threadgroup_memory(kernel, set, local, max)?; - kernel.pipeline(core, (local, lengths.as_slice(), module == Module::Tiles))? + kernel.pipeline(core, inner.variant(module, local, lengths))? } }; self.last = Some(Last { @@ -1269,6 +1269,14 @@ pub(crate) struct Lengths { } impl Lengths { + /// `count` lengths of 0: a kernel's threadgroup arguments, none of which the encoder set. + pub(crate) fn zeros(count: usize) -> Lengths { + Lengths { + words: [0; BUFFER_SLOTS as usize], + count: count.min(BUFFER_SLOTS as usize) as u8, + } + } + /// One length for each threadgroup argument. pub(crate) fn as_slice(&self) -> &[u32] { &self.words[..usize::from(self.count)] diff --git a/crates/metal2vulkan-runtime/src/lib.rs b/crates/metal2vulkan-runtime/src/lib.rs index 1a7839068..d24a7777a 100644 --- a/crates/metal2vulkan-runtime/src/lib.rs +++ b/crates/metal2vulkan-runtime/src/lib.rs @@ -65,7 +65,7 @@ pub use blit::{BlitCommandEncoder, BufferLayout, TexturePlace}; pub use block::Block; pub use buffer::{Buffer, MAX_BUFFER_LENGTH}; pub use command::{CommandBuffer, CommandBufferError, CommandBufferStatus, DeviceLoss}; -pub use counters::{Counters, Gauges, Metrics, SiteAllocations, Timed}; +pub use counters::{Counters, Gauges, Metrics, SiteAllocations, Timed, VariantMake, VariantStart}; #[cfg(windows)] pub use d3d11::D3d11Plane; pub use depth_stencil::DepthStencilState; diff --git a/crates/metal2vulkan-runtime/src/pipeline.rs b/crates/metal2vulkan-runtime/src/pipeline.rs index 23f734d6b..4920756b7 100644 --- a/crates/metal2vulkan-runtime/src/pipeline.rs +++ b/crates/metal2vulkan-runtime/src/pipeline.rs @@ -41,11 +41,14 @@ //! it and waits for it, then records, so there is one recorded form. Each such wait is a //! first-use wait, counted with its time //! ([`Metrics::first_use_waits`](crate::Metrics::first_use_waits)). No translation runs after the -//! make. +//! make. Each make of a `VkPipeline` is kept in the device's counters as it ends +//! ([`Counters::variant_makes`]): its key, who started it (the state's make, a +//! [`ComputePipelineState::prepare_dispatch`] call or a first use) and the first-use waits that +//! waited for it. use crate::arrays::BINDINGS; use crate::cache; -use crate::counters::{FirstUse, Gauge, Metric}; +use crate::counters::{Counters, FirstUse, Gauge, Metric, VariantMake, VariantStart}; use crate::device::{lock, Core}; use crate::encoder::{ decide, size_checked, threadgroup_memory, Dispatch, Lengths, Module, BUFFER_SLOTS, @@ -110,6 +113,30 @@ pub struct DispatchVariant { lengths: Lengths, } +impl DispatchVariant { + /// Its `VkPipeline`'s key among its kernel's variants. + fn key(&self) -> Key<'_> { + ( + self.local, + self.lengths.as_slice(), + self.module == Module::Tiles, + ) + } +} + +#[cfg(test)] +impl DispatchVariant { + /// For the tests: the key of content `content`'s whole module at one thread. + pub(crate) fn of_content(content: u64) -> DispatchVariant { + DispatchVariant { + content, + module: Module::Whole, + local: [1, 1, 1], + lengths: Lengths::default(), + } + } +} + /// The number the next [`Compiled`] takes: each content made has its own, never reused in the /// process, which a [`DispatchVariant`] names it by. static CONTENTS: AtomicU64 = AtomicU64::new(0); @@ -389,12 +416,20 @@ struct More { /// The variants made past the cells. made: Vec<(Variant, vk::Pipeline)>, /// The variants a thread is making now. - pending: Vec<([u32; 3], Vec, bool)>, + pending: Vec, +} + +/// A variant a thread is making now, and the first-use waits that wait for it +/// ([`VariantMake::waits`]): how many, and when the earliest began. +struct Making { + variant: DispatchVariant, + waits: u32, + first_wait: u64, } impl More { - fn pending(&self, (size, lengths, tiles): Key<'_>) -> Option { - (self.pending.iter()).position(|(s, l, t)| *s == size && l == lengths && *t == tiles) + fn pending(&self, key: Key<'_>) -> Option { + (self.pending.iter()).position(|making| making.variant.key() == key) } } @@ -448,25 +483,41 @@ impl Variants { } } -/// A variant entered as pending under [`Variants`]'s lock, for the thread that makes it: the -/// entry leaves when this ends, made or not, panicking included, and wakes the waiting -/// dispatches. +/// A variant entered as pending under [`Variants`]'s lock, for the thread that makes it, started +/// by `start` at `began`: the entry leaves when this ends, made or not, panicking included, the +/// make is kept in the device's counters ([`Counters::variant_makes`]), and the waiting dispatches +/// wake. struct Pending<'a> { variants: &'a Variants, - key: Key<'a>, + counters: &'a Counters, + variant: DispatchVariant, + start: VariantStart, + began: u64, made: Option<(Variant, vk::Pipeline)>, } impl Drop for Pending<'_> { fn drop(&mut self) { let mut more = lock(&self.variants.more); - if let Some(at) = more.pending(self.key) { - more.pending.swap_remove(at); - } + let at = more.pending(self.variant.key()); + let making = at.map(|at| more.pending.swap_remove(at)); + let made = self.made.is_some(); if let Some((variant, pipeline)) = self.made.take() { self.variants.keep(&mut more, variant, pipeline); } drop(more); + let ended = host_time(); + let (waits, first_wait) = making.map_or((0, 0), |making| (making.waits, making.first_wait)); + self.counters.variant_made(|number| VariantMake { + number, + variant: self.variant, + start: self.start, + began: self.began, + ended, + made, + waits, + first_wait, + }); self.variants.ended.notify_all(); } } @@ -923,19 +974,15 @@ impl Compiled { // A tiling kernel's grids one deep run on one `VkPipeline`, made with the state: its // tiles', or an image-only kernel's square workgroups'. let first = match &compiled.form { - Form::Tiled => Some((&compiled.whole, [GRID_TILE_THREADS, 1, 1], true)), - Form::Square => Some((&compiled.whole, SQUARE, false)), + Form::Tiled => Some((&compiled.whole, Module::Tiles, [GRID_TILE_THREADS, 1, 1])), + Form::Square => Some((&compiled.whole, Module::Whole, SQUARE)), Form::Sized { .. } => None, }; - if let Some((kernel, size, tiles)) = first { - let variant = Variant { - size, - threadgroup_lengths: vec![0; kernel.interface.threadgroups.len()], - tiles, - }; - let made = kernel.make(&compiled.core, &variant)?; - let variants = &kernel.variants; - variants.keep(&mut lock(&variants.more), variant, made); + if let Some((kernel, module, size)) = first { + let lengths = Lengths::zeros(kernel.interface.threadgroups.len()); + let variant = compiled.variant(module, size, lengths); + let more = lock(&kernel.variants.more); + kernel.make_pending(&compiled.core, more, variant, VariantStart::State, None)?; } // An observing kernel at the descriptor's `requiredThreadsPerThreadgroup`, the size its // dispatches give: the `VkPipeline`s a whole grid and a ragged one run, where the module @@ -947,8 +994,8 @@ impl Compiled { let found = compiled.dispatched(dispatch, size, &[]); if let Some((kernel, module, local, lengths)) = found { if kernel.interface.threadgroups.is_empty() { - let key = (local, lengths.as_slice(), module == Module::Tiles); - kernel.make_ahead(&compiled.core, key); + let variant = compiled.variant(module, local, lengths); + kernel.make_ahead(&compiled.core, variant, VariantStart::State); } } } @@ -1543,8 +1590,8 @@ impl ComputePipelineState { return; }; let core = &compiled.core; - let key = (local, lengths.as_slice(), module == Module::Tiles); - if let Some(nanos) = kernel.make_ahead(core, key) { + let variant = compiled.variant(module, local, lengths); + if let Some(nanos) = kernel.make_ahead(core, variant, VariantStart::Ahead) { core.counters.made_ahead(nanos); } } @@ -1572,12 +1619,7 @@ impl ComputePipelineState { let compiled = &self.inner.compiled; let (size, set) = (threads_per_threadgroup, threadgroup_memory_lengths); let (_, module, local, lengths) = compiled.dispatched(dispatch, size, set)?; - Some(DispatchVariant { - content: compiled.id, - module, - local, - lengths, - }) + Some(compiled.variant(module, local, lengths)) } /// `maxTotalThreadsPerThreadgroup`: the translator's answer for the device, which is Metal's @@ -1741,6 +1783,22 @@ impl Compiled { } } + /// The key of the dispatches that run `module` at workgroup size `local` with threadgroup + /// memory `lengths`: its [`DispatchVariant`]. + pub(crate) fn variant( + &self, + module: Module, + local: [u32; 3], + lengths: Lengths, + ) -> DispatchVariant { + DispatchVariant { + content: self.id, + module, + local, + lengths, + } + } + /// What a dispatch of `dispatch` at threadgroup size `size`, with the encoder's threadgroup /// memory lengths `set`, runs, decided as the dispatch decides it: its kernel, its module, its /// workgroup size and its kernel's threadgroup memory lengths. None where the dispatch refuses @@ -1816,13 +1874,18 @@ impl Kernel { unsafe { core.device.create_shader_module(&info, None) } } - /// The `VkPipeline` of the variant `key`, made now where it is not yet: the calling thread - /// waits for it, a first-use wait, so what is recorded never depends on when a compile - /// finishes. Where another thread is making it, the call waits for that make, also a - /// first-use wait, and makes it itself where that one failed. One of the kernel's first - /// [`VARIANT_CELLS`] variants is found with no lock. - pub(crate) fn pipeline(&self, core: &Core, key: Key<'_>) -> Result { + /// The `VkPipeline` of `variant`, made now where it is not yet: the calling thread waits for + /// it, a first-use wait, so what is recorded never depends on when a compile finishes. Where + /// another thread is making it, the call waits for that make, also a first-use wait counted in + /// that make's [`VariantMake::waits`], and makes it itself where that one failed. One of the + /// kernel's first [`VARIANT_CELLS`] variants is found with no lock. + pub(crate) fn pipeline( + &self, + core: &Core, + variant: DispatchVariant, + ) -> Result { let variants = &self.variants; + let key = variant.key(); if let Ok(pipeline) = variants.in_cells(key) { return Ok(pipeline); } @@ -1840,22 +1903,37 @@ impl Kernel { } return Ok(pipeline); } - if more.pending(key).is_none() { + let Some(at) = more.pending(key) else { break; + }; + if !waits { + let making = &mut more.pending[at]; + making.waits = making.waits.saturating_add(1); + making.first_wait = match making.first_wait { + 0 => began, + first => first.min(began), + }; } waits = true; more = (variants.ended.wait(more)).unwrap_or_else(PoisonError::into_inner); } - let pipeline = self.make_pending(core, more, key)?; + let start = VariantStart::FirstUse; + let pipeline = self.make_pending(core, more, variant, start, Some(began))?; waited(core); Ok(pipeline) } - /// [`ComputePipelineState::prepare_dispatch`]'s make of the variant `key`: none where it is - /// made or a thread is making it; else made on the calling thread, and its nanoseconds where - /// it was made. - pub(crate) fn make_ahead(&self, core: &Core, key: Key<'_>) -> Option { + /// A make of `variant` ahead of its dispatches, started by `start`: none where it is made or a + /// thread is making it; else made on the calling thread, and its nanoseconds where it was + /// made. + pub(crate) fn make_ahead( + &self, + core: &Core, + variant: DispatchVariant, + start: VariantStart, + ) -> Option { let variants = &self.variants; + let key = variant.key(); if variants.in_cells(key).is_ok() { return None; } @@ -1864,33 +1942,44 @@ impl Kernel { return None; } let began = host_time(); - let made = self.make_pending(core, more, key).ok(); + let made = self.make_pending(core, more, variant, start, None).ok(); made.map(|_| host_time().saturating_sub(began)) } - /// Makes the variant `key`, which `more`, the lock held, shows neither made nor pending: - /// entered as pending, made with the lock released, and kept. + /// Makes `variant`, which `more`, the lock held, shows neither made nor pending, started by + /// `start`: entered as pending, with the first-use wait that began at `wait` where a dispatch + /// makes it, made with the lock released, kept, and kept in the device's counters + /// ([`Counters::variant_makes`]). fn make_pending( &self, core: &Core, mut more: MutexGuard<'_, More>, - key: Key<'_>, + variant: DispatchVariant, + start: VariantStart, + wait: Option, ) -> Result { - let (size, lengths, tiles) = key; - more.pending.push((size, lengths.to_vec(), tiles)); + more.pending.push(Making { + variant, + waits: u32::from(wait.is_some()), + first_wait: wait.unwrap_or(0), + }); drop(more); let mut pending = Pending { variants: &self.variants, - key, + counters: &core.counters, + variant, + start, + began: host_time(), made: None, }; - let variant = Variant { + let (size, lengths, tiles) = variant.key(); + let made = Variant { size, threadgroup_lengths: lengths.to_vec(), tiles, }; - let pipeline = self.make(core, &variant)?; - pending.made = Some((variant, pipeline)); + let pipeline = self.make(core, &made)?; + pending.made = Some((made, pipeline)); Ok(pipeline) } diff --git a/crates/metal2vulkan-runtime/src/tests/first_use_sites.rs b/crates/metal2vulkan-runtime/src/tests/first_use_sites.rs index 636794018..b10a3b59d 100644 --- a/crates/metal2vulkan-runtime/src/tests/first_use_sites.rs +++ b/crates/metal2vulkan-runtime/src/tests/first_use_sites.rs @@ -1,7 +1,9 @@ //! First-use waits by site, without a device: each wait adds to its own site's count, time and -//! longest, and to the total's. +//! longest, and to the total's. The counters keep the last variant makes to end, past their bound +//! the oldest leaving first. -use crate::counters::{Counters, FirstUse}; +use crate::counters::{Counters, FirstUse, VARIANT_MAKES}; +use crate::{DispatchVariant, VariantMake, VariantStart}; /// A wait at each site adds to that site alone and to the total; the longest is each one's own. #[test] @@ -45,3 +47,35 @@ fn each_first_use_wait_adds_to_its_site_and_the_total() { (4, 26_000, 11_000) ); } + +/// The counters keep the last 256 variant makes to end, numbered from 0 in that order: filled +/// past the bound, the oldest leave first, and a read answers the kept makes from its number on. +#[test] +fn the_counters_keep_the_last_variant_makes_past_their_bound() { + let counters = Counters::new(); + let total = VARIANT_MAKES as u64 + 44; + for content in 0..total { + counters.variant_made(|number| VariantMake { + number, + variant: DispatchVariant::of_content(content), + start: VariantStart::Ahead, + began: 2 * content, + ended: 2 * content + 1, + made: true, + waits: 0, + first_wait: 0, + }); + } + let kept = counters.variant_makes(0); + let numbers: Vec = kept.iter().map(|make| make.number).collect(); + assert_eq!(numbers, (44..total).collect::>()); + assert!( + (kept.iter()).all(|make| make.variant == DispatchVariant::of_content(make.number)), + "each make keeps its own key" + ); + let last: Vec = (counters.variant_makes(total - 3).iter()) + .map(|make| make.number) + .collect(); + assert_eq!(last, [total - 3, total - 2, total - 1]); + assert!(counters.variant_makes(total).is_empty()); +} diff --git a/crates/metal2vulkan-runtime/src/tests/translate.rs b/crates/metal2vulkan-runtime/src/tests/translate.rs index 39fd04b78..b277a547c 100644 --- a/crates/metal2vulkan-runtime/src/tests/translate.rs +++ b/crates/metal2vulkan-runtime/src/tests/translate.rs @@ -751,6 +751,91 @@ mod on_device { }); } + /// Each make of a kernel's `VkPipeline` is kept in the device's counters with its key and who + /// started it: a tiling kernel's tiles by the state's creation, a size `prepare_dispatch` was + /// given by that call, and a size only a dispatch gives by the dispatch, a first-use wait + /// counted on the make. Each key is the one `dispatch_variant` answers for the dispatch, and + /// the first-use waits the dispatch added are the waits its make counts. + #[test] + fn every_device_keeps_each_variant_make_with_its_key_and_who_started_it() { + use crate::{Counters, Dispatch, VariantMake, VariantStart}; + + let (Some(tiling), Some(observing)) = ( + descriptor("a1_bool_from_float"), + descriptor("icb_replay_grid_template"), + ) else { + return; + }; + let next = |counters: &Counters| { + (counters.variant_makes(0).last()).map_or(0, |make| make.number + 1) + }; + let one = |name: &str, makes: Vec, what: &str| -> VariantMake { + assert_eq!(makes.len(), 1, "{name}: {what}: {makes:?}"); + let make = makes[0]; + assert!( + make.made && make.began <= make.ended, + "{name}: {what}: {make:?}" + ); + make + }; + each_device("variant_makes", |name, _, device| { + let counters = device.counters(); + let from = next(&counters); + let tiles = state(name, &device, &tiling); + let make = one(name, counters.variant_makes(from), "the state's tiles"); + let key = tiles.dispatch_variant(Dispatch::Threads([300, 1, 1]), [4, 1, 1], &[]); + assert_eq!( + (Some(make.variant), make.start, make.waits, make.first_wait), + (key, VariantStart::State, 0, 0), + "{name}: the state's tiles" + ); + + let state = state(name, &device, &observing); + let length = |size: [u32; 3]| (4 * size.iter().product::()).next_multiple_of(16); + let (grid, size) = ([8, 4, 1], [4, 2, 1]); + let lengths = [(0, length(size))]; + let from = next(&counters); + state.prepare_dispatch(Dispatch::Threads(grid), size, &lengths); + let make = one(name, counters.variant_makes(from), "prepare_dispatch"); + let key = state.dispatch_variant(Dispatch::Threads(grid), size, &lengths); + assert_eq!( + (Some(make.variant), make.start, make.waits), + (key, VariantStart::Ahead, 0), + "{name}: prepare_dispatch" + ); + + let (groups, size) = ([3, 2, 1], [2, 2, 1]); + let lengths = [(0, length(size))]; + let (from, before) = (next(&counters), counters.metrics()); + grid_template_run( + name, + &device, + &state, + (groups, size, How::Groups), + length(size), + ) + .unwrap_or_else(|error| panic!("{name}: {error}")); + let after = counters.metrics(); + let make = one(name, counters.variant_makes(from), "the first use"); + let key = state.dispatch_variant(Dispatch::Threadgroups(groups), size, &lengths); + assert_eq!( + (Some(make.variant), make.start, make.waits), + (key, VariantStart::FirstUse, 1), + "{name}: the first use" + ); + assert_eq!( + after.first_use_variant_waits - before.first_use_variant_waits, + 1, + "{name}: the first use's wait" + ); + assert!( + make.first_wait > 0 && make.first_wait <= make.began, + "{name}: the wait began before the make: {make:?}" + ); + println!("{name}: variant makes kept: the state's, prepare_dispatch's, a first use's"); + }); + } + /// A state's make counts the time of its `vkCreateComputePipelines` calls in /// `Metrics::pipeline_creation_nanos` and of its calls into the translator in /// `translation_nanos`: each above 0, and the two, made on the make's own thread, within the diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 6fb7ad7d8..e28c0a739 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -791,6 +791,7 @@ enum metal2vulkan-runtime::StoreAction #[derive(Clone, Copy, Debug, Default, Par enum metal2vulkan-runtime::SurfaceCopy #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[non_exhaustive] pub enum SurfaceCopy enum metal2vulkan-runtime::SurfaceForm #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum SurfaceForm enum metal2vulkan-runtime::TextureViewKind #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum TextureViewKind +enum metal2vulkan-runtime::VariantStart #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum VariantStart enum metal2vulkan-runtime::VisibilityResultMode #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum VisibilityResultMode enum metal2vulkan-runtime::floor::Missing #[derive(Clone, Debug, PartialEq, Eq)] #[non_exhaustive] pub enum Missing enum metal2vulkan::bind::AccessClass #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[non_exhaustive] pub enum AccessClass @@ -1882,6 +1883,14 @@ field metal2vulkan-runtime::Timed.over_1_ms pub over_1_ms: u64 field metal2vulkan-runtime::Timed.over_20_ms pub over_20_ms: u64 field metal2vulkan-runtime::Timed.over_5_ms pub over_5_ms: u64 field metal2vulkan-runtime::Timed.total_nanos pub total_nanos: u64 +field metal2vulkan-runtime::VariantMake.began pub began: u64 +field metal2vulkan-runtime::VariantMake.ended pub ended: u64 +field metal2vulkan-runtime::VariantMake.first_wait pub first_wait: u64 +field metal2vulkan-runtime::VariantMake.made pub made: bool +field metal2vulkan-runtime::VariantMake.number pub number: u64 +field metal2vulkan-runtime::VariantMake.start pub start: VariantStart +field metal2vulkan-runtime::VariantMake.variant pub variant: DispatchVariant +field metal2vulkan-runtime::VariantMake.waits pub waits: u32 field metal2vulkan-runtime::VertexDescriptor.attributes pub attributes: BTreeMap field metal2vulkan-runtime::VertexDescriptor.layouts pub layouts: BTreeMap field metal2vulkan-runtime::Viewport.height pub height: f64 @@ -6546,6 +6555,7 @@ method metal2vulkan-runtime::ComputePipelineState::texture_accesses pub fn textu method metal2vulkan-runtime::ComputePipelineState::thread_execution_width pub fn thread_execution_width(&self) -> u32 method metal2vulkan-runtime::Counters::gauges pub fn gauges(&self) -> Gauges method metal2vulkan-runtime::Counters::metrics pub fn metrics(&self) -> Metrics +method metal2vulkan-runtime::Counters::variant_makes pub fn variant_makes(&self, from: u64) -> Vec method metal2vulkan-runtime::DepthStencilState::descriptor pub fn descriptor(&self) -> &DepthStencilDescriptor method metal2vulkan-runtime::DepthStencilState::precision_note pub fn precision_note(&self) -> Option method metal2vulkan-runtime::Device::argument_buffers_support pub fn argument_buffers_support(&self) -> ArgumentBuffersTier @@ -7626,6 +7636,7 @@ struct metal2vulkan-runtime::TextureLevelQuery #[derive(Clone, Copy, Debug, Part struct metal2vulkan-runtime::TexturePlace #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub struct TexturePlace struct metal2vulkan-runtime::TextureSwizzleChannels #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct TextureSwizzleChannels struct metal2vulkan-runtime::Timed #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[non_exhaustive] pub struct Timed +struct metal2vulkan-runtime::VariantMake #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[non_exhaustive] pub struct VariantMake struct metal2vulkan-runtime::VertexDescriptor #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[non_exhaustive] pub struct VertexDescriptor struct metal2vulkan-runtime::Viewport #[derive(Clone, Copy, Debug, PartialEq)] pub struct Viewport struct metal2vulkan-runtime::floor::BelowFloor #[derive(Clone, Debug, PartialEq, Eq)] pub struct BelowFloor @@ -9494,6 +9505,9 @@ variant metal2vulkan-runtime::TextureViewKind::PixelFormat PixelFormat variant metal2vulkan-runtime::TextureViewKind::Slices Slices variant metal2vulkan-runtime::TextureViewKind::SurfacePixelFormat SurfacePixelFormat variant metal2vulkan-runtime::TextureViewKind::TextureType TextureType +variant metal2vulkan-runtime::VariantStart::Ahead Ahead +variant metal2vulkan-runtime::VariantStart::FirstUse FirstUse +variant metal2vulkan-runtime::VariantStart::State State variant metal2vulkan-runtime::VisibilityResultMode::Boolean Boolean variant metal2vulkan-runtime::VisibilityResultMode::Counting Counting variant metal2vulkan-runtime::VisibilityResultMode::Disabled Disabled