vkCreateSwapchainKHR:内部绘图创建失败

vkCreateSwapchainKHR: internal drawable creation failed

我的 Vulkan 应用程序可以正常工作,但由于某种原因它停止工作(我不相信我触及了任何可能破坏它的东西,除了将我的引擎项目设为 .lib 而不是 .dll)并开始提供验证层中的 "vkCreateSwapchainKHR: internal drawable creation failed" 错误。 vkCreateSwapchainKHR returns VK_ERROR_VALIDATION_FAILED_EXT.

我已经检查过这个答案: Wat does the "vkCreateSwapchainKHR:internal drawable creation failed." means,但这不是我的问题,(正如我所说,它一直在工作,直到它不再工作)。这是我认为相关的所有代码,如果您需要其他内容,请评论:

Window 创建:

/* Initialize the library */
if (!glfwInit())

    /* Create a windowed mode window and its OpenGL context */
    glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
    glfwWindowHint(GLFW_DECORATED, _WCI.IsDecorated);
    GLFWWindow = glfwCreateWindow(Extent.Width, Extent.Height, _WCI.Name.c_str(), nullptr, nullptr);

    if (!GLFWWindow) glfwTerminate();

    //glfwMakeContextCurrent(GLFWWindow);

    uint32 Count = 0;
    auto ff = glfwGetRequiredInstanceExtensions(&Count);

    GS_BASIC_LOG_MESSAGE("GLFW required extensions:")
    for (uint8 i = 0; i < Count; ++i)
    {
        GS_BASIC_LOG_MESSAGE("%d: %s", i, ff[i]);
    }

    WindowObject = glfwGetWin32Window(GLFWWindow);
    WindowInstance = GetModuleHandle(nullptr);

我使用了正确的实例扩展:

const char* Extensions[] = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME, VK_EXT_DEBUG_UTILS_EXTENSION_NAME };
VKSwapchainCreator VulkanRenderContext::CreateSwapchain(VKDevice* _Device, VkSwapchainKHR _OldSwapchain) const
{
    VkSwapchainCreateInfoKHR SwapchainCreateInfo = { VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR };

    SwapchainCreateInfo.surface = Surface.GetHandle();
    SwapchainCreateInfo.minImageCount = 3;
    SwapchainCreateInfo.imageFormat = Format.format;
    SwapchainCreateInfo.imageColorSpace = Format.colorSpace;
    SwapchainCreateInfo.imageExtent = Extent2DToVkExtent2D(RenderExtent);
    //The imageArrayLayers specifies the amount of layers each image consists of. This is always 1 unless you are developing a stereoscopic 3D application.
    SwapchainCreateInfo.imageArrayLayers = 1;
    SwapchainCreateInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
    SwapchainCreateInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
    SwapchainCreateInfo.queueFamilyIndexCount = 0;
    SwapchainCreateInfo.pQueueFamilyIndices = nullptr;
    SwapchainCreateInfo.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
    SwapchainCreateInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
    SwapchainCreateInfo.presentMode = PresentMode;
    SwapchainCreateInfo.clipped = VK_TRUE;
    SwapchainCreateInfo.oldSwapchain = _OldSwapchain;

    return VKSwapchainCreator(_Device, &SwapchainCreateInfo);
}

我的 GPU 支持 VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHRVK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR

    VkBool32 Supports = 0;
    vkGetPhysicalDeviceSurfaceSupportKHR(_PD, PresentationQueue.GetQueueIndex(), _Surface, &Supports);

    VkSurfaceCapabilitiesKHR SurfaceCapabilities = {};
    vkGetPhysicalDeviceSurfaceCapabilitiesKHR(_PD, _Surface, &SurfaceCapabilities);

    VkBool32 Supported = 0;
    vkGetPhysicalDeviceSurfaceSupportKHR(_PD, PresentationQueue.GetQueueIndex(), _Surface, &Supported);

    auto bb = vkGetPhysicalDeviceWin32PresentationSupportKHR(_PD, PresentationQueue.GetQueueIndex());

这里的所有内容 returns 都是正确的,尽管我觉得 VkSurfaceCapabilitiesKHR 为 currentExtent、minImageExtent 和 maxImageExtent 返回相同的范围似乎很可疑。

解决方案是从 if 内部删除 glfwInit 调用并将其放在外部。

if (!glfwInit()) -> glfwInit()

不知道为什么,如果有人知道为什么这会导致问题,我很想知道。

/* Initialize the library */
if (!glfwInit())

    /* Create a windowed mode window and its OpenGL context */
    glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
    glfwWindowHint(GLFW_DECORATED, _WCI.IsDecorated);

如果这是您的实际代码,则表示 "if glfwInit() succeeds skip glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);"。正如我们所知,不调用提示会导致错误。

if里面应该没有否定吧。并且(这不是 Python)它应该有范围 {} 来覆盖所有初始化代码。