CreateSwapchain asks the driver for the present modes twice at every rebuild: on Mesa's Wayland that is two sets of round trips, 24 ms of every resize on the phone #202
Labels
No labels
claude:blocked
claude:done
claude:failed
claude:in-progress
claude:ready
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Catcrafts/Crafter.Graphics#202
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Window::CreateSwapchaincallsvkGetPhysicalDeviceSurfacePresentModesKHRtwice, for the count and for the list, every time it makes a swapchain, so at every resize. On Mesa's Wayland WSI each of the two calls sets up connection state of its own: a registry, seven globals bound, the dmabuf feedback fetched, three round trips with the compositor, and all of it destroyed again. On a Fairphone 6 the two together take a median 24 ms of the 87 ms between the configure of a resize and the first frame at the new size. The list they return is the same every time. Line numbers refer to89111e0.Details
implementations/Crafter.Graphics-Window.cpp:1749-1751: the two calls.:1752-1761use the list for one thing, to pickswapchainPresentModefrompresentModeandCRAFTER_PRESENT_IMMEDIATE.RebuildSwapchain,:794): a new size, fromResizeor from a configure by way ofRebuildIfDeferred; a swapchain out of date;SetPresentMode(:903). Only the last changes what the list is asked for.SwapchainCapabilities, called right after, shows no round trip of its own in a resize. At a window's start the trace also has queries on queues the driver namesmesa formats queryandmesa image count query; in a resize it has the twomesa present modes queryones and nothing else beforevkCreateSwapchainKHR.Concrete case
A Fairphone 6 (KWin 6.8.2, Mesa 26.2.6 Turnip, scale 2.85) running a scratch program with one text field against the library at
89111e0, underWAYLAND_DEBUG=1. The on-screen keyboard was brought up and dismissed by hand 22 times; each time KWin resizes the maximized window between 392 x 796 and 392 x 534, and the library makes a swapchain. Over the 23 resizes to 392 x 796, in ms from the configure:Over the 22 resizes to 392 x 534 the queries take a median 26.2 ms of 70.2.
One of them, with the time since its configure. libwayland prints the name of each message's queue, and the driver names this one. Only the requests are listed; the registry's globals and the other events come in between.
Not measured: what the two calls cost with NVIDIA's driver, or on Win32.
Suggested fix
Ask once and keep the list: at the window's first swapchain, and again in
SetPresentMode, the one moment the list decides something new and not one where 24 ms matter. A rebuild for a new size or for a swapchain out of date uses the list the window has.What that gives up: a mode the surface gains or loses under a running window is not seen until the next
SetPresentMode. In the trace the query bindswp_tearing_control_manager_v1andwp_fifo_manager_v1among the compositor's globals, so on Mesa's Wayland the list would follow those; what it depends on in each driver was not read.A smaller step that gives up nothing: one call instead of two, into an array large enough for every
VkPresentModeKHRthere is. Half the time.Either way the query has still been made for the surface before its first swapchain.
SwapchainImageCountmakes swapchains in every present mode underCRAFTER_GRAPHICS_VALIDATIONand would show the validation layer objecting to a mode it has not seen listed.A test for it could come from
ResizeViewport, which already replays itsWAYLAND_DEBUGlog: on a Mesa driver the log names the queue, so the replay can count the registries a rebuild binds onmesa present modes query.Found measuring where the time of a keyboard resize goes on the phone, with the fix for #199 in place, 2026-11-20.
The rest of that time, the driver allocating the buffers of the new swapchain, is #203: a resize that needs no new swapchain needs neither.