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

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

Open
2 tasks done
neatnoise opened this issue Sep 15, 2024 · 38 comments
Open
2 tasks done

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

neatnoise opened this issue Sep 15, 2024 · 38 comments

Comments

@neatnoise
Copy link

neatnoise commented Sep 15, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Is your issue described in the documentation?

  • 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 neatnoise changed the title Screen Tearing/VSync Issue in KDE Plasma Wayland Screen Tearing/VSync Issue in KDE Plasma Wayland, Gnome Wayland Sep 16, 2024
@DistantThunder
Copy link

Glad to know I'm not the only one:

@DistantThunder
Copy link

DistantThunder commented Sep 19, 2024

Could this be it?

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

@neatnoise
Copy link
Author

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
Copy link
Author

@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

@ReenigneArcher
Copy link
Member

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

@neatnoise
Copy link
Author

@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

@DistantThunder
Copy link

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

@neatnoise
Copy link
Author

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

@DistantThunder
Copy link

DistantThunder commented Sep 23, 2024

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

@neatnoise
Copy link
Author

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

@DistantThunder
Copy link

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

@ReenigneArcher
Copy link
Member

No, it's not compiled yet.

@DistantThunder
Copy link

DistantThunder commented Sep 23, 2024

No, it's not compiled yet.

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

@ReenigneArcher
Copy link
Member

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

@DistantThunder
Copy link

@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.

@ReenigneArcher
Copy link
Member

Thanks for the update

@DistantThunder
Copy link

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.

@neatnoise
Copy link
Author

@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

@DistantThunder
Copy link

DistantThunder commented Sep 27, 2024

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

@neatnoise
Copy link
Author

@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

@DistantThunder
Copy link

@neatnoise Current master looks broken:

I had to correct cbs imports as well (DistantThunder/sunshine-build-deps@f4d417c)

What commit did you use?

@neatnoise
Copy link
Author

FFmpeg/FFmpeg@a577d31 This one. I didn’t have to change anything to build it

@DistantThunder
Copy link

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.

@ReenigneArcher
Copy link
Member

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.

@DistantThunder
Copy link

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

image

image

@neatnoise
Copy link
Author

neatnoise commented Sep 30, 2024

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 ../../../

@DistantThunder
Copy link

@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.

@neatnoise
Copy link
Author

This is FFmpeg/FFmpeg@a577d31 commit build
ffmpeg_build_dev.zip

@DistantThunder
Copy link

DistantThunder commented Oct 5, 2024

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

@ReenigneArcher
Copy link
Member

We're working on updating ffmpeg to 7.1, which will properly fix this. LizardByte/build-deps#359

@ReenigneArcher ReenigneArcher reopened this Oct 5, 2024
@DistantThunder
Copy link

Yes, I just made a build using cgutman repo as a remote and the build worked with latest master this time.
The tearing is gone, now is just the old issue of the stream becoming stutter-y and clip-pey whenever I'm not at 60 fps.

@neatnoise
Copy link
Author

I have similar conclusions. Tearing is fixed, but there is kind of stuttering. The feeling is similar like network lags in games, it backs off and forward a bit when the character is moved. Probably also ffmpeg causes it.

@neatnoise
Copy link
Author

neatnoise commented Nov 19, 2024

I recorded a video displaying the stuttering issue. Looks like the frames are not displayed in order, or in the right time (delayed). It adds latency unfortunately, it is hard to react for the user in fast games and tiring for the eyes. No screen tearing. The issue is specially visible when the frames are generated close to 60 fps (45-59 fps) with 60 hz monitor. FFMPEG master was used https://www.youtube.com/watch?v=D8LE-SqZV6w

@5685C4A059D5
Copy link

Did the update to ffmpeg 7.1 fix the tearing? I still have tearing issues on v2024.1211.191744 (fedora 41, installed from the beta copr).

@ReenigneArcher
Copy link
Member

Those still experiencing stuttering, do you have VSync enabled or disabled? If enabled, can you try disabling it and report back?

@5685C4A059D5
Copy link

Do you mean in the game? I get tearing with both vsync on and off.

@neatnoise
Copy link
Author

I experience stuttering with latest master of sunshine. There is no tearing with vsync on for me.

@Trasen
Copy link

Trasen commented Feb 22, 2025

Experiencing this exact issue on latest Bazzite. The comment previously about "frames are not outputted in order" rings.

Locking in-game fps to 30 on a 60 or 120fps capture makes it more obvious, almost looks like the captured frames loop over each other on the client.

Is it possible that instead of dropping off-frames the capture re-use 3-4 frames until sync has been achived?

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

Successfully merging a pull request may close this issue.

5 participants