From 4767dbad5be1ab39129d1eda26b634df092a2542 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 17 Jun 2018 20:48:02 +0200 Subject: [PATCH] Workaround Nvidia bugs. This solution is still bad, as it really does wait for the query results, which stalls the CPU. --- TracyVulkan.hpp | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/TracyVulkan.hpp b/TracyVulkan.hpp index 632101df..1e4fdace 100644 --- a/TracyVulkan.hpp +++ b/TracyVulkan.hpp @@ -107,16 +107,38 @@ public: if( m_tail == m_head ) return; + auto cnt = m_head < m_tail ? QueryCount - m_tail : m_head - m_tail; int64_t res[QueryCount]; - const auto cnt = m_head < m_tail ? QueryCount - m_tail : m_head - m_tail; - vkGetQueryPoolResults( m_device, m_query, m_tail, cnt, sizeof( res ), res, sizeof( *res ), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT ); + + // This memset is required, because Nvidia drivers seem to break Vulkan spec: "If VK_QUERY_RESULT_WITH_AVAILABILITY_BIT + // is set, the final integer value written for each query is non-zero if the query's status was available or zero if the + // status was unavailable." + // Nvidia drivers in some cases do not write the non-zero value, even if the following zero values are written. + memset( res, 0xFF, sizeof( *res ) * cnt ); + + if( vkGetQueryPoolResults( m_device, m_query, m_tail, cnt, sizeof( res ), res, sizeof( *res ), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WITH_AVAILABILITY_BIT ) == VK_NOT_READY ) + { + unsigned int idx; + for( idx=0; idxget_tail_index(); - unsigned int idx; - for( idx=0; idx