Draw on the GPU: the desktop with OpenGL ES, apps through linux-dmabuf
The host's rasteriser has a GPU half (raster_gpu.c): the same primitives, drawn the same way, on machines with a real GPU and OpenGL ES 3, straight into the display's buffers in a login session. EGL and GLES are loaded at run time; without them everything is drawn on the CPU as before (CHANDRA_GPU=0 does that too). zwp_linux_dmabuf_v1 lets apps draw on the GPU as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d81003f176
commit
cfb25fe699
26 files changed
+2485
-105
No files matched your search
+44
-6
@@ -1,14 +1,52 @@
|
||||
# Rendering, animations and machines without a GPU
|
||||
|
||||
Chandra draws the desktop on the CPU on every machine: the host (build/wasmhost)
|
||||
rasterises each frame into its own framebuffer and hands it to the display (KMS, X11, a
|
||||
nested Wayland window). A GPU never makes Chandra's own frames cheaper. What it changes is how
|
||||
much CPU is left: with a GPU, apps (browsers, video, games) draw there; without one they draw
|
||||
with llvmpipe or their own software paths on the same cores as Chandra.
|
||||
On a machine with a GPU the host (build/wasmhost) draws the desktop on it, and apps hand over the
|
||||
buffers they drew on it. Anywhere else the host rasterises each frame on the CPU and apps use shared
|
||||
memory, as before. The component never knows the difference: it sends the same draw operations.
|
||||
|
||||
## Drawing on the GPU
|
||||
|
||||
At start the host looks for a GPU and logs it (or why there is none):
|
||||
|
||||
gpu: drawing on Mesa Intel(R) HD Graphics 4600 (HSW GT2)
|
||||
|
||||
- **The desktop** (`wasmhost/bin/raster_gpu.c`): OpenGL ES 3 on a DRM render node, with libEGL and
|
||||
libGLESv2 loaded at run time, so neither is needed to build or to run without a GPU. It takes
|
||||
raster_stub.c's calls and draws the same shapes (within rounding), into a texture that keeps its
|
||||
contents, so only damage is redrawn.
|
||||
- **The display** (`--drm`): the finished frame is drawn into the display's own buffers (the DRM dumb
|
||||
buffers, shared as dmabufs), scaled and turned as the output is. When the GPU can't draw there,
|
||||
the frame is read back and copied, which works on any display.
|
||||
- **A nested window, X11, screenshots, recordings, the remote mirror** need the pixels on the CPU: the
|
||||
part that changed is read back when one of them asks.
|
||||
- **Apps** (`compositor/wayland/dmabuf.mbt`): `zwp_linux_dmabuf_v1` version 4. Without it Mesa's EGL and
|
||||
Vulkan draw on the CPU whatever GPU there is. A committed buffer is copied on the GPU and
|
||||
released at once. Formats: 8-bit RGB with or without alpha, in every layout the driver samples.
|
||||
|
||||
Which GPU: the first render node whose driver is a real one (the list below), or the one
|
||||
`CHANDRA_RENDER_NODE` names. `CHANDRA_GPU=0`, `CHANDRA_RENDER=software` and `LIBGL_ALWAYS_SOFTWARE=1`
|
||||
keep to the CPU. `CHANDRA_GPU=1` takes whatever OpenGL there is (a virtual machine's, llvmpipe,
|
||||
NVIDIA's). NVIDIA's proprietary driver is not used by itself: the code relies on implicit sync
|
||||
(the kernel ordering buffer use), which that driver lacks.
|
||||
|
||||
If a login session dies within seconds of first drawing on the display with the GPU, the next one
|
||||
keeps to the CPU once (`~/.local/state/chandra/gpu-starting`).
|
||||
|
||||
Not done: handing an app's buffer to the display without any copy, dmabufs to the host compositor
|
||||
when nested, recovering from a GPU reset, OpenGL ES 2 only GPUs (they use the CPU).
|
||||
|
||||
`scripts/test-gpu.sh` (`just test-gpu`) compares both rasterisers on this machine's GPU and draws
|
||||
through real display buffers, without needing a free display.
|
||||
|
||||
On an HD 4600 (Haswell), 1920x1080, median time to rasterise a frame, CPU then GPU: the overview
|
||||
gliding with four windows 8 ms, 1 ms; a full-screen terminal scrolling 8 ms, 3 ms. alacritty (OpenGL)
|
||||
scrolling: 7 frames a second drawing in software, 42 on the GPU. vkcube (Vulkan) showed
|
||||
no frames at all without dmabufs, and 57 a second with them.
|
||||
|
||||
## Software or hardware mode
|
||||
|
||||
At start Chandra looks for a GPU and logs what it decided:
|
||||
Apart from where the pixels are drawn, the shell asks less of a machine without a GPU. At start it
|
||||
looks for one and logs what it decided:
|
||||
|
||||
rendering: software (no GPU found)
|
||||
rendering: hardware (GPU: amdgpu)
|
||||
|
||||
Reference in new issue
Block a user