diff --git a/crates/metal2vulkan-runtime/src/counters.rs b/crates/metal2vulkan-runtime/src/counters.rs index 956055b6c..4542f5691 100644 --- a/crates/metal2vulkan-runtime/src/counters.rs +++ b/crates/metal2vulkan-runtime/src/counters.rs @@ -903,6 +903,8 @@ struct Atomics { /// The first [`OVER_COPY_KINDS`] kinds copied, in that order ([`Counters::over_copy_kinds`]). over_kinds: Mutex>, over_copies_unkept_kind: AtomicU64, + /// Each [`OverCause`]'s copies of a kind not kept, at its index. + over_unkept_by_cause: [AtomicU64; OVER_CAUSES], attachment_read_copies: AtomicU64, attachment_read_copy_bytes: AtomicU64, resolve_copies: AtomicU64, @@ -2087,6 +2089,7 @@ impl Counters { let over = |cause: OverCause| { (a.over_by_cause[cause as usize].each_ref()).map(|n| n.load(Relaxed)) }; + let unkept = |cause: OverCause| a.over_unkept_by_cause[cause as usize].load(Relaxed); let stage = |stage: Stage| (a.stages[stage as usize].each_ref()).map(|n| n.load(Relaxed)); let stage_nanos = |stage: Stage| a.stage_nanos[stage as usize].load(Relaxed); // A dispatch's barrier counts in one source, and each barrier in one cause; their sums @@ -2307,6 +2310,20 @@ impl Counters { over_copies_image_memory: over(OverCause::ImageMemory)[0], over_copy_bytes_image_memory: over(OverCause::ImageMemory)[1], over_copies_unkept_kind: a.over_copies_unkept_kind.load(Relaxed), + over_copies_unkept_kind_host_memory: unkept(OverCause::HostMemory), + over_copies_unkept_kind_host_memory_restore: unkept(OverCause::HostMemoryRestore), + over_copies_unkept_kind_dma_buf: unkept(OverCause::DmaBuf), + over_copies_unkept_kind_dma_bufs: unkept(OverCause::DmaBufs), + over_copies_unkept_kind_dedicated: unkept(OverCause::Dedicated), + over_copies_unkept_kind_surface: unkept(OverCause::Surface), + over_copies_unkept_kind_spilled: unkept(OverCause::Spilled), + over_copies_unkept_kind_linear: unkept(OverCause::Linear), + over_copies_unkept_kind_linear_features: unkept(OverCause::LinearFeatures), + over_copies_unkept_kind_view_storage: unkept(OverCause::ViewStorage), + over_copies_unkept_kind_pitch: unkept(OverCause::Pitch), + over_copies_unkept_kind_render_reach: unkept(OverCause::RenderReach), + over_copies_unkept_kind_alignment: unkept(OverCause::Alignment), + over_copies_unkept_kind_image_memory: unkept(OverCause::ImageMemory), attachment_read_copies: a.attachment_read_copies.load(Relaxed), attachment_read_copy_bytes: a.attachment_read_copy_bytes.load(Relaxed), resolve_copies: a.resolve_copies.load(Relaxed), @@ -3400,8 +3417,51 @@ pub struct Metrics { pub over_copy_bytes_image_memory: u64, /// Of [`over_copies`](Self::over_copies), those of a kind /// [`Counters::over_copy_kinds`] does not name: first copied once it held its 256 kinds. Not - /// 0 says the kinds are full and the copies are not all named. + /// 0 says the kinds are full and the copies are not all named; the + /// `over_copies_unkept_kind_` fields say which causes those copies had, one field a cause. pub over_copies_unkept_kind: u64, + /// Of [`over_copies_unkept_kind`](Self::over_copies_unkept_kind), those of + /// [`OverCause::HostMemory`]: they count in [`over_copies_host_memory`](Self::over_copies_host_memory) too. + pub over_copies_unkept_kind_host_memory: u64, + /// Of [`over_copies_unkept_kind`](Self::over_copies_unkept_kind), those of + /// [`OverCause::HostMemoryRestore`]: they count in [`over_copies_host_memory_restore`](Self::over_copies_host_memory_restore) too. + pub over_copies_unkept_kind_host_memory_restore: u64, + /// Of [`over_copies_unkept_kind`](Self::over_copies_unkept_kind), those of + /// [`OverCause::DmaBuf`]: they count in [`over_copies_dma_buf`](Self::over_copies_dma_buf) too. + pub over_copies_unkept_kind_dma_buf: u64, + /// Of [`over_copies_unkept_kind`](Self::over_copies_unkept_kind), those of + /// [`OverCause::DmaBufs`]: they count in [`over_copies_dma_bufs`](Self::over_copies_dma_bufs) too. + pub over_copies_unkept_kind_dma_bufs: u64, + /// Of [`over_copies_unkept_kind`](Self::over_copies_unkept_kind), those of + /// [`OverCause::Dedicated`]: they count in [`over_copies_dedicated`](Self::over_copies_dedicated) too. + pub over_copies_unkept_kind_dedicated: u64, + /// Of [`over_copies_unkept_kind`](Self::over_copies_unkept_kind), those of + /// [`OverCause::Surface`]: they count in [`over_copies_surface`](Self::over_copies_surface) too. + pub over_copies_unkept_kind_surface: u64, + /// Of [`over_copies_unkept_kind`](Self::over_copies_unkept_kind), those of + /// [`OverCause::Spilled`]: they count in [`over_copies_spilled`](Self::over_copies_spilled) too. + pub over_copies_unkept_kind_spilled: u64, + /// Of [`over_copies_unkept_kind`](Self::over_copies_unkept_kind), those of + /// [`OverCause::Linear`]: they count in [`over_copies_linear`](Self::over_copies_linear) too. + pub over_copies_unkept_kind_linear: u64, + /// Of [`over_copies_unkept_kind`](Self::over_copies_unkept_kind), those of + /// [`OverCause::LinearFeatures`]: they count in [`over_copies_linear_features`](Self::over_copies_linear_features) too. + pub over_copies_unkept_kind_linear_features: u64, + /// Of [`over_copies_unkept_kind`](Self::over_copies_unkept_kind), those of + /// [`OverCause::ViewStorage`]: they count in [`over_copies_view_storage`](Self::over_copies_view_storage) too. + pub over_copies_unkept_kind_view_storage: u64, + /// Of [`over_copies_unkept_kind`](Self::over_copies_unkept_kind), those of + /// [`OverCause::Pitch`]: they count in [`over_copies_pitch`](Self::over_copies_pitch) too. + pub over_copies_unkept_kind_pitch: u64, + /// Of [`over_copies_unkept_kind`](Self::over_copies_unkept_kind), those of + /// [`OverCause::RenderReach`]: they count in [`over_copies_render_reach`](Self::over_copies_render_reach) too. + pub over_copies_unkept_kind_render_reach: u64, + /// Of [`over_copies_unkept_kind`](Self::over_copies_unkept_kind), those of + /// [`OverCause::Alignment`]: they count in [`over_copies_alignment`](Self::over_copies_alignment) too. + pub over_copies_unkept_kind_alignment: u64, + /// Of [`over_copies_unkept_kind`](Self::over_copies_unkept_kind), those of + /// [`OverCause::ImageMemory`]: they count in [`over_copies_image_memory`](Self::over_copies_image_memory) too. + pub over_copies_unkept_kind_image_memory: u64, /// Idle allocations the block-maker thread freed: one at a time, each once it had been idle, /// holding no live block, for 250 ms, whatever the device's queues were doing. pub allocations_freed: u64, diff --git a/crates/metal2vulkan-runtime/src/tests/over_causes.rs b/crates/metal2vulkan-runtime/src/tests/over_causes.rs index 205bc7730..13b6fbf60 100644 --- a/crates/metal2vulkan-runtime/src/tests/over_causes.rs +++ b/crates/metal2vulkan-runtime/src/tests/over_causes.rs @@ -65,6 +65,27 @@ fn pair(metrics: &Metrics, cause: OverCause) -> (u64, u64) { } } +/// `cause`'s copies of a kind the counters did not keep, of `metrics`. +fn unkept(metrics: &Metrics, cause: OverCause) -> u64 { + let m = metrics; + match cause { + OverCause::HostMemory => m.over_copies_unkept_kind_host_memory, + OverCause::HostMemoryRestore => m.over_copies_unkept_kind_host_memory_restore, + OverCause::DmaBuf => m.over_copies_unkept_kind_dma_buf, + OverCause::DmaBufs => m.over_copies_unkept_kind_dma_bufs, + OverCause::Dedicated => m.over_copies_unkept_kind_dedicated, + OverCause::Surface => m.over_copies_unkept_kind_surface, + OverCause::Spilled => m.over_copies_unkept_kind_spilled, + OverCause::Linear => m.over_copies_unkept_kind_linear, + OverCause::LinearFeatures => m.over_copies_unkept_kind_linear_features, + OverCause::ViewStorage => m.over_copies_unkept_kind_view_storage, + OverCause::Pitch => m.over_copies_unkept_kind_pitch, + OverCause::RenderReach => m.over_copies_unkept_kind_render_reach, + OverCause::Alignment => m.over_copies_unkept_kind_alignment, + OverCause::ImageMemory => m.over_copies_unkept_kind_image_memory, + } +} + /// Each cause's pair moved from `before` to `after`, in [`CAUSES`] order. fn moved(before: &Metrics, after: &Metrics) -> Vec<(OverCause, (u64, u64))> { CAUSES @@ -140,7 +161,8 @@ fn each_memory_class_counts_its_copies_bytes_alone() { /// The counters name each kind once, at its first copy, in that order, up to 256 kinds; a read /// from a number answers the kinds from it on. Filled past the bound, a copy of a kind first -/// copied after the 256th counts as unkept, each time, and a copy of a kept kind never does. +/// copied after the 256th counts as unkept, each time, under its cause too, and a copy of a kept +/// kind never does. #[test] fn the_counters_name_each_copied_kind_once_up_to_their_bound() { let counters = Counters::new(); @@ -164,6 +186,20 @@ fn the_counters_name_each_copied_kind_once_up_to_their_bound() { let m = counters.metrics(); assert_eq!(m.over_copies_unkept_kind, 4); assert_eq!(m.over_copies, kinds.len() as u64 + 5); + // The three unkept kinds' causes, the first of them copied twice. + let causes: Vec<(OverCause, u64)> = (CAUSES.iter()) + .map(|&cause| (cause, unkept(&m, cause))) + .filter(|&(_, copies)| copies > 0) + .collect(); + let cause = |at: usize| kinds[at].cause; + let expected: [(OverCause, u64); 3] = [ + (cause(OVER_COPY_KINDS), 2), + (cause(OVER_COPY_KINDS + 1), 1), + (cause(OVER_COPY_KINDS + 2), 1), + ]; + assert_eq!(causes, expected); + let sum: u64 = CAUSES.iter().map(|&cause| unkept(&m, cause)).sum(); + assert_eq!(sum, m.over_copies_unkept_kind); } #[cfg(any(m2v_gpu, m2v_cpu_icd))] diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index 44cce20ff..13e280448 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -1548,6 +1548,20 @@ field metal2vulkan-runtime::Metrics.over_copies_render_reach pub over_copies_ren field metal2vulkan-runtime::Metrics.over_copies_spilled pub over_copies_spilled: u64 field metal2vulkan-runtime::Metrics.over_copies_surface pub over_copies_surface: u64 field metal2vulkan-runtime::Metrics.over_copies_unkept_kind pub over_copies_unkept_kind: u64 +field metal2vulkan-runtime::Metrics.over_copies_unkept_kind_alignment pub over_copies_unkept_kind_alignment: u64 +field metal2vulkan-runtime::Metrics.over_copies_unkept_kind_dedicated pub over_copies_unkept_kind_dedicated: u64 +field metal2vulkan-runtime::Metrics.over_copies_unkept_kind_dma_buf pub over_copies_unkept_kind_dma_buf: u64 +field metal2vulkan-runtime::Metrics.over_copies_unkept_kind_dma_bufs pub over_copies_unkept_kind_dma_bufs: u64 +field metal2vulkan-runtime::Metrics.over_copies_unkept_kind_host_memory pub over_copies_unkept_kind_host_memory: u64 +field metal2vulkan-runtime::Metrics.over_copies_unkept_kind_host_memory_restore pub over_copies_unkept_kind_host_memory_restore: u64 +field metal2vulkan-runtime::Metrics.over_copies_unkept_kind_image_memory pub over_copies_unkept_kind_image_memory: u64 +field metal2vulkan-runtime::Metrics.over_copies_unkept_kind_linear pub over_copies_unkept_kind_linear: u64 +field metal2vulkan-runtime::Metrics.over_copies_unkept_kind_linear_features pub over_copies_unkept_kind_linear_features: u64 +field metal2vulkan-runtime::Metrics.over_copies_unkept_kind_pitch pub over_copies_unkept_kind_pitch: u64 +field metal2vulkan-runtime::Metrics.over_copies_unkept_kind_render_reach pub over_copies_unkept_kind_render_reach: u64 +field metal2vulkan-runtime::Metrics.over_copies_unkept_kind_spilled pub over_copies_unkept_kind_spilled: u64 +field metal2vulkan-runtime::Metrics.over_copies_unkept_kind_surface pub over_copies_unkept_kind_surface: u64 +field metal2vulkan-runtime::Metrics.over_copies_unkept_kind_view_storage pub over_copies_unkept_kind_view_storage: u64 field metal2vulkan-runtime::Metrics.over_copies_view_storage pub over_copies_view_storage: u64 field metal2vulkan-runtime::Metrics.over_copy_bytes pub over_copy_bytes: u64 field metal2vulkan-runtime::Metrics.over_copy_bytes_alignment pub over_copy_bytes_alignment: u64