Skip to content

Commit

Permalink
rendervulkan: Better logging/handling of device loss/fatal errors
Browse files Browse the repository at this point in the history
Log vk result and such so we can track what happened.
  • Loading branch information
misyltoad committed Jan 12, 2024
1 parent 20cac0d commit 7fcfbf0
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/rendervulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ static void vk_errorf(VkResult result, const char *fmt, ...) {
vk_log.errorf("%s (VkResult: %d)", buf, result);
}

// For when device is up and it would be totally fatal to fail
#define vk_check( x ) \
do \
{ \
VkResult check_res = VK_SUCCESS; \
if ( ( check_res = ( x ) ) != VK_SUCCESS ) \
{ \
vk_errorf( check_res, #x " failed!" ); \
abort(); \
} \
} while ( 0 )

template<typename Target, typename Base>
Target *pNextFind(const Base *base, VkStructureType sType)
{
Expand Down Expand Up @@ -1217,12 +1229,7 @@ uint64_t CVulkanDevice::submitInternal( CVulkanCmdBuffer* cmdBuffer )
.pSignalSemaphores = &m_scratchTimelineSemaphore,
};

VkResult res = vk.QueueSubmit( cmdBuffer->queue(), 1, &submitInfo, VK_NULL_HANDLE );

if ( res != VK_SUCCESS )
{
assert( 0 );
}
vk_check( vk.QueueSubmit( cmdBuffer->queue(), 1, &submitInfo, VK_NULL_HANDLE ) );

return nextSeqNo;
}
Expand All @@ -1237,8 +1244,7 @@ uint64_t CVulkanDevice::submit( std::unique_ptr<CVulkanCmdBuffer> cmdBuffer)
void CVulkanDevice::garbageCollect( void )
{
uint64_t currentSeqNo;
VkResult res = vk.GetSemaphoreCounterValue(device(), m_scratchTimelineSemaphore, &currentSeqNo);
assert( res == VK_SUCCESS );
vk_check( vk.GetSemaphoreCounterValue(device(), m_scratchTimelineSemaphore, &currentSeqNo) );

resetCmdBuffers(currentSeqNo);
}
Expand All @@ -1255,9 +1261,7 @@ void CVulkanDevice::wait(uint64_t sequence, bool reset)
.pValues = &sequence,
} ;

VkResult res = vk.WaitSemaphores(device(), &waitInfo, ~0ull);
if (res != VK_SUCCESS)
assert( 0 );
vk_check( vk.WaitSemaphores( device(), &waitInfo, ~0ull ) );

if (reset)
resetCmdBuffers(sequence);
Expand Down Expand Up @@ -1297,8 +1301,7 @@ CVulkanCmdBuffer::~CVulkanCmdBuffer()

void CVulkanCmdBuffer::reset()
{
VkResult res = m_device->vk.ResetCommandBuffer(m_cmdBuffer, 0);
assert(res == VK_SUCCESS);
vk_check( m_device->vk.ResetCommandBuffer(m_cmdBuffer, 0) );
m_textureRefs.clear();
m_textureState.clear();
}
Expand All @@ -1310,17 +1313,15 @@ void CVulkanCmdBuffer::begin()
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
};

VkResult res = m_device->vk.BeginCommandBuffer(m_cmdBuffer, &commandBufferBeginInfo);
assert(res == VK_SUCCESS);
vk_check( m_device->vk.BeginCommandBuffer(m_cmdBuffer, &commandBufferBeginInfo) );

clearState();
}

void CVulkanCmdBuffer::end()
{
insertBarrier(true);
VkResult res = m_device->vk.EndCommandBuffer(m_cmdBuffer);
assert(res == VK_SUCCESS);
vk_check( m_device->vk.EndCommandBuffer(m_cmdBuffer) );
}

void CVulkanCmdBuffer::bindTexture(uint32_t slot, std::shared_ptr<CVulkanTexture> texture)
Expand Down

0 comments on commit 7fcfbf0

Please sign in to comment.