Judging by Vulkan barriers explained, it seems like each vkCmdPipelineBarrier
introduces a dependency between two subsequent pipeline “runs”. For a typical scenario of a shader A that writes an image and a shader B that samples the same image, it might look like this:
- dispatch shader that writes to image A
vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, ...);
- dispatch shader that reads from image A
This defines a dependency from the first shader execution's color attachment stage to the second shader execution's fragment stage. But what to do if I want to run independent commands in between? For example
- dispatch shader that writes to image A
- dispatch unrelated shader that doesn't touch image A
vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, ...);
- dispatch shader that reads from image A
This still works, but is inefficient: because the fragment shader stage now has to wait for the color attachment output stage of the previous, unrelated shader. How do I specify a dependency on the shader before it?