bkaradzic / bgfx

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
https://bkaradzic.github.io/bgfx/overview.html
BSD 2-Clause "Simplified" License
15.11k stars 1.95k forks source link

Fix Vulkan swapchain invalidation issue. #3379

Closed mcourteaux closed 1 day ago

mcourteaux commented 1 day ago

Should fix:

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, the VkRenderPassBeginInfo::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: