-
Notifications
You must be signed in to change notification settings - Fork 560
Description
As stated in http://disq.us/p/32wdmkz, a recent Vulkan Validation Layer update exposed the problem that most Vulkan tutorials (also vkguide, and other derivative works of VulkanTutorial) and Vulkan programs (even vkcube) did not correctly make use of semaphores to synchronize presentation.
I am not a Vulkan professor, and here's my understanding. In the following code:
VkSemaphore signalSemaphores[] = {renderFinishedSemaphores[currentFrame]};
submitInfo.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = signalSemaphores;
vkQueueSubmit(graphicsQueue, 1, &submitInfo, inFlightFences[currentFrame]);
Here we are actually expecting that the renderFinishedSemaphores[currentFrame]
to have already been acquired/consumed by presentation queue during the several previous iterations. However there's no guarantee. So it is possible for the graphics queue to signal an already signaled semaphore.
To fix this problem, program should create the renderFinishedSemaphores
array of swapChainImages.size()
semaphores, and use the imageIndex
returned from vkAcquireNextImageKHR
to index into the array, ensuring that the semaphore has been acquired/consumed:
kennyalive/vulkan-base@27bcaad
JasonPhone/vrtr@c459d88
JorriFransen/v10@3652d32
I also made my personal fix on my own Java version tutorial: old -> new