A presentable image starts out in VK_IMAGE_LAYOUT_UNDEFINED
but will be VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
after they have been presented once.
There are 3 options. Ordered from best to worst (IMO):
Simply set the initialLayout of the attachment in the renderPass to VK_IMAGE_LAYOUT_UNDEFINED
or transition from VK_IMAGE_LAYOUT_UNDEFINED
every time. This is allowed and will imply that you don't care about the data still in the image. Most often you will be clearing or fully overwriting the image anyway.
valid Usage [of VkImageMemoryBarrier]
[...]
- oldLayout must be
VK_IMAGE_LAYOUT_UNDEFINED
,VK_IMAGE_LAYOUT_PREINITIALIZED
or the current layout of the image region affected by the barrier
Keep track of which images have been through the pipeline already and select the oldLayout
accordingly when recording the commandBuffer.
Do the transitions after creating the swapchain but using vkAcquireNextImageKHR
and vkQueuePresentKHR
to ensure the application owns the image while transitioning. There is no guarantee in which order you get the images So it may be possible one image never gets returned.