From 2f855f30a741900396aa08e8eff9726bc20afba6 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 25 Apr 2020 19:29:32 -0700 Subject: Improved surface orientation change detection in Vulkan swap chain --- .../GraphicsEngineVulkan/src/SwapChainVkImpl.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp index fac1482f..b6337999 100644 --- a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp @@ -818,12 +818,12 @@ void SwapChainVkImpl::RecreateVulkanSwapchain(DeviceContextVkImpl* pImmediateCtx void SwapChainVkImpl::Resize(Uint32 NewWidth, Uint32 NewHeight, SURFACE_TRANSFORM NewPreTransform) { - auto RecreateSwapChain = TSwapChainBase::Resize(NewWidth, NewHeight, NewPreTransform); + bool RecreateSwapChain = false; #if PLATFORM_ANDROID - if (!RecreateSwapChain && m_VkSurface != VK_NULL_HANDLE) + if (m_VkSurface != VK_NULL_HANDLE) { - // Check orinetation change + // Check orientation const auto* pRenderDeviceVk = m_pRenderDevice.RawPtr(); const auto& PhysicalDevice = pRenderDeviceVk->GetPhysicalDevice(); const auto vkDeviceHandle = PhysicalDevice.GetVkDeviceHandle(); @@ -835,8 +835,20 @@ void SwapChainVkImpl::Resize(Uint32 NewWidth, Uint32 NewHeight, SURFACE_TRANSFOR { if (m_CurrentSurfaceTransform != surfCapabilities.currentTransform) { + // Surface orientation has changed - we need to recreate the swap chain RecreateSwapChain = true; } + + constexpr auto Rotate90TransformFlags = + VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR | + VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR | + VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR | + VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR; + if ((surfCapabilities.currentTransform & Rotate90TransformFlags) != 0) + { + // The surface is rotated 90/270 degrees - swap width and height + std::swap(NewWidth, NewHeight); + } } else { @@ -845,6 +857,9 @@ void SwapChainVkImpl::Resize(Uint32 NewWidth, Uint32 NewHeight, SURFACE_TRANSFOR } #endif + if (TSwapChainBase::Resize(NewWidth, NewHeight, NewPreTransform)) + RecreateSwapChain = true; + if (RecreateSwapChain) { auto pDeviceContext = m_wpDeviceContext.Lock(); -- cgit v1.2.3