vk_buffer: settle the first work on the VkBuffer it hands out, reading it apart once

28dcdcaed2's hand-out read the buffer's VkBuffer a second time, through
Buffer::at, to find the fills waiting on it. A no-copy buffer's import
counts each read apart by its reason, so vk_buffer of a no-copy buffer
now counted a Binding read beside its VkBuffer read. In the lavapipe
suite (job 8946), host_import_counts::each_read_apart_counts_for_its_reason_once_and_each_import_for_its_keeping
read [1, 1, 1, 0, 0, 0] where it expects [1, 1, 0, 0, 0, 0].

settle_first_work now takes the VkBuffer from its caller. vk_buffer reads
it once, for VkBuffer, and settles with it. export_memory_fd passes its
own buffer's, which is no import. hand_out only notes the hand-out again.

(cherry picked from commit 3d3ea570b4f1d90263c22a1f7456bb1a94264f9f)
This commit is contained in:
Anees Iqbal committed 2026-11-08 09:42:34 -08:00
1 parent d84bc3269f
commit 5c62a353ca
3 files changed
+15 -15

No files matched your search

+10 -12
View File
@@ -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(|_, _| {}),
@@ -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)?;
+4 -2
View File
@@ -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,