Hi!
Posting here as i’m investigating a swapchain synchronisation issue and hoping that anyone can try to reproduce this with the sample app/has an idea as to what is going on.
Description:
After swapchain recreation, vkAcquireNextImageKHR sometimes/randomly retrieves the same image index back to back (even in the case of tripple buffering) causing the visual output to look extremely choppy. This can be (sometimes) fixed by destroying and recreating the swapchain again.
I can reproduce this with this repository ( GitHub - SaschaWillems/Vulkan: C++ examples for the Vulkan graphics API ) which is a popular vulkan tutorial / reference implementation.
I’m on Windows 11 with a Nvidia Geforce RTX 5070 TI on the latest driver version 591.59 using a dual monitor setup.
Build instructions for the sample: [ Repository: GitHub - SaschaWillems/Vulkan: C++ examples for the Vulkan graphics API ]
git clone --recursive https://github.com/SaschaWillems/Vulkan.git
cd Vulkan
cmake -G "Visual Studio 17 2022" -A x64
Open vulkanExamples.sln, build everything and set the startup project to “deferred”.
Note that you have to enable vsync by modifying the “Settings” struct in vulkanexamplebase.h:
sruct Settings {
...
bool vsync = true; //<<<<<<<<< SET THIS TO TRUE!
...
} settings;
Then you can start the sample.
I have recorded a video on my screen via screencapture to show the stuttering behavior (Moving the camera with the mouse to see how smooth it is):
Stutter starts at around 0:18 seconds. I force a swapchain refresh/recreation by moving the window around. Note that it often looks fine but sometimes after a forced swapchain refresh the visual output is not smooth anymore.
Note that the stuttering can even happen at the first startup (so after the first swapchain initialisation, without previously deleting an existing swapchain) making me suspect that this is a driver issue.
For debugging purposes 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 on the right side of the screen.)
//added in prepareFrame() of vulkanExamplesBase.cpp around the acquireNextImage() call:
auto previous = currentImageIndex;
VkResult result = swapChain.acquireNextImage(presentCompleteSemaphores[currentBuffer], currentImageIndex);
std::string out = "SC: " + std::to_string(previous) + " > " + std::to_string(currentImageIndex)+"\n";
OutputDebugString(out.c_str());
Note in the video that once the stutter happens, the same image index will be acquired from the swapchain back-to back multiple times.
So instead of having an image index rotation like 0 > 1, 0 >1, 0 > 1, etc…
we get 1 > 1, 0 > 0, 1 > 1, etc…
As far as i can tell the sample does everything correct according to spec? It uses two semaphores (1 for frame acqusition and 1 for signaling) as well as a fence to wait until the command buffer was submitted on the CPU side before calling vkAcquireNextImageKHR.
Anyone an idea as to what the cause of this could be? Could this be a driver issue?