Is there a proper way to sync across multiple submits?

example (2nd example, modified slightly, added queuesubmit) taken from https://github.com/KhronosGroup/Vulkan-Docs/wiki/Synchronization-Examples

First dispatch reads from a storage buffer, second dispatch writes to that storage buffer.

comment from original example: execution dependencies are sufficient. A pipeline barrier or event without a any access flags is an execution dependency.

vkCmdDispatch(commandbuffer1...);

VkMemoryBarrier2KHR memoryBarrier = {
  ...
  .srcStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT_KHR,
  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT_KHR };

VkDependencyInfoKHR dependencyInfo = {
    ...
    1,              // memoryBarrierCount
    &memoryBarrier, // pMemoryBarriers
    ...
}

vkCmdPipelineBarrier2KHR(commandBuffer1, &dependencyInfo);

// what if VkQueueSubmit here
VkSubmitInfo submitinfo{};
....
submitinfo. pCommandBuffers = commandbuffer1;
VkQueueSubmit(queue, 1,&submitinfo, fence1);
-------------------submit1---------------------------

vkCmdDispatch(commandbuffer2, ...);


VkSubmitInfo submitinfo2{};
....
submitinfo2. pCommandBuffers = commandbuffer2;
VkQueueSubmit(queue, 1,&submitinfo, fence2);
-------------------submit2---------------------------


// waitfence1..wait fence2

what does the Barrier do in this case? maybe it has no effect since the barrier only works on commandBuffer1? is there a proper way to sync across multiple submits?

Command buffers are tools for bundling commands so that they can be submitted in a series. When it comes to synchronization, command buffers do not matter.

All that matters is the order of commands submitted to the queue.

Now yes, that order is stored by command buffers. But as far as synchronization is concerned, there is no difference between having two commands, one after the other in the same CB, and having those same two commands in two CBs within the same batch.

Note that batches have their own synchronization: the wait and signal semaphores attached to them.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.