From d85bb580256d409f9ddefdc7a08122e45a8e7fc2 Mon Sep 17 00:00:00 2001 From: Eugene Golushkov Date: Fri, 15 Nov 2024 18:05:22 +0100 Subject: [PATCH] [Vk] keep strong reference to previous VulkanInstance in VulkanDevice for resource releasing purposes --- RenderSystems/Vulkan/include/OgreVulkanDevice.h | 10 +++++----- RenderSystems/Vulkan/src/OgreVulkanDevice.cpp | 10 ++++++---- RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp | 6 +++--- RenderSystems/Vulkan/src/OgreVulkanWindow.cpp | 4 ++-- .../src/Windowing/Android/OgreVulkanAndroidWindow.cpp | 4 ++-- .../Vulkan/src/Windowing/X11/OgreVulkanXcbWindow.cpp | 6 +++--- .../src/Windowing/win32/OgreVulkanWin32Window.cpp | 2 +- 7 files changed, 22 insertions(+), 20 deletions(-) diff --git a/RenderSystems/Vulkan/include/OgreVulkanDevice.h b/RenderSystems/Vulkan/include/OgreVulkanDevice.h index cc3200351b..f2ee6d911a 100644 --- a/RenderSystems/Vulkan/include/OgreVulkanDevice.h +++ b/RenderSystems/Vulkan/include/OgreVulkanDevice.h @@ -134,7 +134,7 @@ namespace Ogre }; // clang-format off - VkInstance mInstance; + std::shared_ptr mInstance; VkPhysicalDevice mPhysicalDevice; VkDevice mDevice; VkPipelineCache mPipelineCache; @@ -177,10 +177,10 @@ namespace Ogre FastArray &outQueueCiArray ); public: - VulkanDevice( VkInstance instance, const VulkanPhysicalDevice &physicalDevice, - VulkanRenderSystem *renderSystem ); - VulkanDevice( VkInstance instance, const VulkanExternalDevice &externalDevice, - VulkanRenderSystem *renderSystem ); + VulkanDevice( const std::shared_ptr &instance, + const VulkanPhysicalDevice &physicalDevice, VulkanRenderSystem *renderSystem ); + VulkanDevice( const std::shared_ptr &instance, + const VulkanExternalDevice &externalDevice, VulkanRenderSystem *renderSystem ); ~VulkanDevice(); protected: diff --git a/RenderSystems/Vulkan/src/OgreVulkanDevice.cpp b/RenderSystems/Vulkan/src/OgreVulkanDevice.cpp index 09345983b8..8f3f00854a 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanDevice.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanDevice.cpp @@ -452,7 +452,8 @@ namespace Ogre //------------------------------------------------------------------------- //------------------------------------------------------------------------- //------------------------------------------------------------------------- - VulkanDevice::VulkanDevice( VkInstance instance, const VulkanPhysicalDevice &physicalDevice, + VulkanDevice::VulkanDevice( const std::shared_ptr &instance, + const VulkanPhysicalDevice &physicalDevice, VulkanRenderSystem *renderSystem ) : mInstance( instance ), mPhysicalDevice( 0 ), @@ -468,7 +469,8 @@ namespace Ogre setPhysicalDevice( physicalDevice ); } //------------------------------------------------------------------------- - VulkanDevice::VulkanDevice( VkInstance instance, const VulkanExternalDevice &externalDevice, + VulkanDevice::VulkanDevice( const std::shared_ptr &instance, + const VulkanExternalDevice &externalDevice, VulkanRenderSystem *renderSystem ) : mInstance( instance ), mPhysicalDevice( externalDevice.physicalDevice ), @@ -580,7 +582,7 @@ namespace Ogre PFN_vkGetPhysicalDeviceFeatures2KHR GetPhysicalDeviceFeatures2KHR = (PFN_vkGetPhysicalDeviceFeatures2KHR)vkGetInstanceProcAddr( - mInstance, "vkGetPhysicalDeviceFeatures2KHR" ); + mInstance->mVkInstance, "vkGetPhysicalDeviceFeatures2KHR" ); void **lastNext = &deviceFeatures2.pNext; @@ -884,7 +886,7 @@ namespace Ogre { PFN_vkGetPhysicalDeviceFeatures2KHR GetPhysicalDeviceFeatures2KHR = (PFN_vkGetPhysicalDeviceFeatures2KHR)vkGetInstanceProcAddr( - mInstance, "vkGetPhysicalDeviceFeatures2KHR" ); + mInstance->mVkInstance, "vkGetPhysicalDeviceFeatures2KHR" ); void **lastNext = &deviceFeatures2.pNext; diff --git a/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp b/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp index 6fcab03c81..7127647af3 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp @@ -1101,9 +1101,9 @@ namespace Ogre : *mInstance->findByName( mVulkanSupport->getSelectedDeviceName() ); if( !externalDevice ) - mDevice = new VulkanDevice( mInstance->mVkInstance, mActiveDevice, this ); + mDevice = new VulkanDevice( mInstance, mActiveDevice, this ); else - mDevice = new VulkanDevice( mInstance->mVkInstance, *externalDevice, this ); + mDevice = new VulkanDevice( mInstance, *externalDevice, this ); mNativeShadingLanguageVersion = 450; @@ -2437,7 +2437,7 @@ namespace Ogre { if( name == "VkInstance" ) { - *(VkInstance *)pData = mDevice->mInstance; + *(VkInstance *)pData = mDevice->mInstance->mVkInstance; return; } else if( name == "VkPhysicalDevice" ) diff --git a/RenderSystems/Vulkan/src/OgreVulkanWindow.cpp b/RenderSystems/Vulkan/src/OgreVulkanWindow.cpp index e10dbbab5c..615de1cf2f 100644 --- a/RenderSystems/Vulkan/src/OgreVulkanWindow.cpp +++ b/RenderSystems/Vulkan/src/OgreVulkanWindow.cpp @@ -564,7 +564,7 @@ namespace Ogre destroySwapchain(); if( mSurfaceKHR ) { - vkDestroySurfaceKHR( mDevice->mInstance, mSurfaceKHR, 0 ); + vkDestroySurfaceKHR( mDevice->mInstance->mVkInstance, mSurfaceKHR, 0 ); mSurfaceKHR = 0; } } @@ -719,7 +719,7 @@ namespace Ogre { if( name == "RENDERDOC_DEVICE" ) { - *static_cast( pData ) = mDevice->mInstance; + *static_cast( pData ) = mDevice->mInstance->mVkInstance; return; } else diff --git a/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp b/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp index cff0bacd65..cfa6b703c2 100644 --- a/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp +++ b/RenderSystems/Vulkan/src/Windowing/Android/OgreVulkanAndroidWindow.cpp @@ -400,8 +400,8 @@ namespace Ogre VkAndroidSurfaceCreateInfoKHR andrSurfCreateInfo; makeVkStruct( andrSurfCreateInfo, VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR ); andrSurfCreateInfo.window = mNativeWindow; - VkResult result = - vkCreateAndroidSurfaceKHR( mDevice->mInstance, &andrSurfCreateInfo, 0, &mSurfaceKHR ); + VkResult result = vkCreateAndroidSurfaceKHR( mDevice->mInstance->mVkInstance, + &andrSurfCreateInfo, 0, &mSurfaceKHR ); checkVkResult( result, "vkCreateAndroidSurfaceKHR" ); const uint32 newWidth = static_cast( ANativeWindow_getWidth( mNativeWindow ) ); diff --git a/RenderSystems/Vulkan/src/Windowing/X11/OgreVulkanXcbWindow.cpp b/RenderSystems/Vulkan/src/Windowing/X11/OgreVulkanXcbWindow.cpp index 228f552f55..f5d7a59163 100644 --- a/RenderSystems/Vulkan/src/Windowing/X11/OgreVulkanXcbWindow.cpp +++ b/RenderSystems/Vulkan/src/Windowing/X11/OgreVulkanXcbWindow.cpp @@ -202,9 +202,9 @@ namespace Ogre PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR get_xcb_presentation_support = (PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)vkGetInstanceProcAddr( - mDevice->mInstance, "vkGetPhysicalDeviceXcbPresentationSupportKHR" ); + mDevice->mInstance->mVkInstance, "vkGetPhysicalDeviceXcbPresentationSupportKHR" ); PFN_vkCreateXcbSurfaceKHR create_xcb_surface = (PFN_vkCreateXcbSurfaceKHR)vkGetInstanceProcAddr( - mDevice->mInstance, "vkCreateXcbSurfaceKHR" ); + mDevice->mInstance->mVkInstance, "vkCreateXcbSurfaceKHR" ); if( !get_xcb_presentation_support( mDevice->mPhysicalDevice, mDevice->mGraphicsQueue.mFamilyIdx, mConnection, mScreen->root_visual ) ) @@ -218,7 +218,7 @@ namespace Ogre xcbSurfCreateInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; xcbSurfCreateInfo.connection = mConnection; xcbSurfCreateInfo.window = mXcbWindow; - create_xcb_surface( mDevice->mInstance, &xcbSurfCreateInfo, 0, &mSurfaceKHR ); + create_xcb_surface( mDevice->mInstance->mVkInstance, &xcbSurfCreateInfo, 0, &mSurfaceKHR ); VulkanTextureGpuManager *textureManager = static_cast( textureGpuManager ); diff --git a/RenderSystems/Vulkan/src/Windowing/win32/OgreVulkanWin32Window.cpp b/RenderSystems/Vulkan/src/Windowing/win32/OgreVulkanWin32Window.cpp index bfab5fadae..6214cac10c 100644 --- a/RenderSystems/Vulkan/src/Windowing/win32/OgreVulkanWin32Window.cpp +++ b/RenderSystems/Vulkan/src/Windowing/win32/OgreVulkanWin32Window.cpp @@ -477,7 +477,7 @@ namespace Ogre VkSurfaceKHR surface; - VkResult result = vkCreateWin32SurfaceKHR( mDevice->mInstance, &createInfo, 0, &surface ); + VkResult result = vkCreateWin32SurfaceKHR( mDevice->mInstance->mVkInstance, &createInfo, 0, &surface ); checkVkResult( result, "vkCreateWin32SurfaceKHR" ); mSurfaceKHR = surface;