From 0c4c7101708ae0fc9030ea2cae7e24d3edb5e8cd Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 14 Aug 2019 11:20:13 +0100 Subject: [PATCH] Don't re-check fences within the same expire pass * If we check a fence each time it's referenced, we risk getting a different answer the second time we check and expiring it too early. --- util/test/demos/vk/vk_test.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/util/test/demos/vk/vk_test.cpp b/util/test/demos/vk/vk_test.cpp index 1349bbecf..607fc2f9e 100644 --- a/util/test/demos/vk/vk_test.cpp +++ b/util/test/demos/vk/vk_test.cpp @@ -22,6 +22,7 @@ * THE SOFTWARE. ******************************************************************************/ +#include #include "../test_common.h" #define VMA_IMPLEMENTATION @@ -1049,12 +1050,19 @@ void VulkanWindow::Present(VkQueue queue) } std::set doneFences; + std::map fenceStatus; + + // only test each fence once so we avoid the problem of testing a fence once, finding it's not + // ready, then testing it again in a second use and finding that it's now ready, and deleting + // it + for(VkFence f : fences) + fenceStatus[f] = vkGetFenceStatus(m_Test->device, f); for(int level = 0; level < VK_COMMAND_BUFFER_LEVEL_RANGE_SIZE; level++) { for(auto it = pendingCommandBuffers[level].begin(); it != pendingCommandBuffers[level].end();) { - if(vkGetFenceStatus(m_Test->device, it->second) == VK_SUCCESS) + if(fenceStatus[it->second] == VK_SUCCESS) { freeCommandBuffers[level].push_back(it->first); doneFences.insert(it->second);