Skip to content

[WIP] linux-explicit-synchronization-v1: new protocol implementation

Simon Ser requested to merge github/fork/emersion/explicit-sync into master

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 calls wlr_buffer_set_in_fence
  • At render time, the renderer waits for wlr_buffer.in_fence_fd. After rendering, it creates an EGLSyncKHR and exposes it via wlr_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 via wlr_renderer_get_out_fence (if rendering) or via wlr_buffer.in_fence_fd (if direct scan-out). After commit, it exposes the FD retrieved from OUT_FENCE_PTR via wlr_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 with wlr_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:

Merge request reports