External subpass dependency synchronization

Let’s say we have two subpasses, the first one contains an image as a color attachment and the second one uses this image as a texture.

renderPass1 = {
    initialLayout = undefined,
    finalLayout = shader read only optimal
};

We need to synchronise the color attachment output and fragment shader stage in subpass dependency.
It’s all clear here:

Subpass dependency in renderPass1
srcSubpass = lastSubpass,
dstSubpass = VK_SUBPASS_EXTERNAL,
srcStageMask = color attachment output,
srcAccessMask = color attachment write,
dstStageMask = fragment shader,
dstAccessMask = shader read

And here it is not clear:

Subpass dependency in renderPass2
srcSubpass = VK_SUBPASS_EXTERNAL,
dstSubpass = 0,
srcStageMask = color attachment output,
srcAccessMask = color attachment write,
dstStageMask = fragment shader,
dstAccessMask = shader read

I have a question: How does this synchronise the transition of the image layout from renderPass1 to finalLayout? How can the subpassDependency of one renderPass synchronise the layout transition of another renderPass?

My previous question was answered that layout transition happens between two synchronisation areas. Then the question arises: In this situation it only works with the transition to the finalLayout or with layout transitions at the beginning of the subpass too?

You seem… strangely fixated on the synchronization of layout transitions. Layout transitions are specifically defined in a way so that you don’t have to think about their synchronization as a distinct operation. That’s why there’s no stage for them. That’s why there’s no special way of mentioning them or an action command to provoke them.

Any question of how layout transitions work with a particular synchronization setup has one answer: they work correctly.

More specifically, if your synchronization is correct without considering layout transitions, if the source stages/accesses are properly synchronized with the destination stages/accesses, then any layout transitions that happen as part of that synchronization process cannot break that correctness. Similarly, if your synchronization is broken with regard to source/destination stages/accesses, layout transitions cannot fix it.

1 Like

You are right, the topic of synchronizing layout transitions is really difficult for me. What you wrote was very helpful for me. Thank you!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.