From dc6e7a79385aa9267f1482f52598ede921eb2ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 28 Jun 2020 09:52:53 +0200 Subject: [PATCH 1/2] Move the Vulkan swapchain out-of-date checking to the vkQueuePresentKHR call. --- ext/native/thin3d/VulkanRenderManager.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ext/native/thin3d/VulkanRenderManager.cpp b/ext/native/thin3d/VulkanRenderManager.cpp index 573f0ce6c5..9a3a9e5e43 100644 --- a/ext/native/thin3d/VulkanRenderManager.cpp +++ b/ext/native/thin3d/VulkanRenderManager.cpp @@ -1031,14 +1031,11 @@ void VulkanRenderManager::BeginSubmitFrame(int frame) { if (res == VK_SUBOPTIMAL_KHR) { // Hopefully the resize will happen shortly. Ignore - one frame might look bad or something. WLOG("VK_SUBOPTIMAL_KHR returned - ignoring"); - outOfDateFrames_++; } else if (res == VK_ERROR_OUT_OF_DATE_KHR) { WLOG("VK_ERROR_OUT_OF_DATE_KHR returned - not presenting"); frameData.skipSwap = true; - outOfDateFrames_++; } else { _assert_msg_(G3D, res == VK_SUCCESS, "vkAcquireNextImageKHR failed! result=%s", VulkanResultToString(res)); - outOfDateFrames_ = 0; } VkCommandBufferBeginInfo begin{ VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO }; @@ -1141,13 +1138,22 @@ void VulkanRenderManager::EndSubmitFrame(int frame) { present.waitSemaphoreCount = 1; VkResult res = vkQueuePresentKHR(vulkan_->GetGraphicsQueue(), &present); - // TODO: Deal with VK_SUBOPTIMAL_KHR ? - if (res == VK_ERROR_OUT_OF_DATE_KHR || res == VK_SUBOPTIMAL_KHR) { - // ignore, it'll be fine. this happens sometimes during resizes, and we do make sure to recreate the swap chain. + // TODO: Deal with VK_SUBOPTIMAL_KHR here too? + if (res == VK_ERROR_OUT_OF_DATE_KHR) { + // We clearly didn't get this in vkAcquireNextImageKHR because of the skipSwap check above. + // Do the increment. + outOfDateFrames_++; + } else if (res == VK_SUBOPTIMAL_KHR) { + outOfDateFrames_++; + } else if (res != VK_SUCCESS) { + _assert_msg_(G3D, false, "vkQueuePresentKHR failed! result=%s", VulkanResultToString(res)); } else { - _assert_msg_(G3D, res == VK_SUCCESS, "vkQueuePresentKHR failed! result=%s", VulkanResultToString(res)); + // Success + outOfDateFrames_ = 0; } } else { + // We only get here if vkAcquireNextImage returned VK_ERROR_OUT_OF_DATE. + outOfDateFrames_++; frameData.skipSwap = false; } } From e8370b94c0458f7116ebf789490e63701f6b0eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 28 Jun 2020 20:06:44 +0200 Subject: [PATCH 2/2] Remove irrelevant comment --- ext/native/thin3d/VulkanRenderManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ext/native/thin3d/VulkanRenderManager.cpp b/ext/native/thin3d/VulkanRenderManager.cpp index 9a3a9e5e43..d8d50bae3a 100644 --- a/ext/native/thin3d/VulkanRenderManager.cpp +++ b/ext/native/thin3d/VulkanRenderManager.cpp @@ -1138,7 +1138,6 @@ void VulkanRenderManager::EndSubmitFrame(int frame) { present.waitSemaphoreCount = 1; VkResult res = vkQueuePresentKHR(vulkan_->GetGraphicsQueue(), &present); - // TODO: Deal with VK_SUBOPTIMAL_KHR here too? if (res == VK_ERROR_OUT_OF_DATE_KHR) { // We clearly didn't get this in vkAcquireNextImageKHR because of the skipSwap check above. // Do the increment.