libretro / libretro/RetroArch

[Video/Wayland] Explicitly waiting for eglSwapBuffers() to complete.

Open
#14,409 41 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug: wayland platform: linux
Dominant language
C
Stars
14.1k
Forks
2.2k
Avg merge
7h 35m
Merged PRs (30d)
51

Description

Description

Currently, RetroArch will show noticeable input lag when using the OpenGL backend on the Wayland context (the max_swapchain setting is not available on Wayland + OpenGL).

Buffer swapping is done here for Wayland: https://github.com/libretro/RetroArch/blob/911308327dc1f06531575f9f606b21a0a25ac38a/gfx/drivers_context/wayland_ctx.c#L518
...but it lacks a mean to block until eglSwapBuffers() completes.
eglSwapBuffers() is by default a synchronous/blocking function: in theory it doesn't return until the requested buffer swap is done. This behavior can be changed with eglSwapInterval(1), which make subsequent eglSwapBuffers() calls return immediately.

However, blocking eglSwapBuffers() as things go internally on Wayland means "you can send a new frame", not "the issued buffer swap is complete and the new contents are on screen".
That's why waiting for the buffer swap event "manually" after eglSwapBuffers() can be a good idea.

In the KMS/DRM backend of SDL2, I use events to be notified on the buffer swap completion:
https://github.com/libsdl-org/SDL/blob/5b2884cb0203cc63bf9753f8b55ea4c6c6f19cfb/src/video/kmsdrm/SDL_kmsdrmvideo.c#L391

So, any idea on what would be the equivalent in Wayland for explicitly blocking until the requested buffer swap is completed?

Expected behavior

RetroArch on Wayland using OpenGL should have less input lag.

Actual behavior

RetroArch on Wayland using OpenGL has noticeable input lag.

Steps to reproduce the bug
  1. Run RetroArch on Wayland with the OpenGL driver.
  2. You get input lag.
Bisect Results

Has always happened.

Version/Commit

Every version or RetroArch has this problem: as of today, there's no mechanism implemented to explicitly wait for vsync after the egl_swap_buffers() call here:
https://github.com/libretro/RetroArch/blob/911308327dc1f06531575f9f606b21a0a25ac38a/gfx/drivers_context/wayland_ctx.c#L514

Environment information
  • OS: GNU/Linux with Wayland and any compositor
  • Compiler: gcc 10.x, doesn't matter for this.

@Themaister Can you please give me some input here? Are there Wayland-specific mechanisms to force wait for completion after an eglSwapBuffers() call?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with gfx/drivers_context/wayland_ctx.c around the eglSwapBuffers() call at lines 514–518, then compare the swap-completion handling in SDL's src/video/kmsdrm/SDL_kmsdrmvideo.c. Determine the appropriate Wayland mechanism and verify that the OpenGL backend explicitly waits for buffer-swap completion and reduces the reported input lag.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux
Domain
desktop, operating-systems
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.