cube: Rebuild swapchain only on a real size change - #1250
Open
perpetualbits wants to merge 1 commit into
Open
Conversation
|
Author perpetualbits not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
|
Author perpetualbits not on autobuild list. Waiting for curator authorization before starting CI build. |
|
|
handle_surface_configure() calls demo_resize() on every xdg_surface.configure. A compositor also sends configure for state changes -- activation, maximization, tiling -- and those usually carry the size the surface already has, so the swapchain and every image, view, framebuffer and command buffer are destroyed and recreated for nothing. On a local compositor a recreation costs about a millisecond and nobody notices. It is very visible wherever Vulkan calls are expensive: under a compositor using focus-follows-mouse, moving the pointer across the window produced a configure per crossing, and each one froze the demo for roughly a second. Measured over such a setup, 60 s per run, pointer crossing only: unpatched, 178 configures caused 92 swapchain rebuilds and 9 visible stalls with a worst case of 1117 ms; patched, 392 configures (391 of them carrying an unchanged size) caused 1 rebuild and 0 stalls with a worst case of 104 ms, and the demo drew 4.3x as many frames in the same wall clock. Behaviour was checked natively first, where the change makes no visible difference. Guarding on !swapchain_ready keeps the first configure creating the swapchain. The VK_ERROR_OUT_OF_DATE_KHR and VK_SUBOPTIMAL_KHR paths in draw() remain the safety net for anything that invalidates the swapchain without changing the size, which is how vkgears in mesa-demos has always handled this.
perpetualbits
force-pushed
the
wayland-resize-only-on-size-change
branch
from
September 2, 2026 00:25
e6b5163 to
28c4399
Compare
|
Author perpetualbits not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
|
Author perpetualbits not on autobuild list. Waiting for curator authorization before starting CI build. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
On Wayland,
handle_surface_configure()callsdemo_resize()on everyxdg_surface.configure. A compositor also sendsconfigurefor state changes — activation, maximization, tiling — and those usually carry the size the surface already has, so the swapchain and every image, view, framebuffer and command buffer are destroyed and recreated for nothing.Locally a recreation costs about a millisecond and nobody notices. It becomes very visible wherever Vulkan calls are expensive. Under a compositor using focus-follows-mouse, moving the pointer across the window produces a
configureper crossing, and each one froze the demo for roughly a second.Measured
60 s per run, pointer crossing only, same machine and compositor both times:
The patched run also drew 4.3x as many frames in the same wall clock. Behaviour was checked natively first, where the change makes no visible difference.
Why this is safe
!demo->swapchain_readykeeps the first configure creating the swapchain.VK_ERROR_OUT_OF_DATE_KHR/VK_SUBOPTIMAL_KHRpaths indraw()remain the safety net for anything that invalidates the swapchain without changing the size.vkgearsin mesa-demos has always handled it: record the size, compare, recreate only on a real difference.Found while running
vkcubeover a remoting layer, where each Vulkan call is a network round trip and the cost of a needless rebuild is impossible to miss.https://claude.ai/code/session_0153BQRRKAJcRSxUxRuEHQQs