If we have RenderPass A, B and C submitted in sequence.
A write image I as color attachment.
B Read image I as sampled Image in Fragment Shader.
C Read image I as sampled Image in Vertex Shader.
B and C has no depencies.
Is there a viable approach can achieve maximum overlapping between A, B and C?
Here are 2 solutions I tried:
The first synchronize solution came into my mind is just insert a single barrier b1 between A and B with
b1.srcStage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
b1.dstStage = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
b1.srcAccess = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
b1.dstAccess = VK_ACCESS_SHADER_READ_BIT
b1.srcLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
b1.dstLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
Submitted like A->b1->B->C
It should work, Memory modified by A will be visible before VertexStage of B&C, However b1 will prevent VertexStage of B from overlapping with A
The second solution is change the b1.dstStage to VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT (let’s call it b1′), b1′ sync A and B more resonable, however this barrier is not enough to syncronize C.
since C read image I in vertex shader which stage is before FragmentStage, we need insert another barrier b2 between B and C to ensure C can see the memory modified by A, which I’m not so sure how, I believe one conservative way is
b2.srcStage = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
b2.dstStage = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
//no memory modify from B. execution barrier alone should handle this
Submitted like A->**b1**->B->**b2**->C In this solution b1
allows VertexStage of B overlaping with A, But, as you can see, b2 introduced a false excution dependency from B to C and block VertexStage of C from overlapping with FragmentStage of B which obviously an overkill.
Thus overlapping is sub-optimal in both solutions.
HandsonicV4 Lee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.