Reusing the same host-visible buffer on different queue families

Viewed 142

Considering host-visible buffers (mostly related to streaming buffers, i.e. buffers backed by VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT memory), let's imagine the following usage pattern:

  1. Write new data to the mapped address on the host (after the proper synchronization).
  2. Read the buffer with contents written in step 1 on queue family A.
  3. Write new data to the mapped address on the host (after the proper synchronization).
  4. Read the buffer with contents written in step 3 on queue family B.

Now, if I omit the queue family ownership transfer (QFOT), is the data written in step 3 inaccessible to queue family B in step 4?

The data written on the host becomes visible to the device when I submit the command(s) of step 4 using vkQueueSubmit, due to the implicit memory dependency of the host write ordering guarantee.

How does it play with different queue families?

1 Answers

OK, so we have a CPU modifiable buffer. And for some reason, this buffer was created in exclusive mode. And you want to do the following:

  1. Write data to the buffer.
  2. Copy the data using queue family A.
  3. Write data to the buffer.
  4. Copy the data using queue family B.

In order for step 4 to work, you are required to do an ownership transfer. The standard spells this out right before what you quoted:

If memory dependencies are correctly expressed between uses of such a resource between two queues in different families, but no ownership transfer is defined, the contents of that resource are undefined for any read accesses performed by the second queue family.

You do have dependencies correctly expressed (I assume). But copying data is a "read access". And it is being performed by queue family B, which is different from queue family A. Therefore, step 4 (a "read access") triggers this clause: "the contents of that resource are undefined".

"Contents" means all of the contents. The ones you wrote in step 1 and step 3. All of them are undefined for step 4, unless you do a queue family ownership transfer.

Related