From e44d4d31f82bc7c6fbd8baeee0598d807b4b80e3 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 2 Dec 2026 08:09:46 -0800 Subject: [PATCH] rt tests: a command buffer whose signals fill its queue's room completes with no host wait One command buffer signals an event IN_FLIGHT times, a fill after each, with nothing else in flight, no later commit and no host wait. Its parts before its last go at their signals, one submission each, and fill the queue's room (submit::room); its last part is held for room. Red at development's tip: the command buffer stays Scheduled. The parts carry nothing that retires, so the completion thread waits on the host and never reads the progress semaphore; the submit thread's settled value stays below the first part and the held last part never goes. --- .../metal2vulkan-runtime/src/tests/command.rs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/crates/metal2vulkan-runtime/src/tests/command.rs b/crates/metal2vulkan-runtime/src/tests/command.rs index 378f0adcc..84efa0647 100644 --- a/crates/metal2vulkan-runtime/src/tests/command.rs +++ b/crates/metal2vulkan-runtime/src/tests/command.rs @@ -2756,6 +2756,50 @@ pub(crate) mod on_device { }); } + /// The parts of a command buffer that go at its signals, before its last part, are + /// submissions its queue counts in flight, and the completion thread sees them complete: one + /// command buffer that signals an event [`IN_FLIGHT`] times, a fill after each, with nothing + /// else in flight, no later commit and no host wait, fills its queue's room with those parts, + /// and its last part goes once the first completes. Its completed handler runs; it took one + /// submission a part. + #[test] + fn every_device_completes_a_command_buffer_whose_signals_fill_its_room() { + each_device("command_signal_parts", |name, _, device| { + let mut arena = Arena::new(&device); + let buffer = arena.buffer(); + let queue = queue(&device); + let event = shared_event(&device); + let before = device.counters().metrics().submissions; + let command_buffer = queue.command_buffer().expect("a command buffer"); + for value in 1..=IN_FLIGHT as u32 { + (command_buffer.encode_signal_event(event.as_event(), value.into())) + .expect("a signal"); + fill(&command_buffer, &buffer, value); + } + let (sender, completed) = mpsc::channel(); + (command_buffer.add_completed_handler(move |_| { + let _ = sender.send(()); + })) + .expect("a handler"); + command_buffer.commit().expect("a commit"); + assert!( + completed.recv_timeout(PATIENCE).is_ok(), + "{name}: completed with no host wait, status {:?}", + command_buffer.status() + ); + assert_eq!(command_buffer.status(), CommandBufferStatus::Completed); + assert_eq!(event.signaled_value(), IN_FLIGHT as u64, "{name}"); + assert_eq!(word(&buffer), IN_FLIGHT as u32, "{name}"); + let submissions = device.counters().metrics().submissions - before; + assert_eq!( + submissions, + IN_FLIGHT as u64 + 1, + "{name}: one submission a part" + ); + drop((command_buffer, event, buffer, arena, queue, device)); + }); + } + /// A command buffer joins a held group only while the group's expected GPU runs, summed, stay /// within `GROUP_RUN`, each its queue's expected run: behind three running submissions, three /// fills on a queue whose command buffers ran 1 ms go as one group, and on a queue whose