From 3a87e34389639c71c983c8b1f430853a8813d76d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 7 Oct 2018 09:54:57 +0200 Subject: [PATCH] Make window resize work with Vulkan. I do still get the occasional lost device so there's some sync bug remaining. --- Common/Vulkan/VulkanContext.cpp | 15 ++++++++++++++- SDL/SDLVulkanGraphicsContext.h | 8 +++----- ext/native/thin3d/VulkanRenderManager.cpp | 2 ++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Common/Vulkan/VulkanContext.cpp b/Common/Vulkan/VulkanContext.cpp index aeb29f20eaf2..1292d2ab0215 100644 --- a/Common/Vulkan/VulkanContext.cpp +++ b/Common/Vulkan/VulkanContext.cpp @@ -648,7 +648,6 @@ void VulkanContext::ReinitSurface(int width, int height) { surface_ = VK_NULL_HANDLE; } - ILOG("Creating Vulkan surface (%d, %d)", width, height); switch (winsys_) { #ifdef _WIN32 case WINDOWSYSTEM_WIN32: @@ -726,8 +725,22 @@ void VulkanContext::ReinitSurface(int width, int height) { _assert_msg_(G3D, false, "Vulkan support for chosen window system not implemented"); break; } + width_ = width; height_ = height; + + // In case we didn't get a width and height, try to recover it from the surface. + // Useful with SDL. + if (width_ < 0) { + VkSurfaceCapabilitiesKHR caps; + if (VK_SUCCESS == vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_devices_[physical_device_], surface_, &caps)) { + if (caps.currentExtent.width != 0xFFFFFFFF && caps.currentExtent.height != 0xFFFFFFFF) { + width_ = caps.currentExtent.width; + height_ = caps.currentExtent.height; + } + } + } + ILOG("Created Vulkan surface (%d x %d)", width_, height_); } bool VulkanContext::InitQueue() { diff --git a/SDL/SDLVulkanGraphicsContext.h b/SDL/SDLVulkanGraphicsContext.h index 42883b670048..97045e071b9e 100644 --- a/SDL/SDLVulkanGraphicsContext.h +++ b/SDL/SDLVulkanGraphicsContext.h @@ -25,16 +25,14 @@ class SDLVulkanGraphicsContext : public GraphicsContext { } void Resize() override { - /* draw_->HandleEvent(Draw::Event::LOST_BACKBUFFER, vulkan_->GetBackbufferWidth(), vulkan_->GetBackbufferHeight()); vulkan_->DestroyObjects(); - // TODO: Take from real window dimensions - int width = 1024; - int height = 768; + // We now get the size from the Vk surface, can safely pass in nonsense. + int width = -1; + int height = -1; vulkan_->ReinitSurface(width, height); vulkan_->InitObjects(); draw_->HandleEvent(Draw::Event::GOT_BACKBUFFER, vulkan_->GetBackbufferWidth(), vulkan_->GetBackbufferHeight()); - */ } void SwapInterval(int interval) override { diff --git a/ext/native/thin3d/VulkanRenderManager.cpp b/ext/native/thin3d/VulkanRenderManager.cpp index f18b6129bccf..334ff8ea6a1f 100644 --- a/ext/native/thin3d/VulkanRenderManager.cpp +++ b/ext/native/thin3d/VulkanRenderManager.cpp @@ -857,7 +857,9 @@ void VulkanRenderManager::BeginSubmitFrame(int frame) { VkResult res = vkAcquireNextImageKHR(vulkan_->GetDevice(), vulkan_->GetSwapchain(), UINT64_MAX, acquireSemaphore_, (VkFence)VK_NULL_HANDLE, &frameData.curSwapchainImage); 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"); } else if (res == VK_ERROR_OUT_OF_DATE_KHR) { + WLOG("VK_ERROR_OUT_OF_DATE_KHR returned - not presenting"); frameData.skipSwap = true; } else { _assert_msg_(G3D, res == VK_SUCCESS, "vkAcquireNextImageKHR failed! result=%s", VulkanResultToString(res));