diff --git a/crates/metal2vulkan-rt/README.md b/crates/metal2vulkan-rt/README.md index 2653b2f8c..e1f7b87e4 100644 --- a/crates/metal2vulkan-rt/README.md +++ b/crates/metal2vulkan-rt/README.md @@ -515,7 +515,8 @@ that touch blocks first. - Values the runtime reads back from GPU-written memory decide nothing beyond the reading command buffer's own results (`src/readback.rs`; a rule test holds every such read there). The sites: the two timestamp queries of a command buffer, which decide only its `gpu_start_time`, through - arithmetic defined for every value and never later than its `gpu_end_time`; and + arithmetic defined for every value and never later than its `gpu_end_time`, read once both were + written by a completed submission, waiting for the driver to make them available; and `Texture::get_bytes`'s copy out of its staging span, whose bytes reach only the caller's buffer, at offsets and lengths from the call's checked region. The parameter ring and an indirect dispatch's arguments are read only by the GPU: the runtime writes the ring and diff --git a/crates/metal2vulkan-rt/src/complete.rs b/crates/metal2vulkan-rt/src/complete.rs index 79d14aff9..1f2e3d19d 100644 --- a/crates/metal2vulkan-rt/src/complete.rs +++ b/crates/metal2vulkan-rt/src/complete.rs @@ -321,11 +321,15 @@ impl Retiree { } } - /// A completed command buffer's two timestamps. + /// A completed command buffer's two timestamps, where it wrote both: the read waits for them, + /// and a query never written would never become available. fn stamps(&self, core: &Core) -> Option<(u64, u64)> { match &self.item { Item::Command { - cb, error: None, .. + cb, + error: None, + written: 2, + .. } => cb.stamps(core), _ => None, } diff --git a/crates/metal2vulkan-rt/src/readback.rs b/crates/metal2vulkan-rt/src/readback.rs index f6e85adcb..3e50b96ae 100644 --- a/crates/metal2vulkan-rt/src/readback.rs +++ b/crates/metal2vulkan-rt/src/readback.rs @@ -9,12 +9,18 @@ use ash::vk; /// A completed command buffer's two timestamps, from its queue's pool; None where the driver does /// not report both, so the command buffer's GPU times stay 0. /// +/// The read waits for the two values (`VK_QUERY_RESULT_WAIT_BIT`): a driver may make a timestamp +/// available only after the submission's signal (MoltenVK 1.4.2 on an M3 Max did for most +/// command buffers, which then had no times). Both were written by a submission that completed, +/// so Vulkan makes them available; the caller reads only such queries. +/// /// Bound: the values only decide that command buffer's `GPUStartTime`, through arithmetic defined -/// for every value that gives a time no later than its `GPUEndTime`. The read does not wait. +/// for every value that gives a time no later than its `GPUEndTime`. /// /// # Safety /// -/// `pool` is a timestamp pool of `device` with the queries `first` and `first + 1`. +/// `pool` is a timestamp pool of `device` with the queries `first` and `first + 1`, both written +/// by a submission that completed. pub(crate) unsafe fn timestamps( device: &ash::Device, pool: vk::QueryPool, @@ -23,7 +29,12 @@ pub(crate) unsafe fn timestamps( let mut values = [0_u64; 2]; // SAFETY: by the caller; `values` holds two 64-bit results. let read = unsafe { - device.get_query_pool_results(pool, first, &mut values, vk::QueryResultFlags::TYPE_64) + device.get_query_pool_results( + pool, + first, + &mut values, + vk::QueryResultFlags::TYPE_64 | vk::QueryResultFlags::WAIT, + ) }; read.ok().map(|()| (values[0], values[1])) }