繁体   English   中英

Vulkan:调整窗口大小后重新创建交换链时出现图像错误

[英]Vulkan: Image error when recreating the swapchain after a window resize

所以我试图通过重新创建交换链及其图像视图以及所有这些来处理窗口大小调整。 这是我正在使用的方法:

void VxRenderer::recreateSwapchain() {
    device.waitIdle();

    for (uint32_t i = 0; i < swapchainImageCount; ++i) {
        vkDestroyFramebuffer(device, framebuffers[i], nullptr);
        vkDestroyImageView(device, swapchainImageViews[i], nullptr);
    }

    vkResetCommandPool(device, commandPool, 0);
    vkDestroyPipeline(device, pipeline, nullptr);
    vkDestroySwapchainKHR(device, swapchain, nullptr);

    createSwapchain();
    getSwapchainImages();
    createSwapchainImageViews();
    createFramebuffers();
    createGraphicsPipeline();
    recordCommandBuffers();
}

问题是有时我在调整大小时收到此错误:

Validation Error: [ VUID-VkPresentInfoKHR-pImageIndices-01296 ] Object 0: handle = 0x1d7260c6cc8,
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)

它说问题来自VkPresentInfoKHR结构中pImageIndices中的VkPresentInfoKHR ,我将其写为:

uint32_t imageIndex;
VkResult result =
        vkAcquireNextImageKHR(device, swapchain, UINT64_MAX, imageAcquiredSemaphores[currentImage], VK_NULL_HANDLE, &imageIndex);

if (result == VK_ERROR_OUT_OF_DATE_KHR) {
    recreateSwapchain();
    return;
}

...

VkPresentInfoKHR presentInfo;
presentInfo.sType              = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
presentInfo.pNext              = nullptr;
presentInfo.waitSemaphoreCount = 1;
presentInfo.pWaitSemaphores    = &renderFinishedSemaphores[currentImage];
presentInfo.swapchainCount     = 1;
presentInfo.pSwapchains        = &swapchain;
presentInfo.pImageIndices      = &imageIndex;
presentInfo.pResults           = nullptr;

您需要将您的图像从未定义的布局转换为可呈现的图像格式,具体取决于您正在使用它做什么。 例如,如果您将其用作着色器中的纹理,则它需要位于SHADER_READ_ONLY_OPTIMAL布局中。

您可以通过多种方式做到这一点,其中之一是您可以提交到临时队列的图像内存屏障 并且您绝对需要在重新创建交换链后执行此操作,因为窗口大小调整操作会使整个上下文无效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM