Non-optimal synchronization with VkSubpassDependency

VkSubpassDependency dependency;
        dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
        dependency.dstSubpass = 0;
        dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
        dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
        dependency.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
        dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;

In this code depth attachment is forced to wait for color attachment write. How to avoid this? And is it even possible to create dependencies only for certain attachments?

Well, let me ask you a question: is anything in subpass 0 going to access both the color and depth attachments? If nothing in subpass 0 needs to do color attachment accesses (perhaps it is a depth pre-pass?), then the dependency should not include color writes. And if some commands in subpass 0 do access the color attachment, then there is nothing to avoid since accessing both is the point of the subpass.

And if there is a group of commands that only access the depth attachment, and are followed by a set of commands that access both depth and color attachments, then make them into separate subpasses.

Hmm, it is certainly expressible. You can have two dependencies; one with color-to-color, and other with depth-to-depth stage.

Alternatively the depth stuff could be put in the dstSubpass = VK_SUBPASS_EXTERNAL Dependency.

1 Like

There is a draw command in 0 subpass. It accesses depth attachment and color attachment. But why do we need color attachment during fragment tests? Subpass dependency shows that, for example, at the early fragment tests stage we will wait for the previous render pass instance to finish working with color attachment.

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