gpt4 book ai didi

vulkan - "vkCreateSwapchainKHR:internal drawable creation failed."是什么意思

转载 作者:行者123 更新时间:2023-12-04 23:39:45 29 4
gpt4 key购买 nike

我总是卡在交换链的创建上,我不知道为什么。我启用了验证层,我得到的最好的 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 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;
    }
    }

    最佳答案

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

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

    glfwWindowHint( GLFW_CLIENT_API, GLFW_NO_API );

    在创建窗口之前。

    关于vulkan - "vkCreateSwapchainKHR:internal drawable creation failed."是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41379529/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com