Skip to content

Commit

Permalink
Merge pull request #13066 from hrydgard/vulkan-outofdate-handling
Browse files Browse the repository at this point in the history
Move the Vulkan swapchain out-of-date checking to the vkQueuePresentKHR call
  • Loading branch information
hrydgard authored Jul 13, 2020
2 parents 09238ed + e8370b9 commit 59af3d5
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions ext/native/thin3d/VulkanRenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -1141,13 +1138,21 @@ 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.
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;
}
}
Expand Down

0 comments on commit 59af3d5

Please sign in to comment.