Skip to content

Commit

Permalink
[Vk] fixed recovering from real rather than simulated device lost
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenegff committed Dec 18, 2024
1 parent e593dc7 commit 2565807
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 39 deletions.
2 changes: 1 addition & 1 deletion RenderSystems/Vulkan/include/OgreVulkanQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace Ogre
VkSemaphoreArray mGpuWaitSemaphForCurrCmdBuff;
FastArray<VkPipelineStageFlags> mGpuWaitFlags;
/// Collection of semaphore we will signal when our queue
/// submitted in commitAndNextCommandBuffer is done
/// submitted in commitAndNextCommandBuffer is done. Semaphores are owned.
VkSemaphoreArray mGpuSignalSemaphForCurrCmdBuff;
// clang-format on

Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/Vulkan/include/Vao/OgreVulkanVaoManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ namespace Ogre
VulkanDevice *getDevice() const { return mDevice; }

/// Insert into the end of semaphoreArray 'numSemaphores'
/// number of semaphores that are safe for use.
/// number of semaphores that are safe for use. Transfers ownership.
void getAvailableSemaphores( VkSemaphoreArray &semaphoreArray, size_t numSemaphores );
VkSemaphore getAvailableSemaphore();

Expand Down
60 changes: 24 additions & 36 deletions RenderSystems/Vulkan/src/OgreVulkanQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,49 +76,35 @@ namespace Ogre
{
vkDeviceWaitIdle( mDevice );

{
FastArray<PerFrameData>::iterator itor = mPerFrameData.begin();
FastArray<PerFrameData>::iterator endt = mPerFrameData.end();

while( itor != endt )
{
VkFenceArray::const_iterator itFence = itor->mProtectingFences.begin();
VkFenceArray::const_iterator enFence = itor->mProtectingFences.end();

while( itFence != enFence )
vkDestroyFence( mDevice, *itFence++, 0 );
itor->mProtectingFences.clear();

vkDestroyCommandPool( mDevice, itor->mCmdPool, 0 );
itor->mCommands.clear();
itor->mCurrentCmdIdx = 0;
mWindowsPendingSwap.clear();

++itor;
}
}
for( PerFrameData &perFrameData : mPerFrameData )
{
RefCountedFenceMap::const_iterator itor = mRefCountedFences.begin();
RefCountedFenceMap::const_iterator endt = mRefCountedFences.end();
for( VkFence fence : perFrameData.mProtectingFences )
vkDestroyFence( mDevice, fence, 0 );
perFrameData.mProtectingFences.clear();

while( itor != endt )
{
// If recycleAfterRelease == false, then they were destroyed with mProtectingFences
if( itor->second.recycleAfterRelease )
vkDestroyFence( mDevice, itor->first, 0 );
++itor;
}

mRefCountedFences.clear();
vkDestroyCommandPool( mDevice, perFrameData.mCmdPool, 0 );
perFrameData.mCommands.clear();
perFrameData.mCurrentCmdIdx = 0;
}

VkFenceArray::const_iterator itor = mAvailableFences.begin();
VkFenceArray::const_iterator endt = mAvailableFences.end();

while( itor != endt )
vkDestroyFence( mDevice, *itor++, 0 );
for( RefCountedFenceMap::value_type &elem : mRefCountedFences )
{
// If recycleAfterRelease == false, then they were destroyed with mProtectingFences
if( elem.second.recycleAfterRelease )
vkDestroyFence( mDevice, elem.first, 0 );
}
mRefCountedFences.clear();

for( VkFence fence : mAvailableFences )
vkDestroyFence( mDevice, fence, 0 );
mAvailableFences.clear();

for( VkSemaphore sem : mGpuSignalSemaphForCurrCmdBuff )
vkDestroySemaphore( mDevice, sem, 0 );
mGpuSignalSemaphForCurrCmdBuff.clear();

mDevice = 0;
}
}
Expand Down Expand Up @@ -1256,7 +1242,7 @@ namespace Ogre
VkResult result = vkQueueSubmit( mQueue, 1u, &submitInfo, fence );
if( result != VK_SUCCESS )
mOwnerDevice->mIsDeviceLost = true;
checkVkResult( result, "vkQueueSubmit" );
// we need some cleanup before checking result

mGpuWaitSemaphForCurrCmdBuff.clear();

Expand All @@ -1274,6 +1260,8 @@ namespace Ogre

mPendingCmds.clear();

checkVkResult( result, "vkQueueSubmit" );

if( submissionType >= SubmissionType::EndFrameAndSwap )
{
for( size_t windowIdx = 0u; windowIdx < numWindowsPendingSwap; ++windowIdx )
Expand Down
2 changes: 2 additions & 0 deletions RenderSystems/Vulkan/src/OgreVulkanRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,8 @@ namespace Ogre

fireEvent( "DeviceRestored" );

mDevice->mIsDeviceLost = false;

uint64 passedTime = ( timer.getMicroseconds() - startTime ) / 1000;
LogManager::getSingleton().logMessage( "Vulkan: Device was restored in " +
StringConverter::toString( passedTime ) + "ms" );
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/Vulkan/src/Vao/OgreVulkanVaoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ namespace Ogre
//-----------------------------------------------------------------------------------
bool VulkanVaoManager::flushAllGpuDelayedBlocks( const bool bIssueBarrier )
{
if( bIssueBarrier )
if( bIssueBarrier && !mDevice->mIsDeviceLost )
{
if( mDevice->mGraphicsQueue.getEncoderState() == VulkanQueue::EncoderGraphicsOpen )
{
Expand Down

0 comments on commit 2565807

Please sign in to comment.