Wat 执行“vkCreateSwapchainKHR:internal drawable 创建失败".方法 [英] Wat does the "vkCreateSwapchainKHR:internal drawable creation failed." means

查看:33
本文介绍了Wat 执行“vkCreateSwapchainKHR:internal drawable 创建失败".方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是卡在交换链的创建上,我不知道为什么.我启用了验证层,我得到的最好的 anwser 是:

  • vkCreateSwapchainKHR:内部可绘制对象创建失败

我有一张 Nvidia GTX960 卡.我在上面运行了一些 vulkan 样本,所以它必须支持 vulkan.

这是我的交换链创建者功能:

void Renderer::createSwapChain(VkSwapchainKHR *swapchain,VkPhysicalDevice *dev,VkDevice *vulk_dev,VkSurfaceKHR *surface, uint32_t family_index,VkExtent2D *extent) {uint32_t 格式计数;VkFormat 格式;VkBool32 支持;vkGetPhysicalDeviceSurfaceSupportKHR(*dev, family_index, *surface, &support);如果(!支持){fprintf(*Renderer::error_log, "%d :Surface 不支持.", __LINE__);fclose(*Renderer::error_log);退出(-1);}vkGetPhysicalDeviceSurfaceFormatsKHR(*dev, *surface, &format_count, nullptr);矢量<VkSurfaceFormatKHR>表面格式(格式计数);vkGetPhysicalDeviceSurfaceFormatsKHR(*dev, *surface, &format_count,surface_format.data());if(1 == format_count &&surface_format[0].format == VK_FORMAT_UNDEFINED) {格式 = VK_FORMAT_B8G8R8A8_UNORM;infos.format.color_format = VK_FORMAT_B8G8R8A8_UNORM;}别的 {格式=表面格式[0].格式;}VkFormat depth_format = VK_FORMAT_D16_UNORM;VkFormatProperties format_props;vkGetPhysicalDeviceFormatProperties(*dev, depth_format, &format_props);如果(format_props.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT){infos.tiling = VK_IMAGE_TILING_LINEAR;}else if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {infos.tiling = VK_IMAGE_TILING_OPTIMAL;}别的 {fprintf(*Renderer::error_log, "%d: VK_FORMAT_D16_UNORM 不被支持",__LINE__);fclose(*Renderer::error_log);退出(-1);}VkPresentModeKHR present_mode_selected = VK_PRESENT_MODE_FIFO_KHR;uint32_t present_modes_c;vkGetPhysicalDeviceSurfacePresentModesKHR(*dev, *surface, &present_modes_c, nullptr);矢量<VkPresentModeKHR>present_modes(present_modes_c);vkGetPhysicalDeviceSurfacePresentModesKHR(*dev, *surface,&present_modes_c,present_modes.data());for (int i = 0; i 

解决方案

我最近遇到了完全相同的问题,该问题是由 GLFW 窗口中的 OpenGL 上下文引起的.

因此,如果您碰巧使用 GLFW,请添加一行

glfwWindowHint( GLFW_CLIENT_API, GLFW_NO_API );

在创建窗口之前.

I am always stuck at the swapchain creation, and I don't know why. I enabled the validation layers, and the best anwser I got is:

  • vkCreateSwapchainKHR: internal drawable creation failed

I have an Nvidia GTX960 card. i ran some vulkan samples on it so, It must support vulkan.

Here is my swapchain creator function:

void Renderer::createSwapChain(VkSwapchainKHR *swapchain,VkPhysicalDevice *dev,VkDevice *vulk_dev,VkSurfaceKHR *surface, uint32_t family_index,VkExtent2D *extent) {
    uint32_t format_count;
    VkFormat format;

    VkBool32 support;
    vkGetPhysicalDeviceSurfaceSupportKHR(*dev, family_index, *surface, &support);
    if (!support) {
        fprintf(*Renderer::error_log, "%d :Surface is not supported.", __LINE__);
        fclose(*Renderer::error_log);
        exit(-1);
    }

    vkGetPhysicalDeviceSurfaceFormatsKHR(*dev, *surface, &format_count, nullptr);
    vector<VkSurfaceFormatKHR> surface_format(format_count);
    vkGetPhysicalDeviceSurfaceFormatsKHR(*dev, *surface, &format_count, surface_format.data());

    if( 1 == format_count && surface_format[0].format == VK_FORMAT_UNDEFINED) {
        format = VK_FORMAT_B8G8R8A8_UNORM;
        infos.format.color_format = VK_FORMAT_B8G8R8A8_UNORM;
    }else {
        format = surface_format[0].format;
    }

    VkFormat depth_format = VK_FORMAT_D16_UNORM;
    VkFormatProperties format_props;
    vkGetPhysicalDeviceFormatProperties(*dev, depth_format, &format_props);
    if (format_props.linearTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
        infos.tiling = VK_IMAGE_TILING_LINEAR;
    }else if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
        infos.tiling = VK_IMAGE_TILING_OPTIMAL;
    }else {
        fprintf(*Renderer::error_log, "%d: VK_FORMAT_D16_UNORM is not supported",__LINE__);
        fclose(*Renderer::error_log);
        exit(-1);
    }

    VkPresentModeKHR present_mode_selected = VK_PRESENT_MODE_FIFO_KHR;
    uint32_t present_modes_c;

    vkGetPhysicalDeviceSurfacePresentModesKHR(*dev, *surface, &present_modes_c, nullptr);
    vector<VkPresentModeKHR> present_modes(present_modes_c);
    vkGetPhysicalDeviceSurfacePresentModesKHR(*dev, *surface,&present_modes_c,present_modes.data());
    for (int i = 0; i < present_modes_c; i++) {
        if (present_modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) {
            cout << "Mailbox supported." << endl;
            present_mode_selected = VK_PRESENT_MODE_MAILBOX_KHR;
        }
    }
    VkSurfaceCapabilitiesKHR capabilities;
    vkGetPhysicalDeviceSurfaceCapabilitiesKHR(*dev, *surface, &capabilities);

    if (capabilities.maxImageExtent.width < (*extent).width) {
        (*extent).width = capabilities.maxImageExtent.width;
    }
    if (capabilities.maxImageExtent.height < (*extent).height) {
        (*extent).height = capabilities.maxImageExtent.height;
    }
    VkCompositeAlphaFlagBitsKHR composite_alpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
    if (capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR) {
        composite_alpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
    }else if (capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR) {
        composite_alpha =VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR;
    }
    VkSurfaceTransformFlagBitsKHR transform;
    if (capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) {
        transform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
    }else {
        transform = capabilities.currentTransform;
    }

    VkSwapchainCreateInfoKHR swapchain_ci = {};
    swapchain_ci.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
    swapchain_ci.pNext = NULL;
    swapchain_ci.surface = *surface;
    swapchain_ci.minImageCount = capabilities.minImageCount;
    swapchain_ci.imageFormat = format;
    swapchain_ci.imageExtent = capabilities.currentExtent;
    swapchain_ci.preTransform = transform;
    swapchain_ci.compositeAlpha = composite_alpha;
    swapchain_ci.imageArrayLayers = 1;
    swapchain_ci.presentMode = present_mode_selected;
    swapchain_ci.oldSwapchain = VK_NULL_HANDLE;
    swapchain_ci.clipped = true;
    swapchain_ci.imageColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
    swapchain_ci.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
    swapchain_ci.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
    swapchain_ci.queueFamilyIndexCount = 0;

    if (VK_SUCCESS != vkCreateSwapchainKHR(*vulk_dev, &swapchain_ci, nullptr, swapchain)) {
        fprintf(*Renderer::error_log, "%d: Couldn't create Swapchain", __LINE__);
        fclose(*Renderer::error_log);
        exit(-1);
    }else {
        cout << "Swapchain created successfully" << endl;
    }
}

解决方案

I recently had this exact same problem, the problem was caused by OpenGL context in a GLFW window.

So if you happen to be using GLFW, include a line

glfwWindowHint( GLFW_CLIENT_API, GLFW_NO_API );

before you create a window.

这篇关于Wat 执行“vkCreateSwapchainKHR:internal drawable 创建失败".方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆