diff --git a/crates/metal2vulkan-runtime/README.md b/crates/metal2vulkan-runtime/README.md index 154d3d08f..823433f7a 100644 --- a/crates/metal2vulkan-runtime/README.md +++ b/crates/metal2vulkan-runtime/README.md @@ -1902,7 +1902,13 @@ made, with no lock, and never rewritten for layouts. (`Metrics::pieces_passed`), unless it holds a buffer or texture the cut one holds (by the ids the hazards track them by, a heap's resources by the heap's), waits on a fence the cut one updates, or either reaches memory outside its resources: then it goes after the last piece - (`Metrics::shared_holds`). The cut command buffer is scheduled as its first piece is submitted, + (`Metrics::shared_holds`), held only while the cut one's next piece is ready; where that piece + waits for an event not yet met, it goes, as Metal's wait stops only its own queue, and the + signal may come from the queue it holds. Across queues, work goes to the device in any order, + except that a command buffer never goes ahead of an earlier-committed one it shares a tracked + resource or a fence with, and an event wait holds only its own queue. Two readers of one + resource share it here, so a read waits behind a cut command buffer that only reads what it + reads, though no write orders them: an over-hold. The cut command buffer is scheduled as its first piece is submitted, where none of its later pieces waits for an event, and its GPU times run from its first piece's start to its last piece's end, the runs of what went between its pieces included, as on the UHD 630 under macOS 26.7.1 a running command buffer's end moved by the run of one that started @@ -2152,7 +2158,8 @@ while the driver's exit handler waited on a lock, with every runtime thread alre dispatch whose own expected run passes 4 ms, a render pass and the encoders after it, the dispatches of a kernel whose rate is not yet measured, and the commands of a piece that writes a Managed buffer or while copies over a texture are owed. It waits behind every piece of a cut - command buffer that holds one of its buffers or textures, a read of a read included. Metal + command buffer that holds one of its buffers or textures, a read of a read included, except + while that command buffer's next piece waits for an event. Metal starts it beside the running command buffer: on a Radeon Pro 5300M another queue's command buffer started 0.21 to 0.40 ms after its commit beside a running one (job m3-max-68137), and on an Intel UHD 630 under macOS 26.7.1 one of a queue at a lower priority number started about diff --git a/crates/metal2vulkan-runtime/src/counters.rs b/crates/metal2vulkan-runtime/src/counters.rs index f639be4f3..0f51e18d8 100644 --- a/crates/metal2vulkan-runtime/src/counters.rs +++ b/crates/metal2vulkan-runtime/src/counters.rs @@ -2646,7 +2646,7 @@ pub struct Metrics { /// Command buffers held behind every piece of a cut command buffer of another queue, /// committed before them, as they hold a buffer or texture it holds (by the ids the hazards /// track them by), wait on a fence it updates, or either reaches memory outside its - /// resources. + /// resources: held while its next piece is ready, not while that piece waits for an event. pub shared_holds: u64, /// Elements of set 1's sampler arrays written (`vkUpdateDescriptorSets`): a sampler state's or /// a constexpr sampler's placement and its going write only the elements whose sampler diff --git a/crates/metal2vulkan-runtime/src/submit.rs b/crates/metal2vulkan-runtime/src/submit.rs index 7a5e6a524..cf623749c 100644 --- a/crates/metal2vulkan-runtime/src/submit.rs +++ b/crates/metal2vulkan-runtime/src/submit.rs @@ -1762,14 +1762,17 @@ impl WorkState { } /// Marks each FIFO whose head, committed after a cut command buffer of another queue, the head - /// of its own with pieces not yet staged, shares a resource with it (`Gpu::shares`): held until that - /// command buffer's every piece is staged, counted once a head - /// (`Metrics::shared_holds`). + /// of its own with pieces not yet staged, shares a resource with it (`Gpu::shares`): held while + /// that command buffer's next piece is ready, until its every piece is staged, counted once a + /// head (`Metrics::shared_holds`). One whose next piece waits for an event not yet met holds + /// no other queue, as Metal's wait stops only its own queue: the signal it waits for may come + /// from the queue it would hold. fn block_shared(&mut self, counters: &Counters) { let cuts: Vec<(usize, u64)> = (self.fifos.iter().enumerate()) .filter_map(|(index, fifo)| { let pending = fifo.head()?; - pending.gpu.cut.then_some((index, pending.seq)) + let next = pending.gpu.segments.get(pending.next); + (pending.gpu.cut && next.is_some_and(ready)).then_some((index, pending.seq)) }) .collect(); for index in 0..self.fifos.len() {