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

+40 -6
View File
@@ -106,6 +106,10 @@ enum ObjKind {
/// zwp_text_input_manager_v3 and its zwp_text_input_v3 objects (text_input.mbt).
ObjTextInputMgr
ObjTextInput
/// zwp_linux_dmabuf_v1, a zwp_linux_buffer_params_v1 and a feedback object (dmabuf.mbt).
ObjDmabuf
ObjDmabufParams(UInt)
ObjDmabufFeedback
}
///|
@@ -223,6 +227,8 @@ struct ClientConn {
surfaces : Map[UInt, SurfaceState]
shm_pools : Map[UInt, ShmPoolState]
shm_buffers : Map[UInt, ShmBufferState]
dmabuf_params : Map[UInt, DmabufParams]
dmabuf_buffers : Map[UInt, DmabufBuffer]
xdg_surfaces : Map[UInt, XdgSurfaceState]
subsurfaces : Map[UInt, SubState]
toplevels : Map[UInt64, ToplevelState]
@@ -267,6 +273,8 @@ fn ClientConn::new(client_id : UInt, fd : Int) -> ClientConn {
surfaces: {},
shm_pools: {},
shm_buffers: {},
dmabuf_params: {},
dmabuf_buffers: {},
xdg_surfaces: {},
subsurfaces: {},
toplevels: {},
@@ -384,6 +392,9 @@ pub(all) struct WaylandServer {
/// so clients stop drawing frames nobody sees: (client id, callback id), sent on release.
mut hold_frames : Bool
held_frames : Array[(UInt, UInt)]
/// Client buffers on the GPU (dmabuf.mbt): the host's side, and what it supports once asked.
mut dmabuf_host : DmabufHost
mut dmabuf_support : (UInt64, Array[(UInt, UInt64)])?
}
///|
@@ -422,6 +433,8 @@ pub fn WaylandServer::listen(
drop_pending: None,
hold_frames: false,
held_frames: [],
dmabuf_host: DmabufHost::system(),
dmabuf_support: None,
})
}
@@ -456,6 +469,7 @@ pub fn WaylandServer::close(self : WaylandServer) -> Unit {
}
self.transfers.clear()
for c in self.clients {
c.drop_dmabufs(self.dmabuf_host)
c.close_all()
}
self.clients.clear()
@@ -471,7 +485,7 @@ fn WaylandServer::next_serial(self : WaylandServer) -> UInt {
}
///|
fn emit_registry_globals(c : ClientConn, reg_id : UInt) -> Unit {
fn emit_registry_globals(c : ClientConn, reg_id : UInt, dmabuf : Bool) -> Unit {
let globals : Array[(UInt, String, UInt)] = [
(1U, "wl_compositor", 5U),
(2U, "wl_shm", 1U),
@@ -486,6 +500,9 @@ fn emit_registry_globals(c : ClientConn, reg_id : UInt) -> Unit {
(11U, "zwp_primary_selection_device_manager_v1", 1U),
(12U, "zwp_text_input_manager_v3", 1U),
]
if dmabuf {
globals.push((13U, "zwp_linux_dmabuf_v1", 4U))
}
for g in globals {
let w = WireWriter::new()
w.u32(g.0)
@@ -602,10 +619,15 @@ fn send_decoration_mode(c : ClientConn, deco_id : UInt, mode : UInt) -> Unit {
}
///|
fn snapshot_shm_buffer(
fn WaylandServer::snapshot_buffer(
self : WaylandServer,
c : ClientConn,
buf_id : UInt,
) -> @scene.ShmBufferSnapshot? {
match c.dmabuf_buffers.get(buf_id) {
Some(b) => return self.snapshot_dmabuf(b)
None => ()
}
let buf = match c.shm_buffers.get(buf_id) {
Some(b) => b
None => return None
@@ -676,7 +698,7 @@ fn WaylandServer::dispatch_msg(
// get_registry(registry: new_id)
let reg_id = reader.u32()
c.objects.set(reg_id, ObjRegistry)
emit_registry_globals(c, reg_id)
emit_registry_globals(c, reg_id, self.dmabuf_formats().1.length() > 0)
}
ObjRegistry =>
if opcode == 0U {
@@ -713,6 +735,9 @@ fn WaylandServer::dispatch_msg(
c.objects.set(new_id, ObjPrimaryManager)
} else if iface == "zwp_text_input_manager_v3" {
c.objects.set(new_id, ObjTextInputMgr)
} else if iface == "zwp_linux_dmabuf_v1" {
c.objects.set(new_id, ObjDmabuf)
self.dmabuf_bound(c, new_id, ver)
} else if iface == "wl_subcompositor" {
c.objects.set(new_id, ObjSubcompositor)
} else if iface == "wl_output" {
@@ -798,7 +823,7 @@ fn WaylandServer::dispatch_msg(
} else {
match surf.attached_buffer {
Some(bid) =>
match snapshot_shm_buffer(c, bid) {
match self.snapshot_buffer(c, bid) {
Some(snap) => events.push(SubsurfaceCommitted(wid, sid, ax, ay, Some(snap)))
None => ()
}
@@ -815,7 +840,7 @@ fn WaylandServer::dispatch_msg(
Some(tl) =>
if tl.popup_parent is Some(_) {
let snap = match surf.attached_buffer {
Some(bid) => snapshot_shm_buffer(c, bid)
Some(bid) => self.snapshot_buffer(c, bid)
None => None
}
events.push(PopupCommitted(wid, snap))
@@ -832,7 +857,7 @@ fn WaylandServer::dispatch_msg(
)
} else {
let snap = match surf.attached_buffer {
Some(bid) => snapshot_shm_buffer(c, bid)
Some(bid) => self.snapshot_buffer(c, bid)
None => None
}
if snap is Some(_) {
@@ -1213,6 +1238,7 @@ fn WaylandServer::dispatch_msg(
None => None
}
c.shm_buffers.remove(buf_id)
self.dmabuf_buffer_gone(c, buf_id)
c.objects.remove(buf_id)
send_delete_id(c, buf_id)
match pool_id {
@@ -1220,6 +1246,13 @@ fn WaylandServer::dispatch_msg(
None => ()
}
}
ObjDmabuf => self.dmabuf_request(c, obj_id, opcode, reader)
ObjDmabufParams(id) => self.dmabuf_params_request(c, id, opcode, reader)
ObjDmabufFeedback =>
if opcode == 0U {
c.objects.remove(obj_id)
send_delete_id(c, obj_id)
}
ObjXdgWmBase =>
if opcode == 0U {
c.objects.remove(obj_id)
@@ -1723,6 +1756,7 @@ pub fn WaylandServer::poll_events(
self.win_to_client.remove(wid)
events.push(ToplevelClosed(wid))
}
c.drop_dmabufs(self.dmabuf_host)
c.close_all()
self.dnd_client_gone(c.client_id, events)
if self.kbd_client == Some(c.client_id) {