Skip to content
Permalink
Browse files

- apply vk_hdr immediately and delay initial swapchain creation until…

… first image needs to be acquired
  • Loading branch information...
dpjudas committed Apr 11, 2019
1 parent db4310c commit 095ea3ce76cba098f337f79122ee6e83f339f4b7
@@ -549,11 +549,7 @@ uint32_t VulkanFrameBuffer::GetCaps()

void VulkanFrameBuffer::SetVSync(bool vsync)
{
if (swapChain->vsync != vsync)
{
swapChain.reset();
swapChain = std::make_unique<VulkanSwapChain>(device);
}
// This is handled in VulkanSwapChain::AcquireImage.
}

void VulkanFrameBuffer::CleanForRestart()
@@ -92,7 +92,7 @@ class VulkanFrameBuffer : public SystemBaseFrameBuffer

TArray<uint8_t> GetScreenshotBuffer(int &pitch, ESSType &color_type, float &gamma) override;

void SetVSync(bool vsync);
void SetVSync(bool vsync) override;

void Draw2D() override;

@@ -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)
@@ -16,7 +16,6 @@ class VulkanSwapChain

void Recreate();

bool vsync;
VkSwapchainKHR swapChain = VK_NULL_HANDLE;
VkSurfaceFormatKHR swapChainFormat;
VkPresentModeKHR swapChainPresentMode;
@@ -44,6 +43,8 @@ class VulkanSwapChain

int lastSwapWidth = 0;
int lastSwapHeight = 0;
bool lastVsync = false;
bool lastHdr = false;

VulkanSwapChain(const VulkanSwapChain &) = delete;
VulkanSwapChain &operator=(const VulkanSwapChain &) = delete;

0 comments on commit 095ea3c

Please sign in to comment.
You can’t perform that action at this time.