diff --git a/neo/renderer/RenderCommon.h b/neo/renderer/RenderCommon.h index e113f8f7..4c16a3a2 100644 --- a/neo/renderer/RenderCommon.h +++ b/neo/renderer/RenderCommon.h @@ -1422,7 +1422,7 @@ struct glimpParms_t // Helper functions for using SDL2 and Vulkan on Linux. std::vector get_required_extensions(); #if defined( USE_NVRHI ) - bool CreateSDLWindowSurface( VkInstance instance, VkSurfaceKHR* surface ); + vk::Result CreateSDLWindowSurface( vk::Instance instance, vk::SurfaceKHR* surface ); #else extern vulkanContext_t vkcontext; #endif diff --git a/neo/sys/DeviceManager_VK.cpp b/neo/sys/DeviceManager_VK.cpp index 9aa07c99..1a1d9c41 100644 --- a/neo/sys/DeviceManager_VK.cpp +++ b/neo/sys/DeviceManager_VK.cpp @@ -479,7 +479,7 @@ void DeviceManager_VK::installDebugCallback() .setPfnCallback( vulkanDebugCallback ) .setPUserData( this ); - vk::Result res = m_VulkanInstance.createDebugReportCallbackEXT( &info, nullptr, &m_DebugReportCallback ); + const vk::Result res = m_VulkanInstance.createDebugReportCallbackEXT( &info, nullptr, &m_DebugReportCallback ); assert( res == vk::Result::eSuccess ); } @@ -677,7 +677,7 @@ bool DeviceManager_VK::findQueueFamilies( vk::PhysicalDevice physicalDevice, vk: vk::Bool32 presentSupported; // SRS - Use portable implmentation for detecting presentation support vs. Windows-specific Vulkan call if( queueFamily.queueCount > 0 && - vkGetPhysicalDeviceSurfaceSupportKHR( physicalDevice, i, surface, &presentSupported ) == VK_SUCCESS ) + physicalDevice.getSurfaceSupportKHR( i, surface, &presentSupported ) == vk::Result::eSuccess ) { if( presentSupported ) { @@ -911,26 +911,22 @@ bool DeviceManager_VK::createDevice() */ bool DeviceManager_VK::createWindowSurface() { - VkResult err = VK_SUCCESS; - // Create the platform-specific surface #if defined( VULKAN_USE_PLATFORM_SDL ) // SRS - Support generic SDL platform for linux and macOS - if( !CreateSDLWindowSurface( m_VulkanInstance, ( VkSurfaceKHR* )&m_WindowSurface ) ) - { - err = VK_ERROR_NATIVE_WINDOW_IN_USE_KHR; - } + const vk::Result res = CreateSDLWindowSurface( m_VulkanInstance, &m_WindowSurface ); + #elif defined( VK_USE_PLATFORM_WIN32_KHR ) - VkWin32SurfaceCreateInfoKHR surfaceCreateInfo = {}; - surfaceCreateInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; - surfaceCreateInfo.hinstance = ( HINSTANCE )windowInstance; - surfaceCreateInfo.hwnd = ( HWND )windowHandle; - err = vkCreateWin32SurfaceKHR( m_VulkanInstance, &surfaceCreateInfo, nullptr, ( VkSurfaceKHR* )&m_WindowSurface ); + auto surfaceCreateInfo = vk::Win32SurfaceCreateInfoKHR() + .setHinstance( ( HINSTANCE )windowInstance ) + .setHwnd( ( HWND )windowHandle ); + + const vk::Result res = m_VulkanInstance.createWin32SurfaceKHR( &surfaceCreateInfo, nullptr, &m_WindowSurface ); #endif - if( err != VK_SUCCESS ) + if( res != vk::Result::eSuccess ) { - common->FatalError( "Failed to create a Vulkan window surface, error code = %s", nvrhi::vulkan::resultToString( err ) ); + common->FatalError( "Failed to create a Vulkan window surface, error code = %s", nvrhi::vulkan::resultToString( res ) ); return false; } @@ -1041,12 +1037,13 @@ bool DeviceManager_VK::CreateDeviceAndSwapChain() } // SRS - when USE_MoltenVK defined, load libMoltenVK vs. the default libvulkan - const vk::DynamicLoader dl( "libMoltenVK.dylib" ); + static const vk::DynamicLoader dl( "libMoltenVK.dylib" ); #else enabledExtensions.layers.insert( "VK_LAYER_KHRONOS_validation" ); } - const vk::DynamicLoader dl; + // SRS - make static so ~DynamicLoader() does not prematurely unload vulkan dynamic lib + static const vk::DynamicLoader dl; #endif const PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = // NOLINT(misc-misplaced-const) dl.getProcAddress( "vkGetInstanceProcAddr" ); diff --git a/neo/sys/sdl/sdl_vkimp.cpp b/neo/sys/sdl/sdl_vkimp.cpp index 1823e40e..9f139885 100644 --- a/neo/sys/sdl/sdl_vkimp.cpp +++ b/neo/sys/sdl/sdl_vkimp.cpp @@ -90,15 +90,15 @@ std::vector get_required_extensions() #if defined( USE_NVRHI ) // SRS - Helper function for creating SDL Vulkan surface within DeviceManager_VK() when NVRHI enabled -bool CreateSDLWindowSurface( VkInstance instance, VkSurfaceKHR* surface ) +vk::Result CreateSDLWindowSurface( vk::Instance instance, vk::SurfaceKHR* surface ) { - if( !SDL_Vulkan_CreateSurface( window, instance, surface ) ) + if( !SDL_Vulkan_CreateSurface( window, ( VkInstance )instance, ( VkSurfaceKHR* )surface ) ) { common->Warning( "Error while creating SDL Vulkan surface: %s", SDL_GetError() ); - return false; + return vk::Result::eErrorSurfaceLostKHR; } - return true; + return vk::Result::eSuccess; } bool DeviceManager::CreateWindowDeviceAndSwapChain( const glimpParms_t& parms, const char* windowTitle )