summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Vulkan/SwapChain.cpp
diff options
context:
space:
mode:
authorStenzek <stenzek@users.noreply.github.com>2018-02-20 01:19:45 +1000
committerGitHub <noreply@github.com>2018-02-20 01:19:45 +1000
commit93c502fef8980bf6f6db7316738857bb0818debf (patch)
tree7e14390a62a600c8ec89ad39a77919748d6152f1 /Source/Core/VideoBackends/Vulkan/SwapChain.cpp
parent456c2f42c350e15402eea169a2cc87878327c1fc (diff)
parent0dddaf9d7d0837a574c6e8d255bebb3947f09a0e (diff)
Merge pull request #6330 from stenzek/resizing
Improve handling of surface change/resize events in graphics backends
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan/SwapChain.cpp')
-rw-r--r--Source/Core/VideoBackends/Vulkan/SwapChain.cpp27
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;