Commit 7d31a47fc7c367390bd8fda2ea6ab1e5819b7d6d

Shahbaz Youssefi 2022-04-23T00:19:15

Vulkan: Optimize away eglSwapBuffers for single buffer surfaces For single buffer surfaces, eglSwapBuffers serves two purposes: - Switch to/from single buffer mode - Implicitly issue a glFlush Simultaneously, for single buffer surfaces, glFlush serves three purposes: - Submit the commands - Call queue present (if necessary) - Throttle the CPU In this mode, ContextVk::flush() already redirects to the surface, calling WindowSurfaceVk::swapImpl() which calls back to ContextVk::flushImpl() (to submit the commands), calls queue present and throttles the CPU. If the application calls eglSwapBuffers(), the exact same thing happens (i.e. WindowSurfaceVk::swapImpl() is called to the same effect). Calling swapImpl() leads to an addition of the corresponding submit serial to the "swap history". The CPU throttling code always throttles the CPU to the serial of two swaps ago. Unnecessary calls to eglSwapBuffers() (when there is no command to be flushed) in single buffer mode would thus lead to the CPU throttled to the end of the last submission, effectively turning into a glFinish(). In this change, eglSwapBuffers() in single buffer mode, when not switching to/from this mode, is redirected to glFlush() as it's functionally equivalent. Simultaneously, ContextVk now tracks whether it has any pending commands for submission at all, and skips glFlush() altogether if there are none. Together, this results in the unnecessary eglSwapBuffers() to become no-op. Bug: b/229908040 Change-Id: I0e3b4a8b7eb4f6b0e0ed22260644825fc67dd330 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3603841 Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>