Runtime test: an unkept over-copy kind counts under its cause too (red)

Metrics::over_copies_unkept_kind counts the over-copies whose kind the counters did not keep,
the 256 kinds being full, as one number, so a reader cannot say which cause those copies had:
a consumer's walk on the Radeon 780M showed 138 of them in one arm of four, and nothing named
their cause.

This adds one field a cause, over_copies_unkept_kind_<cause>, beside the cause's pair
(over_copies_<cause> and over_copy_bytes_<cause>), and extends
the_counters_name_each_copied_kind_once_up_to_their_bound: filled past the bound with kinds of
the causes in turn, the three unkept kinds (dedicated twice, surface and spilled once each) must
count under their causes, and the causes must sum to the aggregate. The fields are read from
counters that nothing moves yet, so the test fails: every cause reads 0 against 2, 1 and 1.

The API signature table is blessed for the 14 fields. The runtime-sources pin does not move
(counters.rs is not among its inputs).
This commit is contained in:
Anees Iqbal committed 2026-12-03 08:40:28 -08:00
1 parent b531238180
commit 269e501b4f
3 files changed
+112 -2

No files matched your search

+61 -1
View File
@@ -903,6 +903,8 @@ struct Atomics {
/// The first [`OVER_COPY_KINDS`] kinds copied, in that order ([`Counters::over_copy_kinds`]).
over_kinds: Mutex<Vec<OverCopyKind>>,
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,
@@ -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))]
@@ -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
Can't render this file because it is too large.