Apps drawing with Vulkan on wl_shm (Delta, Zed) show every frame
CI / test (push) Failing after 16s

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:
Claude committed 2026-11-25 19:09:18 +00:00
1 parent 85f6ff42f4
commit 8f88d93d9f
14 files changed
+309 -41

No files matched your search

+31 -18
View File
@@ -44,7 +44,8 @@ enum ObjKind {
ObjPointer
ObjKeyboard
ObjTouch
ObjOutput
/// wl_output with the version the client bound (done and scale are since version 2).
ObjOutput(UInt)
ObjSubcompositor
ObjSubsurface
ObjDataManager
@@ -77,6 +78,9 @@ struct ShmBufferState {
///|
struct SurfaceState {
/// Pending state: the buffer attached since the last commit. A commit takes it, so a commit
/// without a new attach (a client changing only its regions or geometry) neither shows the
/// old buffer again nor releases it a second time: the client may already be drawing into it.
mut attached_buffer : UInt?
mut pending_frame_cb : UInt?
mut xdg_surface_id : UInt?
@@ -343,14 +347,17 @@ fn emit_shm_formats(c : ClientConn, shm_id : UInt) -> Unit {
}
///|
fn emit_seat_info(c : ClientConn, seat_id : UInt) -> Unit {
fn emit_seat_info(c : ClientConn, seat_id : UInt, ver : UInt) -> Unit {
let w1 = WireWriter::new()
w1.u32(3U) // pointer (1) | keyboard (2)
c.send_msg(w1.finish_msg(seat_id, 0U))
let w2 = WireWriter::new()
w2.str("seat0")
c.send_msg(w2.finish_msg(seat_id, 1U))
// wl_seat.name is since version 2: a v1 client (vkcube) aborts on an event it has no handler for.
if ver >= 2U {
let w2 = WireWriter::new()
w2.str("seat0")
c.send_msg(w2.finish_msg(seat_id, 1U))
}
}
///| The output changed size (the nested window was resized): tell every bound wl_output.
@@ -365,14 +372,16 @@ pub fn WaylandServer::set_output_size(self : WaylandServer, w : Int, h : Int) ->
continue
}
for id, kind in c.objects {
if kind is ObjOutput {
if kind is ObjOutput(over) {
let m = WireWriter::new()
m.u32(3U) // current | preferred
m.i32(w)
m.i32(h)
m.i32(60000)
c.send_msg(m.finish_msg(id, 1U))
c.send_msg(WireWriter::new().finish_msg(id, 2U)) // done
if over >= 2U {
c.send_msg(WireWriter::new().finish_msg(id, 2U)) // done
}
}
}
}
@@ -384,6 +393,7 @@ fn emit_output_info(
out_id : UInt,
w_px : Int,
h_px : Int,
ver : UInt,
) -> Unit {
let g = WireWriter::new()
g.i32(0)
@@ -403,12 +413,14 @@ fn emit_output_info(
m.i32(60000)
c.send_msg(m.finish_msg(out_id, 1U))
let s = WireWriter::new()
s.i32(1)
c.send_msg(s.finish_msg(out_id, 3U))
let d = WireWriter::new()
c.send_msg(d.finish_msg(out_id, 2U))
// scale and done are since version 2.
if ver >= 2U {
let s = WireWriter::new()
s.i32(1)
c.send_msg(s.finish_msg(out_id, 3U))
let d = WireWriter::new()
c.send_msg(d.finish_msg(out_id, 2U))
}
}
///|
@@ -521,7 +533,7 @@ fn WaylandServer::dispatch_msg(
} else if iface == "wl_seat" {
c.objects.set(new_id, ObjSeat)
c.seat_ver = ver
emit_seat_info(c, new_id)
emit_seat_info(c, new_id, ver)
} else if iface == "wp_cursor_shape_manager_v1" {
c.objects.set(new_id, ObjCursorShapeMgr)
} else if iface == "wl_data_device_manager" {
@@ -529,8 +541,8 @@ fn WaylandServer::dispatch_msg(
} else if iface == "wl_subcompositor" {
c.objects.set(new_id, ObjSubcompositor)
} else if iface == "wl_output" {
c.objects.set(new_id, ObjOutput)
emit_output_info(c, new_id, self.output_w, self.output_h)
c.objects.set(new_id, ObjOutput(ver))
emit_output_info(c, new_id, self.output_w, self.output_h, ver)
}
}
ObjCompositor =>
@@ -613,6 +625,7 @@ fn WaylandServer::dispatch_msg(
}
None => ()
}
surf.attached_buffer = None
match surf.pending_frame_cb {
Some(cb_id) => {
surf.pending_frame_cb = None
@@ -1146,8 +1159,8 @@ pub fn WaylandServer::poll_events(
for idx = 0; idx < self.clients.length(); idx = idx + 1 {
let c = self.clients[idx]
while c.alive {
let (n, rfd) = @sys.recvmsg_fd(c.fd, scratch, 8192)
if rfd >= 0 {
let (n, rfds) = @sys.recvmsg_fds(c.fd, scratch, 8192)
for rfd in rfds {
c.pending_fds.push(rfd)
}
if n > 0 {