From 1e583d5e0cae4ebce7b6d2bd2f969d4c05bc2926 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 19 Nov 2026 07:47:44 -0800 Subject: [PATCH] conformance: the running-signal case's MTLEvent reading may be Committed on rt alone, where its submit thread is still busy On the Iris Xe, event-wait-behind-a-running-signal's MTLEvent row read the waiting command buffer Committed with no handler run, where the M3 Max had scheduled it while the signaller ran. This held in 3 of 3 runs (m3-max-52564). The trace showed why. The waiter's wait was met at once by the signal's staging. rt's one submit thread was still inside the signaller's vkQueueSubmit2, the device's first submission, which took 27-30 ms on ANV. The waiter was scheduled 0.02 ms after that call returned. Apple defines Scheduled as all dependencies resolved and the command buffer scheduled for execution, and promises no time between the two. The planner ruled this a timing difference and not a conformance bug. The case now declares, on rt's run alone (Justification::NewRuntimeAccepted), that the MTLEvent row's waiting status while the signaller runs may be Committed or Scheduled, and its handlers none or the scheduled one. The declaration cites a new accepted difference in docs/API.md, 'The new runtime schedules a command buffer once its submit thread is free'. The shared event's row is not loosened: both runtimes hold its waiter until the value is reached. The old runtime's run compares both sites exactly. New test: a_wait_met_by_a_running_signal_may_read_committed_on_the_new_runtime_alone. It checks that the Iris answers are no divergence on rt and are rows on the old runtime, that the shared event's sites still diverge, and that a status other than the two still diverges. --- .../src/cases/event_orders.rs | 62 ++++++++++++++- crates/metal2vulkan-conformance/src/tests.rs | 75 +++++++++++++++++++ docs/API.md | 13 ++++ 3 files changed, 146 insertions(+), 4 deletions(-) diff --git a/crates/metal2vulkan-conformance/src/cases/event_orders.rs b/crates/metal2vulkan-conformance/src/cases/event_orders.rs index 7795f420b..95552d233 100644 --- a/crates/metal2vulkan-conformance/src/cases/event_orders.rs +++ b/crates/metal2vulkan-conformance/src/cases/event_orders.rs @@ -36,6 +36,12 @@ //! alone ([`LONG_FILLS`] of [`LONG_FILL_BYTES`] into a private buffer): no loop runs on the GPU, //! so nothing can hang. //! +//! On `metal2vulkan-rt` the `MTLEvent` row's waiting command buffer may still read `Committed`, +//! with no handler run, though its wait is met: the new runtime schedules a command buffer once +//! its device's one submit thread is free, and Metal promises no time between a command buffer's +//! dependencies resolving and its scheduling. The case declares that on the new runtime's run +//! alone, in its allowances. +//! //! # What this pulls forward //! //! Every one of these numbers was ours before. `runtime_lane::events` runs the shapes on the @@ -77,12 +83,13 @@ //! such a design is written down and left unbuilt. The runtime's typed refusals of both stay //! `runtime_lane` assertions. +use crate::allowance::{Allowance, Justification, Loosening}; use crate::case::{Abort, Case, Input, MetalSource, Side}; use crate::event_orders::{ COMPLETED, HELD_FOR, LONG_FILLS, LONG_FILL_BYTES, RUNNING_WINDOW, SCHEDULED, SCRATCH, SIGNAL_WAIT, }; -use crate::transcript::{Node, Observed, Sites, Value}; +use crate::transcript::{Negative, Node, Observed, Sites, Value}; /// A wait committed before the signal that meets it. pub const CROSS_QUEUE_WAIT: &str = "event-cross-queue-wait"; @@ -163,7 +170,7 @@ impl Case for EventOrder { MetalSource::Run } - fn allowances(&self) -> Vec { + fn allowances(&self) -> Vec { // The cross-queue row is the one row of the family that reads an answer back out of a // `Shared` buffer, and on a device without unified memory the runtime announces // `shared-in-system-memory` for it (`crate::replay::shared_memory_notice` holds the whole @@ -176,8 +183,11 @@ impl Case for EventOrder { match self.shape { // The waiting command buffer's scratch is read back out of a `Shared` buffer, as // the cross-queue row's is. - Shape::CrossQueueWait | Shape::WaitBehindRunningSignal => { - vec![crate::replay::shared_memory_notice()] + Shape::CrossQueueWait => vec![crate::replay::shared_memory_notice()], + Shape::WaitBehindRunningSignal => { + let mut allowances = vec![crate::replay::shared_memory_notice()]; + allowances.extend(scheduled_once_the_submit_thread_is_free()); + allowances } Shape::HighestSignal | Shape::Held | Shape::SignalBeforeWait => Vec::new(), } @@ -290,3 +300,47 @@ impl Case for EventOrder { Ok(()) } } + +/// The slug of `docs/API.md`'s accepted difference that says when `metal2vulkan-rt` schedules a +/// command buffer ([`scheduled_once_the_submit_thread_is_free`]). +const SCHEDULED_ONCE_THE_SUBMIT_THREAD_IS_FREE: &str = + "the-new-runtime-schedules-a-command-buffer-once-its-submit-thread-is-free"; + +/// The declaration [`WAIT_BEHIND_A_RUNNING_SIGNAL`]'s `MTLEvent` row needs on `metal2vulkan-rt`'s +/// run: the waiting command buffer's status while the signaller runs may be `Committed` or +/// `Scheduled`, and its handlers then none or the scheduled one. +/// +/// **What it rests on**, the accepted difference [`SCHEDULED_ONCE_THE_SUBMIT_THREAD_IS_FREE`] +/// names: Apple's `Scheduled` is "All dependencies have been resolved and the command buffer has +/// been scheduled for execution", with no time promised between the two, and the new runtime +/// schedules a command buffer on its device's one submit thread, once that thread's earlier +/// `vkQueueSubmit2` calls have returned, whichever queue they were for. Where the signaller's call +/// outlasts the reading, the waiting one, its wait already met by that signal, is still +/// `Committed` with no handler run. +/// +/// **It loosens those two sites alone, and only on the new runtime** +/// ([`Justification::NewRuntimeAccepted`]), so the old runtime's answers still compare exactly. +/// The shared event's row is not loosened: both runtimes hold its waiting command buffer until +/// the value is reached, as Metal does. +fn scheduled_once_the_submit_thread_is_free() -> Vec { + let justified = + || Justification::new_runtime_accepted(SCHEDULED_ONCE_THE_SUBMIT_THREAD_IS_FREE); + vec![ + Allowance::new( + "case/order/event/waiting/status-while-the-signaller-runs", + Loosening::AnyOf(vec![ + Value::unit_variant("Committed"), + Value::unit_variant("Scheduled"), + ]), + justified(), + ), + Allowance::new( + "case/order/event/waiting/handlers-while-the-signaller-runs", + Loosening::AnyOf(vec![ + Value::Nothing(Negative::RanNothing), + Value::Lines(vec![SCHEDULED.to_owned()]), + ]), + justified(), + ), + ] +} diff --git a/crates/metal2vulkan-conformance/src/tests.rs b/crates/metal2vulkan-conformance/src/tests.rs index defd3bcf8..87c7aec26 100644 --- a/crates/metal2vulkan-conformance/src/tests.rs +++ b/crates/metal2vulkan-conformance/src/tests.rs @@ -3008,6 +3008,81 @@ fn a_new_texture_s_fresh_read_is_unchecked_on_the_new_runtime_alone() { assert!(!Verdict::of(&found, &Validated::NotRun).is_compliant()); } +/// **The running-signal case's `MTLEvent` reading may be `Committed` on the new runtime's run +/// alone.** The case names the accepted difference that the new runtime schedules a command +/// buffer once its submit thread is free ([`Justification::NewRuntimeAccepted`]): on +/// `metal2vulkan-rt`'s run a waiting command buffer still `Committed` with no handler run, where +/// Metal had scheduled it, is no divergence; on the old runtime's the same answers are the sites' +/// rows. The shared event's reading is not loosened, and a status other than the two is a row on +/// either run. +#[test] +fn a_wait_met_by_a_running_signal_may_read_committed_on_the_new_runtime_alone() { + let case = (crate::cases::event_orders::all().into_iter()) + .find(|case| case.name() == crate::cases::event_orders::WAIT_BEHIND_A_RUNNING_SIGNAL) + .expect("the running-signal case"); + let allowances = case.allowances(); + let row = |name: &str, status: &str, handlers: Value| { + Node::branch( + name, + vec![ + Node::leaf( + "waiting/status-while-the-signaller-runs", + Observed::value(Value::unit_variant(status)), + ), + Node::leaf( + "waiting/handlers-while-the-signaller-runs", + Observed::value(handlers), + ), + ], + ) + }; + let scheduled = || Value::Lines(vec!["scheduled".to_owned()]); + let none = || Value::Nothing(Negative::RanNothing); + let transcript = |event: (&str, Value), shared: (&str, Value)| { + Transcript::new(vec![ + row("order/event", event.0, event.1), + row("order/shared-event", shared.0, shared.1), + ]) + }; + let metal = transcript(("Scheduled", scheduled()), ("Committed", none())); + let ours = transcript(("Committed", none()), ("Committed", none())); + // The divergences' paths, sorted: the handlers' site ahead of the status's. + let paths = |found: &crate::compare::Comparison| -> Vec { + let mut paths: Vec = found.divergences.iter().map(|at| at.path.clone()).collect(); + paths.sort(); + paths + }; + let event_sites = [ + "case/order/event/waiting/handlers-while-the-signaller-runs", + "case/order/event/waiting/status-while-the-signaller-runs", + ]; + let old = Offered::notices(&[]); + let found = compare(&metal, &ours, &allowances, old); + assert_eq!(paths(&found), event_sites, "{found:?}"); + + let rt = old.on_new_runtime(true); + let found = compare(&metal, &ours, &allowances, rt); + assert!(found.divergences.is_empty(), "{found:?}"); + assert!(found.bad_allowances.is_empty(), "{found:?}"); + + // The shared event's reading is not the declaration's. + let shared = transcript(("Scheduled", scheduled()), ("Scheduled", scheduled())); + let found = compare(&metal, &shared, &allowances, rt); + assert_eq!( + paths(&found), + [ + "case/order/shared-event/waiting/handlers-while-the-signaller-runs", + "case/order/shared-event/waiting/status-while-the-signaller-runs", + ], + "{found:?}" + ); + + // Nor is a status other than `Committed` or `Scheduled`. + let completed = transcript(("Completed", scheduled()), ("Committed", none())); + let found = compare(&metal, &completed, &allowances, rt); + assert_eq!(paths(&found), event_sites[1..], "{found:?}"); +} + /// **A venue's own answer at a site that differs on a venue presenting Metal's compression is the /// site's one row.** [`crate::replay::without_compression`] holds only where the venue keeps no /// texture compressed; on the Mac that recorded the case (MoltenVK on the M3 Max) it holds diff --git a/docs/API.md b/docs/API.md index 4394b448f..3fddd04c8 100644 --- a/docs/API.md +++ b/docs/API.md @@ -6625,6 +6625,19 @@ each item named states the rule in full. of the same functions answered an object maximum of 64, where a first compile answers 1024 (`mesh_pipeline_limits.m`). +**Queues and command buffers** + +- **The new runtime schedules a command buffer once its submit thread is free** + (`metal2vulkan-rt`'s `CommandBuffer::status`, `add_scheduled_handler` and + `wait_until_scheduled`). Apple defines `MTLCommandBufferStatusScheduled` as "All dependencies + have been resolved and the command buffer has been scheduled for execution", and promises no + time between the two. The new runtime schedules each command buffer on the device's one submit + thread, once that thread's earlier `vkQueueSubmit2` calls have returned, whichever queue they + were for (the runtime's README, the known gaps of queues). So a command buffer whose wait an + earlier submission's signal meets stays `Committed`, its scheduled handlers not run, for as long + as that submission's driver call lasts, where an Apple M3 Max had scheduled it while the + signalling command buffer still ran. + **Process exit** - **On Linux, an exit while the driver still runs the runtime's work past the exit's wait for it