summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Vulkan/SwapChain.cpp
diff options
context:
space:
mode:
authorshuffle2 <godisgovernment@gmail.com>2016-10-04 01:47:59 -0700
committerGitHub <noreply@github.com>2016-10-04 01:47:59 -0700
commitea33405febf183058bb30a22f4f627fed4bb8e17 (patch)
tree6222aceb31b2d6d922a8b3e45331b42fa1abba2d /Source/Core/VideoBackends/Vulkan/SwapChain.cpp
parent037f0a1803c274ce7e9f97ff9b7baed2955b9004 (diff)
parent28e5fa8d261cd486e9339a66d91b4713e83d9a14 (diff)
Merge pull request #4270 from stenzek/vulkan-defer-fix
Vulkan: Miscellaneous minor fixes
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan/SwapChain.cpp')
-rw-r--r--Source/Core/VideoBackends/Vulkan/SwapChain.cpp30
1 files changed, 19 insertions, 11 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/SwapChain.cpp b/Source/Core/VideoBackends/Vulkan/SwapChain.cpp
index f0a35fd526..899f931c6d 100644
--- a/Source/Core/VideoBackends/Vulkan/SwapChain.cpp
+++ b/Source/Core/VideoBackends/Vulkan/SwapChain.cpp
@@ -24,8 +24,8 @@
namespace Vulkan
{
-SwapChain::SwapChain(void* native_handle, VkSurfaceKHR surface)
- : m_native_handle(native_handle), m_surface(surface)
+SwapChain::SwapChain(void* native_handle, VkSurfaceKHR surface, bool vsync)
+ : m_native_handle(native_handle), m_surface(surface), m_vsync_enabled(vsync)
{
}
@@ -127,9 +127,10 @@ VkSurfaceKHR SwapChain::CreateVulkanSurface(VkInstance instance, void* hwnd)
#endif
}
-std::unique_ptr<SwapChain> SwapChain::Create(void* native_handle, VkSurfaceKHR surface)
+std::unique_ptr<SwapChain> SwapChain::Create(void* native_handle, VkSurfaceKHR surface, bool vsync)
{
- std::unique_ptr<SwapChain> swap_chain = std::make_unique<SwapChain>(native_handle, surface);
+ std::unique_ptr<SwapChain> swap_chain =
+ std::make_unique<SwapChain>(native_handle, surface, vsync);
if (!swap_chain->CreateSwapChain() || !swap_chain->CreateRenderPass() ||
!swap_chain->SetupSwapChainImages())
@@ -198,7 +199,7 @@ bool SwapChain::SelectPresentMode()
};
// If vsync is enabled, prefer VK_PRESENT_MODE_FIFO_KHR.
- if (g_ActiveConfig.IsVSync())
+ if (m_vsync_enabled)
{
// Try for relaxed vsync first, since it's likely the VI won't line up with
// the refresh rate of the system exactly, so tearing once is better than
@@ -280,8 +281,8 @@ void SwapChain::DestroyRenderPass()
if (!m_render_pass)
return;
- g_command_buffer_mgr->DeferResourceDestruction(m_render_pass);
- m_render_pass = nullptr;
+ vkDestroyRenderPass(g_vulkan_context->GetDevice(), m_render_pass, nullptr);
+ m_render_pass = VK_NULL_HANDLE;
}
bool SwapChain::CreateSwapChain()
@@ -456,11 +457,8 @@ VkResult SwapChain::AcquireNextImage(VkSemaphore available_semaphore)
bool SwapChain::ResizeSwapChain()
{
- if (!CreateSwapChain())
- return false;
-
DestroySwapChainImages();
- if (!SetupSwapChainImages())
+ if (!CreateSwapChain() || !SetupSwapChainImages())
{
PanicAlert("Failed to re-configure swap chain images, this is fatal (for now)");
return false;
@@ -469,6 +467,16 @@ bool SwapChain::ResizeSwapChain()
return true;
}
+bool SwapChain::SetVSync(bool enabled)
+{
+ if (m_vsync_enabled == enabled)
+ return true;
+
+ // Resizing recreates the swap chain with the new present mode.
+ m_vsync_enabled = enabled;
+ return ResizeSwapChain();
+}
+
bool SwapChain::RecreateSurface(void* native_handle)
{
// Destroy the old swap chain, images, and surface.