Pikachuxxxx / Razix

High Performance Game Engine for Production Pipeline
https://pikachuxxxx.github.io/razix-website/
Apache License 2.0
470 stars 25 forks source link

Vulkan swapchain and RT layout transition validation error #83

Open Pikachuxxxx opened 2 years ago

Pikachuxxxx commented 2 years ago

The swapchain image is in VK_IMAGE_LAYOUT_UNDEFINED layout, but to present the image, it should be in either VK_IMAGE_LAYOUT_PRESENT_SRC_KHR or VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR.

[VULKAN]  - Validation ERROR :
message ID : -945112042
ID Name : VUID-VkPresentInfoKHR-pImageIndices-01296
Message : Validation Error: [ VUID-VkPresentInfoKHR-pImageIndices-01296 ] Object 0: handle = 0x22b53b62620, type = VK_OBJECT_TYPE_QUEUE; | MessageID = 0xc7aabc16 | vkQueuePresentKHR(): pSwapchains[0] 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://github.com/KhronosGroup/Vulkan-Docs/search?q=)VUID-VkPresentInfoKHR-pImageIndices-01296)

We can manually transition the layout of swapchain image to VK_IMAGE_LAYOUT_PRESENT_SRC_KHR before presenting to resolve this issue using memory and pipeline barriers, however now VK_IMAGE_LAYOUT_PRESENT_SRC_KHR is not a layout fit for rendering in the next frame. So before rendering, we need to transition the image back into VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL. Hence it must be done once before presenting and again after presenting to make sure the format of the swapchain images is properly transitioned.

============================================================ Razix Engine Stats Version : 0.20.1 Configuration : [Debug | Release | Distribution] Release Stage : Development Release Date : 9-1-2022 OS : Windows 10 Home Processor : Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz 2.60 GHz Vulkan API Version : 1.2.186 GPU Name : NVIDIA GeForce RTX 2060 Vendor ID : 4318 Device Type : DISCRETE GPU Driver Version : 497.116.0

Pikachuxxxx commented 2 years ago

Vulkan Swapchain or RT initial render target layout transition issue