Skip to content

Instantly share code, notes, and snippets.

@nanokatze
Created December 9, 2025 00:10
Show Gist options
  • Select an option

  • Save nanokatze/f66f8bd11088c5a886a666040e13d7fe to your computer and use it in GitHub Desktop.

Select an option

Save nanokatze/f66f8bd11088c5a886a666040e13d7fe to your computer and use it in GitHub Desktop.
Vulkan sync

Ordering

/* 1 */ vkCmdDispatch(cb, 1, 1, 1);
/* 2 */ vkCmdDispatch(cb, 1, 1, 1);

dispatches 1 and 2 aren't ordered wrt each other. So the threads spawned by 1 and 2 may start in any order, execute in parallel, and complete in any order.

/* 1 */ vkCmdDispatch(cb, 1, 1, 1);
        vkCmdPipelineBarrier2(cb,
                              srcStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
                              srcAccessMask = VK_ACCESS_2_MEMORY_WRITE_BIT,
                              dstStageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
                              dstAccessMask = VK_ACCESS_2_MEMORY_READ_BIT | VK_ACCESS_2_MEMORY_WRITE_BIT);
/* 2 */ vkCmdDispatch(cb, 1, 1, 1);

now, the thread spawned by dispatch 1 will start, execute and complete before the thread spawned by dispatch 2 will start, execute and complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment