Attachment preservation in multiple subpass dependency graph

The Vulkan specification permits a subpass to have multiple dependencies. So consider the possibility that subpass 2 depends on both subpass 1 and subpass 0, but there is no dependency between 0 and 1.

Now, consider the behavior of attachments in this case. Suppose subpass 0 uses attachment 0 as a color attachment, and subpass 1 uses attachment 1 as a color attachment. What happens if subpass 2 uses both attachments?

When dealing with attachment preservation, the specification says the following:

The contents of an attachment within the render area become undefined at the start of a subpass S if all of the following conditions are true:

  • The attachment is used as a color, depth/stencil, or resolve attachment in any subpass in the render pass.
  • There is a subpass S[sub]1[/sub] that uses or preserves the attachment, and a subpass dependency from S[sub]1[/sub] to S.
  • The attachment is not used or preserved in subpass S.

This does not apply here. Subpass 0 uses attachment 0, and there is a dependency to subpass 2, which also uses the attachment. There is no dependency between subpass 1 and 0.

This suggests that the implementation is required to preserve attachments in such a case. If that is the case, what is the point of having the rule about making the attachment undefined to begin with? It seems strange that implementations are allowed to toss away unpreserved images if you add a dependency between 0 and 1, but without that dependency, it must preserve that image. Even though it is probably executing the subpasses in the exact same order.

It lets the implementation know how much memory a subpass needs to cache at minimum by only looking at how many attachments it uses or preserves. And allows for reordering of subpasses based on how much memory would be required.

For example if subpass 0 uses 3 attachments and subpass 1 only a single independent one while subpass 2 uses them all. Then the implementation can swap 0 and 1 and save the memory of 2 attachments during execution.