Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux-pipewire: Add explicit sync support #11708

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dkorkmazturk
Copy link

Description

This change leverages PipeWire's ability to share DRM syncobj fds to implement an explicit synchronization solution.

Motivation and Context

It is possible for OBS to receive incomplete frames from the compositor if the graphics drivers in use do not support implicit synchronization (e.g. NVIDIA drivers). The compositors usually try to workaround this issue by waiting all render operations to complete before sharing frames with OBS. However, this has performance implications for the compositors. Similarly, OBS should also make sure that all the rendering operations sourcing the received buffer are complete before returning the respective pw_buffer back to the compositor, or it would risk the image it is working on getting overwritten without some type of synchronization.

How Has This Been Tested?

Recorded the screen using "Screen Capture (PipeWire)" option as the source on a Wayland session on GNOME 47.3, which supports explicit sync for screencasting. Verified that explicit sync was in use by attaching a debugger to OBS.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Performance enhancement (non-breaking change which improves efficiency)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

This extension is needed for using explicit sync in the PipeWire plugin.

Signed-off-by: Doğukan Korkmaztürk <[email protected]>
@tytan652 tytan652 added the Linux Affects Linux label Jan 7, 2025
@kkartaltepe
Copy link
Collaborator

Please work with upstream pipewire and compositors to document the pipewire protocol and how to correctly handle explicit sync. (google doesnt bring up anything for SPA_META_SyncTimeline)

First two commits seem ok for adding fence support at first glance.

@kkartaltepe kkartaltepe self-assigned this Jan 8, 2025
This change adds a new type named gs_sync_t and related functions to X11
and Wayland EGL backends to abstract DRM syncobjs and their various
uses.

Signed-off-by: Doğukan Korkmaztürk <[email protected]>
It is possible for OBS to receive incomplete frames from the compositor
if the graphics drivers in use do not support implicit synchronization.
The compositors usually try to workaround this issue by waiting all
render operations to complete before sharing frames with OBS. However,
this has performance implications for the compositors. Similarly, OBS
should also make sure that all the rendering operations sourcing the
received buffer are complete before returning the respective pw_buffer
back to the compositor, or it would risk the image it is working on
getting overwritten without some type of synchronization.

This change leverages PipeWire's ability to share DRM syncobj fds to
implement an explicit synchronization solution to solve the problem
described above. The usage of these DRM syncobjs is negotiated with the
compositor that OBS is running on. So OBS can still work even if the
compositor does not support explicit synchronization.

Signed-off-by: Doğukan Korkmaztürk <[email protected]>
@dkorkmazturk
Copy link
Author

I believe it has already been documented by upstream here: https://docs.pipewire.org/page_dma_buf.html

@kkartaltepe
Copy link
Collaborator

I believe it has already been documented by upstream here: https://docs.pipewire.org/page_dma_buf.html

Thanks.

What compositor other than gnome was involved, do they have a tentative implementation this can be tested against? Are any other clients like chromium already onboard with this protocol? Basically just like when we originally implemented pipewire we dont want to include something that will only work for one compositor or risk changing dramatically when other users more important than us request changes to the protocol that break our implementation.

Also, how does cross device dmabuf sharing work in this protocol, right now it seems the fences are all assumed to be on a single device if I understand the drm calls correctly (or can the fences be imported across device?). Cross device issues are already coming up a fair bit in the current pipewire dmabuf protocol unfortunately...

@dkorkmazturk
Copy link
Author

What compositor other than gnome was involved, do they have a tentative implementation this can be tested against?

KWin has an implementation that should be released with KWin 6.3: https://invent.kde.org/plasma/kwin/-/merge_requests/6204

Are any other clients like chromium already onboard with this protocol? Basically just like when we originally implemented pipewire we dont want to include something that will only work for one compositor or risk changing dramatically when other users more important than us request changes to the protocol that break our implementation.

I believe GNOME and KDE implementations should cover the majority of the Linux users.

So far, the only client that I know that takes advantage of explicit sync is NvFBC (NVIDIA's proprietary screen recording solution).

I am not sure if the explicit sync logic can really dramatically change. The only change required on the PipeWire side was the addition of SPA_META_SyncTimeline meta type. The DRM syncobj mechanism used for implementing this feature is also used by Wayland's linux-drm-syncobj-v1 protocol, which is implemented by both Mesa and NVIDIA drivers.

Also, how does cross device dmabuf sharing work in this protocol, right now it seems the fences are all assumed to be on a single device if I understand the drm calls correctly (or can the fences be imported across device?). Cross device issues are already coming up a fair bit in the current pipewire dmabuf protocol unfortunately...

DRM syncobjs should be importable across devices and it does not change how dmabufs are shared. I may be able to test these changes in a multiple device configuration later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Linux Affects Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants