From 2d0c9127f339b60e6f4de7bd8cb40168399e7390 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 15 Dec 2019 11:32:43 +0100 Subject: [PATCH] [vulkan] Don't create a swap chain if the window size is 0 This can actually happen on win32, and creating a zero-sized swap chain is illegal. --- src/vulkan/vulkan_presenter.cpp | 6 ++++++ src/vulkan/vulkan_presenter.h | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/vulkan/vulkan_presenter.cpp b/src/vulkan/vulkan_presenter.cpp index ab604bd4..6958e576 100644 --- a/src/vulkan/vulkan_presenter.cpp +++ b/src/vulkan/vulkan_presenter.cpp @@ -131,6 +131,12 @@ namespace dxvk::vk { m_info.imageExtent = pickImageExtent(caps, desc.imageExtent); m_info.imageCount = pickImageCount(caps, m_info.presentMode, desc.imageCount); + if (!m_info.imageExtent.width || !m_info.imageExtent.height) { + m_info.imageCount = 0; + m_info.format = { VK_FORMAT_UNDEFINED, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR }; + return VK_SUCCESS; + } + VkSurfaceFullScreenExclusiveInfoEXT fullScreenInfo; fullScreenInfo.sType = VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_INFO_EXT; fullScreenInfo.pNext = nullptr; diff --git a/src/vulkan/vulkan_presenter.h b/src/vulkan/vulkan_presenter.h index 3211c075..09695c96 100644 --- a/src/vulkan/vulkan_presenter.h +++ b/src/vulkan/vulkan_presenter.h @@ -177,6 +177,18 @@ namespace dxvk::vk { VkResult recreateSwapChain( const PresenterDesc& desc); + /** + * \brief Checks whether a Vulkan swap chain exists + * + * On Windows, there are situations where we cannot create + * a swap chain as the surface size can reach zero, and no + * presentation can be performed. + * \returns \c true if the presenter has a swap chain. + */ + bool hasSwapChain() const { + return m_swapchain; + } + private: Rc m_vki;