Fix Vulkan swapchain invalidation issue. #3379
Merged
+87
−40
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.
Should fix:
vkDeviceWaitIdle
in to be sure).The SDL entry code had a bug where the user resizing the window, triggers a window resize event, which calls SDL_SetWindowSize(), which triggers a window size. This loop reverted the window size to the previous size.
To fix the main issue with the Vulkan backend, I clamp the swapchain size to what the driver allows. I set the
m_resolution
of the swapchain and framebuffer to the actual result after clamping, instead of what the user requests. This way, one of the next frames, when the user's windowing code catches up with the resize, both the requested resolution and the Vulkan-allowed resolution match, and both are again in sync. Additionally, as the view rect passed from the user is still lagging behind in such cases, theVkRenderPassBeginInfo::renderArea
is also clamped to the actual resolution of the current framebuffer resolution.Review from @pezcode would be nice (especially regarding the deleted comment about ignoring
m_needToRefreshSwapchain
).CC @MohammedKHC, @LittleCodingFox, @GlaireDaggers.
Many thanks to @GlaireDaggers for some initial investigation, which made fixing this quite a bit easier.
Tested and confirmed to be working on: