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

+32 -4
View File
@@ -48,6 +48,8 @@ struct State {
raster: raster::Raster,
/// Runs the panel modules; set once the engine exists.
pl: Option<plasmoid::Runtime>,
/// Fds beyond the first that arrived with the last `recvmsg` on a socket, for `take-fd`.
extra_fds: std::collections::HashMap<i32, std::collections::VecDeque<i32>>,
}
fn sockaddr_un(path: &str) -> (libc::sockaddr_un, libc::socklen_t) {
@@ -447,6 +449,12 @@ impl Host for State {
fn close_fd(&mut self, fd: i32) {
if fd >= 0 {
// A closed client socket's number is reused by the next one: drop what it left.
if let Some(left) = self.extra_fds.remove(&fd) {
for f in left {
unsafe { libc::close(f) };
}
}
unsafe { libc::close(fd) };
}
}
@@ -470,20 +478,28 @@ impl Host for State {
}
fn recvmsg(&mut self, fd: i32, max_len: u32) -> Received {
// Fds from the previous read nobody took would leak: close them.
if let Some(left) = self.extra_fds.remove(&fd) {
for f in left {
unsafe { libc::close(f) };
}
}
let mut data = vec![0u8; max_len as usize];
if data.is_empty() {
return Received { count: 0, fd: -1, data };
}
unsafe {
let mut iov = libc::iovec { iov_base: data.as_mut_ptr() as *mut _, iov_len: data.len() };
let space = libc::CMSG_SPACE((std::mem::size_of::<i32>() * 4) as u32) as usize;
// A client flushes up to 28 fds (libwayland's limit) in one sendmsg, e.g. a Vulkan
// swapchain making a wl_shm_pool per image: every one is needed, in order.
let space = libc::CMSG_SPACE((std::mem::size_of::<i32>() * 32) as u32) as usize;
let mut cbuf = vec![0u8; space];
let mut msg: libc::msghdr = std::mem::zeroed();
msg.msg_iov = &mut iov;
msg.msg_iovlen = 1;
msg.msg_control = cbuf.as_mut_ptr() as *mut _;
msg.msg_controllen = space as _;
let n = libc::recvmsg(fd, &mut msg, 0);
let n = libc::recvmsg(fd, &mut msg, libc::MSG_CMSG_CLOEXEC);
if n < 0 {
let e = *libc::__errno_location();
let c = if e == libc::EAGAIN || e == libc::EWOULDBLOCK { -1 } else { -2 };
@@ -497,10 +513,10 @@ impl Host for State {
let fds = libc::CMSG_DATA(cm) as *const i32;
for i in 0..n_fds {
let f = *fds.add(i);
if i == 0 {
if got < 0 {
got = f;
} else {
libc::close(f);
self.extra_fds.entry(fd).or_default().push_back(f);
}
}
}
@@ -511,6 +527,18 @@ impl Host for State {
}
}
fn take_fd(&mut self, sock: i32) -> i32 {
let q = match self.extra_fds.get_mut(&sock) {
Some(q) => q,
None => return -1,
};
let f = q.pop_front().unwrap_or(-1);
if q.is_empty() {
self.extra_fds.remove(&sock);
}
f
}
fn sendmsg(&mut self, fd: i32, data: Vec<u8>, send_fd: i32) -> i32 {
if data.is_empty() {
return 0;