Fix #130164: Vulkan: Freeze when resizing window

When resizing window some platforms could freeze. The cause was that
depending on a platform the swap chain could get out of date when
acquiring the next swapchain image or when presenting the swap chain
image to the queue.

We only covered one scenario. This PR implements the scenario to
recreating the swap chain when the image could not be acquired.

Pull Request: https://projects.blender.org/blender/blender/pulls/130909
This commit is contained in:
Jeroen Bakker
2024-11-25 15:31:09 +01:00
parent 10e663e001
commit 69f94df026

View File

@@ -546,7 +546,18 @@ GHOST_TSuccess GHOST_ContextVK::swapBuffers()
assert(vulkan_device.has_value() && vulkan_device->device != VK_NULL_HANDLE);
VkDevice device = vulkan_device->device;
vkAcquireNextImageKHR(device, m_swapchain, UINT64_MAX, VK_NULL_HANDLE, m_fence, &s_currentImage);
/* Some platforms (NVIDIA/Wayland) can receive an out of date swapchain when acquiring the next
* swapchain image. Other do it when calling vkQueuePresent. */
VkResult result = VK_ERROR_OUT_OF_DATE_KHR;
while (result == VK_ERROR_OUT_OF_DATE_KHR) {
result = vkAcquireNextImageKHR(
device, m_swapchain, UINT64_MAX, VK_NULL_HANDLE, m_fence, &s_currentImage);
if (result == VK_ERROR_OUT_OF_DATE_KHR) {
destroySwapchain();
createSwapchain();
}
}
VK_CHECK(vkWaitForFences(device, 1, &m_fence, VK_TRUE, UINT64_MAX));
VK_CHECK(vkResetFences(device, 1, &m_fence));
@@ -569,7 +580,7 @@ GHOST_TSuccess GHOST_ContextVK::swapBuffers()
present_info.pImageIndices = &s_currentImage;
present_info.pResults = nullptr;
VkResult result = VK_SUCCESS;
result = VK_SUCCESS;
{
std::scoped_lock lock(vulkan_device->queue_mutex);
result = vkQueuePresentKHR(m_present_queue, &present_info);