Write same color buffer in different sub-passes of the render pass

Hi all,

I wrote a VkRenderPass. There are two color and depth attachment VkAttachmentDescriptions and we note they are C0, C1, D0, and D1. I list the details of each VkAttachmentDescription as follows:
C0 : LoadOp clear, StoreOp Store.
D0 : LoadOp clear, StoreOp Store.
C1 : LoadOp load, StoreOp Store.
D1 : LoadOp load, StoreOp Store.

And I wrote two sub-passes for this VkRenderPass, the first sub-pass (note SP1) use C0 as color attachment and D0 as depth attachment. The second sub-pass (note SP2) use C1 as color attachment and D1 as depth attachment. The VkSubPassDependency between SP1 and SP2 describe as follows :
srcPipelineStage : Bottom.
dstPipelineStage : Top
It means draw commands in SP2 need wait SP1 finished. I try to avoid write-after-write hazard.(I’m not sure it’s correct usage or not?)

Now let us see my render flow.

Firstly, I have two VkImages, one is used as color buffer(note Cb). Another is used as depth buffer(note Db).

Secondly, I wrote four VkImageViews for bind the color and depth buffer for VkFrameBuffer(note FB). I specify the four ImageViews as follows :
ImageView 0 bind with color buffer Cb.
ImageView 1 bind with depth buffer Db.
ImageView 2 bind with color buffer Cb.
ImageView 3 bind with depth buffer Db.

And then, the draw flow are list as follow :
BeginRenderPass with FB( current is SP0)
vkCmdDraw for quad1. (we call this C00)
vkCmdDraw for quad2. (we call this C01)
vkCmdNextRenderPass (current should be SP1)
vkCmdDraw for quad1. (we call this C00)
vkCmdDraw for quad2. (we call this C01)
EndRenderPass

Finally, I can see the result is my expect.

But I have some questions about this rendering flow.

The first is about multiple sub-passes. I found some informations and they tell me that the execution between sub-passes are asyncheonization. Is it real?

If it’s real(command execution is asynchronization between sub-passes), the second question is coming.

The pipeline stages of the draw commands in same sub-pass progress are step-by-steps?

For example, C00 and C01 are draw cmds in SP0. Is the execution about C00 and C01 like this :

SP0 => C00 TOP -> C01 TOP -> C00 VERTEX INPUT -> C01 VERTEX INPUT -> C00 VERTEX SHADER -> C01 VERTEX SHADER -> … C00 BOTTOM -> C01 BOTTOM.
(Because I think it should execute by the steps in this example, thus VkSubPassDependency be able to use for synchronizing sub-passes.)

They are my two question.

B.R.
LaChen

The title of your question seems distinct from the content of it. Your question’s text describes a circumstance where the two subpasses write to entirely different images, rather than the “same color buffer”.

Your subpasses do not appear to have dependencies on one another. Unless you are using the products of the first subpass to compute the second, there doesn’t seem to be any reason for a dependency here.

The dependency between the two subpasses ensures that one will finish before the other starts. However, if you remove the dependency, then there is no execution ordering between the two subpasses.

Except where an execution dependency exists, or the Vulkan standard says otherwise, commands execute in an order largely determined by Vulkan itself.

The primary place where implicit execution order happens revolves around per-fragment operations (that aren’t fragment shader invocations). This ensures that blending operations are ordered, so that blending/depth tests/etc will act on data created by from previous drawing operations in the command list.

Hi,
At first, I’m very appreciating your answer. Now I will describe my question and explanation about your answer.
1.

I bind a VkImage(format RGBA_8888) to two ImageViews. Those ImageViews are used distinctly at SP1 and SP2. So I think when draw commands are executed, the VkImage will be filled at SP1 and SP2.

Actually, I want the result is all commands in SP2 are executed after all commands are finished in SP1.
So I wrote the dependency for SP1 and SP2. But I’m not sure it’s correct usage or not.

About question “The pipeline stages of the draw commands in same sub-pass progress are step-by-steps?”

I think SubpassDependency is similar with vkCmdBarrier. Therefore, I think commands in same subpass will execute like this:
C00 TOP -> C01 TOP -> C00 VERTEX INPUT -> C01 VERTEX INPUT -> C00 BOTTONM->C01 BOTTOM.
But is it right ?

B.R.
GuanZhi