Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vulkan attachment description

Tags:

vulkan

Render pass attachments require the fields initial layout and final layout and are described as such in the documentation:

initialLayout is the layout the attachment image subresource will be in when a render pass instance begins.

finalLayout is the layout the attachment image subresource will be transitioned to when a render pass instance ends. During a render pass instance, an attachment can use a different layout in each subpass, if desired.

Does this mean that the attachments will be transitioned automatically when we call and end a render pass instance or does it mean the programmer is expected to do the transition to these layouts prior and after the render pass? Thanks

like image 591
Temp4890 Avatar asked Mar 13 '23 02:03

Temp4890


1 Answers

Note the difference in language:

initialLayout is the layout the attachment image subresource will be in when a render pass instance begins.

finalLayout is the layout the attachment image subresource will be transitioned to when a render pass instance ends.

It makes it more clear if you consider that a render pass needs to automatically insert layout transitions between subpasses. To do that, at any point it must know the layout the attachment is currently in and the layout it needs to transition to. InitialLayout provides information about the layout the image subresource is in when it enters the render pass.

An automatic layout transition does happen at the beginning of the render pass, however, from initialLayout to the layout specified in the attachment reference of the subpass that first uses the attachment. Similarly, there is an automatic layout transition from the layout used by the last subpass to the layout assigned to finalLayout.

I assume the same rules that apply to oldLayout of image barriers also apply to initialLayout here. Notably:

oldLayout must be VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_PREINITIALIZED or the current layout of the image region affected by the barrier.

Therefore initialLayout can be used as a hint to whether or not you want to discard the contents of the image. I am surprised valid image layouts aren't included in the valid usage for the attachment description as well.

like image 139
Quinchilion Avatar answered Mar 27 '23 16:03

Quinchilion