VulkanHostDisplay: Avoid redundant resizes

This commit is contained in:
Connor McLaughlin 2022-06-05 01:11:39 +10:00 committed by refractionpcsx2
parent 3910b047d4
commit ca3833e71b
3 changed files with 15 additions and 3 deletions

View File

@ -674,6 +674,8 @@ namespace Vulkan
vkDestroySwapchainKHR(g_vulkan_context->GetDevice(), m_swap_chain, nullptr); vkDestroySwapchainKHR(g_vulkan_context->GetDevice(), m_swap_chain, nullptr);
m_swap_chain = VK_NULL_HANDLE; m_swap_chain = VK_NULL_HANDLE;
m_window_info.surface_width = 0;
m_window_info.surface_height = 0;
} }
VkResult SwapChain::AcquireNextImage() VkResult SwapChain::AcquireNextImage()
@ -685,7 +687,7 @@ namespace Vulkan
m_image_available_semaphore, VK_NULL_HANDLE, &m_current_image); m_image_available_semaphore, VK_NULL_HANDLE, &m_current_image);
} }
bool SwapChain::ResizeSwapChain(u32 new_width /* = 0 */, u32 new_height /* = 0 */) bool SwapChain::ResizeSwapChain(u32 new_width, u32 new_height, float new_scale)
{ {
DestroySwapChainImages(); DestroySwapChainImages();
DestroySemaphores(); DestroySemaphores();
@ -696,6 +698,8 @@ namespace Vulkan
m_window_info.surface_height = new_height; m_window_info.surface_height = new_height;
} }
m_window_info.surface_scale = new_scale;
if (!CreateSwapChain() || !SetupSwapChainImages() || !CreateSemaphores()) if (!CreateSwapChain() || !SetupSwapChainImages() || !CreateSemaphores())
{ {
DestroySemaphores(); DestroySemaphores();

View File

@ -58,6 +58,7 @@ namespace Vulkan
__fi const WindowInfo& GetWindowInfo() const { return m_window_info; } __fi const WindowInfo& GetWindowInfo() const { return m_window_info; }
__fi u32 GetWidth() const { return m_window_info.surface_width; } __fi u32 GetWidth() const { return m_window_info.surface_width; }
__fi u32 GetHeight() const { return m_window_info.surface_height; } __fi u32 GetHeight() const { return m_window_info.surface_height; }
__fi float GetScale() const { return m_window_info.surface_scale; }
__fi u32 GetCurrentImageIndex() const { return m_current_image; } __fi u32 GetCurrentImageIndex() const { return m_current_image; }
__fi u32 GetImageCount() const { return static_cast<u32>(m_images.size()); } __fi u32 GetImageCount() const { return static_cast<u32>(m_images.size()); }
__fi VkImage GetCurrentImage() const { return m_images[m_current_image].image; } __fi VkImage GetCurrentImage() const { return m_images[m_current_image].image; }
@ -71,7 +72,7 @@ namespace Vulkan
VkResult AcquireNextImage(); VkResult AcquireNextImage();
bool RecreateSurface(const WindowInfo& new_wi); bool RecreateSurface(const WindowInfo& new_wi);
bool ResizeSwapChain(u32 new_width = 0, u32 new_height = 0); bool ResizeSwapChain(u32 new_width = 0, u32 new_height = 0, float new_scale = 1.0f);
bool RecreateSwapChain(); bool RecreateSwapChain();
// Change vsync enabled state. This may fail as it causes a swapchain recreation. // Change vsync enabled state. This may fail as it causes a swapchain recreation.

View File

@ -121,9 +121,16 @@ bool VulkanHostDisplay::ChangeRenderWindow(const WindowInfo& new_wi)
void VulkanHostDisplay::ResizeRenderWindow(s32 new_window_width, s32 new_window_height, float new_window_scale) void VulkanHostDisplay::ResizeRenderWindow(s32 new_window_width, s32 new_window_height, float new_window_scale)
{ {
if (m_swap_chain->GetWidth() == new_window_width && m_swap_chain->GetHeight() == new_window_height)
{
// skip unnecessary resizes
m_window_info.surface_scale = new_window_scale;
return;
}
g_vulkan_context->WaitForGPUIdle(); g_vulkan_context->WaitForGPUIdle();
if (!m_swap_chain->ResizeSwapChain(new_window_width, new_window_height)) if (!m_swap_chain->ResizeSwapChain(new_window_width, new_window_height, new_window_scale))
{ {
// AcquireNextImage() will fail, and we'll recreate the surface. // AcquireNextImage() will fail, and we'll recreate the surface.
Console.Error("Failed to resize swap chain. Next present will fail."); Console.Error("Failed to resize swap chain. Next present will fail.");