Skip to content

Commit

Permalink
GS/Vulkan: Simplify and refactor swap chains
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek authored and refractionpcsx2 committed May 9, 2023
1 parent 3f0ecc2 commit 2b8b43c
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 200 deletions.
25 changes: 12 additions & 13 deletions pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ static VkAttachmentLoadOp GetLoadOpForTexture(GSTextureVK* tex)
// clang-format on
}

static VkPresentModeKHR GetPreferredPresentModeForVsyncMode(VsyncMode mode)
{
if (mode == VsyncMode::On)
return VK_PRESENT_MODE_FIFO_KHR;
else if (mode == VsyncMode::Adaptive)
return VK_PRESENT_MODE_FIFO_RELAXED_KHR;
else
return VK_PRESENT_MODE_IMMEDIATE_KHR;
}

static constexpr VkClearValue s_present_clear_color = {{{0.0f, 0.0f, 0.0f, 1.0f}}};

GSDeviceVK::GSDeviceVK()
Expand Down Expand Up @@ -283,7 +273,7 @@ bool GSDeviceVK::UpdateWindow()
return false;
}

m_swap_chain = VKSwapChain::Create(m_window_info, surface, GetPreferredPresentModeForVsyncMode(m_vsync_mode),
m_swap_chain = VKSwapChain::Create(m_window_info, surface, m_vsync_mode,
Pcsx2Config::GSOptions::TriStateToOptionalBoolean(GSConfig.ExclusiveFullscreenControl));
if (!m_swap_chain)
{
Expand Down Expand Up @@ -365,7 +355,16 @@ void GSDeviceVK::SetVSync(VsyncMode mode)

// This swap chain should not be used by the current buffer, thus safe to destroy.
g_vulkan_context->WaitForGPUIdle();
m_swap_chain->SetVSync(GetPreferredPresentModeForVsyncMode(mode));
if (!m_swap_chain->SetVSync(mode))
{
// Try switching back to the old mode..
if (!m_swap_chain->SetVSync(m_vsync_mode))
{
pxFailRel("Failed to reset old vsync mode after failure");
m_swap_chain.reset();
}
}

m_vsync_mode = mode;
}

Expand Down Expand Up @@ -648,7 +647,7 @@ bool GSDeviceVK::CreateDeviceAndSwapChain()
// NOTE: This is assigned afterwards, because some platforms can modify the window info (e.g. Metal).
if (surface != VK_NULL_HANDLE)
{
m_swap_chain = VKSwapChain::Create(m_window_info, surface, GetPreferredPresentModeForVsyncMode(m_vsync_mode),
m_swap_chain = VKSwapChain::Create(m_window_info, surface, m_vsync_mode,
Pcsx2Config::GSOptions::TriStateToOptionalBoolean(GSConfig.ExclusiveFullscreenControl));
if (!m_swap_chain)
{
Expand Down
1 change: 1 addition & 0 deletions pcsx2/GS/Renderers/Vulkan/VKContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class VKContext
bool vk_ext_line_rasterization : 1;
bool vk_ext_rasterization_order_attachment_access : 1;
bool vk_ext_full_screen_exclusive : 1;
bool vk_ext_surface_maintenance1 : 1;
bool vk_khr_driver_properties : 1;
bool vk_khr_fragment_shader_barycentric : 1;
bool vk_khr_shader_draw_parameters : 1;
Expand Down

0 comments on commit 2b8b43c

Please sign in to comment.