Yuri Dolotkazin
Yuri Dolotkazin

Reputation: 479

VkSubpassDependency specification clarification

I am trying to understand the specification of the VkSubpassDependency structure.

Link to VkSubpassDependency structure is on the specification page

The part that confuses me a lot is the relationship between (srcSubpass, dstSubpass) and (srcStageMask, dstStageMask).

The case where srcSubpass is equal to dstSubpass is the same as a pipeline barrier and doesn't raise any questions for me. However, other cases are quite questionnable.

The specification says:

If srcSubpass is equal to VK_SUBPASS_EXTERNAL, the first synchronization scope includes commands that occur earlier in submission order than the vkCmdBeginRenderPass used to begin the render pass instance. Otherwise, the first set of commands includes all commands submitted as part of the subpass instance identified by srcSubpass and any load, store or multisample resolve operations on attachments used in srcSubpass. In either case, the first synchronization scope is limited to operations on the pipeline stages determined by the source stage mask specified by srcStageMask.

By using the definition of syncronisation scopes given by the specification in synchronization-dependencies I interpret the specification this way:

I interpret in this case that the dependency works in the following way: srcSubpass executes freely over the pipeline stages until it reaches the stage given in srcStageMask parameter and stalls until the dstSubpass reaches the stage described in dstStageMask.

In that case I am getting confused about determining the first syncronisation scope.

Because the srcSubpass is equal to VK_SUBPASS_EXTERNAL then the first synchronisation scope includes commands that occur earlier in the submission order than the vkCmdBeginRenderPass used to begin the render pass instance as the specification says. Because the external commands may not have any interaction with the pipeline stages, it makes the interpretation of srcStageMask quite ambiguous. Because nothing relates to the pipeline stage may not be outside the render pass: Does the line from the specification: "In either case, the first synchronization scope is limited to operations on the pipeline stages determined by the source stage mask specified by srcStageMask." refers to the pipeline stages inside dstSubpass and that extends the first syncronistaion scope down to srcStageMask stage in dstSubpass?

Upvotes: 1

Views: 1439

Answers (1)

krOoze
krOoze

Reputation: 13276

You are largely answering your questions. I think the problem is you have the wrong intuition about pipeline stages.

Think about all the commands you have submitted to a queue. Each command is at any point in some pipeline stage, and all commands proceed through the pipeline independently (I should say asynchronously). Think of the pipeline as a playing board, and think of the commands as pegs that go on that board. Everything else should start making sense with that new intuition.

A Pipeline Barrier\Subpass Dependency introduces a dependency. The effect is all the commands in the source scope have to finish at least the srcStageMask stage in their execution, before any of the commands in the destination scope are even allowed to start the dstStageMask stage of their execution.


srcSubpass == dstSubpass is a special case that does nothing but declare a subpass self-dependency. All it does is allow you to later use vkCmdPipelineBarrier inside that Subpass recording. That works mostly like a normal Pipeline Barrier, except it is limited to the commands inside that Subpass, and it is not allowed to change Image Layouts.

srcSubpass < dstSubpass case introduces a dependency between those two Subpasses. The commands recorded in the srcSubpass are the source scope, and the commands in dstSubpass are the destination scope. I.e. all commands in the source subpass must reach at least srcStage, before any of the commands in the destination subpass are allowed to start the dstStage of their execution.

VK_SUBPASS_EXTERNAL refers to the outside of the Render Pass Instance.

I.e. if srcSubpass == VK_SUBPASS_EXTERNAL, then the source scope is all commands recorded before vkCmdBeginRenderPass and anything earlier in submission order. So, this Subpass Dependency would say all commands before the render pass instance have to reach at least their srcStage stage of execution, before any of the commands of the dstSubpass enter their dstStage stages.

If dstSubpass == VK_SUBPASS_EXTERNAL then the destination scope is all commands recorded after vkCmdEndRenderPass (and also later in submission order). So, this Subpass Dependency would say all commands recorded in the srcSubpass subpass have to reach at least their srcStage stage of execution, before any of the commands after the Render Pass Instance enter their dstStage stages of execution.

Upvotes: 7

Related Questions