Vulkan: Can't find info on a particular usecase, regarding preserve attachments, in the Spec

Viewed 98

Imagine a usecase where an attachment is included in the first subpass of a RenderPass as a preserve attachment. I'll defined the "first subpass" as subpass A, where there is a RenderPass with N subpasses, and there are dependencies between its subpasses where A must be executed first.

Now, that usecase doesn't make sense to me. However, I went to look for clarity about that in the Spec and, so far, I haven't come across anything forbidding it. In my code, I'm handling this now by issuing an assertion failure when I detected that. But, I would really like to hear from the Spec's mouth that this is, in fact, not a legal/sensical thing to do. I'm trying to avoid making assumptions.

If someone knows where I could find reliable info regarding this usecase, please point me to it.

1 Answers

Preserve attachments exist to deal with the following scenario:

You have a subpass A which manipulates an attachment. You have a subpass C which uses the data generated into that attachment by A. Therefore, there is some dependency between A and C. However, you also have a subpass B which depends on some other data generated by A, and which C depends on as well (thus, A and C's dependency can be implicit based on the A->B and B->C dependencies).

That is, subpass B must execute between A and C. But let's also say that subpass B itself doesn't use the particular attachment that A generated for C.

Because the execution graph requires that B execute between A and C, any hardware that implements this execution graph may need to allocate some storage within subpass B to make sure that this attachment's contents are preserved. On tile based renderers in particular, such storage is often at a premium. Therefore, the Vulkan API requires that you explicitly state in subpass B's definition that the attachment from A needs to be preserved while B is executing, even though B doesn't use it for anything.

This is the only place where preserving an attachment matters. Even so, there is nothing in the Vulkan specification that forbids the use of a preserve attachment outside of this scenario. You will find no statement in the specification that says that this is forbidden, only a statement about where preserve attachments are necessary.

Now, this doesn't mean you should just shove preserve attachments anywhere. You should use them when they are required, but that's it.

Related