Andrew Tomazos
Andrew Tomazos

Reputation: 68618

vkCmdUpdateBuffer before render pass synchronization?

Does the following:

vkCmdUpdateBuffer(c, uniform_buffer, ...);
vkCmdBeginRenderPass(c, ...);
vkCmdBindDescriptorSets(c, ..., uniform_buffer_descriptor, ...);
vkCmdDraw(c, ...);

(ie the vkCmdDraw will use the VkBuffer that was just updated by vkCmdUpdateBuffer.)

...require synchronization by a barrier or other means? Or will the buffer update complete before the draw command executes? How did you figure that out?

Upvotes: 1

Views: 272

Answers (2)

krOoze
krOoze

Reputation: 13246

There are about only two expeptions in Vulkan that have implicit synchronization. Everything else must be synchronized by the user.

Le specification:

This command [vkCmdUpdateBuffer] is treated as “transfer” operation, for the purposes of synchronization barriers.

Upvotes: 0

Jesse Hall
Jesse Hall

Reputation: 6787

Yes, you need a barrier both to make sure the draw doesn't start before the buffer update completes, and to ensure coherence. Commands are started in the order they're added to the command buffer, but can operate concurrently and complete out of order. With very few exceptions, any time you have a data dependency (aka hazard) of the form read-after-write, write-after-write, or write-after-read between two commands, then you need to explicitly enforce ordering and coherence between those commands.

Upvotes: 2

Related Questions