Wayland: every new size makes a new swapchain, 87 ms on the phone in which the wallpaper shows where the keyboard was: let an application keep a larger swapchain and crop it with the viewport #203
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#203
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
Every new size makes a new swapchain. On a Fairphone 6 that takes a median 87 ms when the on-screen keyboard goes and the window grows back, most of it the driver allocating the three new buffers. Since the fix for #199 a window keeps its old size on screen until the first frame at the new one, so for those 87 ms KWin, which removes the keyboard at once, shows its background where the keyboard was. Before that fix the last frame was shown stretched over the keyboard's place for the same time.
A window whose swapchain is as large as the larger of the two sizes needs no new buffers to go between them. The viewport can show the part of the buffer that is drawn (
wp_viewport.set_source), and the answer to the configure is then the next frame. It costs memory for as long as the window is the smaller size, so it has to be the application's choice and off by default. Line numbers refer to89111e0.Details
Where the 87 ms go, by the medians of the trace below: about 2 ms until the library starts on the rebuild, about 24 ms in the driver's present-mode queries (#202 is about those), about 60 ms from the end of those to the last of the three new buffers, which by the order of the calls is
vkCreateSwapchainKHR, and about 1 ms to draw and present the frame. The 60 ms are the driver's, and no caching in the library takes them away: only a resize that needs no new swapchain does.implementations/Crafter.Graphics-Window.cpp:853-885(TakeDeferredSize) and:887-891(RebuildIfDeferred): a size that changeswidthorheightmakes the swapchain again.:1773-1787and:1808(CreateSwapchain): the swapchain's extent iswidthxheight. A Wayland surface has no extent of its own.:2101-2118(SendFrameSurfaceState): the one place a request goes to the window'swp_viewport,set_destinationat:2108. The library never sendsset_source(lib/viewporter.h:363), so a surface always shows its whole buffer.What already goes by the window's size and not by the image's, and so would draw into the top-left
widthxheightof a larger image as it is:implementations/Crafter.Graphics-UI.cpp:107-206,-UI-Shared.cpp:32-44), andRect::FromWindow(interfaces/Crafter.Graphics-UI.cppm:153);RTPass(interfaces/Crafter.Graphics-RTPass.cppm:75,:128-129);widthxheight(-Window.cpp:1568);Not looked at: the examples' and the consumers' own passes and shaders. One that takes the image's size for the window's (
imageSize()in a shader, a blit of the whole image) would draw outside the part that is shown.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, drawing on demand and asking for a frame fromonFrameOwed, underWAYLAND_DEBUG=1. The on-screen keyboard was brought up and dismissed by hand 22 times. All 44 resizes were answered as #199 asks: every acknowledgement was committed with a buffer of the configured size and that size as the destination. What the owner saw: "its smoother but there is still the issue with dismissing the keyboard: the keyboard dissapears instantly, showing the phone background, and there is a delay until the app fills the void again".In ms from the configure, medians (least, most):
One keyboard hide: the present-mode queries run from 1.5 to 24.5 ms, the three 1118 x 2269 buffers are created at 53.7, 68.7 and 79.1 ms, and the frame's destination, acknowledgement, attach and commit follow at 79.6 to 79.8 ms. When the keyboard comes the same wait is there and does not show, since the keyboard covers the part of the window that is to go.
The memory: the buffers are XBGR8888, so 10.1 MB each at 1118 x 2269 and 6.8 MB each at 1118 x 1522, three of them. Keeping the larger ones while the keyboard is up is 30 MB where the window now has 20.
The application decides
The owner, when this was filed: "we need to make sure that its controlled by the application, for this specific case applications can enable it, otherwise they use memory nothing".
wp_viewporteronly. Without a viewport there is no crop, and the window stays at its exact size, as it stays at scale 1. By design rule 1 the members are the Wayland block's.Suggested fix
width,height: what the passes draw at) and the swapchain's extent become two things.CreateSwapchainmakes the larger of the window's size and what the application asked to keep.TakeDeferredSizeandRebuildIfDeferredtell the two cases apart.onResizestill has to fire, since what is sized after the window changes, though the images stay; its comment ("the old images have been destroyed",interfaces/Crafter.Graphics-Window.cppm:82-90) then holds for a rebuild only. To decide.SendFrameSurfaceStatesendswp_viewport.set_source(0, 0, width, height)beside the destination, with the first frame drawn at a size that is not the buffer's, and unsets it (all four -1) with the first frame at the buffer's own size. Like the destination it is state the next commit applies, so it goes out there and nowhere else (#199).ConfigureResizereads the source off the wire as it reads the destination, and gets the cases: a size within the extent, one beyond it, the application turning the reserve on and off.ResizeViewport's replay learns the source rectangle, so that "the destination in effect is the size of the buffer in effect" becomes "of the part of the buffer shown". And a check on pixels that a frame drawn at the smaller size into the larger image comes out right,CaptureNextFrameincluded.Found by the owner trying the on-screen keyboard by hand on the phone at
89111e0, 2026-11-20.