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
@@ -0,0 +1,106 @@
|
||||
///| zwp_linux_dmabuf_v1: what an app that draws on the GPU asks for, against a pretend GPU.
|
||||
|
||||
///|
|
||||
struct FakeGpu {
|
||||
imported : Array[(Int, UInt64, Int, Int, UInt, Bool)]
|
||||
captured : Array[UInt]
|
||||
released : Array[UInt]
|
||||
}
|
||||
|
||||
///|
|
||||
const XR24 : UInt = 0x34325258U
|
||||
|
||||
///|
|
||||
fn with_fake_gpu(comp : @host.ChandraCompositor) -> FakeGpu {
|
||||
let g : FakeGpu = { imported: [], captured: [], released: [] }
|
||||
comp.server.dmabuf_host = {
|
||||
support: () => (0xe280UL, [(XR24, 0UL), (XR24, 0x0100000000000001UL)]),
|
||||
import_buffer: (planes, modifier, w, h, fourcc, flip) => {
|
||||
g.imported.push((planes.length(), modifier, w, h, fourcc, flip))
|
||||
if fourcc == XR24 { 40U + g.imported.length().reinterpret_as_uint() } else { 0U }
|
||||
},
|
||||
capture: id => {
|
||||
g.captured.push(id)
|
||||
7000U + g.captured.length().reinterpret_as_uint()
|
||||
},
|
||||
release: id => g.released.push(id),
|
||||
}
|
||||
g
|
||||
}
|
||||
|
||||
///| create_params, add one plane, create_immed: the wl_buffer.
|
||||
fn dmabuf_buffer(c : TestWaylandClient, dmabuf : UInt, fourcc : UInt, flags : UInt) -> UInt {
|
||||
let params = c.alloc_id()
|
||||
let a = @wayland.WireWriter::new()
|
||||
a.u32(params)
|
||||
c.send(a.finish_msg(dmabuf, 1U))
|
||||
let fd = @sys.memfd_create("plane", 4096)
|
||||
let p = @wayland.WireWriter::new()
|
||||
p.u32(0U)
|
||||
p.u32(0U)
|
||||
p.u32(1280U)
|
||||
p.u32(0x01000000U)
|
||||
p.u32(1U)
|
||||
c.send(p.finish_msg(params, 1U), send_fd=fd)
|
||||
@sys.close_fd(fd)
|
||||
let buf = c.alloc_id()
|
||||
let b = @wayland.WireWriter::new()
|
||||
b.u32(buf)
|
||||
b.i32(320)
|
||||
b.i32(200)
|
||||
b.u32(fourcc)
|
||||
b.u32(flags)
|
||||
c.send(b.finish_msg(params, 3U))
|
||||
c.send(@wayland.WireWriter::new().finish_msg(params, 0U))
|
||||
buf
|
||||
}
|
||||
|
||||
///|
|
||||
test "dmabuf buffers show their window and are released at once" {
|
||||
let socket_path = "/tmp/wayland-moon-dmabuf-" + @sys.getpid().to_string() + ".sock"
|
||||
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
|
||||
let gpu = with_fake_gpu(comp)
|
||||
let (c, shm, surf, xdg, _tl, _deco) = open_and_configure_client(comp, socket_path, "T", "t")
|
||||
commit_shm_frame(comp, c, shm, surf, xdg, 1UL)
|
||||
let dmabuf = bind_global(c, 2U, "zwp_linux_dmabuf_v1", 4U)
|
||||
let buf = dmabuf_buffer(c, dmabuf, XR24, 1U)
|
||||
attach_commit(comp, c, surf, Some(buf))
|
||||
pump(comp, 3)
|
||||
assert_eq(gpu.imported.length(), 1)
|
||||
let (planes, modifier, w, h, fourcc, flip) = gpu.imported[0]
|
||||
assert_eq(planes, 1)
|
||||
assert_eq(modifier, 0x0100000000000001UL)
|
||||
assert_eq((w, h), (320, 200))
|
||||
assert_eq(fourcc, XR24)
|
||||
assert_true(flip)
|
||||
assert_eq(gpu.captured, [41U])
|
||||
let s = comp.windows.get(1UL).unwrap().surface.unwrap()
|
||||
assert_eq((s.width, s.height, s.format, s.host_id), (320, 200, 1, 7001U))
|
||||
// Destroying the wl_buffer forgets the import.
|
||||
c.send(@wayland.WireWriter::new().finish_msg(buf, 0U))
|
||||
pump(comp, 2)
|
||||
assert_eq(gpu.released, [41U])
|
||||
// A buffer the GPU can't read shows nothing and breaks nothing.
|
||||
let bad = dmabuf_buffer(c, dmabuf, 0x3231564eU, 0U)
|
||||
attach_commit(comp, c, surf, Some(bad))
|
||||
pump(comp, 3)
|
||||
assert_eq(gpu.imported.length(), 2)
|
||||
assert_eq(gpu.captured.length(), 1)
|
||||
assert_eq(comp.windows.get(1UL).unwrap().surface.unwrap().host_id, 7001U)
|
||||
// The client going away releases what it left.
|
||||
ignore(dmabuf_buffer(c, dmabuf, XR24, 0U))
|
||||
pump(comp, 2)
|
||||
assert_eq(gpu.imported.length(), 3)
|
||||
@sys.close_fd(c.fd)
|
||||
pump(comp, 3)
|
||||
assert_eq(gpu.released, [41U, 43U])
|
||||
comp.close()
|
||||
}
|
||||
|
||||
///|
|
||||
test "no dmabuf global without a GPU" {
|
||||
let socket_path = "/tmp/wayland-moon-nodmabuf-" + @sys.getpid().to_string() + ".sock"
|
||||
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
|
||||
assert_eq(comp.server.dmabuf_formats().1.length(), 0)
|
||||
comp.close()
|
||||
}
|
||||
Reference in new issue
Block a user