In Sascha Willems's offscreen rendering sample, there are 2 VkSubpassDependency for the main renderPass, and 2 for the offscreen renderPass. First, I often see pairs of VkSubpassDependency, and don't understand why.
VkSubpassDependency of the main renderPass:
dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL;
dependencies[0].dstSubpass = 0;
dependencies[0].srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
dependencies[0].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependencies[0].srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
dependencies[1].srcSubpass = 0;
dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL;
dependencies[1].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependencies[1].dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
dependencies[1].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
dependencies[1].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
VkSubpassDependency of the offScreen renderPass:
dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL;
dependencies[0].dstSubpass = 0;
dependencies[0].srcStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
dependencies[0].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependencies[0].srcAccessMask = VK_ACCESS_SHADER_READ_BIT;
dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
dependencies[1].srcSubpass = 0;
dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL;
dependencies[1].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
dependencies[1].dstStageMask = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
dependencies[1].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
dependencies[1].dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
In the main renderPass, is the second VkSubpassDependency (dependencies[1]) only here for the presentation to the swapchain? Is it mandatory?
For the offScreen renderPass, in a general way I don't understand the point of dependencies[0]:
As we only need to write into the framebuffer, and tell the main renderPass when it is finished, it seems to me that's what the dependencies[1] do.
What is the meaning of dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL; because there is no other pass involved before the offscreen renderPass. Is it just for the offscreen renderpass to wait the main renderPass finish the presentation into the swapchain?
My last question is more specific: if I use these 4 VkSubpassDependency, in a similar way Sasha does in this sample, so in order to do an offscreen renderPass, I've got a validation error "Dependency graph must be specified such that an earlier pass cannot depend on a later pass." I can't find anything about this error on the internet. I just found that this error is triggered because: dependency.srcSubpass > dependency.dstSubpass. Any idea?
Here is the link for Sascha Willems's offscreen rendering sample: https://github.com/SaschaWillems/Vulkan/blob/master/examples/offscreen/offscreen.cpp