Advertise zwp_linux_dmabuf_v1 so Mesa EGL clients stop using llvmpipe
- Add zwp_linux_dmabuf_v1 (v4 feedback names the render node). Only linear ARGB8888 and XRGB8888 are accepted, because the compositor reads a buffer by mapping its dma-buf. - Bracket dma-buf reads with DMA_BUF_IOCTL_SYNC in the compositor and in the wasm host, so the CPU sees the GPU's finished writes. - Keep every wl_surface.frame callback since the last commit instead of only the last one. Zed and Mesa's EGL queue several and wait on all of them. - rs_capture maps a dma-buf afresh on each capture rather than using the pool cache, which could hand a later buffer an earlier buffer's pixels. - Restart xdg-desktop-portal in the background once the compositor socket exists, so the restart no longer delays compositor startup by about 30 s.
This commit is contained in:
1 parent
d81003f176
commit
51852f0dac
5 files changed
+366
-16
No files matched your search
@@ -16,6 +16,8 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <linux/dma-buf.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -759,6 +761,12 @@ static const uint8_t *pool_map(int fd, const struct stat *st) {
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Wait for the GPU to finish writing a dma-buf before the CPU reads it; harmless on shm files. */
|
||||
static int dmabuf_sync(int fd, int start) {
|
||||
struct dma_buf_sync sync = { .flags = (start ? DMA_BUF_SYNC_START : DMA_BUF_SYNC_END) | DMA_BUF_SYNC_READ };
|
||||
return ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync);
|
||||
}
|
||||
|
||||
/* Copy a client buffer (stride * height bytes at `offset` of the file behind fd, little-endian
|
||||
* B, G, R, A/X) into a surface. 0 on failure. */
|
||||
uint32_t rs_capture(int32_t fd, int32_t offset, int32_t stride, int32_t w, int32_t h, int32_t format) {
|
||||
@@ -766,11 +774,27 @@ uint32_t rs_capture(int32_t fd, int32_t offset, int32_t stride, int32_t w, int32
|
||||
int64_t len = (int64_t)stride * h, end = offset + len;
|
||||
struct stat st;
|
||||
if (fstat(fd, &st) < 0 || st.st_size < end) return 0;
|
||||
const uint8_t *p = pool_map(fd, &st);
|
||||
if (!p) return 0;
|
||||
/* A dma-buf is mapped afresh every time: the cache would hand a later buffer the mapping of an
|
||||
* earlier one that had the same inode and size (the window then shows another app's pixels). */
|
||||
int is_dmabuf = dmabuf_sync(fd, 1) == 0;
|
||||
const uint8_t *p;
|
||||
if (is_dmabuf) {
|
||||
p = mmap(NULL, (size_t)st.st_size, PROT_READ, MAP_SHARED, fd, 0);
|
||||
if (p == MAP_FAILED) { dmabuf_sync(fd, 0); return 0; }
|
||||
} else {
|
||||
p = pool_map(fd, &st);
|
||||
if (!p) return 0;
|
||||
}
|
||||
uint8_t *rgba = px_alloc((size_t)w * h * 4);
|
||||
if (!rgba) return 0;
|
||||
if (!rgba) {
|
||||
if (is_dmabuf) { munmap((void *)p, (size_t)st.st_size); dmabuf_sync(fd, 0); }
|
||||
return 0;
|
||||
}
|
||||
int opaque = swizzle_rows(p + offset, stride, rgba, w, h, format == 1);
|
||||
if (is_dmabuf) {
|
||||
dmabuf_sync(fd, 0);
|
||||
munmap((void *)p, (size_t)st.st_size);
|
||||
}
|
||||
do { next_surface++; } while (next_surface == 0 || surface(next_surface));
|
||||
Surface *sf = malloc(sizeof *sf);
|
||||
sf->id = next_surface; sf->w = w; sf->h = h; sf->rgba = rgba; sf->opaque = opaque;
|
||||
|
||||
Reference in new issue
Block a user