MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / BInitVulkanInstance

Method BInitVulkanInstance

samples/hellovr_vulkan/hellovr_vulkan_main.cpp:765–926  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Purpose: Initialize Vulkan VkInstance -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

763// Purpose: Initialize Vulkan VkInstance
764//-----------------------------------------------------------------------------
765bool CMainApplication::BInitVulkanInstance()
766{
767 VkResult nResult;
768
769 //----------------------//
770 // VkInstance creation //
771 //----------------------//
772 // Query OpenVR to determine which instance extensions need to be enabled before creating the instance
773 std::vector< std::string > requiredInstanceExtensions;
774 if ( !GetVulkanInstanceExtensionsRequired( requiredInstanceExtensions ) )
775 {
776 dprintf( "Could not determine OpenVR Vulkan instance extensions.\n" );
777 return false;
778 }
779
780 // Additional required instance extensions
781 requiredInstanceExtensions.push_back( VK_KHR_SURFACE_EXTENSION_NAME );
782#if defined ( _WIN32 )
783 requiredInstanceExtensions.push_back( VK_KHR_WIN32_SURFACE_EXTENSION_NAME );
784#else
785 requiredInstanceExtensions.push_back( VK_KHR_XLIB_SURFACE_EXTENSION_NAME );
786#endif
787
788 uint32_t nEnabledLayerCount = 0;
789 VkLayerProperties *pLayerProperties = nullptr;
790 char **ppEnabledLayerNames = nullptr;
791
792 // Enable validation layers
793 if ( m_bDebugVulkan )
794 {
795 // OpenVR: no unique_objects when using validation with SteamVR
796 char const *pInstanceValidationLayers[] =
797 {
798 "VK_LAYER_GOOGLE_threading",
799 "VK_LAYER_LUNARG_parameter_validation",
800 "VK_LAYER_LUNARG_object_tracker",
801 "VK_LAYER_LUNARG_image",
802 "VK_LAYER_LUNARG_core_validation",
803 "VK_LAYER_LUNARG_swapchain"
804 };
805
806 uint32_t nInstanceLayerCount = 0;
807 VkResult nResult = vkEnumerateInstanceLayerProperties( &nInstanceLayerCount, nullptr );
808 if ( nResult == VK_SUCCESS && nInstanceLayerCount > 0 )
809 {
810 pLayerProperties = new VkLayerProperties[ nInstanceLayerCount ];
811 ppEnabledLayerNames = new char*[ nInstanceLayerCount ];
812 nResult = vkEnumerateInstanceLayerProperties( &nInstanceLayerCount, pLayerProperties );
813 if ( nResult != VK_SUCCESS )
814 {
815 dprintf( "Error vkEnumerateInstanceLayerProperties in %d\n", nResult );
816 return false;
817 }
818
819 uint32_t nLayerIndex = 0;
820 for ( nLayerIndex = 0; nLayerIndex < nInstanceLayerCount; nLayerIndex++ )
821 {
822 for ( uint32_t nLayer = 0; nLayer < _countof( pInstanceValidationLayers ); nLayer++ )

Callers

nothing calls this directly

Calls 2

sizeMethod · 0.80
dprintfFunction · 0.70

Tested by

no test coverage detected