From 881f55999995f683b160e58faac9943453e76d7f Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sat, 21 Nov 2026 08:31:27 -0800 Subject: [PATCH] Harness: the busy-GPU row bounds each gauge at both reads, not their growth releases_under_work allowed each gauge to grow by eight iterations' worth between its reads at iterations 100 and 200. A leak of one texture per iteration passes that. The row now asserts an absolute bound at both reads, in what the first iteration added: - releases_waiting and textures: IN_FLIGHT + 1 = 4 iterations' worth (128 and 64), one for each command buffer in flight and one for the one being made; - texture_block_bytes: 2 * IN_FLIGHT - 1 = 5 iterations' worth (655360 for 8 images of 16 KiB). In today's runtime an image is held by the upload that zeroed it until its own command buffer retires, then its release is queued against every command buffer committed so far, so images stay 5 iterations where views stay 3. A runtime that frees the image sooner only lowers the reads. The row's line prints each gauge's two reads and its bound. Checked against every recorded read of the row (rounds 5a04298008 and 7c1baad228, 17 legs): the highest were textures 56, releases_waiting 96 (hawkpoint and the Iris Xe) and texture_block_bytes 557056 (34 images; the 2080 and the 3090), all within the new bounds. A four-iteration bytes bound would have failed those two. The test keeps its name; the round selects it. --- crates/metal2vulkan-harness/src/authored.rs | 9 ++-- crates/metal2vulkan-harness/src/rt/own.rs | 46 +++++++++++++++------ crates/metal2vulkan-harness/tests/rt.rs | 4 +- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/crates/metal2vulkan-harness/src/authored.rs b/crates/metal2vulkan-harness/src/authored.rs index ef014264e..223c2521d 100644 --- a/crates/metal2vulkan-harness/src/authored.rs +++ b/crates/metal2vulkan-harness/src/authored.rs @@ -264,9 +264,12 @@ pub enum OwnRow { /// 1 GiB (four fills of a 256 MiB `Private` buffer), releasing the textures and views, then /// waiting for the command buffer committed two before it, so that three are in flight. The /// releases waiting, the live textures and the texture blocks' bytes, read after the 100th - /// and the 200th iteration with that work in flight, are each to grow by no more than eight - /// iterations' worth between the two reads: a release that waits for work committed after it - /// grows them, and fails the row. + /// and the 200th iteration with that work in flight, are each to stay within its bound at + /// both reads: four iterations' worth of releases waiting and of live textures, one for each + /// command buffer in flight and one for the one being made, and five of the texture blocks' + /// bytes, as the runtime today frees an image two command buffers after its views. A release + /// that waits for more work than that, or a texture never freed, passes a bound and fails the + /// row. ReleasesUnderWork, } diff --git a/crates/metal2vulkan-harness/src/rt/own.rs b/crates/metal2vulkan-harness/src/rt/own.rs index 41e1e3d81..c0ab99367 100644 --- a/crates/metal2vulkan-harness/src/rt/own.rs +++ b/crates/metal2vulkan-harness/src/rt/own.rs @@ -83,8 +83,13 @@ const SIDE: u32 = 64; const FILL_LEN: u64 = 256 << 20; const FILLS: u32 = 4; -/// The iterations' worth a gauge of the releases row may grow from its first read to its second. -const FLAT_ITERATIONS: u64 = 8; +/// The iterations' worth of releases waiting and of live textures the releases row allows at +/// each read: one for each command buffer in flight and one for the one being made. +const HELD_ITERATIONS: u64 = IN_FLIGHT as u64 + 1; + +/// The iterations' worth of the texture blocks' bytes the releases row allows at each read: the +/// iterations whose images today's runtime still holds ([`releases_under_work`]). +const PLACED_ITERATIONS: u64 = 2 * IN_FLIGHT as u64 - 1; /// `row` on a device of its own on `physical`. pub(super) fn run(physical: &rt::PhysicalDevice, row: OwnRow) -> Result { @@ -175,38 +180,55 @@ fn releases_under_work(device: &rt::Device) -> Result { drop((buffer, block)); let (textures, bytes) = each.ok_or("no iteration ran")?; let [first, second] = [&reads[0], &reads[1]]; - // Each texture and view leaves its image or views and its index. + // The bounds, held at both reads, in what the first iteration added. A read follows the wait + // for the command buffer committed `IN_FLIGHT - 1` iterations before. Each texture and view + // leaves its image or views and its index, released at its drop against the command buffers + // committed by then: `HELD_ITERATIONS` iterations' worth of releases waiting and of live + // textures, one for each command buffer in flight and one for the one being made. An image + // stays longer, in today's structure: the upload that zeroed it rides its iteration's command + // buffer and holds it until that retires, and its release is then queued against every + // command buffer committed so far, the `IN_FLIGHT - 1` after its own. So an iteration's views + // stay `IN_FLIGHT` iterations and its images `PLACED_ITERATIONS`, here 3 and 5, and the texture + // blocks' bytes, the images' places, are allowed `PLACED_ITERATIONS` iterations' worth. A + // runtime that frees an image sooner only lowers the reads. let gauges = [ ( "releases_waiting", first.releases_waiting, second.releases_waiting, - 2 * textures, + 2 * textures * HELD_ITERATIONS, + ), + ( + "textures", + first.textures, + second.textures, + textures * HELD_ITERATIONS, ), - ("textures", first.textures, second.textures, textures), ( "texture_block_bytes", first.texture_block_bytes, second.texture_block_bytes, - bytes, + bytes * PLACED_ITERATIONS, ), ]; let shown = (gauges.iter()) - .map(|(gauge, first, second, _)| format!("{gauge} {first} -> {second}")) + .map(|(gauge, first, second, bound)| { + format!("{gauge} {first} -> {second} (at most {bound})") + }) .collect::>() .join(", "); let [at, then] = READ_AFTER; let line = format!( "{shown} from iteration {at} to {then}, {IN_FLIGHT} command buffers writing 1 GiB each in flight" ); - let grown: Vec<&str> = (gauges.iter()) - .filter(|(_, first, second, each)| *second > first + each * FLAT_ITERATIONS) + let over: Vec<&str> = (gauges.iter()) + .filter(|(_, first, second, bound)| first.max(second) > bound) .map(|(gauge, ..)| *gauge) .collect(); - if !grown.is_empty() { + if !over.is_empty() { return Err(format!( - "{} grew by more than {FLAT_ITERATIONS} iterations' worth under the work: {line}", - grown.join(", ") + "{} passed its bound under the work: {line}", + over.join(", ") ) .into()); } diff --git a/crates/metal2vulkan-harness/tests/rt.rs b/crates/metal2vulkan-harness/tests/rt.rs index b5b0dfb65..45f940792 100644 --- a/crates/metal2vulkan-harness/tests/rt.rs +++ b/crates/metal2vulkan-harness/tests/rt.rs @@ -31,8 +31,8 @@ fn a_range_given_back_is_the_next_taken_and_live_buffers_lie_apart() { } /// The runtime's row `releases_under_work` passes its check: textures released while three -/// command buffers keep the GPU running leave no more waiting at the 200th iteration than at the -/// 100th, give or take eight iterations' worth. +/// command buffers keep the GPU running leave, at the 100th and the 200th iteration, no more +/// waiting and live than the work in flight accounts for. #[test] fn releases_under_work_in_flight_stay_flat() { let device = rt::system_default(None).unwrap();