Potential fix for the synchronization issue. Needs review. #3303
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In order to help debugging, I created a new macro
VK_TRACE
similar toVK_CHECK
to also be able to trace and warn for Vulkan calls that have a result which is assigned to a variable and further used. That causes a lot of lines to be changed, but the real change is not that big.@pezcode, can you share your thoughts on this proposed fix?
So, in summary, the proposed fix will
vkWaitForFences
on the rendering-done fence from the oldest in-flight frame. I believe that this should causevkAcquireNextImageKHR
to always simply return the next frame in the swapchain deterministically.In case we don't get the next frame, it is detected, as the fence for the rendering work for the frame-in-flight is stored in the swapchain
m_renderDoneFence
(similar to the semaphore; always the next one by index) AND in them_backBufferFence
(indexed by the frame number returned by thevkAcquireNextImageKHR
). If the fence we just waited for, doesn't match the fence for that particular frame, we wait for that one too (which I genuinely think doesn't do anything reasonable as that should never happen and we are just fully screwed in that case) and print a warning (if in debug).Would fix #3302.