diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 439d170e9..47181b06b 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -549,11 +549,7 @@ uint32_t VulkanFrameBuffer::GetCaps() void VulkanFrameBuffer::SetVSync(bool vsync) { - if (swapChain->vsync != vsync) - { - swapChain.reset(); - swapChain = std::make_unique(device); - } + // This is handled in VulkanSwapChain::AcquireImage. } void VulkanFrameBuffer::CleanForRestart() diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index 5a64d4b68..98d8c9412 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -92,7 +92,7 @@ public: TArray GetScreenshotBuffer(int &pitch, ESSType &color_type, float &gamma) override; - void SetVSync(bool vsync); + void SetVSync(bool vsync) override; void Draw2D() override; diff --git a/src/rendering/vulkan/system/vk_swapchain.cpp b/src/rendering/vulkan/system/vk_swapchain.cpp index 4a5320761..bcdb1c36a 100644 --- a/src/rendering/vulkan/system/vk_swapchain.cpp +++ b/src/rendering/vulkan/system/vk_swapchain.cpp @@ -6,29 +6,12 @@ EXTERN_CVAR(Bool, vid_vsync); -CUSTOM_CVAR(Bool, vk_hdr, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) -{ - Printf("This won't take effect until " GAMENAME " is restarted.\n"); -} +CVAR(Bool, vk_hdr, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG); void I_GetVulkanDrawableSize(int *width, int *height); -VulkanSwapChain::VulkanSwapChain(VulkanDevice *device) : vsync(vid_vsync), device(device) +VulkanSwapChain::VulkanSwapChain(VulkanDevice *device) : device(device) { - try - { - SelectFormat(); - SelectPresentMode(); - if (!CreateSwapChain()) - I_Error("Could not create vulkan swapchain"); - GetImages(); - CreateViews(); - } - catch (...) - { - ReleaseResources(); - throw; - } } VulkanSwapChain::~VulkanSwapChain() @@ -38,11 +21,13 @@ VulkanSwapChain::~VulkanSwapChain() uint32_t VulkanSwapChain::AcquireImage(int width, int height, VulkanSemaphore *semaphore, VulkanFence *fence) { - if (lastSwapWidth != width || lastSwapHeight != height || !swapChain) + if (lastSwapWidth != width || lastSwapHeight != height || lastVsync != vid_vsync || lastHdr != vk_hdr || !swapChain) { Recreate(); lastSwapWidth = width; lastSwapHeight = height; + lastVsync = vid_vsync; + lastHdr = vk_hdr; } uint32_t imageIndex; @@ -132,6 +117,9 @@ void VulkanSwapChain::Recreate() bool VulkanSwapChain::CreateSwapChain(VkSwapchainKHR oldSwapChain) { + SelectFormat(); + SelectPresentMode(); + int width, height; I_GetVulkanDrawableSize(&width, &height); @@ -266,7 +254,7 @@ void VulkanSwapChain::SelectPresentMode() I_Error("No surface present modes supported"); swapChainPresentMode = VK_PRESENT_MODE_FIFO_KHR; - if (vsync) + if (vid_vsync) { bool supportsFifoRelaxed = std::find(presentModes.begin(), presentModes.end(), VK_PRESENT_MODE_FIFO_RELAXED_KHR) != presentModes.end(); if (supportsFifoRelaxed) diff --git a/src/rendering/vulkan/system/vk_swapchain.h b/src/rendering/vulkan/system/vk_swapchain.h index 0aed7fcf2..a07bc0d90 100644 --- a/src/rendering/vulkan/system/vk_swapchain.h +++ b/src/rendering/vulkan/system/vk_swapchain.h @@ -16,7 +16,6 @@ public: void Recreate(); - bool vsync; VkSwapchainKHR swapChain = VK_NULL_HANDLE; VkSurfaceFormatKHR swapChainFormat; VkPresentModeKHR swapChainPresentMode; @@ -44,6 +43,8 @@ private: int lastSwapWidth = 0; int lastSwapHeight = 0; + bool lastVsync = false; + bool lastHdr = false; VulkanSwapChain(const VulkanSwapChain &) = delete; VulkanSwapChain &operator=(const VulkanSwapChain &) = delete;