Why is video tearing such a problem in Linux?

95,555

Solution 1

This is all due to the fact that the X server is out-dated, ill-suitable for today's graphics hardware and basically all the direct video card communication is done as an extension ("patch") over the ancient bloated core. The X server provides no builtin means of synchronization between user rendering the window and the screen displaying a window, so the content changes in the middle of rendering. This is one of the well-known issues of the X server (it has many, the entire model of what the server does and is outdated - event handling in subwindows, metadata about windows, graphical primitives for direct drawing...). Widget toolkits mostly want to gloss over all this, but tearing is still a problem because there is no mechanism to handle that. Additional problems arise when you have multiple cards that require different drivers, and on top of all this, opengl library has a hard-wired dependency on xlib, so you can't really use it independently without going through X.

Wayland, which is somewhat unenthusiastically trying to replace X, supports a pedantic vsync synchronization in its core, and is advertised to have every frame exactly perfect.

If you quickly google "wayland video tearing" you'll find more information on everything.

Solution 2

If you're using an nvidia driver >= 365.20, then try enabling the "Force Full Composition Pipeline" option in nvidia-settings.

enter image description here

Solution 3

Screen tearing appears mostly because of two reasons - drivers that aren't there yet, and lack of vsync with certain window managers.

As for drivers, both free and proprietary drivers support free-tearing compositing (nvidia and amd both). Be aware that e.g. enabling tear-free desktop in catalyst (fglrx) may cause frame drop and lags, so it is usually disabled by default. As for open driver, vsync should be enabled by default. So screen tearing issue may be solved by trying different drivers and configuring them.

As for window managers, it's known that Openbox, Awesome and others lightweight wms don't support tear-free. XFCE (xfwm, to be specific) has fixed it in recent releases, 4.11/12 now have Vsync. Major desktop environments also have no problems with tearing, including GNOME, KDE, Unity and Cinnamon.

If you still experience screen tearing, your option is to try another compositing manager like Compton or Kwin. Kwin is the window manager for KDE and I have experience of using kwin in XFCE when it didn't support vsync and it worked really well.

So the solution here is experimentation, what is broken in one combination of driver/wm can work in another. I believe the situation will improve soon since open-source drivers are becoming more advanced and switching to wayland may get rid of old issues with Xorg.

Solution 4

I had a strong tearing here and now it is solved.

After reading this (wonderful explanation) of how an Xorg server works I realized that X server paints window updates directly to the memory card at any random time unless you use a compositing enabled window manager.

When compositing is enabled the window manager put together all the changes from the different window memory buffers, creates a resulting image for the whole screen and dump it to the display card on one shot.

Most modern distributions have a compositing window manager. KWin for KDE, Mutter for Gnome, Muffin for Cinnamon, Marco for Mate, xfwm for XFCE, etc. However compositing could be disabled to save resources.

In my case compositing was disabled in KDE4. Once enabled the tearing went away. EDIT: I also needed to change on KWin options the VSync strategy from Automatic to Reuse screen contents in order to get rid of tearing just as explained in this kwin specific bug report.

The driver options can be also a factor. In my case the default options works ok. Arch Wiki have great documentation about the options for different display cards such as Intel cards or NVIDIA cards.

To check if an option is enabled in your current xorg configuration you can check the log. For example, to check if DRI is enabled:

cat /var/log/Xorg.0.log | grep DRI

Solution 5

The solution is here: Linux Mint 17.3 MATE now comes with Compton.

Just go to Desktop Settings -> Windows -> Window Manager and choose Metacity + Compton. That's it.

I have AMD video card and it works out of the box for open source driver.

For proprietary AMD driver, when HTML5 videos are maximized to full screen, you might see blue color that will fill the whole screen. To fix this, create and chmod +x the script below:

#!/bin/bash
killall compton 2> /dev/null
compton -b --unredir-if-possible

Run it whenever you restart the system, but don't try to add it to Startup Applications -- it might break startup for some reason.

Share:
95,555

Related videos on Youtube

Ravenstine
Author by

Ravenstine

Updated on September 18, 2022

Comments

  • Ravenstine
    Ravenstine over 1 year

    I've used many variants of Linux(mostly Debian derivatives) for over a decade now. One problem that I haven't seen solved satisfactorily is the issue of horizontal tearing, or Vsync not being properly implemented.

    I say this because I use used 5 different distros on 4 different computers with various monitors and Nvidia/AMD/ATI/Intel graphics cards; every time, there has been an issue with video tearing with even slight motion.

    This is a big problem, especially since even Windows XP doesn't have these issues on modern hardware. If anyone is going to use Linux for anything, why would they want constant defects to show up when doing anything non-CLI?

    I'm guessing that either few developers know about this problem or care enough to fix it. I've tried just about every compositor out there, and usually the best they can do is minimize the issue but not eliminate it. Shouldn't it be as simple as synchronizing with the refresh rate of the monitor? Is there some politics among the OSS community that's preventing anyone from committing code that fixes this?

    Every time I've asked for help on this issue in the past, it either gets treated as an edge case(which I find difficult to believe it is given the amount of times I've replicated the problem) or I get potential solutions that at most minimize the tearing.

    • Sparhawk
      Sparhawk about 9 years
      You don't mention which DE you use. KDE has been fine with tearing for a year or so now.
    • Govind
      Govind about 9 years
      How could one easily replicate the problem? In a Debian/Ubuntu/Mint computer?
    • GuinnessJeff
      GuinnessJeff about 9 years
      This XKCD just seems to fit so well here...
    • labyrinth
      labyrinth about 9 years
      My experience with tearing has been completely different. I'm a very happy gaming and watching movies on Linux. Steam has really made Linux a viable platform for great games. I've been playing Witcher 2 and Talos Principle lately, and I haven't seen any tearing in some 50 hours of game play. This is with an Nvidia card with proprietary drivers on Arch. I agree with Xen2050 that this question would be more useful if exact specs were given for your builds. I'm not denying there is a problem, I just have had a very good experience.
    • Zan Lynx
      Zan Lynx about 9 years
      With Nvidia compositing solved the problem for me, when I used to use Nvidia back in 2007. Not in full screen though because full screen windows turn off the compositor, it assumes you're going to run an OpenGL game I think. With Intel, have you tried setting Section "Device" Option "TearFree" "true" in X? It doubles video RAM use but I think it'll work.
    • inf3rno
      inf3rno over 8 years
      I got terrible tearing by Mint + Cinnamon, XFCE, Mate. I am testing further, maybe I'll find a distro, which I can use to watch youtube movies.
    • Ravenstine
      Ravenstine over 8 years
      @inf3rno The best practical answer I could figure out was to simply use a newer kernel than what gets shipped with "stable" distros, which are usually relatively ancient and don't have good support for even year or two old graphics cards. I've switched to using Debian testing and haven't had any tearing issues since. On a side note, I'd probably never use a "stable" version of Debian again for my own personal use.
    • inf3rno
      inf3rno over 8 years
      @user10800 I tried with the latest kernel in the 3.16.x series. The results were the same, still tearing. When I tried to restore the old kernel, Cinnamon crashed after every reboot. According to some forums I should use 3.19.x and vivid drivers, but I am not sure that would not cause Mint or the actual DE to crash. I'll give it a try. That's all I can do with Mint.
  • Ivan
    Ivan about 9 years
    Not really. KDE (with Kwin or other composer) still tears like hell with NVidia or Intel.
  • kagali-san
    kagali-san about 9 years
    @HalosGhost wayland evangelism on the go :) still no network session support?
  • Jakob Bennemann
    Jakob Bennemann about 9 years
    @kagali-san I didn't say Wayland was perfect (it isn't). But it's definitely better than X. :)
  • user1686
    user1686 about 9 years
    @kagali-san: Weston has had its RDP backend merged just a year ago, if you find that somehow relevant to a question about video tearing.
  • user1579506
    user1579506 about 9 years
    Openbox etc. do work tear-free - you simply have to run a separate compositor, e.g. compton works wonderfully.
  • nass
    nass about 9 years
    @wingedsubmariner, when you guys refer to openbox, do you also mean fluxbox?
  • nass
    nass about 9 years
    also, extremely helpful that you note what is the state of WM in different window environments.
  • user1579506
    user1579506 about 9 years
    @nass Absolutely. The window manager is never a limiting factor.
  • Tobia Tesan
    Tobia Tesan over 7 years
    @orion: and thanks to you this very page is now the #1 result for wayland video tearing :P
  • karatedog
    karatedog over 7 years
    On XFCE (in Xubuntu 16.04) compositing is enabled by default but syncing to the vertical blank is not. Use the xfwm4-tweaks-settings command to show the tweaker application and on the Compositor tab you can find the above option. Turning it on made a huge difference, and can be checked here: vsynctester.com/index.html (turn the feature on/off while the displaying the animation). It is not perfect, there are some missed frames though, but much better than when it is turned off.
  • Tobia
    Tobia over 7 years
    Does Wayland support executing X11 programs on one computer and displaying their windows on another? (running Wayland) That's quite critical for many of us.
  • Jerther
    Jerther over 7 years
    nVidia Quadro on a Lenovo W520, Fedora 25 and this worked :)
  • Rast
    Rast about 7 years
    also if you have no such option, click "advanced settings" at the bottom of the window and it will show up. why this "full composition pipeline" is not enabled by default?..
  • Ruslan
    Ruslan about 7 years
    @Rast Because it used to have some performance problems.
  • Rolf
    Rolf about 6 years
    I'm running Weston on Wayland and experiencing tearing. It's very subtle but I have seen none in Windows 10. I have done a quick test under X. It seems that windowed performance is much worse, but I'm not sure about full screen, it seemed pretty close. So Wayland is better than X but still not totally there. Oh it depends on the hardware too. I'm running i915 graphics. By the way, I'm "testing" Netflix on Chrome, which runs on Xwayland, so X is still involved - I'm not sure what I'm doing.
  • Ruslan
    Ruslan over 5 years
    BTW, it appears that at least Intel drivers also have a TearFree option you can put into the corresponding Device section. I've just tried it, and it gives results very similar to nvidia's Full Composition Pipeline.
  • FragmentalStew
    FragmentalStew about 5 years
    I can't seem to get the setting to save on reboots I tried creating a ~/.xinitrc file and putting "nvidia-settings --load-config-only & . /etc/X11/xinit/xinitrc" in it but that didn't seem to work
  • Time4Tea
    Time4Tea about 4 years
    I found this answer very helpful. Practically eliminates the tearing issues for me.
  • brainplot
    brainplot about 4 years
    No need for cat here; grep accepts file names. grep DRI /var/log/Xorg.0.log.
  • musicin3d
    musicin3d over 3 years
    I'm on version 384.130, and this option is not available, even with advanced settings on. :(