Prevent screen tearing when using proprietary NVIDIA Linux drivers
There’s no doubt that NVIDIA’s proprietary Linux drivers are the best when it comes to gaming and high performance 3D graphics in general; even at the expense of running closed source software. Still, despite the driver’s robust OpenGL performance and overall stability, there’s one issue I’ve yet to see fixed out of the box: screen tearing.
Depending on your setup, the desktop environment, driver-specific and X11 settings all offer different methods to either lower the amount of visual tearing or remove it entirely. Here are some of the methods I’ve discovered. Chances are the first method won’t work, so in that case, give a try to the other options listed.
Change compositor settings
Depending on the desktop environment you use, this might be the easiest (and thus the first) method you’ll try. In my case, KDE Plasma 5 has a setting (you can find it in System Settings -> Display and Monitor -> Compositor) for tearing prevention, complete with more than two options to choose from. Some of them don’t eliminate tearing entirely and some may not work depending on the driver you are using (if you’re not using the proprietary driver, that is). Put simply, Full screen repaints tries to eliminate tearing entirely and Only when cheap eliminates tearing only in full screen applications. Changing the Rendering backend might also resolve the issue.
Again, whether this option works with your setup depends on the desktop environment you’re using; it might require dabbling with configuration files or it might not be an option at all.
Change driver settings
To change the driver settings, open up a console and type sudo nvidia-settings
.
You might not have nvidia-settings installed already; in that case try installing the application using your package manager
(sudo apt-get install nvidia-settings
). Since some Linux distributions don’t offer non-free software out of the box,
you might have to change your repository settings before you can install the application (for Ubuntu and derivatives,
try enabling the multiverse repository as described here).
Once you have opened the application, there are a few settings you can change to prevent tearing:
- OpenGL Settings -> Sync to VBlank (enable)
- PowerMizer -> Preferred Mode (set this to Prefer Maximum Performance)
Once you’re done, click Quit to close the application and save the settings. Chances are you’ll need to restart your computer to see the results, so do that as well.
Didn’t work? There’s still something you can try to fix screen tearing.
Modify xorg.conf
Start by opening a console and typing the following command to edit the Xorg configuration file (we’re using nano to edit the configuration file, but you can choose a different editor if you wish):
sudo nano /etc/X11/xorg.conf
There’s a chance the file won’t exist, which means you’ll need to generate one first. To do that, open nvidia-settings as described in the previous method and select the X Server Display Configuration tab. From there, select Save to X Configuration File and save the configuration file to /etc/X11/xorg.conf
If the configuration file already exists, make a copy of it before modifying it.
The easiest would be to make a local copy named xorg.conf.backup; you can do it with the following command: sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.backup
Once you have done either of the previous steps (created a new X11 file or backed up the existing one), find the following line:
Section "Screen"
...
...
Option "metamodes" "DVI-I-1: nvidia-auto-select +4480+0, HDMI-0: nvidia-auto-select +0+240, DP-1: nvidia-auto-select +1920+0"
...
...
EndSection
Your own file might differ slightly, but our point of interest is the metamodes line.
Append it with { ForceCompositionPipeline = On }
and place it before the quotes.
In my case, the line would now look like this:
Option "metamodes" "DVI-I-1: nvidia-auto-select +4480+0, HDMI-0: nvidia-auto-select +0+240, DP-1: nvidia-auto-select +1920+0 { ForceCompositionPipeline = On }"
Now that you’re done, save the file (for Nano, press Ctrl+X followed by Y and Enter) and try restarting the computer and seeing if the edit worked. If it didn’t, you might notice that the /etc/X11/xorg.conf file has been renamed to /etc/X11/xorg.conf.05212016 or something similar, especially if the xorg.conf file didn’t exist in the first place. In this case, we’ll just need to create the X11 configuration file with nvidia-settings, but save it to /usr/share/X11/xorg.conf.d/nvidia.conf (the filename can be something besides nvidia, as long as it is in the right directory) instead. After that, edit the file as described in the previous paragraph and try restarting your computer again.
If luck has it, your Linux desktop should finally be free of screen tearing. In my case, it wasn’t until I edited the X11.conf file that the screen tearing disappeared. Again, your mileage may vary and depending on the scenario none of the methods described here would not work.