[WIP] linux-explicit-synchronization-v1: new protocol implementation
This patch adds support for the linux-explicit-synchronization-unstable-v1 protocol. No support has been added for sync fences yet. The protocol is already useful as-is because it offers per-commit release events (wl_buffer.release is global state). We still need to actually use the fences provided by clients before exposing the protocol. We also need to send our fences to clients if we use the GL renderer, otherwise clients might start re-using buffers before our rendering is complete.
More information about explicit sync: https://lwn.net/Articles/814587/
To test, run weston-simple-dmabuf-egl -m
.
Sway PR: https://github.com/swaywm/sway/pull/5113
Since wlr_client_buffer
are created at wl_surface.commit
time, there's no need for any additional per-commit wlr_surface
state. We'll need that once we try waiting for client buffer fences before starting rendering.
Here's the new sync fence API:
void wlr_buffer_set_in_fence(struct wlr_buffer *buffer, int fd);
void wlr_buffer_add_out_fence(struct wlr_buffer *buffer, int fd);
int wlr_renderer_dup_out_fence(struct wlr_renderer *renderer);
bool wlr_renderer_wait_in_fence(struct wlr_renderer *renderer, int fd);
int wlr_output_get_out_fence(struct wlr_output *output);
-
zwp_linux_surface_synchronization_v1.set_acquire_fence
callswlr_buffer_set_in_fence
- At render time, the renderer waits for
wlr_buffer.in_fence_fd
. After rendering, it creates anEGLSyncKHR
and exposes it viawlr_renderer_get_out_fence
.wlr_buffer_add_out_fence
is called with this FD. - The DRM backend sets the
IN_FENCE_FD
property to the FD provided viawlr_renderer_get_out_fence
(if rendering) or viawlr_buffer.in_fence_fd
(if direct scan-out). After commit, it exposes the FD retrieved fromOUT_FENCE_PTR
viawlr_output_get_out_fence
. If direct scan-out is used,wlr_buffer_add_out_fence
is called with this FD. - On buffer release, the protocol implementation sends
zwp_linux_buffer_release.fenced_release
withwlr_buffer.out_fence_fd
.
TODO:
-
Renderer support -
DRM support -
attach_render -
attach_buffer -
Cursor -
Multi-GPU -
get_out_fence
-
-
Only expose the extension if both the renderer and the backend support explicit sync -
Fix FreeBSD build
Follow-up issues:
- Make the backend release buffers early with a fence (e.g. directly after a commit on DRM)
- Don't use a buffer if it isn't ready (see "The good, but complicated way" in https://github.com/swaywm/wlroots/issues/894)