VulkanTutorial
VulkanTutorial copied to clipboard
Order of the updateUniformBuffer and imagesInFlight fence
I thought I should ask before going through the trouble of making the PR. It seems that inside the drawFrame
function the order of calls to updateUniformBuffer
and vkWaitForFences(device, 1, &imagesInFlight[imageIndex], VK_TRUE, UINT64_MAX);
is inverted.
For example in code/29_multisampling.cpp
we have:
void drawFrame() {
vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
uint32_t imageIndex;
VkResult result = vkAcquireNextImageKHR(device, swapChain, UINT64_MAX, imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex);
if (result == VK_ERROR_OUT_OF_DATE_KHR) {
recreateSwapChain();
return;
} else if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) {
throw std::runtime_error("failed to acquire swap chain image!");
}
updateUniformBuffer(imageIndex);
if (imagesInFlight[imageIndex] != VK_NULL_HANDLE) {
vkWaitForFences(device, 1, &imagesInFlight[imageIndex], VK_TRUE, UINT64_MAX);
}
imagesInFlight[imageIndex] = inFlightFences[currentFrame];
/// ...
}
If imagesInFlight[imageIndex]
is suppose to be used to make sure GPU processing is done before the uniform buffer with index imageIndex
is updated then the call updateUniformBuffer
should be after the wait.
Yeah, that should be changed.
Yep had some hard time debugging this after applying what I've learned from the compute shader chapter. Uniforms waited for the compute shader to finish before updating, but updating the uniforms updated the camera as well, which was read from the graphics shader (still in flight).