Skip to content

Commit

Permalink
[Vk] keep strong reference to previous VulkanInstance in VulkanDevice…
Browse files Browse the repository at this point in the history
… for resource releasing purposes
  • Loading branch information
eugenegff committed Nov 22, 2024
1 parent 70cfcb4 commit d85bb58
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
10 changes: 5 additions & 5 deletions RenderSystems/Vulkan/include/OgreVulkanDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace Ogre
};

// clang-format off
VkInstance mInstance;
std::shared_ptr<VulkanInstance> mInstance;
VkPhysicalDevice mPhysicalDevice;
VkDevice mDevice;
VkPipelineCache mPipelineCache;
Expand Down Expand Up @@ -177,10 +177,10 @@ namespace Ogre
FastArray<VkDeviceQueueCreateInfo> &outQueueCiArray );

public:
VulkanDevice( VkInstance instance, const VulkanPhysicalDevice &physicalDevice,
VulkanRenderSystem *renderSystem );
VulkanDevice( VkInstance instance, const VulkanExternalDevice &externalDevice,
VulkanRenderSystem *renderSystem );
VulkanDevice( const std::shared_ptr<VulkanInstance> &instance,
const VulkanPhysicalDevice &physicalDevice, VulkanRenderSystem *renderSystem );
VulkanDevice( const std::shared_ptr<VulkanInstance> &instance,
const VulkanExternalDevice &externalDevice, VulkanRenderSystem *renderSystem );
~VulkanDevice();

protected:
Expand Down
10 changes: 6 additions & 4 deletions RenderSystems/Vulkan/src/OgreVulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ namespace Ogre
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
VulkanDevice::VulkanDevice( VkInstance instance, const VulkanPhysicalDevice &physicalDevice,
VulkanDevice::VulkanDevice( const std::shared_ptr<VulkanInstance> &instance,
const VulkanPhysicalDevice &physicalDevice,
VulkanRenderSystem *renderSystem ) :
mInstance( instance ),
mPhysicalDevice( 0 ),
Expand All @@ -468,7 +469,8 @@ namespace Ogre
setPhysicalDevice( physicalDevice );
}
//-------------------------------------------------------------------------
VulkanDevice::VulkanDevice( VkInstance instance, const VulkanExternalDevice &externalDevice,
VulkanDevice::VulkanDevice( const std::shared_ptr<VulkanInstance> &instance,
const VulkanExternalDevice &externalDevice,
VulkanRenderSystem *renderSystem ) :
mInstance( instance ),
mPhysicalDevice( externalDevice.physicalDevice ),
Expand Down Expand Up @@ -580,7 +582,7 @@ namespace Ogre

PFN_vkGetPhysicalDeviceFeatures2KHR GetPhysicalDeviceFeatures2KHR =
(PFN_vkGetPhysicalDeviceFeatures2KHR)vkGetInstanceProcAddr(
mInstance, "vkGetPhysicalDeviceFeatures2KHR" );
mInstance->mVkInstance, "vkGetPhysicalDeviceFeatures2KHR" );

void **lastNext = &deviceFeatures2.pNext;

Expand Down Expand Up @@ -884,7 +886,7 @@ namespace Ogre
{
PFN_vkGetPhysicalDeviceFeatures2KHR GetPhysicalDeviceFeatures2KHR =
(PFN_vkGetPhysicalDeviceFeatures2KHR)vkGetInstanceProcAddr(
mInstance, "vkGetPhysicalDeviceFeatures2KHR" );
mInstance->mVkInstance, "vkGetPhysicalDeviceFeatures2KHR" );

void **lastNext = &deviceFeatures2.pNext;

Expand Down
6 changes: 3 additions & 3 deletions RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -2437,7 +2437,7 @@ namespace Ogre
{
if( name == "VkInstance" )
{
*(VkInstance *)pData = mDevice->mInstance;
*(VkInstance *)pData = mDevice->mInstance->mVkInstance;
return;
}
else if( name == "VkPhysicalDevice" )
Expand Down
4 changes: 2 additions & 2 deletions RenderSystems/Vulkan/src/OgreVulkanWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ namespace Ogre
destroySwapchain();
if( mSurfaceKHR )
{
vkDestroySurfaceKHR( mDevice->mInstance, mSurfaceKHR, 0 );
vkDestroySurfaceKHR( mDevice->mInstance->mVkInstance, mSurfaceKHR, 0 );
mSurfaceKHR = 0;
}
}
Expand Down Expand Up @@ -719,7 +719,7 @@ namespace Ogre
{
if( name == "RENDERDOC_DEVICE" )
{
*static_cast<VkInstance *>( pData ) = mDevice->mInstance;
*static_cast<VkInstance *>( pData ) = mDevice->mInstance->mVkInstance;
return;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32>( ANativeWindow_getWidth( mNativeWindow ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
Expand All @@ -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<VulkanTextureGpuManager *>( textureGpuManager );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d85bb58

Please sign in to comment.