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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With