Skip to content

Zero-copy GPU frames for Linux apps (experimental, off by default) - #313

Open
szymonkucko wants to merge 3 commits into
SimonSchubert:mainfrom
szymonkucko:zero-copy-pr
Open

szymonkucko wants to merge 3 commits into
SimonSchubert:mainfrom
szymonkucko:zero-copy-pr

Conversation

@szymonkucko

@szymonkucko szymonkucko commented Nov 17, 2026 •

Copy link
Copy Markdown

Linux apps that render on the GPU (Turnip or PanVK, GL through zink) currently present through Mesa's sw WSI: every frame is read back into a wl_shm buffer 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

  • Compositor (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 ordinary wl_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.release goes out once the transaction that replaced the buffer completed and its release fence signaled. Where a layer can't work (a TextureView tile, or wl_shm content over the buffer, which would end up beneath it) the buffer is copied in like shm content (overlaysFit, unit-tested).
  • Guest Vulkan layer (scripts/zero-copy/oma_zero_copy_layer.c, implicit, enabled by OMA_ZERO_COPY=1): takes over swapchains of Wayland surfaces on our compositor, imports the dma-bufs as VK_EXT_image_drm_format_modifier LINEAR 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=1 prints FPS and time spent waiting on the compositor and the GPU.
  • Switch (Gpu.zeroCopy, Settings › linux): adds OMA_ZERO_COPY=1 to the graphics environment of apps started afterwards. The layer and its manifest are managed files in /usr/local (from assets/zero-copy, built by scripts/zero-copy/build.sh, 35 KB), installed wherever there's a GPU and inert without the variable. One app can opt out with OMA_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):

app old path zero-copy
vkcube 31–55 FPS, 71% 60 FPS, 19.5%
eglgears_wayland (zink) 24–60 FPS, 69% 60 FPS, 24%
wgpu game, 2160×1644, VSync off 60–63 FPS, ~90% 59–61 FPS, ~12%
wgpu game, 2160×1644, VSync on 18–20 FPS, ~55% 30 FPS, ~11%
two GPU windows at once (zink full screen, vkcube pop-up) – 53 and 57–59 FPS, 32%

With VSync on, the wgpu game (winit's pre_present_notify) only starts a frame once the previous one's wl_surface.frame is 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):

app old path zero-copy
vkcube 60 FPS, 75.5% 60 FPS, 24.8%
eglgears_wayland (zink) 34–44 FPS, 59% old path (see BGRA below)

Limitations

  • BGRA only on Adreno. Zink renders into BGRA swapchains. On Mali, SurfaceFlinger aborts (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.
  • Linear buffers. The buffers are allocated with CPU_READ_RARELY so 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.
  • Synchronization is the simple kind: present blocks the app's thread until the GPU has finished the frame (0.9–1.4 ms per frame on the Snapdragon, 2.5 ms for vkcube on the Dimensity), so the app can't prepare the next frame meanwhile, and the buffer is committed without a fence. Explicit sync can come later.
  • A hidden window gets no frame callbacks: FIFO apps drop to one frame a second, MAILBOX apps aren't throttled.

Tested

  • ./gradlew :owl:test :app:testFossDebugUnitTest :owl:owlJar :app:assembleFossDebug :app:lintFossDebug passes, and :app:lintPlayDebug (CI green on the fork). New tests: OverlaysFitTest, and in GpuTest that the switch only adds its variable and the manifest matches the installed path.
  • Tried on two phones: Snapdragon 8 Gen 3 (Adreno 750, Turnip) and Dimensity 7300 (Mali-G615 MC2, PanVK-kbase), see below.
  • New UI text is in strings_linux.xml with every values-* translation.
  • OWL changes: none.
  • Launcher-written files changed: the layer and its manifest are new managed files (Gpu.managed, Policy.Owned), and the switch is a new preference that defaults to off. Upgrading from main keeps everything as it was (below).

On the phones:

  • Both SoCs: upgrade from 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).
  • Snapdragon only: the switch in Settings on and off, the wgpu game, folding and unfolding a foldable (the window moving between displays), and a GPU buffer in a home screen tile (the copy fallback).
  • Release build: R8 keeps the new JNI names (checked in the APK).

Trying it

Settings › linux › gpu acceleration on, then "gpu frames without copies" on, then start e.g. vkcube or eglgears_wayland. OMA_ZERO_COPY_STATS=1 vkcube prints frame rate and waits; dumpsys SurfaceFlinger | grep omalauncher-ahb shows the layers.

🤖 Generated with Claude Code

Szymon Kucko and others added 3 commits November 18, 2026 00:04
…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>
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.

1 participant