From 7fcfbf00f4bde7cefc6ab03966dea4371ee0b44c Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Fri, 12 Jan 2024 16:33:34 +0000 Subject: [PATCH] rendervulkan: Better logging/handling of device loss/fatal errors Log vk result and such so we can track what happened. --- src/rendervulkan.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/rendervulkan.cpp b/src/rendervulkan.cpp index f31d8a931d..8194ca2bc4 100644 --- a/src/rendervulkan.cpp +++ b/src/rendervulkan.cpp @@ -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 Target *pNextFind(const Base *base, VkStructureType sType) { @@ -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; } @@ -1237,8 +1244,7 @@ uint64_t CVulkanDevice::submit( std::unique_ptr cmdBuffer) void CVulkanDevice::garbageCollect( void ) { uint64_t currentSeqNo; - VkResult res = vk.GetSemaphoreCounterValue(device(), m_scratchTimelineSemaphore, ¤tSeqNo); - assert( res == VK_SUCCESS ); + vk_check( vk.GetSemaphoreCounterValue(device(), m_scratchTimelineSemaphore, ¤tSeqNo) ); resetCmdBuffers(currentSeqNo); } @@ -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); @@ -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(); } @@ -1310,8 +1313,7 @@ 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(); } @@ -1319,8 +1321,7 @@ void CVulkanCmdBuffer::begin() 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 texture)