Skip to content

Commit

Permalink
[Vk] some safety for mPso, mPso->rsData, mComputePso, mComputePso->rs…
Browse files Browse the repository at this point in the history
…Data access
  • Loading branch information
eugenegff committed Feb 17, 2025
1 parent 8af3ecb commit ca8475d
Showing 1 changed file with 38 additions and 20 deletions.
58 changes: 38 additions & 20 deletions RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1874,11 +1874,14 @@ namespace Ogre
mComputeTableDirty = true;
}

// NOTE: right now we never skip compute pipeline creation, but better be safe than sorry
OGRE_ASSERT_LOW( pso->rsData );
VulkanHlmsPso *vulkanPso = static_cast<VulkanHlmsPso *>( pso->rsData );
delayed_vkDestroyPipeline( mVaoManager, mDevice->mDevice, vulkanPso->pso, 0 );
delete vulkanPso;
pso->rsData = 0;
if( VulkanHlmsPso *vulkanPso = static_cast<VulkanHlmsPso *>( pso->rsData ) )
{
pso->rsData = 0;
delayed_vkDestroyPipeline( mVaoManager, mDevice->mDevice, vulkanPso->pso, 0 );
delete vulkanPso;
}
}
//-------------------------------------------------------------------------
void VulkanRenderSystem::_beginFrame() {}
Expand Down Expand Up @@ -1959,6 +1962,7 @@ namespace Ogre

// check, if we deferred pipeline compilation due to the skipped deadline
// TODO: set some fallback? Dummy here, or more clever at compilation site?
// this also ensures, that if mPso is not null then mPso->rsData is valid
if( pso && !pso->rsData )
pso = 0;

Expand All @@ -1968,10 +1972,10 @@ namespace Ogre
{
VulkanRootLayout *oldRootLayout = 0;
if( mPso )
oldRootLayout = reinterpret_cast<VulkanHlmsPso *>( mPso->rsData )->rootLayout;
oldRootLayout = static_cast<VulkanHlmsPso *>( mPso->rsData )->rootLayout;

OGRE_ASSERT_LOW( pso->rsData );
VulkanHlmsPso *vulkanPso = reinterpret_cast<VulkanHlmsPso *>( pso->rsData );
VulkanHlmsPso *vulkanPso = static_cast<VulkanHlmsPso *>( pso->rsData );
VkCommandBuffer cmdBuffer = mDevice->mGraphicsQueue.getCurrentCmdBuffer();
vkCmdBindPipeline( cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, vulkanPso->pso );

Expand All @@ -1990,16 +1994,22 @@ namespace Ogre
{
mDevice->mGraphicsQueue.getComputeEncoder();

// check, if we deferred pipeline compilation due to the skipped deadline
// NOTE: right now we never skip compute pipelines compilations
// this also ensures, that if mComputePso is not null then mComputePso->rsData is valid
if( pso && !pso->rsData )
pso = 0;

if( mComputePso != pso )
{
if( pso )
{
VulkanRootLayout *oldRootLayout = 0;
if( mComputePso )
oldRootLayout = reinterpret_cast<VulkanHlmsPso *>( mComputePso->rsData )->rootLayout;
oldRootLayout = static_cast<VulkanHlmsPso *>( mComputePso->rsData )->rootLayout;

OGRE_ASSERT_LOW( pso->rsData );
VulkanHlmsPso *vulkanPso = reinterpret_cast<VulkanHlmsPso *>( pso->rsData );
VulkanHlmsPso *vulkanPso = static_cast<VulkanHlmsPso *>( pso->rsData );
VkCommandBuffer cmdBuffer = mDevice->mGraphicsQueue.getCurrentCmdBuffer();
vkCmdBindPipeline( cmdBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, vulkanPso->pso );

Expand Down Expand Up @@ -2068,9 +2078,12 @@ namespace Ogre
if( !mTableDirty )
return;

VulkanVaoManager *vaoManager = static_cast<VulkanVaoManager *>( mVaoManager );
VulkanRootLayout *rootLayout = reinterpret_cast<VulkanHlmsPso *>( mPso->rsData )->rootLayout;
rootLayout->bind( mDevice, vaoManager, mGlobalTable );
if( mPso )
{
VulkanVaoManager *vaoManager = static_cast<VulkanVaoManager *>( mVaoManager );
VulkanRootLayout *rootLayout = static_cast<VulkanHlmsPso *>( mPso->rsData )->rootLayout;
rootLayout->bind( mDevice, vaoManager, mGlobalTable );
}
mGlobalTable.reset();
mTableDirty = false;
}
Expand All @@ -2080,10 +2093,13 @@ namespace Ogre
if( !mComputeTableDirty )
return;

VulkanVaoManager *vaoManager = static_cast<VulkanVaoManager *>( mVaoManager );
VulkanRootLayout *rootLayout =
reinterpret_cast<VulkanHlmsPso *>( mComputePso->rsData )->rootLayout;
rootLayout->bind( mDevice, vaoManager, mComputeTable );
if( mComputePso )
{
VulkanVaoManager *vaoManager = static_cast<VulkanVaoManager *>( mVaoManager );
VulkanRootLayout *rootLayout =
static_cast<VulkanHlmsPso *>( mComputePso->rsData )->rootLayout;
rootLayout->bind( mDevice, vaoManager, mComputeTable );
}
mComputeTable.reset();
mComputeTableDirty = false;
}
Expand Down Expand Up @@ -3519,11 +3535,13 @@ namespace Ogre
mPso = 0;
}

OGRE_ASSERT_LOW( pso->rsData );
VulkanHlmsPso *vulkanPso = static_cast<VulkanHlmsPso *>( pso->rsData );
delayed_vkDestroyPipeline( mVaoManager, mDevice->mDevice, vulkanPso->pso, 0 );
delete vulkanPso;
pso->rsData = 0;
// graphics pipeline creation could have been skipped
if( VulkanHlmsPso *vulkanPso = static_cast<VulkanHlmsPso *>( pso->rsData ) )
{
pso->rsData = 0;
delayed_vkDestroyPipeline( mVaoManager, mDevice->mDevice, vulkanPso->pso, 0 );
delete vulkanPso;
}
}

void VulkanRenderSystem::_hlmsMacroblockCreated( HlmsMacroblock *newBlock )
Expand Down

0 comments on commit ca8475d

Please sign in to comment.