Skip to content

cube: Rebuild swapchain only on a real size change - #1250

Open
perpetualbits wants to merge 1 commit into
KhronosGroup:mainfrom
perpetualbits:wayland-resize-only-on-size-change
Open

cube: Rebuild swapchain only on a real size change#1250
perpetualbits wants to merge 1 commit into
KhronosGroup:mainfrom
perpetualbits:wayland-resize-only-on-size-change

Conversation

@perpetualbits

Copy link
Copy Markdown

On Wayland, 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.

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 configure per 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:

configures swapchain rebuilds visible stalls worst stall
unpatched 178 92 9 1117 ms
patched 392 (391 same-size) 1 0 104 ms

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_ready keeps the first configure creating the swapchain.
  • The VK_ERROR_OUT_OF_DATE_KHR / VK_SUBOPTIMAL_KHR paths in draw() remain the safety net for anything that invalidates the swapchain without changing the size.
  • This is how vkgears in mesa-demos has always handled it: record the size, compare, recreate only on a real difference.

Found while running vkcube over 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

@ci-tester-lunarg

Copy link
Copy Markdown

Author perpetualbits not on autobuild list. Waiting for curator authorization before starting CI build.

1 similar comment
@ci-tester-lunarg

Copy link
Copy Markdown

Author perpetualbits not on autobuild list. Waiting for curator authorization before starting CI build.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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
perpetualbits force-pushed the wayland-resize-only-on-size-change branch from e6b5163 to 28c4399 Compare September 2, 2026 00:25
@ci-tester-lunarg

Copy link
Copy Markdown

Author perpetualbits not on autobuild list. Waiting for curator authorization before starting CI build.

1 similar comment
@ci-tester-lunarg

Copy link
Copy Markdown

Author perpetualbits not on autobuild list. Waiting for curator authorization before starting CI build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants