diff --git a/crates/metal2vulkan-runtime/src/buffer.rs b/crates/metal2vulkan-runtime/src/buffer.rs index 242e7dd91..88d1a1f6c 100644 --- a/crates/metal2vulkan-runtime/src/buffer.rs +++ b/crates/metal2vulkan-runtime/src/buffer.rs @@ -3226,21 +3226,19 @@ impl Buffer { Arc::clone(&self.0.handed_out) } - /// Note that its `VkBuffer` was handed out (`Buffer::vk_buffer`), and make the first work - /// still waiting on it ([`settle_first_work`](Self::settle_first_work)). - pub(super) fn hand_out(&self) -> Result<(), Error> { + /// Note that its `VkBuffer` was handed out (`Buffer::vk_buffer`). + pub(super) fn hand_out(&self) { self.0.handed_out.store(true, Ordering::Release); - self.settle_first_work() } - /// Make the first work still waiting on its `VkBuffer` now, by an internal submission waited - /// for: a new buffer's zeros or staged bytes, or a `Managed` buffer's upload (`clear_first`, - /// `fill_first_from`, `upload`), which the device's next submission would make before its - /// commands (`texture/first_move.rs`), over what the caller's own work wrote through the - /// handle meanwhile. Nothing is submitted where none waits: once any submission of the - /// device's took it. - pub(super) fn settle_first_work(&self) -> Result<(), Error> { - let (raw, _) = self.at(0); + /// Make the first work still waiting on its `VkBuffer` `raw` now, by an internal submission + /// waited for: a new buffer's zeros or staged bytes, or a `Managed` buffer's upload + /// (`clear_first`, `fill_first_from`, `upload`), which the device's next submission would make + /// before its commands (`texture/first_move.rs`), over what the caller's own work wrote + /// through the handle meanwhile. Nothing is submitted where none waits: once any submission of + /// the device's took it. `raw` is the caller's: a no-copy buffer's import counts each read of + /// its `VkBuffer` apart for its reason (`HostImport::note_read_apart`), so this reads none. + pub(super) fn settle_first_work(&self, raw: vk::Buffer) -> Result<(), Error> { let device = &self.0.device; match device.shared().textures.first_moves.fills_wait(raw) { true => device.submit_internal(|_, _| {}), diff --git a/crates/metal2vulkan-runtime/src/exported_memory.rs b/crates/metal2vulkan-runtime/src/exported_memory.rs index 261580bb5..814606e58 100644 --- a/crates/metal2vulkan-runtime/src/exported_memory.rs +++ b/crates/metal2vulkan-runtime/src/exported_memory.rs @@ -272,7 +272,7 @@ impl Buffer { } // The zeros it waits for as it was made go first (`Buffer::settle_first_work`): the // other API may write the memory at once. - self.settle_first_work()?; + self.settle_first_work(self.at(0).0)?; let shared = device.shared(); let found = self.own_placement(|placement, offset| { let exported = lock(&shared.memory).exported(placement)?; diff --git a/crates/metal2vulkan-runtime/src/interop.rs b/crates/metal2vulkan-runtime/src/interop.rs index c2b036948..df37cecae 100644 --- a/crates/metal2vulkan-runtime/src/interop.rs +++ b/crates/metal2vulkan-runtime/src/interop.rs @@ -222,10 +222,12 @@ impl Buffer { /// The `VkBuffer` stays the runtime's: the caller does not destroy it, and uses it only while /// the buffer lives, ordered against the runtime's work on it. pub unsafe fn vk_buffer(&self) -> (vk::Buffer, u64) { + self.hand_out(); + let handle = self.at_for(0, ReadApart::VkBuffer); // A failed submission gives the work back, to the device's next submission; the caller // sees the failure at its next call (a lost device refuses it). - let _ = self.hand_out(); - self.at_for(0, ReadApart::VkBuffer) + let _ = self.settle_first_work(handle.0); + handle } /// No Metal counterpart (an interop hook): where the buffer's byte 0 lies in Vulkan memory,