Commit cecefe53430a27306777fa700fdf0e2d32e96318

Igor Nazarov 2024-11-21T22:11:17

Vulkan: Improve recreateSwapchain() error handling The `WindowSurfaceVk::recreateSwapchain()` method may fail in many points. After failing, state of `WindowSurfaceVk` may become invalid, causing undefined behavior. Invalid state examples: - Skip adding `cleanupData` into the `mOldSwapchains` while `mPresentHistory already cleared (resource leak). - `mSwapchain` may remain `VK_NULL_HANDLE` after the failure. - `lastSwapchain` may be not retired, causing subsequent swapchain creation to fail. Change adds `mLastSwapchain` member to continue tracking last created swapchain during the `mSwapchain` recreation process until it is retired. This process now may span multiple API calls. The `mSwapchain` pointer is invalidated as soon as recreate starts - to indicate that we do not have usable swapchain and still need to create one. Notable difference with the old code is that old swapchain and present history are now collected into the `mOldSwapchains` after new swapchain is created (or old swapchain is retired in case of a failure). Because of this, code can now be simplified and easily refactored into a separate method. The `kMaxOldSwapchains` is now also checked after old swapchain is collected - this is to prevent resource leak if `finish()` fails. Added `cleanUpOldSwapchains()` call to reduce a chance of hitting the `kMaxOldSwapchains` limit. Change also renamed `presentOutOfDate` parameter where it does not always make sense. As a side effect, fixed a bug when calling `prepareForAcquireNextSwapchainImage()` with true, is then replaced with false in the `computePresentOutOfDate()` call. Bug: angleproject:380234227 Change-Id: Ie6d85c1b9760cda68c8fc9368235756659a9bdac Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6040159 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Charlie Lao <cclao@google.com> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>