From c248d8202f0458bc72dca2b093a73009d90100b3 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 19 Nov 2026 07:02:11 -0800 Subject: [PATCH] conformance: two more tracked fence-free cases, behind no busy command buffer and behind one The planner wants to separate the two causes behind fence-none-tracked-behind-busy's answer (Y held none of the updater's words): the blit form, or the busy work queued ahead of the writer. - fence-none-tracked: the same blit form with nothing ahead of the writer. - fence-none-tracked-behind-one: the same with one busy command buffer ahead. FenceShape::TrackedBehindBusy becomes FenceShape::Tracked { busy }. The busy count is in the shape's input words, so the three tracked cases record apart. All six re-record together on the M3. --- .../src/cases/fence_orders.rs | 34 +++++++++++-------- .../src/fence_orders.rs | 21 +++++++----- .../src/metal_side.rs | 12 +++---- .../src/rt_side/fences.rs | 11 +++--- crates/metal2vulkan-conformance/src/tests.rs | 4 ++- 5 files changed, 47 insertions(+), 35 deletions(-) diff --git a/crates/metal2vulkan-conformance/src/cases/fence_orders.rs b/crates/metal2vulkan-conformance/src/cases/fence_orders.rs index daab9ccaf..af3b8525c 100644 --- a/crates/metal2vulkan-conformance/src/cases/fence_orders.rs +++ b/crates/metal2vulkan-conformance/src/cases/fence_orders.rs @@ -1,7 +1,7 @@ //! What a fence orders between two queues, measured on Metal, and what Metal's hazard tracking //! orders between them with no fence ([`crate::fence_orders`] holds the vocabulary). //! -//! Four cases, each one experiment of an **updater** on one queue, which fills a buffer X, and a +//! Six cases, each one experiment of an **updater** on one queue, which fills a buffer X, and a //! **waiter** on another, committed after it, which copies X into a buffer Y: //! //! - [`ORDERED`]: X and Y untracked, so only the fence orders the two. The updater runs a long job, @@ -12,21 +12,20 @@ //! before the release, and Y holds the words it held before. //! - [`EMPTY_WAITER`]: the waiter's encoder only waits on the fence. It completes after the //! updater: X holds the updater's words when its completed handler runs. -//! - [`TRACKED_BEHIND_BUSY`]: no fence, X and Y tracked, and the updater committed behind three -//! busy command buffers of its queue. Metal's hazard tracking runs the waiter after it: Y holds -//! the updater's words. +//! - [`TRACKED`], [`TRACKED_BEHIND_ONE`], [`TRACKED_BEHIND_BUSY`]: no fence, X and Y tracked, and +//! the updater committed behind none, one or three busy command buffers of its queue: what +//! Metal's hazard tracking orders between two queues by itself. Behind three, the M3 Max ran the +//! waiter without the updater's words. //! -//! These are the answers the probe `probes/cross_queue_fence_held_update.m` measured with compute -//! dispatches on an Apple M3 Max under macOS 27.0.1; the recordings hold what Metal answers for -//! this blit form. +//! The first three are the answers the probe `probes/cross_queue_fence_held_update.m` measured +//! with compute dispatches on an Apple M3 Max under macOS 27.0.1; the recordings hold what Metal +//! answers for this blit form. //! //! Every wait is bounded and the one command buffer held is held by an event the probe raises, so //! nothing here can hang; nothing renders, nothing dispatches and no loop runs on the GPU. use crate::case::{Abort, Case, Input, MetalSource, Side}; -use crate::fence_orders::{ - FenceShape, BUSY, BYTES, HELD_BOUND, LONG_FILLS, LONG_FILL_BYTES, WRITTEN, -}; +use crate::fence_orders::{FenceShape, BYTES, HELD_BOUND, LONG_FILLS, LONG_FILL_BYTES, WRITTEN}; use crate::transcript::{Node, Observed, Sites}; /// A fence update on one queue, waited on by another's command buffer committed after it. @@ -41,6 +40,12 @@ pub const EMPTY_WAITER: &str = "fence-empty-waiter"; /// No fence: tracked buffers, the writer behind three busy command buffers of its queue. pub const TRACKED_BEHIND_BUSY: &str = "fence-none-tracked-behind-busy"; +/// No fence: tracked buffers, the writer behind one busy command buffer of its queue. +pub const TRACKED_BEHIND_ONE: &str = "fence-none-tracked-behind-one"; + +/// No fence: tracked buffers, nothing ahead of the writer on its queue. +pub const TRACKED: &str = "fence-none-tracked"; + /// The site each case's answer sits at. const AT: &str = "order"; @@ -50,13 +55,15 @@ pub struct FenceOrderCase { shape: FenceShape, } -/// The four cases. +/// The six cases. pub fn all() -> Vec { [ (ORDERED, FenceShape::Ordered), (HELD_UPDATER, FenceShape::HeldUpdater), (EMPTY_WAITER, FenceShape::EmptyWaiter), - (TRACKED_BEHIND_BUSY, FenceShape::TrackedBehindBusy), + (TRACKED, FenceShape::Tracked { busy: 0 }), + (TRACKED_BEHIND_ONE, FenceShape::Tracked { busy: 1 }), + (TRACKED_BEHIND_BUSY, FenceShape::Tracked { busy: 3 }), ] .into_iter() .map(|(name, shape)| FenceOrderCase { name, shape }) @@ -83,7 +90,6 @@ impl Case for FenceOrderCase { fn inputs(&self) -> Result, String> { let mut job = LONG_FILL_BYTES.to_le_bytes().to_vec(); job.extend(LONG_FILLS.to_le_bytes()); - job.extend((BUSY as u64).to_le_bytes()); job.extend((HELD_BOUND.as_millis() as u64).to_le_bytes()); Ok(vec![ Input::bytes("shape", &self.shape.words()), @@ -92,7 +98,7 @@ impl Case for FenceOrderCase { words.push(WRITTEN); words }), - Input::bytes("long-job-busy-and-bound", &job), + Input::bytes("long-job-and-bound", &job), ]) } diff --git a/crates/metal2vulkan-conformance/src/fence_orders.rs b/crates/metal2vulkan-conformance/src/fence_orders.rs index 58efa5d6e..04bce9b94 100644 --- a/crates/metal2vulkan-conformance/src/fence_orders.rs +++ b/crates/metal2vulkan-conformance/src/fence_orders.rs @@ -45,10 +45,6 @@ pub const LONG_FILL_BYTES: u64 = 64 << 20; /// start it. pub const LONG_FILLS: u32 = 32; -/// The command buffers committed on the updater's queue ahead of it in -/// [`FenceShape::TrackedBehindBusy`], each a long job. -pub const BUSY: usize = 3; - /// How long [`FenceShape::HeldUpdater`] gives the waiter to complete before the probe raises the /// event that holds the updater. Its answer is whether the waiter completed within it. pub const HELD_BOUND: Duration = Duration::from_secs(2); @@ -67,16 +63,25 @@ pub enum FenceShape { /// copies nothing. Its completed handler counts X's words then /// ([`FenceOrder::source_words_when_the_waiter_completed`]). X is untracked. EmptyWaiter, - /// No fence. [`BUSY`] command buffers, each a long job, then the updater, which fills X, are + /// No fence. `busy` command buffers, each a long job, then the updater, which fills X, are /// committed on one queue; the waiter on another copies X into Y. X and Y are tracked, so the /// order is Metal's hazard tracking's. - TrackedBehindBusy, + Tracked { busy: usize }, } impl FenceShape { - /// Whether X and Y are made untracked (`MTLResourceHazardTrackingModeUntracked`). + /// Whether X and Y are made untracked (`MTLResourceHazardTrackingModeUntracked`), which is + /// also whether the updater updates a fence the waiter waits on. pub fn untracked(self) -> bool { - self != FenceShape::TrackedBehindBusy + !matches!(self, FenceShape::Tracked { .. }) + } + + /// The command buffers, each a long job, committed on the updater's queue ahead of it. + pub fn busy(self) -> usize { + match self { + FenceShape::Tracked { busy } => busy, + _ => 0, + } } /// The bytes a case's inputs hold for the shape: its name and what it is made of. diff --git a/crates/metal2vulkan-conformance/src/metal_side.rs b/crates/metal2vulkan-conformance/src/metal_side.rs index c7f434b4d..e46fb360f 100644 --- a/crates/metal2vulkan-conformance/src/metal_side.rs +++ b/crates/metal2vulkan-conformance/src/metal_side.rs @@ -6066,8 +6066,8 @@ impl Side for MetalSide { ) -> Answer { use crate::event_orders::{Status, COMPLETION}; use crate::fence_orders::{ - written_words, FenceOrder, FenceShape, BUSY, BYTES, HELD_BOUND, LONG_FILLS, - LONG_FILL_BYTES, WRITTEN, + written_words, FenceOrder, FenceShape, BYTES, HELD_BOUND, LONG_FILLS, LONG_FILL_BYTES, + WRITTEN, }; objc2::rc::autoreleasepool(|_| { let device = &self.device; @@ -6116,8 +6116,8 @@ impl Side for MetalSide { }; // The busy command buffers ahead of the updater, each a long job, committed at once. let mut busy = Vec::new(); - if shape == FenceShape::TrackedBehindBusy { - for _ in 0..BUSY { + if shape.busy() > 0 { + for _ in 0..shape.busy() { let ahead = command_buffer(&updating_queue)?; let encoder = blit(&ahead)?; long_job(&encoder); @@ -6139,7 +6139,7 @@ impl Side for MetalSide { objc2_foundation::NSRange::new(0, BYTES as usize), WRITTEN, ); - if shape != FenceShape::TrackedBehindBusy { + if shape.untracked() { encoder.updateFence(&fence); } encoder.endEncoding(); @@ -6147,7 +6147,7 @@ impl Side for MetalSide { updater.commit(); let waiter = command_buffer(&waiting_queue)?; let encoder = blit(&waiter)?; - if shape != FenceShape::TrackedBehindBusy { + if shape.untracked() { encoder.waitForFence(&fence); } if shape != FenceShape::EmptyWaiter { diff --git a/crates/metal2vulkan-conformance/src/rt_side/fences.rs b/crates/metal2vulkan-conformance/src/rt_side/fences.rs index 09ba1c959..f3e0f0101 100644 --- a/crates/metal2vulkan-conformance/src/rt_side/fences.rs +++ b/crates/metal2vulkan-conformance/src/rt_side/fences.rs @@ -11,8 +11,7 @@ use super::RtSide; use crate::case::{Answer, Failure}; use crate::event_orders::{Status, COMPLETION}; use crate::fence_orders::{ - written_words, FenceOrder, FenceShape, BUSY, BYTES, HELD_BOUND, LONG_FILLS, LONG_FILL_BYTES, - WRITTEN, + written_words, FenceOrder, FenceShape, BYTES, HELD_BOUND, LONG_FILLS, LONG_FILL_BYTES, WRITTEN, }; use metal2vulkan_rt as rt; use std::sync::mpsc; @@ -46,8 +45,8 @@ impl RtSide<'_> { let gate = device.new_shared_event().map_err(of_rt)?; // The busy command buffers ahead of the updater, each a long job, committed at once. let mut busy = Vec::new(); - if shape == FenceShape::TrackedBehindBusy { - for _ in 0..BUSY { + if shape.busy() > 0 { + for _ in 0..shape.busy() { let ahead = updating_queue.command_buffer().map_err(of_rt)?; let mut encoder = ahead.blit_command_encoder().map_err(of_rt)?; long_job(&mut encoder, &long)?; @@ -65,7 +64,7 @@ impl RtSide<'_> { long_job(&mut encoder, &long)?; } (encoder.fill_buffer(&x, 0..BYTES, WRITTEN)).map_err(of_rt)?; - if shape != FenceShape::TrackedBehindBusy { + if shape.untracked() { encoder.update_fence(&fence).map_err(of_rt)?; } encoder.end_encoding(); @@ -74,7 +73,7 @@ impl RtSide<'_> { updater.commit().map_err(of_rt)?; let waiter = waiting_queue.command_buffer().map_err(of_rt)?; let mut encoder = waiter.blit_command_encoder().map_err(of_rt)?; - if shape != FenceShape::TrackedBehindBusy { + if shape.untracked() { encoder.wait_for_fence(&fence).map_err(of_rt)?; } if shape != FenceShape::EmptyWaiter { diff --git a/crates/metal2vulkan-conformance/src/tests.rs b/crates/metal2vulkan-conformance/src/tests.rs index cd1bf3a92..defd3bcf8 100644 --- a/crates/metal2vulkan-conformance/src/tests.rs +++ b/crates/metal2vulkan-conformance/src/tests.rs @@ -7545,7 +7545,7 @@ fn every_case_carries_a_cost_recording() { /// /// A whole-set run is the only shape that pays a record: a case's counts depend on what ran /// before it in the same process, so a selection cannot pay one however many cases it names. - const AFTER_THE_LAST_RUN: [&str; 18] = [ + const AFTER_THE_LAST_RUN: [&str; 20] = [ "vector-word-phases-0", "vector-word-phases-4", "vector-word-phases-8", @@ -7564,6 +7564,8 @@ fn every_case_carries_a_cost_recording() { "fence-held-updater", "fence-empty-waiter", "fence-none-tracked-behind-busy", + "fence-none-tracked", + "fence-none-tracked-behind-one", ]; /// Cases a whole-set run did not cover although they were committed before it ran.