Synchronisation in Vulkan

In Vulkan, synchronisation is almost entirely under the control of the developer

Synchronisation objects in Vulkan were discussed briefly in Comparing OpenGL ES and Vulkan, but it is useful to go slightly deeper now that some of the basic concepts of Vulkan have been covered.

In Vulkan, concurrency takes three main forms:
  • Between host and device
  • Between commands in a queue
  • Between queues

Types of synchronisation object

Vulkan provides four different object types to help with the synchronisation of the situations mentioned above.

These are:
  • Fences - GPU to CPU syncs. They are signalled by the GPU and can only be waited on by the CPU. They need to be reset manually and are often waited on by functions such as vkWaitForFences().
  • Semaphores - GPU to GPU syncs. They are specifically used to sync queue submissions on the same or different queues. They get signalled by the GPU and can only be waited on by the GPU. As long as they have been waited on they are reset automatically.
  • Events - These can be set, reset and checked on both CPU and GPU. However, they can only be waited on by the GPU. They are limited within a single queue and can also be used to synchronise work within a command buffer.
  • Barriers - These are used to synchronise operations in the command buffer between different stages of the pipeline. There are five different types of barriers:
    • Execution Barriers ensure that any stage specified as a source stage is executed and completed by the command, before the stage specified as destination is started.
    • Memory Barriers ensure the caches are flushed and invalidated between the source stage and destination stage of the execution barriers. They make all resources needed by the stage available at the time it needs for execution.
    • Global Memory Barriers apply to all the memory objects that exit at the time of its execution and not only the ones that are needed by the stage.
    • Buffer Memory apply only to the buffer that is being working on.
    • Image Barriers perform image layout transitions and operations on sub-regions of the image.