Skip to content

Config.GPU on X11 and Wayland through gpu2d's Vulkan back-end (L1) - #157

Merged
tannevaled merged 3 commits into
mainfrom
gpu-linux-l1
Nov 10, 2026
Merged

tannevaled merged 3 commits into
mainfrom
gpu-linux-l1

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

What

Config.GPU on the X11 and Wayland back-ends: frames are drawn by gpu2d's vulkan back-end (gpu2d v0.9.1), then presented through the window's existing CPU path (MIT-SHM / PutImage on X11, wl_shm on Wayland) from the renderer's Pixels(). This is milestone L1 of gpu2d docs/NATIVE.md (Decision 3, fallback 2). No dma-buf: that is L2/L3.

  • internal/gpupath holds the state machine shared by both back-ends, mirroring internal/cocoa/gpu_darwin.go: start when Run starts, whole-frame redraw while the GPU draws, GPU() / GPUError().
  • Where Vulkan is unavailable, or a frame is refused (ErrTooLarge, ErrUnsupported, device lost, timeout), the renderer is released, the error is recorded, and that frame and every later one are drawn on the CPU, as Cocoa does. The first CPU frame after a drop is a whole one even for an incremental root.
  • Android: go-gfx/vulkan's constraint is linux && (amd64 || arm64), which GOOS=android satisfies, and purego then needs cgo there. gpupath therefore refuses on android instead of importing it (the android CI lane stays CGO-free). Not filed upstream from this session; it should be.

Proof

Live, under lavapipe (llvmpipe, LLVM 19.1.7) in a linux/arm64 container (test/gpu-linux/Dockerfile; Xvfb and headless sway started by the tests):

  • X11: the window read back with XGetImage equals the CPU window's and PixelPainter's, 192,000 bytes at 320 × 200 and 312,000 after a resize to 400 × 260 (MIT-SHM present).
  • Wayland: the committed wl_shm buffer equals the CPU window's and PixelPainter's packed as ARGB8888 (1,920,000 bytes, 800 × 600, resized live by sway from 320 × 200), and grim's capture of the output matches at all 480,000 pixels.
  • Break check: flipping one bit in the copied frame fails both protocols (1 byte differs, named by position).
  • CI: new live GPU (lavapipe, X11 + Wayland) lane (same tests, WINDOW_GPU_REQUIRE=1 so a missing driver fails); internal/gpupath joins the 100 % coverage gate (its tests run over a CPU-reference renderer, so the gate needs no Vulkan).

Software numbers (labelled as such)

6 interleaved rounds under abbench --max-load 8, benchstat medians. The GPU path is lavapipe, a CPU rasterizer: under it the GPU path costs about ten times the CPU time and 35 to 52 % more wall time than the CPU path. See README for the table and allocation counts. Real-GPU numbers are pending (fractal is down).

Not done: org landing and docs site updates.

🤖 Generated with Claude Code

tannevaled and others added 2 commits November 10, 2026 15:45
Frames are recorded through gpupainter into a gpu2d list, drawn by
gpu2d/vulkan, and the renderer's Pixels are copied into the window's own
framebuffer, which the back-end presents as ever (MIT-SHM or PutImage on X11,
wl_shm on Wayland). No dma-buf: that is L2 and L3 of gpu2d docs/NATIVE.md,
Decision 3, fallback 2.

internal/gpupath holds the shared state machine. Where Vulkan is unavailable,
or a frame is refused (ErrTooLarge, ErrUnsupported, a lost device), the path
stops for good, records why (GPUError), and that frame and every later one are
drawn on the CPU, as the Cocoa path does. An incremental root redraws whole
frames while the GPU draws, and for the first frame after it stops.

gpu2d is raised to v0.9.1. go-gfx/vulkan's build constraint admits
GOOS=android, which needs cgo for purego, so android gets a refusal instead of
the import.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… README

TestLiveGPUX11ShowsTheCPUFrame reads the window back from Xvfb with XGetImage
and compares it with a window that did not ask for the GPU and with
PixelPainter, before and after a resize. TestLiveGPUWaylandShowsTheCPUFrame
compares the committed wl_shm buffer with the CPU window's and PixelPainter's,
and grim's capture of a private headless sway. Both start their servers
(WINDOW_GPU_SPAWN) and fail rather than skip without a Vulkan device
(WINDOW_GPU_REQUIRE). test/gpu-linux/Dockerfile is the container recipe, the
live-gpu lane the same tests on ubuntu. In-process tests over a CPU-reference
renderer cover the fallbacks (refused frame, refused resize, Vulkan absent)
for both back-ends; internal/gpupath joins the 100% coverage gate.

BenchmarkLiveGPUFrame measures a whole frame, CPU path against GPU path;
README gives the software numbers, labelled as such.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…b there

go-gfx/vulkan v0.2.1 (go-gfx/vulkan#6) no longer builds the purego loader for
GOOS=android, so internal/gpupath imports gpu2d/vulkan everywhere again.
CGO_ENABLED=0 GOOS=android GOARCH=arm64 go vet and build pass without it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tannevaled

Copy link
Copy Markdown
Contributor Author

Updated: rebased on main (live Wayland input is pinned to ubuntu-24.04 by #158, evidence in its commit message), and the android workaround is gone because go-gfx/vulkan v0.2.1 (go-gfx/vulkan#6) builds the stub on android. The rest of the description stands.

🤖 Generated with Claude Code

@tannevaled
tannevaled merged commit ff8a9dd into main Nov 10, 2026
29 checks passed
@tannevaled
tannevaled deleted the gpu-linux-l1 branch November 10, 2026 14:59
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