通过 VkSubpassDependency 的多个附件布局转换

Multiple attachment layout transitions via VkSubpassDependency

我想弄清楚如何使用 VkSubpassDependency 来解释多个附件布局转换(尤其是那些不同类型的)。我看到一个 Sascha Willems example on how to use access masks in the subpass dependency to create an image layout transition to the final layout, but Sascha only uses a single attachment. In my situation I have multiple attachments, one for the color, one for the depth, each with a different final transition. Do I just shove more access mask bits in? from the spec,看起来我实际上必须在 涉及颜色的管道。

Any synchronization command that takes both stage masks and access masks uses both to define the access scopes - only the specified access types performed by the specified stages are included in the access scope. An application must not specify an access flag in a synchronization command if it does not include a pipeline stage in the corresponding stage mask that is able to perform accesses of that type.

我找不到这方面的任何例子,也没有在任何地方看到这个概述。

访问掩码与布局转换无关。对于渲染过程,您不指定布局转换 明确地 附件。相反,您在提供给 VkSubpassDescriptionVkAttachmentReference 中定义附件应用于该子通道的布局。然后渲染通道系统负责在各个​​子通道之间插入适当的过渡,这完全取决于它选择执行子通道的顺序。

当然,由子通道执行依赖性通知的顺序。因此,示例中引用的评论 "Use subpass dependencies for layout transitions" 具有误导性。导致布局转换的不是子通道依赖性;这是渲染通道系统。只是子通道依赖项对渲染通道如何注入布局转换提供了约束。

现在,这些约束确实很重要,因为虽然渲染过程更加自动化,但 Vulkan 仍然是 Vulkan。子通道之间没有明确的依赖关系,它们可以按任何顺序执行。因此,如果一个子通道要使用另一个子通道的渲染产品,即使它只是覆盖那些渲染产品,它们之间仍然必须存在依赖关系。

访问掩码很重要,但对于布局转换而言并不重要。它们对于正确 同步 很重要;它们对于确保源子通道使正确的操作对目标子通道可见很重要。

所以,如果subpass 0写入颜色和深度缓冲区,而subpass 1只关心写入深度缓冲区的值,它们之间的依赖关系只需要说它会访问写入的深度信息(和当然,它打算如何阅读它)。