result = vkCreateInstance (
&(VkInstanceCreateInfo){
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.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,
},
#if !BARE_AS_CAN_BE
.enabledLayerCount = STATIC_ARRAY_SIZE(RequiredInstanceLayers),
.ppEnabledLayerNames = RequiredInstanceLayers,
#else
.enabledLayerCount = 0,
.ppEnabledLayerNames = NULL,
#endif
.enabledExtensionCount = STATIC_ARRAY_SIZE(RequiredInstanceExtensions),
.ppEnabledExtensionNames = RequiredInstanceExtensions
},
NULL,
&renderer->instance
);
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[] = {
"VK_LAYER_LUNARG_standard_validation",
};
static const char* RequiredInstanceExtensions[] = {
"VK_KHR_surface",
"VK_KHR_win32_surface",
#if !BARE_AS_CAN_BE
"VK_EXT_debug_report",
#endif
};
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.