HOWTO fix screen tearing

From LinuxReviews
Jump to navigationJump to search
Pcie-card-icon.svg

Screen tearing can be a problem on GNU/Linux with some combinations of graphics drivers and window-managers such as Xfce 4.12's xfwm4. Luckily, it's easily fixable by adding a minor snippet to Xorg's configuration file.

Create one of the following configuration files in /etc/X11/xorg.conf.d/ (create that folder if it does not exist, there's no such folder on Ubuntu by default but it does look for it and read files in it) with TearFree in a Device section to avoid screen tearing.

Why Xorg Defaults To Screen Tearing

Blond-anime-girl-with-red-questionmark.png
Question: Why do you need to add this to X's configuration?

Imagine the setting Xorg TearFree was reversed and named something like HorribleScreenTearing. That is essentially what the GPU drivers are doing when they default TearFree to false. So why would they do this?

"The "TearFree" option isn't enabled by default because it has drawbacks (higher GPU memory consumption, performance overhead for unredirected fullscreen apps); also, it can be enabled at runtime with xrandr.

Maybe try barking up your DE's tree for not exposing a setting for that.

Don't like tearing? Use Wayland!"

Michel Dänzer, Red Hat Graphics Team, Xorg and Mesa developer and 26th largest contributor to Mesa 20.2.0
in a secret developers hangout called "#radeon on Freenode"
September 30, 2020

Intel iGPUs

File: /etc/X11/xorg.conf.d/20-intel-gpu.conf
Section "Device"
   Identifier  "Intel Graphics"
   Driver      "intel"
   Option      "TearFree"  "true"
EndSection

Some rare Intel CPUs will additionally need "AccelMethod" "uxa". That is usually not the case but that's what you need to add if the above configuration does not completely eliminate screen tearing on Intel GPUs:

File: /etc/X11/xorg.conf.d/20-intel-gpu.conf
Section "Device"
   Identifier  "Intel Graphics"
   Driver      "intel"
   Option      "AccelMethod"  "uxa"
   Option      "TearFree" "true"
EndSection

Do not use "AccelMethod" "uxa" unless you actually need it. That may be the case if your hardware is very old. It is not the case if it's new.

AMD GPUs

If you aren't using an ancient AMD GPU you're using the "amdgpu" driver and you need this:

File: /etc/X11/xorg.conf.d/20-amdgpu.conf
Section "Device"
   Identifier  "AMD Graphics"
   Driver      "amdgpu"
   Option      "TearFree"  "true"
EndSection

If you're using a very rather old AMD graphics card then you're using the "radeon" driver, not "amdgpu", and you will instead you need:

File: /etc/X11/xorg.conf.d/20-radeon.conf
Section "Device"
   Identifier  "AMD Graphics"
   Driver      "radeon"
   Option      "TearFree"  "true"
EndSection

You can check the X log using grep if you are unsure what driver you are using by:

grep drivers /var/log/Xorg.0.log

That will produce a line such as:

[    24.285] (II) Loading /usr/lib64/xorg/modules/drivers/amdgpu_drv.so

or

[    24.285] (II) Loading /usr/lib64/xorg/modules/drivers/radeon_drv.so


or, if you are using an Intel (i)GPU:

[    21.857] (II) Loading /usr/lib64/xorg/modules/drivers/intel_drv.so

Setting TearFree Using xrandr

You can change the TearFree in X using xrandr with:

xrandr --output DisplayPort-0 --set TearFree on

xrandr --verbose will show the TearFree status on the connected displays and xrandr --verbose|grep TearFree will just list the TearFree settings.

A --output option is required and you can not use all. You also cannot specify multiple displays with xrandr --output DisplayPort-0 --output DisplayPort-1 --output DisplayPort-2 --set TearFree on as that only applies it to the last --output.

One possible "solution" is to ask xrandr what displays happen to be connected and use a loop to apply (or disable) TearFree with one command for each display:

xrandr |grep ' connected'|cut -f 1 -d ' '|while read display;do xrandr --output $display --set TearFree on;done

The above one-liner is not at all elegant, but it does work.

notes


avatar

Anonymous (b31d5c12a0)

5 months ago
Score 0
Very nice guide, thank you!
Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.