C语言 Vulkan交换链创建导致崩溃,没有调试信息

epfja78i  于 2023-01-04  发布在  其他
关注(0)|答案(1)|浏览(322)

我正在按照vulkan教程的程序来理解vulkan,我现在正在创建交换链。在此之前,我还创建了示例和调试/验证层,但当我试图创建交换链时,应用程序崩溃。

void createSwapChain() {

    VkSurfaceFormatKHR surfaceFormat;
    surfaceFormat.format=VK_FORMAT_B8G8R8A8_SRGB;
    surfaceFormat.colorSpace=VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
    VkPresentModeKHR presentMode=VK_PRESENT_MODE_FIFO_KHR;
    int width,height;
    glfwGetFramebufferSize(window, &width, &height);
    VkExtent2D extent ={width,height};
    uint32_t imageCount=2;//minimum cap +1
    VkSurfaceCapabilitiesKHR capabilities;
    vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, &capabilities);
    VkSwapchainCreateInfoKHR createInfo={0};
    createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
    createInfo.surface = surface;
    createInfo.minImageCount = imageCount;
    createInfo.imageFormat = surfaceFormat.format;
    createInfo.imageColorSpace = surfaceFormat.colorSpace;
    createInfo.imageExtent = extent;
    createInfo.imageArrayLayers = 1;
    createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;

    createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
//  createInfo.queueFamilyIndexCount = 1;
//  createInfo.pQueueFamilyIndices = NULL;

    createInfo.preTransform = capabilities.currentTransform/*VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR*/;//swapChainSupport.capabilities.currentTransform
    createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;

    createInfo.presentMode = presentMode;
    createInfo.clipped = VK_TRUE;// means obscured images have unimportant color!!
    createInfo.oldSwapchain = VK_NULL_HANDLE;

     if (vkCreateSwapchainKHR(device, &createInfo, NULL, &swapChain) != VK_SUCCESS)
     printf("failed to create swap chain!");

}

有什么想法吗?主机是Eclipse,在Windows 10 64位上安装了MinGW-64 -lglfw 3和-lvulkan-1。
这里是显卡信息:

Available Layers:
         VK_LAYER_AMD_switchable_graphics
         VK_LAYER_VALVE_steam_overlay
         VK_LAYER_VALVE_steam_fossilize
         VK_LAYER_KHRONOS_validation
Available extensions:
         VK_KHR_device_group_creation
         VK_KHR_external_fence_capabilities
         VK_KHR_external_memory_capabilities
         VK_KHR_external_semaphore_capabilities
         VK_KHR_get_physical_device_properties2
         VK_KHR_get_surface_capabilities2
         VK_KHR_surface
         VK_KHR_win32_surface
         VK_EXT_debug_report
         VK_EXT_debug_utils
         VK_EXT_swapchain_colorspace
Instance extension:
         VK_KHR_surface
         VK_KHR_win32_surface
         VK_EXT_debug_utils
Availible devices:
AMD Radeon(TM) Graphics          Type: 1         GeometryShader: Yes
         FamilyIndex: 0 AvailibleQueueCount: 1   Surface Support: Yes    Graphics | Compute | Transfer | Binding
         FamilyIndex: 1 AvailibleQueueCount: 2   Surface Support: Yes     | Compute | Transfer | Binding
         FamilyIndex: 2 AvailibleQueueCount: 1   Surface Support: Yes     |  | Transfer | Binding
   Availible device extensions:  (The required is VK_KHR_swapchain)
         VK_KHR_16bit_storage    VK_KHR_8bit_storage     VK_KHR_bind_memory2
         VK_KHR_buffer_device_address    VK_KHR_copy_commands2   VK_KHR_create_renderpass2
         VK_KHR_dedicated_allocation     VK_KHR_depth_stencil_resolve    VK_KHR_descriptor_update_template
         VK_KHR_device_group     VK_KHR_draw_indirect_count      VK_KHR_driver_properties
         VK_KHR_dynamic_rendering        VK_KHR_external_fence   VK_KHR_external_fence_win32
         VK_KHR_external_memory  VK_KHR_external_memory_win32    VK_KHR_external_semaphore
         VK_KHR_external_semaphore_win32         VK_KHR_format_feature_flags2    VK_KHR_get_memory_requirements2
         VK_KHR_global_priority  VK_KHR_imageless_framebuffer    VK_KHR_image_format_list
         VK_KHR_maintenance1     VK_KHR_maintenance2     VK_KHR_maintenance3
         VK_KHR_maintenance4     VK_KHR_multiview        VK_KHR_pipeline_executable_properties
         VK_KHR_pipeline_library         VK_KHR_push_descriptor  VK_KHR_relaxed_block_layout
         VK_KHR_sampler_mirror_clamp_to_edge     VK_KHR_sampler_ycbcr_conversion         VK_KHR_separate_depth_stencil_layouts
         VK_KHR_shader_atomic_int64      VK_KHR_shader_clock     VK_KHR_shader_draw_parameters
         VK_KHR_shader_float16_int8      VK_KHR_shader_float_controls    VK_KHR_shader_integer_dot_product
         VK_KHR_shader_non_semantic_info         VK_KHR_shader_subgroup_extended_types   VK_KHR_shader_subgroup_uniform_control_flow
         VK_KHR_shader_terminate_invocation      VK_KHR_spirv_1_4        VK_KHR_storage_buffer_storage_class

  Swap chain details:
         Min/max images in swap chain; 1, 16
         Min/max width and height 800 : 600 | 800 : 600
         Pixel format codes(at least we need one no matter what!):       44
         50      58      97      44      50      58      97      58      97      58
         97      97      2       3       4       5       8       37      38      43
         45      51      52      57      64      91      92      122
         color space codes(at least we need one no matter what!):        0
         0       0       0       1000104006      1000104006      1000104006      1000104006      1000104008      1000104008      1000104007
         1000104007      1000104002      0       0       0       0       0       0       0       0
         0       0       0       0       0       0       0       0
  Available presentation modes:
         0 (Immediate)
         2       3 ( FIFO, FIFO_relaxed)
2ic8powd

2ic8powd1#

几件事:
1.问题描述中没有足够的信息让其他人找到问题所在。例如,我们无法说明surface是如何创建的,也无法说明Vulkan设备是如何创建的。最好在某处发布一个完整的可复制示例并指出它。
1.当搜索"vulkan交换链异常"如this onethis one时,有很多匹配项,那里的一些东西可能会提供线索。
1.根据上面提供的信息和链接,我最好的猜测是你在创建设备时没有启用交换链扩展。也许你可以检查一下?
1.验证层应该很有用,您可以在here中找到更多信息,您可以尝试创建一个vk_layer_settings.txt文件,并使用它将消息严重性设置为"info",以便您可以验证该层是否处于活动状态。(它将在此级别打印某种启动消息)您的IDE可能会吞掉来自验证层的文本输出,这样做的目的是验证您是否可以看到任何验证输出。在同一个设置文件中提供一个日志文件名,将验证输出发送到该文件,而不是弄清楚IDE正在做什么,这可能会更容易。您还可以使用vkconfigtool将这些类型的设置应用到验证层。

相关问题