Pipeline barriers across multiple shaders?

Viewed 513

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:

  1. dispatch shader that writes to image A
  2. vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, ...);
  3. 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

  1. dispatch shader that writes to image A
  2. dispatch unrelated shader that doesn't touch image A
  3. vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, ...);
  4. 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?

1 Answers
Related