Home > Mobile >  Vulkan swapchain creation causes crash with no debug information
Vulkan swapchain creation causes crash with no debug information

Time:01-04

I'm following vulkan-tutorial's procedure to understand vulkan, I'm now in creating swapchain. before that I've also created instance and a debug/validation layer but when I'm trying to create swapchain, the app crashes.

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!");

}

Is there any idea? The host is eclipse with MinGW-64 -lglfw3 and -lvulkan-1 on windows 10 64-bit.

And here the graphic card information:

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)

CodePudding user response:

A few things:

  1. There isn't really enough information in the problem description to allow others to locate the problem. For example, we can't tell how surface got created and we can't tell how the Vulkan device got created. It is better to post a complete reproducible example someplace and point to it.

  2. There are a lot of hits when searching for "vulkan swapchain exception" like this one and this one. Something there may give a clue.

  3. Based on what is provided and the links mentioned above, my best guess is that you're not enabling the swapchain extension when creating the device. Perhaps you could check that?

  4. The validation layer should be helpful and you can find more information about it here. You might try making a vk_layer_settings.txt file and use it to set the message severity to "info" so that you can verify that the layer is active. (It will print some sort of startup message at this level) Your IDE might be swallowing the text output coming from the validation layer and the point behind doing this is to verify that you can see any validation output. It may be easier to provide a log filename in the same settings file to send the validation output to that file instead of figuring out what the IDE is doing. You can also use the vkconfig tool to apply these sorts of settings to the validation layer.

  • Related