diff options
| author | Stenzek <stenzek@gmail.com> | 2018-01-26 16:23:24 +1000 |
|---|---|---|
| committer | Stenzek <stenzek@gmail.com> | 2018-02-20 01:15:55 +1000 |
| commit | de632fc9c8d7d026ccad1afc2f72224ee9639023 (patch) | |
| tree | cf182d393ccde05c26d3fa27bc7007e134fbadda /Source/Core/VideoBackends/Vulkan/SwapChain.cpp | |
| parent | 5baf3bbe2e2fb62cac9c1bb4cded45644ebfd3bb (diff) | |
Renderer: Handle resize events on-demand instead of polling
We now differentiate between a resize event and surface change/destroyed
event, reducing the overhead for resizes in the Vulkan backend. It is
also now now safe to change the surface multiple times if the video thread
is lagging behind.
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan/SwapChain.cpp')
| -rw-r--r-- | Source/Core/VideoBackends/Vulkan/SwapChain.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/SwapChain.cpp b/Source/Core/VideoBackends/Vulkan/SwapChain.cpp index 672affeaea..88bb00ee29 100644 --- a/Source/Core/VideoBackends/Vulkan/SwapChain.cpp +++ b/Source/Core/VideoBackends/Vulkan/SwapChain.cpp @@ -14,6 +14,7 @@ #include "VideoBackends/Vulkan/CommandBufferManager.h" #include "VideoBackends/Vulkan/VulkanContext.h" +#include "VideoCommon/RenderBase.h" #if defined(VK_USE_PLATFORM_XLIB_KHR) #include <X11/Xlib.h> @@ -261,11 +262,13 @@ bool SwapChain::CreateSwapChain() VkExtent2D size = surface_capabilities.currentExtent; if (size.width == UINT32_MAX) { - size.width = std::min(std::max(surface_capabilities.minImageExtent.width, 640u), - surface_capabilities.maxImageExtent.width); - size.height = std::min(std::max(surface_capabilities.minImageExtent.height, 480u), - surface_capabilities.maxImageExtent.height); + size.width = std::max(g_renderer->GetBackbufferWidth(), 1); + size.height = std::max(g_renderer->GetBackbufferHeight(), 1); } + size.width = MathUtil::Clamp(size.width, surface_capabilities.minImageExtent.width, + surface_capabilities.maxImageExtent.width); + size.height = MathUtil::Clamp(size.height, surface_capabilities.minImageExtent.height, + surface_capabilities.maxImageExtent.height); // Prefer identity transform if possible VkSurfaceTransformFlagBitsKHR transform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; @@ -468,6 +471,22 @@ bool SwapChain::RecreateSurface(void* native_handle) if (m_surface == VK_NULL_HANDLE) return false; + // The validation layers get angry at us if we don't call this before creating the swapchain. + VkBool32 present_supported = VK_TRUE; + VkResult res = vkGetPhysicalDeviceSurfaceSupportKHR( + g_vulkan_context->GetPhysicalDevice(), g_vulkan_context->GetPresentQueueFamilyIndex(), + m_surface, &present_supported); + if (res != VK_SUCCESS) + { + LOG_VULKAN_ERROR(res, "vkGetPhysicalDeviceSurfaceSupportKHR failed: "); + return false; + } + if (!present_supported) + { + PanicAlert("Recreated surface does not support presenting."); + return false; + } + // Finally re-create the swap chain if (!CreateSwapChain() || !SetupSwapChainImages() || !CreateRenderPass()) return false; |
