1
votes

I've worked through the vulkan-tutorial.com tutorial and tried to write a small program with Vulkan, but I came across the following problem:

The program simply displays an image and runs without errors, but after the size of the window is changed, and thus the swapchain etc. recreated, a validation layer throws an error message in the vkQueuePresentKHR function:

Validation layer: [ VUID-VkPresentInfoKHR-pImageIndices-01296 ] Object: 0x4e3b5f0 (Type = 4) | Images passed to present must be in layout VK_IMAGE_LAYOUT_PRESENT_SRC_KHR or VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR but is in VK_IMAGE_LAYOUT_UNDEFINED. The Vulkan spec states: Each element of pImageIndices must be the index of a presentable image acquired from the swapchain specified by the corresponding element of the pSwapchains array, and the presented image subresource must be in the VK_IMAGE_LAYOUT_PRESENT_SRC_KHR layout at the time the operation is executed on a VkDevice (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-VkPresentInfoKHR-pImageIndices-01296)

This error message does not occur, once or twice, when the swapchain and all other objects that depend on the window size have been recreated and vkQueuePresentKHR has been called.

Why can the swapchain's images be in the wrong layout for a short time and be back in the right layout after a maximum of two loop passes?

1
That depends on how You record command buffers and perform layout transitions. - Ekzuzy
Because bugs never make sense... until you figure them out. Show yer code. - krOoze
ensure you wait for device idle (vkDeviceWaitIdle) before and after resizing. - j-p
Thank you for your answers. j-p, I wait before I resize until the device is idle. After that, waiting for the device has not changed anything. krOoze, which part of the project would be helpful? Ekzuzy, it is unlikely that the error in my code is caused by layout transitions, because unlike my old project, in which the error does not occur, I have not changed anything in this code. In terms of Command Buffers, I have changed a lot, so I have simplified the code a lot and thus tried to find the error, but unfortunately I had no success. - SOUser
@SOUser But if Validation Layers complain that a swapchain image should have a present_src layout but has an undefined layout, then it must be a problem with layout transitions. Maybe render pass setup? Initial and final layouts? - Ekzuzy

1 Answers

0
votes

I know the question is old, but I've been struggling with exactly the same issue and it was a pain to figure it out, so I'd like to leave this answer for others:

What happened in my case, was that after swap chain recreation I lost synchronization between frame buffers and respective swap chain images. This resulted in using wrong frame buffers and thus rendering to different images than requested by the swap chain.

Right after swap chain recreation all images are in VK_IMAGE_LAYOUT_UNDEFINED, causing the validation layer to catch the issue. However once you (incorrectly) render to all of those images, their layout is no longer undefined and the error is not reported anymore.

Of course your program will keep displaying wrong images, but if the scene is static this is impossible to observe.