I am currently trying to incorporate imgui into my vulkan-application.
So i have two render-passes, one for my 3d-scene, and one for imgui.
In my 3d-renderpass i set initialLayout to undefined and finalLayout to attachmentOptimal.
In the imgui-renderpass i set initialLayout to attachmentOptimal and finalLayout to presentSrcKHR.
I also create the following subpass-dependencies:
For my 3d-renderpass:
auto dependency = vk::SubpassDependency{};
dependency.srcStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput;
dependency.srcAccessMask = (vk::AccessFlags)0;
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
dependency.dstStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput;
dependency.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
dependency.dstSubpass = 0;
auto ui_dependency = vk::SubpassDependency{};
ui_dependency.srcStageMask =
vk::PipelineStageFlagBits::eColorAttachmentOutput;
ui_dependency.srcAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
ui_dependency.srcSubpass = 0;
ui_dependency.dstStageMask =
vk::PipelineStageFlagBits::eColorAttachmentOutput;
ui_dependency.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite |
vk::AccessFlagBits::eColorAttachmentRead;
ui_dependency.dstSubpass = VK_SUBPASS_EXTERNAL;
and for the imgui-renderPass:
auto dependency = vk::SubpassDependency();
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
dependency.srcStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput;
dependency.srcAccessMask = vk::AccessFlagBits::eColorAttachmentRead |
vk::AccessFlagBits::eColorAttachmentWrite;
dependency.dstSubpass = 0;
dependency.dstStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput;
dependency.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
auto extern_dependeny = vk::SubpassDependency{};
extern_dependeny.srcSubpass = 0;
extern_dependeny.srcStageMask =
vk::PipelineStageFlagBits::eColorAttachmentOutput;
extern_dependeny.srcAccessMask = vk::AccessFlagBits::eColorAttachmentRead |
vk::AccessFlagBits::eColorAttachmentWrite;
extern_dependeny.dstSubpass = VK_SUBPASS_EXTERNAL;
extern_dependeny.dstStageMask =
vk::PipelineStageFlagBits::eColorAttachmentOutput;
extern_dependeny.dstAccessMask = vk::AccessFlagBits::eMemoryRead;
So i would think that i am correctly defining the dependencies of the render-passes. However, when i submit the two command-buffers, one for the 3d-scene, one for imgui, the validation-layers tell me:
VUID-VkPresentInfoKHR-pImageIndices-01296(ERROR / SPEC): msgNum: -945112042 - Validation Error: [ VUID-VkPresentInfoKHR-pImageIndices-01296 ] Object 0: handle = 0x55eeaedf2f90, name = present_queue, type = VK_OBJECT_TYPE_QUEUE; | MessageID = 0xc7aabc16 | vkQueuePresentKHR(): 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_COLOR_ATTACHMENT_OPTIMAL. 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)
Note that i do submit the command-buffers with two signal-semaphores, with the pipeline-stage-flags of colorAttachmentOutput and BottomOfPipe respectively.
In my call to present, i pass both of these semaphores as wait-semaphores. Does anyone see an obvious error in my subpass-dependencies that would lead to this incorrect behaviour? If other issues could contribute to this error, which i have not mentioned here, let me know and i will happily provide respective code-sections.