There are several ways to handle synchronization in Vulkan. This is how I understand it:
- Fences are GPU to CPU syncs.
- Semaphores are GPU to GPU syncs, they are used to sync queue submissions (on the same or different queues).
- Events are more general, reset and checked on both CPU and GPU.
- Barriers are used for synchronization inside a command buffer.
In my case I have two command buffers. And I want the second command buffer to execute after the first one.
submitInfo.pCommandBuffers = &firstCommandBuffer;
vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE);
// wait for first command buffer to finish
submitInfo.pCommandBuffers = &secondCommandBuffer;
vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE);
What kind of synchronization is best for this?
If I use vkQueueWaitIdle(queue)),
is that the same thing as using a fence or should I use event or semaphores for this?
If I send multiple commandbuffer to the queue at the same time:
std::vector<VkCommandBuffer> submitCmdBuffers = {
firstCommandBuffer,
secondCommandBuffer
};
submitInfo.commandBufferCount = submitCmdBuffers.size();
submitInfo.pCommandBuffers = submitCmdBuffers.data();
Is there still a way to synchronize between the first and the second one?