Create instance

With the extensions and layers checked, we can now create the Vulkan instance. The instance will be the core object controlling our access to the API.

result = vkCreateInstance (
        .pNext = NULL,
        .flags = 0,
        .pApplicationInfo = &(VkApplicationInfo){
            .sType              = VK_STRUCTURE_TYPE_APPLICATION_INFO,
            .pNext              = NULL,
            .pApplicationName   = "RenderApp",
            .applicationVersion = 0,
            .pEngineName        = "VkRenderer",
            .engineVersion      = 0,
            .apiVersion         = VK_API_VERSION_1_0,
        .enabledLayerCount       = STATIC_ARRAY_SIZE(RequiredInstanceLayers),
        .ppEnabledLayerNames     = RequiredInstanceLayers,
        .enabledLayerCount       = 0,
        .ppEnabledLayerNames     = NULL,
        .enabledExtensionCount   = STATIC_ARRAY_SIZE(RequiredInstanceExtensions),
        .ppEnabledExtensionNames = RequiredInstanceExtensions

if ( result != VK_SUCCESS )
    RETURN_ERROR(-1,"vkCreateInstance failed (0x%08X)", (uint32_t)result);

The application info structure is an optional structure, and if it proves inconvenient to fill in, can just be left as NULL.

The layers and extensions specified here will be enabled. Since we are only interested in debug layers in this example, we set the enabled layer count to NULL if BARE_AS_CAN_BE is set. Note, however, we are still required to enable a certain number of extensions. The layers and extensions we use are as follows:

static const char* RequiredInstanceLayers[] = {

static const char* RequiredInstanceExtensions[] = {

The VK_KHR_surface and VK_KHR_win32_surface extensions are the extensions we will require in any case: These extensions are necessary in order to create the swapchain responsible for displaying the images we render on screen.

VK_KHR_surface is a universal extension, whereas VK_KHR_win32_surface is a platform-specific extension. Since the samples provided with this tutorial are made in Windows, we use the _win32 version of the extension. For other platforms, other surface extensions are required. Consult the specification for more information on the surface implementation of other platforms.

VK_EXT_debug_report is an extension which allows debug messages to be received from the debug layers. This extension has no runtime utility and should be disabled in deployment scenarios. Having an option to enable debug layers through command line can be beneficial for remote troubleshooting.