Skip to content

Read a Linux window’s frame back with render-to-image - #9

Open
francois-unity wants to merge 2 commits into
unity/a11y-automationfrom
unity/HUB-8070-linux-render-to-image
Open

francois-unity wants to merge 2 commits into
unity/a11y-automationfrom
unity/HUB-8070-linux-render-to-image

Conversation

@francois-unity

@francois-unity francois-unity commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Lets a Linux window read its frame back through Window::render_to_image in a render-to-image build, as macOS and Windows windows already can.

Why: render-to-image (HUB-7425) compiles Window::render_to_image outside test-support, but no Linux window implemented it, so the trait’s default answered “not implemented for this platform”. Linux windows draw through the WGPU renderer, which already has an offscreen readback for visual tests, compiled only under gpui_wgpu’s test-support. The native Unity Hub needs it for its e2e screenshots on Linux CI, under Xvfb (HUB-8070).

  • First commit: gpui_wgpu gets a render-to-image feature that compiles WgpuRenderer::render_to_image without the rest of test-support (WgpuHeadlessRenderer stays test-only). gpui_linux gets a render-to-image feature, forwarded to gpui_wgpu, and X11Window and WaylandWindow hand render_to_image to their renderer. gpui_platform’s render-to-image turns on gpui_linux/render-to-image. The readback refuses while a window recovers a lost device, as the DirectX one does, rather than panicking on the torn-down GPU resources.
  • Second commit, from review: the readback copies 8-bit rows and only swizzles Bgra8Unorm, which held while it served the headless renderer alone. A window surface can pick another format, so it now refuses those with an error rather than returning swapped channels or a blank image. A second test covers the device-lost half of the guard, and the macOS wgpu stub’s comment no longer claims the readback needs test-support.

Rebased onto unity/a11y-automation at 33d34a1e35 (upstream e8d5955b); the patches are unchanged.

How to test

  • On Linux, under Xvfb with Mesa’s software Vulkan driver: the native Hub’s --features e2e release build compiled this (as a git dependency, so errors only, not lints), and its devtools screenshot wrote a full 1280×800 frame at scale 1 on 3 fresh launches, identical outside a live banner (Unity Hub run 37494475706, private).
  • cargo +1.98.1 test -p gpui_ce_wgpu --features test-support --lib: 32 tests pass, including render_to_image_refuses_without_gpu_resources and render_to_image_refuses_once_the_device_is_lost, each failing without its half of the guard.
  • cargo +1.98.1 clippy --no-deps -p gpui_ce_wgpu --lib --features render-to-image -- -D warnings, and the same with --all-targets --features test-support,render-to-image, are clean.
  • This repo’s CI lints no workspace member with render-to-image, so on a Linux machine also run cargo clippy -p gpui_ce_linux --features render-to-image -- -D warnings and cargo clippy -p gpui_ce_platform --features render-to-image -- -D warnings.
  • Unity Hub pins the same two commits on top of its current pin (unity/HUB-8070-hub-pin-2, 8beebe0250, over unity/HUB-8048-hub-pin-3).

macOS’s opt-in wgpu renderer still answers with its stub; it could switch to this readback in a follow-up.

@francois-unity francois-unity self-assigned this Oct 6, 2026
@chris-addison
chris-addison force-pushed the unity/a11y-automation branch from 2805d34 to 33d34a1 Compare October 6, 2026 18:24
`render-to-image` (HUB-7425) compiles `Window::render_to_image` outside
`test-support`, but no Linux window implemented it, so the trait’s default
answered “not implemented for this platform”. Linux windows draw through the
WGPU renderer, which already has an offscreen readback for visual tests: it
renders the scene into a texture, copies that to a buffer and maps it. That
readback was compiled only under `gpui_wgpu`’s `test-support`.

Give `gpui_wgpu` a `render-to-image` feature that compiles the readback alone
(`WgpuHeadlessRenderer` stays test-only), forward it from `gpui_linux` and
`gpui_platform`, and let the X11 and Wayland windows call it. The readback now
refuses while a window recovers a lost device, as the DirectX one does, rather
than panicking on the torn-down GPU resources.
The offscreen readback copies 8-bit rows and only swizzles `Bgra8Unorm`, which
held while it served the headless renderer alone. A window’s surface can pick
another format when it offers neither 8-bit UNORM one, so refuse those with an
error rather than returning swapped channels or a blank image.

Test the device-lost half of the guard too: the first test only covered
missing GPU resources, so dropping the `device_lost()` check kept it green.
The refusal now names both states, and the macOS `wgpu` stub’s comment no
longer claims the readback needs `test-support`.
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