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:
nandiandClaude Opus 5.5 committed 2026-11-30 16:42:22 -08:00
1 parent d81003f176
commit cfb25fe699
26 files changed
+2485 -105

No files matched your search

+80
View File
@@ -2,6 +2,76 @@
/// surface ids; the pixels live here (raster_stub.c) and never cross the component boundary.
/// What to draw where (layers, the wallpaper cache, damage) is decided here.
///| Look for a GPU to draw on (raster_gpu.c): 1 when there is one. Before anything else here.
/// `session` is 1 for a login session (--drm).
extern "C" fn rs_gpu_init(session : Int) -> Int = "rs_gpu_init"
///|
extern "C" fn rs_dmabuf_device() -> UInt64 = "rs_dmabuf_device"
///|
#borrow(out)
extern "C" fn rs_dmabuf_format(i : Int, out : FixedArray[Int]) -> Int = "rs_dmabuf_format"
///|
#borrow(planes)
extern "C" fn rs_dmabuf_import(
n : Int,
planes : FixedArray[Int],
modifier : UInt64,
w : Int,
h : Int,
fourcc : UInt,
y_invert : Int,
) -> UInt = "rs_dmabuf_import"
///|
extern "C" fn rs_dmabuf_release(id : UInt) = "rs_dmabuf_release"
///|
extern "C" fn rs_dmabuf_capture(id : UInt) -> UInt = "rs_dmabuf_capture"
///| `dmabufs`: the GPU clients should draw on and the buffers it reads.
fn dmabuf_support() -> @wt.Val {
let formats : Array[@wt.Val] = []
let f = FixedArray::make(3, 0)
while rs_dmabuf_format(formats.length(), f) != 0 {
let modifier = f[1].reinterpret_as_uint().to_uint64() |
(f[2].reinterpret_as_uint().to_uint64() << 32)
formats.push(
Record([
("fourcc", U32(f[0].reinterpret_as_uint())),
("modifier", U64(modifier)),
]),
)
}
Record([("device", U64(rs_dmabuf_device())), ("formats", List(formats))])
}
///|
fn import_dmabuf(a : Array[@wt.Val]) -> UInt {
let planes = a[0].to_list()
if planes.length() < 1 || planes.length() > 4 {
return 0U
}
let flat = FixedArray::make(planes.length() * 3, 0)
for i, p in planes {
flat[i * 3] = p.field("fd").to_int()
flat[i * 3 + 1] = p.field("offset").to_uint().reinterpret_as_int()
flat[i * 3 + 2] = p.field("stride").to_uint().reinterpret_as_int()
}
guard a[1] is U64(modifier) else { return 0U }
rs_dmabuf_import(
planes.length(),
flat,
modifier,
a[2].to_int(),
a[3].to_int(),
a[4].to_uint(),
if a[5].to_bool() { 1 } else { 0 },
)
}
///|
extern "C" fn rs_resize(w : Int, h : Int) -> Int = "rs_resize"
@@ -991,6 +1061,16 @@ fn raster_funcs() -> Array[(String, (Array[@wt.Val]) -> Array[@wt.Val])] {
none
},
),
("dmabufs", _ => [dmabuf_support()]),
("import-dmabuf", a => [U32(import_dmabuf(a))]),
("capture-dmabuf", a => [U32(rs_dmabuf_capture(a[0].to_uint()))]),
(
"release-dmabuf",
a => {
rs_dmabuf_release(a[0].to_uint())
none
},
),
("load-image", a => [U32(load_image(a[0].to_string()).reinterpret_as_uint())]),
(
"emoji-font",