Skip to content

random stuttering after swapchain recreation with VK_PRESENT_MODE_FIFO_KHR #1248

@Lewa-dev

Description

@Lewa-dev

Hi!
I've found a possible synchronisation issue causing stuttering with regards to the swapchain acquisition/presentation in the FIFO_KHR mode.
I've noticed this issue in my own vulkan renderer but after checking out the vulkan samples in this repository i can reproduce the exact same behaviour in those samples too which is why i'm posting this here in the hopes that anyone else has an idea as to what is going on. (I'm suspecting a driver issue at this point as i can't find the error anywhere.)

Specs:

  • Windows 11
  • RTX 5070 TI

Issue:
Consistent stuttering/choppy visual output (even though the reported framerate is stable at 60) with VK_PRESENT_MODE_FIFO_KHR in windowed mode. Can be triggered (and fixed) randomly by recreating the swapchain.


I've made a quick video demonstrating this issue in the vulkan samples:

https://www.youtube.com/watch?v=f9PB445C-ms

To make it quick, for debugging purposes that's the changes i've made on the codebase of the samples repository:

  1. force FIFO mode in VulkanSwapchain.cpp:
    VkPresentModeKHR swapchainPresentMode = VK_PRESENT_MODE_FIFO_KHR;
  2. in prepareFrame() of vulkanExamplesBase.cpp i added an output command to print the previous and currently acquired swapchain index to the debug output window (which can be also seen in the video above.)
	auto prev = currentImageIndex;
	VkResult result = swapChain.acquireNextImage(presentCompleteSemaphores[currentBuffer], currentImageIndex);
	std::string out = "SC: " + std::to_string(prev) + " > " + std::to_string(currentImageIndex)+"\n";
	OutputDebugString(out.c_str());

In the video you can see that the sample runs fine and smooth at 60 FPS with a consistent swapchain index rotation. (The debug/console output is on the right side of the screen.)
Example (the format is "SC: [previous index] > [new index]")

SC: 0 > 1
SC: 1 > 0
SC: 0 > 1
SC: 1 > 0
SC: 0 > 1
SC: 1 > 0
SC: 0 > 1
SC: 1 > 0
...

but sometimes after resizing/repositioning the window (triggering a swapchain recreation) the visual output starts to stutter visually, even though the framerate is still reported as 60FPS. (You can see this in the linked video at the timestamp 0:18 )

However if you look at the debug output, you may notice that vkAcquireNextImageKHR often acquires the same swapchain index that was used by the previous frame (possibly causing stalls in the renderpipeline?) which may lead to to the stuttery visual output.

SC: 1 > 1 <<< same index
SC: 1 > 0
SC: 0 > 0 <<< same index
SC: 0 > 1
SC: 1 > 1 <<< same index
SC: 1 > 0
SC: 0 > 0 <<< same index
SC: 0 > 1
SC: 1 > 1 <<< same index
SC: 1 > 0
SC: 0 > 0 <<< same index
SC: 0 > 1
SC: 1 > 1 <<< same index
etc...

This can be (randomly) fixed by recreating the swapchain again.

Is anyone else experiencing this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions