Delta is a GPUI app: it draws with Vulkan, and without linux-dmabuf Mesa's WSI presents through wl_shm, making one wl_shm_pool per swapchain image. libwayland flushes those create_pool requests with all their fds in one sendmsg (vkcube on lavapipe sends 4), but both hosts kept only the first SCM_RIGHTS fd and closed the rest. Every pool but the first had no memory, so only one swapchain image ever reached the screen: stale, frozen or flickering windows. - recvmsg keeps every fd (up to 32), in order: natively through recvmsg_fds, and in the wasm host through a new chandra:host/sys take-fd import. - A commit consumes the attached buffer. A bare commit (GPUI commits after ack_configure) used to re-show and re-release the old buffer, which the client may already be drawing its next frame into. - ARGB8888 client buffers are blended as premultiplied alpha, as wl_shm defines, in both rasterisers (translucent edges were darkened). - wl_seat.name and wl_output.scale/done are only sent to clients that bound version 2 or later (vkcube binds v1 and aborted on them). Regression test: a client flushes three pools with their fds in one message, then commits a bare frame; it fails on the old code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hm8wb1UKxQxf8o6gpz
This commit is contained in:
14 files changed
+309
-41
No files matched your search
@@ -376,3 +376,108 @@ test "a buffer stays valid after its wl_shm_pool is destroyed" {
|
||||
commit_shm_frame(comp, c, shm, surf, xdg, 1UL, destroy_pool=true)
|
||||
assert_true(comp.windows.get(1UL).unwrap().surface is Some(_))
|
||||
}
|
||||
|
||||
///| A solid ARGB8888 frame of `w` x `h` in a new memfd.
|
||||
fn solid_memfd(w : Int, h : Int, b : Byte, g : Byte, r : Byte) -> Int {
|
||||
let px : Array[Byte] = Array(capacity=w * h * 4)
|
||||
for _i = 0; _i < w * h; _i = _i + 1 {
|
||||
px.push(b)
|
||||
px.push(g)
|
||||
px.push(r)
|
||||
px.push(b'\xff')
|
||||
}
|
||||
let fd = @sys.memfd_create("wl-shm-swapchain", w * h * 4)
|
||||
ignore(@sys.pwrite_bytes(fd, Bytes::from_array(px), 0))
|
||||
fd
|
||||
}
|
||||
|
||||
///|
|
||||
fn attach_commit(comp : @host.ChandraCompositor, c : TestWaylandClient, surf : UInt, buf : UInt?) -> Unit {
|
||||
match buf {
|
||||
Some(b) => {
|
||||
let a = @wayland.WireWriter::new()
|
||||
a.u32(b)
|
||||
a.i32(0)
|
||||
a.i32(0)
|
||||
c.send(a.finish_msg(surf, 1U))
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
c.send(@wayland.WireWriter::new().finish_msg(surf, 6U))
|
||||
for _i = 0; _i < 5; _i = _i + 1 {
|
||||
comp.step()
|
||||
@sys.sleep_ms(2)
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
test "swapchain pools sent in one message all keep their fds, and a bare commit keeps the frame" {
|
||||
// Mesa's Vulkan WSI on wl_shm (what GPUI apps like Zed and Delta fall back to) makes one
|
||||
// wl_shm_pool per swapchain image and libwayland flushes them with all their fds in one
|
||||
// sendmsg. Every fd but the first used to be dropped, so those images never showed.
|
||||
let socket_path = "/tmp/wayland-moon-swapchain-" + @sys.getpid().to_string() + ".sock"
|
||||
let theme = @scene.ThemeTokens::moon_night()
|
||||
let comp = @host.ChandraCompositor::new(socket_path, theme, 1280, 720).unwrap()
|
||||
let (c, shm, surf, xdg, _tl, _deco) = open_and_configure_client(
|
||||
comp, socket_path, "Delta", "dev.delta.Delta",
|
||||
)
|
||||
match c.configure_serial {
|
||||
Some(ser) => {
|
||||
let ack = @wayland.WireWriter::new()
|
||||
ack.u32(ser)
|
||||
c.send(ack.finish_msg(xdg, 4U))
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
let w = c.configured_w
|
||||
let h = c.configured_h
|
||||
let fds = [
|
||||
solid_memfd(w, h, b'\x00', b'\x00', b'\xff'),
|
||||
solid_memfd(w, h, b'\x00', b'\xff', b'\x00'),
|
||||
solid_memfd(w, h, b'\xff', b'\x00', b'\x00'),
|
||||
]
|
||||
// Three create_pool + create_buffer requests, flushed together with their three fds.
|
||||
let msg : Array[Byte] = []
|
||||
let bufs : Array[UInt] = []
|
||||
for _i = 0; _i < 3; _i = _i + 1 {
|
||||
let pool = c.alloc_id()
|
||||
let p = @wayland.WireWriter::new()
|
||||
p.u32(pool)
|
||||
p.i32(w * h * 4)
|
||||
for b in p.finish_msg(shm, 0U) {
|
||||
msg.push(b)
|
||||
}
|
||||
let buf = c.alloc_id()
|
||||
let cb = @wayland.WireWriter::new()
|
||||
cb.u32(buf)
|
||||
cb.i32(0)
|
||||
cb.i32(w)
|
||||
cb.i32(h)
|
||||
cb.i32(w * 4)
|
||||
cb.u32(0U)
|
||||
for b in cb.finish_msg(pool, 0U) {
|
||||
msg.push(b)
|
||||
}
|
||||
bufs.push(buf)
|
||||
}
|
||||
assert_true(@sys.sendmsg_fds(c.fd, Bytes::from_array(msg), fds) > 0)
|
||||
let win = comp.windows.get(1UL).unwrap()
|
||||
let cx = win.geometry.x + win.geometry.w / 2
|
||||
let cy = win.geometry.y + win.geometry.h / 2
|
||||
|
||||
attach_commit(comp, c, surf, Some(bufs[2]))
|
||||
assert_eq(comp.compose_frame().pixel(cx, cy), Some(@scene.Rgba::new(0, 0, 0xff, 0xff)))
|
||||
attach_commit(comp, c, surf, Some(bufs[1]))
|
||||
assert_eq(comp.compose_frame().pixel(cx, cy), Some(@scene.Rgba::new(0, 0xff, 0, 0xff)))
|
||||
|
||||
// The buffer was released, so the client draws its next frame into it; a commit without a
|
||||
// new attach (GPUI commits after ack_configure) must not show that half-drawn frame.
|
||||
ignore(@sys.pwrite_bytes(fds[1], Bytes::from_array([b'\x00', b'\x00', b'\xff', b'\xff']), (h / 2 * w + w / 2) * 4))
|
||||
attach_commit(comp, c, surf, None)
|
||||
assert_eq(comp.compose_frame().pixel(cx, cy), Some(@scene.Rgba::new(0, 0xff, 0, 0xff)))
|
||||
for fd in fds {
|
||||
@sys.close_fd(fd)
|
||||
}
|
||||
@sys.close_fd(c.fd)
|
||||
comp.close()
|
||||
}
|
||||
Reference in new issue
Block a user