Sunshine icon indicating copy to clipboard operation
Sunshine copied to clipboard

Screen Tearing/VSync Issue in KDE Plasma Wayland, Gnome Wayland

Open neatnoise opened this issue 1 year ago • 41 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Is your issue described in the documentation?

  • [X] I have read the documentation

Is your issue present in the latest beta/pre-release?

This issue is present in the latest pre-release

Describe the Bug

Even with VSync enabled both in KDE desktop environment settings and individual game settings, screen tearing still occurs in most games that I have. I am running the latest version of Arch Linux with KDE Plasma Wayland (ver 6.1.5) installed. I primarily experience the issue in games through DXVK. Some games handle VSync correctly, while others consistently show tearing (e.g., Amnesia The Bunker, The Witcher, Mafia: Definitive Edition). It is a quite aggressive tearing, after a while it is tiring for the eyes.

This issue occurs across devices when using the Moonlight client (MacOS, iOS), but is not a client problem as the same problem is noticeable on different client systems. Games run correctly on a physically connected monitor with VSync enabled, but tearing appears when using the Moonlight client, even though VSync is also enabled in the client. I use the latest Moonlight (ver 6.0.1) for MacOS (11.7).

EDIT: Gnome 46 Wayland (Arch linux) also has the same issue. So it could be Wayland desktops related.

I recorded a short video showing the issue https://www.youtube.com/watch?v=4bVXx2cKRP8

Steps to Reproduce:

  • Enable VSync in KDE Plasma Wayland settings.
  • Run any game (preferably these with DXVK) and ensure VSync is enabled in the game’s settings.
  • Stream the game via the Moonlight client.
  • Observe the screen tearing issue.

Expected Behavior

No tearing with vsync on.

Additional Context

No response

Host Operating System

Linux

Operating System Version

Latest Arch Linux

Architecture

64 bit

Sunshine commit or version

Latest git master

Package

Linux - AUR (Third Party)

GPU Type

AMD

GPU Model

AMD Radeon RX 580

GPU Driver/Mesa Version

Mesa 24.2.2

Capture Method

wlroots (Linux)

Config

channels = 3
nv_rc = auto
address_family = both
resolutions = [
    1280x720,
    1920x1080
]
encoder = vaapi
file_state = 
fps = [60]
upnp = enabled
nv_preset = default
lan_encryption_mode = 2
wan_encryption_mode = 2
external_ip = 
cert = 
pkey =

Apps

No response

Relevant log output

Sep 06 18:21:37 tm-stc sunshine[1202]: Warning: Unrecognized configurable option [nv_rc]
Sep 06 18:21:37 tm-stc sunshine[1202]: Warning: Unrecognized configurable option [resolutions]
Sep 06 18:21:37 tm-stc sunshine[1202]: Warning: Unrecognized configurable option [fps]
Sep 06 18:21:37 tm-stc sunshine[1202]: Warning: Unrecognized configurable option [nv_preset]
Sep 06 18:21:37 tm-stc sunshine[1202]: [2024-09-06 18:21:37.155]: Info: Sunshine version: 0.0.0.dirty
Sep 06 18:21:37 tm-stc sunshine[1202]: [2024-09-06 18:21:37.156]: Info: Package Publisher: Third Party Publisher
Sep 06 18:21:37 tm-stc sunshine[1202]: [2024-09-06 18:21:37.156]: Info: Publisher Website:
Sep 06 18:21:37 tm-stc sunshine[1202]: [2024-09-06 18:21:37.156]: Info: Get support: https://app.lizardbyte.dev/support
Sep 06 18:21:37 tm-stc sunshine[1202]: [2024-09-06 18:21:37.195]: Info: Found display [wayland-0]
Sep 06 18:21:37 tm-stc sunshine[1202]: [2024-09-06 18:21:37.195]: Info: Found interface: zxdg_output_manager_v1(31) version 3
...skipping...
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.904]: Info: CLIENT CONNECTED
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.907]: Info: /dev/dri/card1 -> amdgpu
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.908]: Info: Found display [wayland-0]
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.908]: Info: Found interface: zxdg_output_manager_v1(31) version 3
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.908]: Info: Found interface: wl_output(63) version 4
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.908]: Info: Resolution: 1920x1080
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.908]: Info: Offset: 0x0
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.908]: Info: Logical size: 1280x720
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.908]: Info: Name: HDMI-A-2
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.908]: Info: Found monitor: Philips Consumer Electronics Company Philips FTV/0x01010101
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.908]: Info: -------- Start of KMS monitor list --------
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.908]: Info: Monitor 0 is HDMI-A-2: Philips Consumer Electronics Company Philips FTV/0x01010101
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.908]: Info: --------- End of KMS monitor list ---------
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.908]: Info: Screencasting with KMS
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.909]: Info: /dev/dri/card1 -> amdgpu
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.909]: Info: Found monitor for DRM screencasting
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.909]: Info: Found connector ID [95]
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.909]: Info: Found cursor plane [61]
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.935]: Info: Creating encoder [h264_vaapi]
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.935]: Info: Color coding: SDR (Rec. 601)
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.935]: Info: Color depth: 8-bit
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.935]: Info: Color range: MPEG
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.985]: Info: vaapi vendor: Mesa Gallium driver 24.2.2-arch1.1 for AMD Radeon RX 580 Series (rade>
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.988]: Error: [h264_vaapi @ 0x711c60508e00] No usable encoding entrypoint found for profile VAPr>
Sep 16 00:21:39 tm-stc sunshine[13427]: [2024-09-16 00:21:39.990]: Info: Retrying with fallback configuration options for [h264_vaapi] after error: Function>
Sep 16 00:21:40 tm-stc sunshine[13427]: [2024-09-16 00:21:40.012]: Info: vaapi vendor: Mesa Gallium driver 24.2.2-arch1.1 for AMD Radeon RX 580 Series (rade>
Sep 16 00:21:40 tm-stc sunshine[13427]: [2024-09-16 00:21:40.016]: Warning: [h264_vaapi @ 0x711c6023da40] Driver does not support some wanted packed headers>
Sep 16 00:21:40 tm-stc sunshine[13427]: [2024-09-16 00:21:40.410]: Info: Found default monitor by name: alsa_output.pci-0000_00_14.2.iec958-stereo.monitor
Sep 16 00:21:40 tm-stc sunshine[13427]: [2024-09-16 00:21:40.446]: Info: Opus initialized: 48 kHz, 2 channels, 512 kbps (total), LOWDELAY

neatnoise avatar Sep 15 '24 22:09 neatnoise

Glad to know I'm not the only one:

  • https://github.com/LizardByte/Sunshine/discussions/3089

DistantThunder avatar Sep 17 '24 19:09 DistantThunder

Could this be it?

  • https://gitlab.freedesktop.org/mesa/mesa/-/issues/11913

It says here the issue existed for years but this seems to have appeared just a few months ago at most.

DistantThunder avatar Sep 19 '24 10:09 DistantThunder

It could be. I'm doing the research too, testing different desktop environments, settings within envs, forcing different driver settings. No success so far. The issue doesn't exist on the physical screen so it might be indeed vaapi, ffmpeg thing.

neatnoise avatar Sep 19 '24 12:09 neatnoise

@DistantThunder great spot. That's the root cause - ffmpeg synchronization during encoding. I compiled the ffmpeg code with the first patch provided in the mesa thread and it fixes tearing issue. They mention that it is a workaround and not real fix, but it does the thing for now so I will use it till the real fix is provided in ffmpeg code. I'm sharing the Linux-x86_64 compiled ffmpeg with the patch that can be used with Sunshine compilation (Sunshine/third-party/build-deps/ffmpeg/Linux-x86_64) ffmpeg_build.zip

neatnoise avatar Sep 22 '24 14:09 neatnoise

@neatnoise could you submit a PR with the patch to https://github.com/LizardByte/build-deps

ReenigneArcher avatar Sep 22 '24 15:09 ReenigneArcher

@neatnoise could you submit a PR with the patch to https://github.com/LizardByte/build-deps

Added FFmpeg Vulkan synchronization fix. Worth to mention that it is a workaround and should be monitored and removed when the real fix is provided in FFmpeg project

neatnoise avatar Sep 22 '24 16:09 neatnoise

@neatnoise Nice! Did you patch your system's ffmpeg?

DistantThunder avatar Sep 23 '24 12:09 DistantThunder

@DistantThunder Sunshine uses its own built static FFmpeg library, not system's one. It is here https://github.com/LizardByte/build-deps

neatnoise avatar Sep 23 '24 19:09 neatnoise

@neatnoise even when building locally (I'm using Git)?

DistantThunder avatar Sep 23 '24 19:09 DistantThunder

Yes, when you clone Sunshine repo and its submodule repos (listed in .gitmodules), one of them is build-deps which includes ffmpeg and other libraries already compiled as a static libraries which Sunshine uses during its build process. I included already fixed compiled ffmpeg by me manually in the previous comment which could be just replaced

neatnoise avatar Sep 23 '24 20:09 neatnoise

Ah yes, thanks for the help, I could do this like this on Arch with the Sunshine PKGBUILD :

  • git+https://github.com/LizardByte/build-deps.git#commit='d9a9e0edd3bfefa604958339eca2db642683ebcf'

DistantThunder avatar Sep 23 '24 20:09 DistantThunder

No, it's not compiled yet.

ReenigneArcher avatar Sep 23 '24 20:09 ReenigneArcher

No, it's not compiled yet.

Sorry, I meant I compiled my own build with the patch. Will test soon.

DistantThunder avatar Sep 23 '24 20:09 DistantThunder

You can't use any git commit for build-deps in a PKGBUILD because the patch hasn't been compiled into the dist branch yet. This is where the submodule points to: https://github.com/LizardByte/build-deps/tree/dist

ReenigneArcher avatar Sep 23 '24 20:09 ReenigneArcher

@ReenigneArcher I eventually made my own build:

https://github.com/DistantThunder/sunshine-build-deps/actions/runs/11020194305/job/30604435143

It makes things noticeably better but the tearing persists.

DistantThunder avatar Sep 25 '24 12:09 DistantThunder

Thanks for the update

ReenigneArcher avatar Sep 25 '24 13:09 ReenigneArcher

I restarted my machine and upgraded to Mesa 24.2.3. I could no longer see the tearing with the same Sunshine build but I had stutters in heavy action scenes with the scene sometimes clipping. Getting closer it seems.

DistantThunder avatar Sep 27 '24 10:09 DistantThunder

@DistantThunder try to use the latest ffmpeg dev code. There is a proper fix already in master ffmpeg branch. It works the best for me.

Change in file https://github.com/LizardByte/build-deps/blob/master/.gitmodules

[submodule "ffmpeg_sources/ffmpeg"]
	path = ffmpeg_sources/ffmpeg
	url = https://github.com/FFmpeg/FFmpeg
	branch = master

reinit git submodules and compile build-deps

neatnoise avatar Sep 27 '24 12:09 neatnoise

@neatnoise Will test. I was afraid Sunshine bindings were not compatible with upstream latest. So I have to remove the patches?

DistantThunder avatar Sep 27 '24 15:09 DistantThunder

@neatnoise Will test. I was afraid Sunshine bindings were not compatible with upstream latest. So I have to remove the patches?

Yes, I built without any patches and works fine

neatnoise avatar Sep 27 '24 15:09 neatnoise

@neatnoise Current master looks broken:

  • https://github.com/DistantThunder/sunshine-build-deps/actions/runs/11075266714/job/30775832935

I had to correct cbs imports as well (https://github.com/DistantThunder/sunshine-build-deps/commit/f4d417c7b993a4a7478827c2c9418a848eceb1be)

What commit did you use?

DistantThunder avatar Sep 27 '24 18:09 DistantThunder

https://github.com/FFmpeg/FFmpeg/commit/a577d313b2c14c855ab8aa69bbe3527bd7727212 This one. I didn’t have to change anything to build it

neatnoise avatar Sep 29 '24 18:09 neatnoise

Ok, I don't know then

                 from /tmp/makepkg/sunshine-git/src/Sunshine/src/cbs.cpp:6:
/tmp/makepkg/sunshine-git/src/Sunshine/third-party/build-deps/ffmpeg/Linux-x86_64/include/cbs/x86/mathops.h:25:10: fatal error: config.h: No such file or directory
   25 | #include "config.h"
      |          ^~~~~~~~~~
compilation terminated.

I can't compile Sunshine using the dist build with that ffmpeg commit.

DistantThunder avatar Sep 30 '24 13:09 DistantThunder

Our "dist" build is pre compiled. We haven't compiled that commit into it. You have to compile ffmpeg yourself, as we do in build-deps, then replace the submodule with your precompiled version.

ReenigneArcher avatar Sep 30 '24 13:09 ReenigneArcher

@ReenigneArcher That's what I do, I point the Sunshine build at my own forked repo:

  • https://github.com/DistantThunder/sunshine-build-deps/tree/dist

image

image

DistantThunder avatar Sep 30 '24 13:09 DistantThunder

I use act to simulate github workflow with modified build-ffmpeg.yml a bit:

  • removed --enable-cuda_llvm switch in ffmpeg extra options
  • removed all other architecture entries with leaving only Linux-x86_64
  • removed ffmpeg patching step
  • pointed branch = master in .gitmodules ffmpeg Then I enter using bash in the docker container, copy all build outputs for sunshine tree In the end I run AUR aur/sunshine-git installation with custom script added to replace original build-deps outputs with my compiled ones
cd third-party/build-deps/ffmpeg
wget https://<url>.zip
unzip ffmpeg_build_dev.zip
rm ffmpeg_build_dev.zip
rm -rf Linux-x86_64
mv ffmpeg_build Linux-x86_64
cd ../../../

neatnoise avatar Sep 30 '24 19:09 neatnoise

@neatnoise Can you zip link your ffmpeg build-deps outputs? I suspect your "copy all build outputs for sunshine tree" may be the key here.

DistantThunder avatar Sep 30 '24 19:09 DistantThunder

This is https://github.com/FFmpeg/FFmpeg/commit/a577d313b2c14c855ab8aa69bbe3527bd7727212 commit build ffmpeg_build_dev.zip

neatnoise avatar Sep 30 '24 21:09 neatnoise

Thank you! For some reasons, some includes for config.h headers are borked in my build.

DistantThunder avatar Oct 05 '24 16:10 DistantThunder

We're working on updating ffmpeg to 7.1, which will properly fix this. https://github.com/LizardByte/build-deps/pull/359

ReenigneArcher avatar Oct 05 '24 17:10 ReenigneArcher