Force V-Sync via command line (windows)

This commit is contained in:
saschawillems 2016-06-12 17:20:42 +02:00
parent 8b08d01157
commit 2425797ca7
3 changed files with 20 additions and 10 deletions

View file

@ -761,6 +761,10 @@ VulkanExampleBase::VulkanExampleBase(bool enableValidation)
{ {
enableValidation = true; enableValidation = true;
} }
if (__argv[i] == std::string("-vsync"))
{
enableVSync = true;
}
} }
#elif defined(__ANDROID__) #elif defined(__ANDROID__)
// Vulkan library is loaded dynamically on Android // Vulkan library is loaded dynamically on Android
@ -1753,5 +1757,5 @@ void VulkanExampleBase::initSwapchain()
void VulkanExampleBase::setupSwapChain() void VulkanExampleBase::setupSwapChain()
{ {
swapChain.create(setupCmdBuffer, &width, &height); swapChain.create(setupCmdBuffer, &width, &height, enableVSync);
} }

View file

@ -57,6 +57,8 @@ private:
bool enableValidation = false; bool enableValidation = false;
// Set to true when the debug marker extension is detected // Set to true when the debug marker extension is detected
bool enableDebugMarkers = false; bool enableDebugMarkers = false;
// Set tot true if v-sync will be forced for the swapchain
bool enableVSync = false;
// fps timer (one second interval) // fps timer (one second interval)
float fpsTimer = 0.0f; float fpsTimer = 0.0f;
// Create application wide Vulkan instance // Create application wide Vulkan instance

View file

@ -235,7 +235,7 @@ public:
} }
// Create the swap chain and get images with given width and height // Create the swap chain and get images with given width and height
void create(VkCommandBuffer cmdBuffer, uint32_t *width, uint32_t *height, VkBool32 vsync = VK_FALSE) void create(VkCommandBuffer cmdBuffer, uint32_t *width, uint32_t *height, bool vsync = false)
{ {
VkResult err; VkResult err;
VkSwapchainKHR oldSwapchain = swapChain; VkSwapchainKHR oldSwapchain = swapChain;
@ -275,12 +275,15 @@ public:
// Select a present mode for the swapchain // Select a present mode for the swapchain
// The VK_PRESENT_MODE_FIFO_KHR mode must always be present as per spec // The VK_PRESENT_MODE_FIFO_KHR mode must always be present as per spec
// This mode waits for the vertical blank ("v-sync") // This mode waits for the vertical blank ("v-sync")
VkPresentModeKHR swapchainPresentMode = VK_PRESENT_MODE_FIFO_KHR; VkPresentModeKHR swapchainPresentMode = VK_PRESENT_MODE_FIFO_KHR;
// If v-sync is not requested, try to find a mailbox mode if present // If v-sync is not requested, try to find a mailbox mode if present
// It's the lowest latency non-tearing present mode available // It's the lowest latency non-tearing present mode available
if (!vsync)
{
for (size_t i = 0; i < presentModeCount; i++) for (size_t i = 0; i < presentModeCount; i++)
{ {
if (presentModes[i] == VK_PRESENT_MODE_MAILBOX_KHR) if (presentModes[i] == VK_PRESENT_MODE_MAILBOX_KHR)
@ -293,6 +296,7 @@ public:
swapchainPresentMode = VK_PRESENT_MODE_IMMEDIATE_KHR; swapchainPresentMode = VK_PRESENT_MODE_IMMEDIATE_KHR;
} }
} }
}
// Determine the number of images // Determine the number of images
uint32_t desiredNumberOfSwapchainImages = surfCaps.minImageCount + 1; uint32_t desiredNumberOfSwapchainImages = surfCaps.minImageCount + 1;