summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-03-27 01:23:21 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-03-27 01:23:21 +0000
commitc38dcef6f61cf97bb7df852c280245146cb87782 (patch)
tree29b04742e1b1bc880f5d14fa9e0ab4c0f3cae6f6 /Graphics/GraphicsEngineVulkan
parentEnabled format validation on MacOS (diff)
downloadDiligentCore-c38dcef6f61cf97bb7df852c280245146cb87782.tar.gz
DiligentCore-c38dcef6f61cf97bb7df852c280245146cb87782.zip
Enabled VSync on Vulkan (fixed https://github.com/DiligentGraphics/DiligentCore/issues/57)
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.hpp1
-rw-r--r--Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp13
2 files changed, 11 insertions, 3 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.hpp
index e58c5f71..289dbe55 100644
--- a/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.hpp
+++ b/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.hpp
@@ -106,6 +106,7 @@ private:
Uint32 m_SemaphoreIndex = 0;
uint32_t m_BackBufferIndex = 0;
bool m_IsMinimized = false;
+ bool m_VSyncEnabled = true;
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp
index 5ed8c222..acee6307 100644
--- a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp
@@ -226,12 +226,13 @@ void SwapChainVkImpl::CreateVulkanSwapChain()
m_SwapChainDesc.Width = swapchainExtent.width;
m_SwapChainDesc.Height = swapchainExtent.height;
- // Mailbox is the lowest latency non-tearing presentation mode
- VkPresentModeKHR swapchainPresentMode = VK_PRESENT_MODE_MAILBOX_KHR;
+ // Mailbox is the lowest latency non-tearing presentation mode.
+ VkPresentModeKHR swapchainPresentMode = m_VSyncEnabled ? VK_PRESENT_MODE_FIFO_KHR : VK_PRESENT_MODE_MAILBOX_KHR;
bool PresentModeSupported = std::find(presentModes.begin(), presentModes.end(), swapchainPresentMode) != presentModes.end();
if (!PresentModeSupported)
{
+ VERIFY(swapchainPresentMode != VK_PRESENT_MODE_FIFO_KHR, "The FIFO present mode is guaranteed by the spec to be supported");
swapchainPresentMode = VK_PRESENT_MODE_FIFO_KHR;
// The FIFO present mode is guaranteed by the spec to be supported
VERIFY(std::find(presentModes.begin(), presentModes.end(), swapchainPresentMode) != presentModes.end(), "FIFO present mode must be supported");
@@ -542,6 +543,9 @@ IMPLEMENT_QUERY_INTERFACE(SwapChainVkImpl, IID_SwapChainVk, TSwapChainBase)
void SwapChainVkImpl::Present(Uint32 SyncInterval)
{
+ if (SyncInterval != 0 && SyncInterval != 1)
+ LOG_WARNING_MESSAGE_ONCE("Vulkan only supports 0 and 1 present intervals");
+
auto pDeviceContext = m_wpDeviceContext.Lock();
if (!pDeviceContext)
{
@@ -612,9 +616,12 @@ void SwapChainVkImpl::Present(Uint32 SyncInterval)
if (m_SemaphoreIndex >= m_SwapChainDesc.BufferCount)
m_SemaphoreIndex = 0;
- auto res = AcquireNextImage(pImmediateCtxVk);
+ bool EnableVSync = SyncInterval != 0;
+
+ auto res = (m_VSyncEnabled == EnableVSync) ? AcquireNextImage(pImmediateCtxVk) : VK_ERROR_OUT_OF_DATE_KHR;
if (res == VK_SUBOPTIMAL_KHR || res == VK_ERROR_OUT_OF_DATE_KHR)
{
+ m_VSyncEnabled = EnableVSync;
RecreateVulkanSwapchain(pImmediateCtxVk);
m_SemaphoreIndex = m_SwapChainDesc.BufferCount - 1; // To start with 0 index when acquire next image