Jump to content
  • Advertisement
puppysss

Could someone can help me about Vulkan API crash ?

This topic is 835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I recently faced a app crash when I run my test source code bin file in Vulkan API 1.0.13.0.

I have Radeon R5 200 series and installed latest driver and AND Vulkan Runtime with Vulkan SDK from LunarG. ( Win7 32 )

#include <stdio.h>
#include <vulkan/vulkan.h>

int main ( int argc , char **argv )
{
    // local data
    VkResult Vk_State ;
    const char *VK_Extension[  ] = { "VK_KHR_SURFACE_EXTENSION_NAME" } ;

    // application
    VkApplicationInfo Vk_AppInfo ;
    Vk_AppInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO ;
    Vk_AppInfo.apiVersion = VK_MAKE_VERSION( 1 , 0 , 13 ) ;
    Vk_AppInfo.applicationVersion = VK_MAKE_VERSION( 0 , 0 , 1 ) ;
    Vk_AppInfo.pApplicationName = "test_vulkan" ;

    // instance
    VkInstanceCreateInfo Vk_InstanceInfo ;
    VkInstance Vk_Instance = VK_NULL_HANDLE ;
    Vk_InstanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO ;
    Vk_InstanceInfo.pApplicationInfo = &Vk_AppInfo ;
    Vk_InstanceInfo.enabledExtensionCount = (uint32_t)1 ;
    Vk_InstanceInfo.ppEnabledExtensionNames = VK_Extension ;

    // output
    printf( "Vulkan is loading...\n" ) ;

    // create instance
    Vk_State = vkCreateInstance( &Vk_InstanceInfo , nullptr , &Vk_Instance ) ;
    if( Vk_State == 0 )
        printf( "Vulkan succeeded!\n" ) ;
    else
        printf( "Vulkan failed...\n" ) ;

    // delete instance
    vkDestroyInstance( Vk_Instance , nullptr ) ;
    return 0 ;
}

Share this post


Link to post
Share on other sites
Advertisement

Vk_AppInfo and Vk_InstanceInfo are not entirely filled. Notice, each Vulkan Vk*CreateInfo structure contains field pNext which potentially may point to the extension specific structure. You MUST nullify it. Otherwise it may contain garbage. Same thing about other fields that you may try to skip. Remember, Vulkan wants you to set everything explicitly and there are no defaults. You skip something and you risk undefined behaviour. The easiest way is to simply fill each Info structure with 0 using memset(), bzero() and any other equivalent, but it's simply better not to be lazy and fill ALL fileds properly.

 

That's first thing. Now there's another problem. You use "VK_KHR_SURFACE_EXTENSION_NAME". This is not name of the extension. It is constant nullterminated string defined in the vulkan.h. The extension you are looking for is VK_KHR_surface

 

After fixes:

 

[source]

#include <vulkan/vulkan.h>
#include <cstdio>
#include <string.h>
 
int main ( int argc , char **argv )
{
    // local data
    VkResult Vk_State ;
    const char *VK_Extension[  ] = { VK_KHR_SURFACE_EXTENSION_NAME } ;
 
    // application
    VkApplicationInfo Vk_AppInfo ;
    memset( &Vk_AppInfo, 0, sizeof( VkApplicationInfo ));
    Vk_AppInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO ;
    Vk_AppInfo.apiVersion = VK_MAKE_VERSION( 1 , 0 , 13 ) ;
    Vk_AppInfo.applicationVersion = VK_MAKE_VERSION( 0 , 0 , 1 ) ;
    Vk_AppInfo.pApplicationName = "test_vulkan" ;
 
    // instance
    VkInstanceCreateInfo Vk_InstanceInfo ;
    memset( &Vk_InstanceInfo, 0, sizeof( VkInstanceCreateInfo ));
    
    VkInstance Vk_Instance = VK_NULL_HANDLE ;
    Vk_InstanceInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO ;
    Vk_InstanceInfo.pApplicationInfo = &Vk_AppInfo ;
    Vk_InstanceInfo.enabledExtensionCount = (uint32_t)1 ;
    Vk_InstanceInfo.ppEnabledExtensionNames = VK_Extension ;
 
    // output
    printf( "Vulkan is loading...\n" ) ;
 
    // create instance
    Vk_State = vkCreateInstance( &Vk_InstanceInfo , nullptr , &Vk_Instance ) ;
    if( Vk_State == 0 )
        printf( "Vulkan succeeded!\n" ) ;
    else
        printf( "Vulkan failed...\n" ) ;
 
    // delete instance
    vkDestroyInstance( Vk_Instance , nullptr ) ;
    return 0 ;
}
 

[/source]

 

Yet another thing. I see you try to initialise things using as little code as possible. Unfortunately this is not a Vulkan way. Start from enumerating capabilities that you are interested. For example VK_KHR_surface is not enough to actually create surface. You need proper WSI extension which is specific for your environment ( for example, in Linux you have choice between VK_KHR_xlib_surface and VK_KHR_xcb_surface ( depends on the window API you going to use ). Always enumerate. Never assume. I know it sounds like a chore but hey, this is Vulkan ;)

Edited by j_uk_dev

Share this post


Link to post
Share on other sites

Very thanks j_uk_dev! :) 

 

 

 

Vulkan wants you to set everything explicitly and there are no defaults.

 

it's not easy to me because I was using opengl until recently.

 

 

 

Always enumerate. Never assume. I know it sounds like a chore but hey, this is Vulkan ;)

 

yup I'll learn enumerating in Vulkan now :)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!