Repository navigation
Zero-copy GPU frames for Linux apps (experimental, off by default) - #313
Open
szymonkucko wants to merge 3 commits into
Open
szymonkucko wants to merge 3 commits into
szymonkucko wants to merge 3 commits into
Conversation
…itor without CPU copies: it allocates AHardwareBuffers for them (oma_ahb_allocator_v1, a private Wayland protocol) and shows each such surface as a layer of its own through ASurfaceControl, and where that can't work (a home screen tile, shm content over the buffer) the buffer is copied in as before; nothing uses it yet Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…O_COPY=1) puts Wayland swapchains into the compositor's buffers, so Vulkan apps and GL apps through zink present without copies, and leaves whatever it can't take to the driver's own swapchain; the launcher carries it but doesn't install or enable it yet Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r gpu acceleration, off until the user turns it on: GPU apps opened afterwards render into the compositor's buffers through the zero-copy layer, which the launcher now keeps in the guest and which stays inert without the switch; one app can opt out with OMA_ZERO_COPY_DISABLE=1 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 of 5 tasks
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.
Linux apps that render on the GPU (Turnip or PanVK, GL through zink) currently present through Mesa's
swWSI: every frame is read back into awl_shmbuffer and then copied again into the window. This PR lets them render straight into buffers the compositor shows as they are, behind a new experimental switch under gpu acceleration in Settings › linux. For the user: GPU apps keep up with the display at a fraction of the launcher's CPU (vkcube on the Snapdragon: a steady 60 FPS at about 20% of a core, instead of 31–55 FPS at 71%). With the switch off, nothing changes for anyone.How it works
wayland/Ahb.kt,cpp/ahb.c,WindowRenderer): a private protocol,oma_ahb_allocator_v1(scripts/zero-copy/oma-ahb-v1.xml). A client asks for a buffer of a size and DRM format; the compositor allocates an AHardwareBuffer, sends its dma-buf (fd, offset, stride, modifier) and the client attaches it as an ordinarywl_buffer. The window shows such a surface as a child layer of its SurfaceView's surface (ASurfaceControl), which the display composes without a copy;wl_buffer.releasegoes out once the transaction that replaced the buffer completed and its release fence signaled. Where a layer can't work (a TextureView tile, orwl_shmcontent over the buffer, which would end up beneath it) the buffer is copied in like shm content (overlaysFit, unit-tested).scripts/zero-copy/oma_zero_copy_layer.c, implicit, enabled byOMA_ZERO_COPY=1): takes over swapchains of Wayland surfaces on our compositor, imports the dma-bufs asVK_EXT_image_drm_format_modifierLINEAR images and presents by attach/commit. FIFO paces on frame callbacks; MAILBOX gets at least four images. Formats it can't take, a driver without dma-buf import, or another compositor go to the driver's own swapchain unchanged.OMA_ZERO_COPY_STATS=1prints FPS and time spent waiting on the compositor and the GPU.Gpu.zeroCopy, Settings › linux): addsOMA_ZERO_COPY=1to the graphics environment of apps started afterwards. The layer and its manifest are managed files in/usr/local(fromassets/zero-copy, built byscripts/zero-copy/build.sh, 35 KB), installed wherever there's a GPU and inert without the variable. One app can opt out withOMA_ZERO_COPY_DISABLE=1 app.Measurements
CPU is the launcher process in
top(100% = one core). Same apps, old path vs. this PR.Snapdragon 8 Gen 3 (Adreno 750, Turnip, 60 Hz panel):
With VSync on, the wgpu game (winit's
pre_present_notify) only starts a frame once the previous one'swl_surface.frameis done, so a frame that takes longer than one 16 ms refresh waits for the next one: 30 FPS. At 30 FPS the GPU also clocks down, which keeps the frames that long.Dimensity 7300 (Mali-G615 MC2, PanVK-kbase):
Limitations
Unable to generate SkImage, colorType BGRA vs. GL_RGBA8) as soon as it draws a BGRA AHardwareBuffer itself, e.g. for a screenshot, which restarts the whole UI. So the compositor offers BGRA only with an Adreno GPU, and zink on Mali keeps the old path; Vulkan apps (RGBA) are zero-copy on both.CPU_READ_RARELYso gralloc keeps them linear (MediaTek would pick AFBC, which can't be imported as such) and the copy fallback can lock them. On Adreno, passes that write the swapchain image cost more than into tiled images (the wgpu game's post passes: +2.8 ms per frame). And on a display rotated against the panel's natural orientation, SurfaceFlinger composed the layer on the GPU in the tests (CLIENT, ROT_90/270) instead of leaving it to the display hardware: vkcube 60 → 47 FPS on the Dimensity, the wgpu game 61–66 → 50–56 FPS on the Snapdragon. UBWC buffers on Adreno should help with the first and maybe the second; not in this PR.Tested
./gradlew :owl:test :app:testFossDebugUnitTest :owl:owlJar :app:assembleFossDebug :app:lintFossDebugpasses, and:app:lintPlayDebug(CI green on the fork). New tests:OverlaysFitTest, and inGpuTestthat the switch only adds its variable and the manifest matches the installed path.strings_linux.xmlwith everyvalues-*translation.Gpu.managed,Policy.Owned), and the switch is a new preference that defaults to off. Upgrading frommainkeeps everything as it was (below).On the phones:
main(switch off, layer installed and inert, apps as before), vkcube on both paths, zink (zero-copy on the Snapdragon, the old path on the Dimensity), 20 screen rotations in a row (no buffers left behind; the launcher's open fds grow the same on the old path), and 12–17 minutes with a rotation every 3 minutes (the launcher's memory and the app's fds flat).Trying it
Settings › linux › gpu acceleration on, then "gpu frames without copies" on, then start e.g.
vkcubeoreglgears_wayland.OMA_ZERO_COPY_STATS=1 vkcubeprints frame rate and waits;dumpsys SurfaceFlinger | grep omalauncher-ahbshows the layers.🤖 Generated with Claude Code