Reputation: 1
I'm encountering validation errors when resizing a window in my Vulkan application. While the application works fine initially, resizing sometimes (about 1 in 2) causes synchronization issues and I receive the following validation errors:
vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] VkCommandBuffer [...] is unrecorded and contains no commands. The Vulkan spec states: Each element of the pCommandBuffers member of each element of pSubmits must be in the pending or executable state.
vkQueuePresentKHR(): pPresentInfo->pSwapchains[0] images passed to present must be in layout VK_IMAGE_LAYOUT_PRESENT_SRC_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 and in VK_IMAGE_LAYOUT_PRESENT_SRC_KHR.
I handle window resizing by recreating the swapchain and all associated resources (framebuffers, image views, etc.) I reset and re-record command buffers after resizing I update descriptor sets Here is my cleanupSwapChain and recreateSwapChain functions:
void cleanupSwapChain() {
gbuffer.cleanupFramebuffers(vulkanDevice, MAXFRAMESINFLIGHT);
gbuffer.cleanupImages(vulkanDevice, MAXFRAMESINFLIGHT);
for (auto imageView : swapChainImageViews) {
vkDestroyImageView(vulkanDevice.getDevice(), imageView, nullptr);
}
swapChainImageViews.clear();
if (gbuffer.getCommandBuffers().size() != swapChainImages.size()) {
gbuffer.freeCommandBuffers(vulkanDevice);
gbuffer.createCommandBuffers(vulkanDevice, MAXFRAMESINFLIGHT);
}
vkDestroySwapchainKHR(vulkanDevice.getDevice(), swapChain, nullptr);
}
void recreateSwapChain() {
int width = 0, height = 0;
glfwGetFramebufferSize(window, &width, &height);
while (width == 0 || height == 0) {
if (glfwWindowShouldClose(window))
return;
glfwGetFramebufferSize(window, &width, &height);
glfwWaitEvents();
}
vkDeviceWaitIdle(vulkanDevice.getDevice());
cleanupSwapChain();
createSwapChain();
createImageViews();
gbuffer.createImageViews(vulkanDevice, swapChainExtent, MAXFRAMESINFLIGHT);
gbuffer.updateDescriptorSets(vulkanDevice, MAXFRAMESINFLIGHT);
gbuffer.createFramebuffers(vulkanDevice, grid, swapChainImageViews, swapChainExtent, MAXFRAMESINFLIGHT);
}
Upvotes: 0
Views: 34