You can sign up to get a daily email of our articles, see the Mailing List page!
Support us on Patreon to keep GamingOnLinux alive. This ensures we have no timed articles and no paywalls. Just good, fresh content! Alternatively, you can donate through Paypal, Flattr and Liberapay.!

I have finally found a way to sort out screen tearing on Nvidia with Linux

Posted by , | Views: 74,521

Update: You can do it easier now with the NVIDIA control panel. See this newer article for info.

Thanks to a few different people for their advice (xpander for the initial advice on a script and HeavyHDx on twitter) I have finally found a way to stop screen tearing with Nvidia proprietary drivers.

I have been struggling with this issue for months across all the different desktop environments I tried (KDE, GNOME, Cinnamon, Unity), and it has caused me a fair amount of headaches and stress, so I am pleased to finally find a solution. It's not perfect, slightly annoying, but also quite useful too.

You have probably heard of ForceFullCompositionPipeline before and that is what I am using. I have two scripts setup on keyboard shortcuts depending on the resolution that I am using (4K or 1080p). Why both? I hear you ask. It's simple, performance in a lot of games at 4K resolution is terrible, and some games have tiny unreadable text, so I run certain games at 1080p.

Here's where the confusion came from...
The problem with ForceFullCompositionPipeline is when you play a game that has a fullscreen mode that changes your desktop resolution, instead of stretching a fullscreen window, is that ForceFullCompositionPipeline is reset back to disabled. If you have noticed screen tearing returning at times even with using ForceFullCompositionPipeline, that could well be your issue too. Like me, if you didn't know that, it was probably bugging you a lot. This is also why simply putting it in an xorg config file will not 100% solve it, where as with this method you can just re-run it any time you need to.

So, here are the two very simple scripts I run. They are both put in plain text files and allowed to run as an executable (right click -> properties -> permissions -> tick "Allow executing file as program").

First up is for the 4K resolution (I have this set to run at start-up so I don't have to mess with xorg stuff directly):
nvidia-settings --assign CurrentMetaMode="DP-4:3840x2160_60 +0+0 { ForceFullCompositionPipeline = On }, DVI-I-1:1920x1080_60 +3840+0 { ForceFullCompositionPipeline = On }"
And for 1080p resolution:
nvidia-settings --assign CurrentMetaMode="DP-4:1920x1080_60 +0+0 { ForceFullCompositionPipeline = On }, DVI-I-1:1920x1080_60 +1920+0 { ForceFullCompositionPipeline = On }"
If you only have one monitor, you won't need the addition part after the comma.

You can run the script at any time. Your monitor(s) will blink, and then come back all sorted.

You will of course need to change things like "DP-4" and "DVI-I-1" to the connections your monitor is using (or monitors in my case as I have two). You can find them out by running the "xrandr" command in terminal. It will give you a list of things, like this:

QuoteDP-4 connected primary 3840x2160+0+0 (normal left inverted right x axis y axis) 621mm x 341mm

 


I hope this helps someone else, as it has been driving me nutty. They are pretty safe scripts to use, I have been testing switching between them constantly, but don't blame me if you blow your computer up.

These two little scripts have literally changed my gaming life on Linux for the better.

Where it becomes even more useful
A nice side-effect of the script: Games like RunningWithRifles which has poor multi-monitor support, it actually turns off my main monitor. Hitting the desktop shortcut I set for it will bring that monitor back, and still allow me to play the game. So not only do you get zero tearing, you get your normal multi-monitor experience back.

Feel free to share what methods you're using on your favourite desktops. Let's see if we can help each other in the comments.

 

0 Likes
We do often include affiliate links to earn us some pennies. We are currently affiliated with GOG and Humble Store. See more information here.
The comments on this article are closed.
70 comments
Page: «7/7
  Go to:

slaapliedje 15 May 2016 at 6:17 pm UTC
View PC info
  • Supporter
I think I've gotten to the point where they just need to fix the paste buffer stuff in Wayland and I can switch to that, and I always thought one of the things Wayland was supposed to fix is this issue with screen tearing.

That said, I'm not getting a whole lot of tearing right now using Debian Sid on my 55" screen. I haven't done much to the configuration either, beyond installing the nVidia drivers. I really need to fix my laptop though so I can actually USE the nVidia side of things. What would have been nice is if they could come up with a chipset that had a really nice powersaving mode so we wouldn't need this PRIME/Optimus nonsense in the first place! Maybe their 10x0 cards will?
Nel 16 May 2016 at 2:00 pm UTC
Xpander
stan
tusharkant15This forces Triple Buffering so the performance does take a hit
Triple buffering is supposed to improve performance compared to double buffering. Well, the framerate should improve, not the latency.

i think the issue where it takes the hit is where game itself has triplebuffer enabled as well.
some games get really jumpy framerate when thats in xorg.. thats with my experience.

just ForceCompositionPipline fixes all tearing for me and no need to use other tweaks.
Did you try to disable your compositor while running games ?

I know the auto-detection doesn't work well since lot of games now play in a borderless window. It's hard for them to detect fullscreen and then auto-disable compositor, and that's what I experienced when I switched from XFCE (without compositor) to KDE (with compositor) 2 years ago. So I chose to do it by myself when needed.

KDE provides a shortcut key to disable it manually, default is Ctrl+Alt+F12 iirc, and can be changed to any key you want (I personally use Pause key). While compositor doesn't hit performance on "low demanding" games, it can cripple fps on "high demanding" games like Feral or Aspyr ones. So I press my "magic key" to improve FPS.

To be honest I hardly believe triple buffer may hit performance, since its very benefit is to improve performance and provide steady FPS, at the cost of a larger usage of VRAM. Your problem should come from somewhere else.
See Nvidia documentation or simply Wikipedia article.
kokoko3k 17 May 2016 at 9:16 am UTC
Oneliners that works for me in all of the metamodes:
Enable:
sh -c "nvidia-settings --assign CurrentMetaMode=\"$(nvidia-settings -t -q CurrentMetaMode |tr -d "\n"|sed 's/ViewPortIn=/ForceFullCompositionPipeline=On, ViewPortIn=/g'|sed 's/.*:://'|sed 's/^ *//;s/ *$//')\""
Disable:
sh -c "nvidia-settings --assign CurrentMetaMode=\"$(nvidia-settings -t -q CurrentMetaMode |tr -d "\n"|sed 's/.*:://'|sed 's/^ *//;s/ *$//')\""

However, forcing ForceFullCompositionPipeline is just like running a compositor (IT IS a simple compositor) plus you lose shadows and candies, see those benchamrks running simple "teapot" mesa demo:

FPS | Window manager | compositor ----------------------------------- 978 openbox NONE 976 kwin NONE 907 openbox Compton opengl 905 kwin kwin opengl 3.1 905 kwin ForceFullCompositionPipeline=on 902 openbox ForceFullCompositionPipeline=on


...that is the 7-8% performance hit i'd expect when running a compositor on my GTX470 (it is negligible when overrall fps are low, but more evident on simple demos like teapot, and in newer cards the performance hit should be even less evident).

So, if you managed to have vsync with userspace compositors like kwin,compton,mutter and so on, i think it is better to use them instead of ForceFullCompositionPipeline.


Last edited by kokoko3k at 17 May 2016 at 9:28 am UTC
Naizugai 19 May 2016 at 2:05 pm UTC
I tried the script in the terminal, but nothing happens?

image
kokoko3k 19 May 2016 at 2:19 pm UTC
You did not correctly quoted the strings.
Also, nvidia driver refers to display with other names (in my case is DPY-2), that's why i suggested a general script (see my previous comment).
Anyway, you're already running a compositor; i don't think is a good idea stacking one on top of another. as you will lose twice the performance in the best case.

BTW:
The fact that the performance drop is the same as running a compositor should REALLY be written in the main article; there's no vodoo magic here.


Last edited by kokoko3k at 19 May 2016 at 2:44 pm UTC
jasondaigo 23 May 2016 at 6:19 pm UTC
i did already use this and it works.BUTying Light still with tearing.I had only tearfree dying light with steamos-compositor which seems not available anymore in AUR.
jasondaigo 23 May 2016 at 6:33 pm UTC
funny enough btw if someone cries about tearing problems a bunch of creeps coming along with this im using KDE shit. a DE nobody wanted to use before. and sticking to one piece of software to solve this is not the linux way, isnt it? lets be honest. its just a shame new users install linux and get eye cancer 50% of the time
Akonady 24 May 2016 at 9:04 pm UTC
DaverballFor me creating a file "Tearing.sh" in /etc/profile.d did the trick:

# /etc/profile.d/Tearing.sh export KWIN_TRIPLE_BUFFER=1

Of course you may still end up having screen tearing in some games that do not have it enabled by default, but at least the desktop experience should be mostly tearing free with that and it also doesn't randomly break by launching a game.

Naturally also relies on you running KDE with Kwin.


THANKS MAN! This worked.

P.S: Why the V-Sync option on nvidia-setting don't works?
Also, the native V-Sync option on KDE plasma do the same as this method?


Last edited by Akonady at 24 May 2016 at 11:48 pm UTC
IDNO 18 June 2016 at 1:06 pm UTC
I found a way to reduce input lag on every game (linux only) xD

in xorg.conf

use this command Option "AutoRepeat" "1000 1" if you have a 1ms keyboard and mouse

you can use it in every layout Section "ServerLayout"

and other one to use in case if xorg not wanna run 1ms speed

xset r rate 1000 1

and add that to start-up if have 1ms and 1000hz mouse or keyboard

and if you not know you can change pointer control xset m 1/1

and if you really like my settings do this for 1/1 acceleration too i guess (linux only)

Option "AccelProfile" "flat" (to enable 1/1 accel need to have a acceleration command in xorg.conf to work) like mine Option "AccelSpeed" "0.3" or some other command


in mouse and serverlayout my secret mouse settings

and i have some few more but can edit it later if you want


This is the one of the reasons i dont use windows cuz i want to change things in it , And i just wanna use command not installing shity programs or program the shit, btw someone tested the windows 10 new windows linux terminal native to do this stuff?


Last edited by IDNO at 18 June 2016 at 1:56 pm UTC
7IJ7o 2 September 2016 at 5:02 am UTC
Nice, very nice. Thank you @liamdawe finally a solution to solve the screentearing which works for me.
  Go to:
While you're here, please consider supporting GamingOnLinux on Patreon or Liberapay. We have no adverts, no paywalls, no timed exclusive articles. Just good, fresh content. Without your continued support, we simply could not continue!

We also accept Paypal donations and subscriptions! If you already are, thank you!
Livestreams & Videos
Community Livestreams
  • Friday Livestream with Samsai
  • Date:
See more!
Popular this week
View by Category
Contact
Latest Comments
Latest Forum Posts