Update 08/09/2019:
It seems that gord0 (OP) is right in his comment. You don't need to go through all of the steps that I had previously described (I'm not deleting them, just in case that someone find's them helpful) to get rid of tearing.
What you have to do to is:
Open NVIDIA X Server Settings.
Go to X Server Display Configuration.
Select the screen that you want.
Click the Advanced button.
Enable Force Composition Pipeline or Force Full Composition Pipeline (try both and enable the one that gives you the best results).
Click the Apply button.
Alternatively, you can enable Force Composition Pipeline or Force Full Composition Pipeline by running the following commands in your terminal:
For Force Composition Pipeline:
nvidia-settings --assign CurrentMetaMode="$(xrandr | sed -nr '/(\S+) connected (primary )?([0-9]+x[0-9]+)(\+\S+).*/{ s//\1: \3 \4 { ForceCompositionPipeline = On }, /; H}; ${ g; s/\n//g; s/, $//; p }')"
For Force Full Composition Pipeline:
nvidia-settings --assign CurrentMetaMode="$(xrandr | sed -nr '/(\S+) connected (primary )?([0-9]+x[0-9]+)(\+\S+).*/{ s//\1: \3 \4 { ForceFullCompositionPipeline = On }, /; H}; ${ g; s/\n//g; s/, $//; p }')"
These commands use xrandr
and sed
with some regular expressions to get the current monitor setup in the appropriate format and use it as input to the nvidia=settings --assign
command, which enables the desired setting.
You should now have no screen tearing.
In case the changes are not persistent and get discarded after reboot, you can do the following:
Run the appropriate, for your case, command from the commands above and make sure that it works correctly, that is you have no screen tearing in your monitors.
Add one of the following commands (depending on what worked best for you) to your startup applications:
For Force Composition Pipeline:
bash -c "sleep 10 && nvidia-settings --assign CurrentMetaMode=\"$(xrandr | sed -nr '/(\S+) connected (primary )?([0-9]+x[0-9]+)(\+\S+).*/{ s//\1: \3 \4 { ForceCompositionPipeline = On }, /; H}; ${ g; s/\n//g; s/, $//; p }')\""
For Force Full Composition Pipeline:
bash -c "sleep 10 && nvidia-settings --assign CurrentMetaMode=\"$(xrandr | sed -nr '/(\S+) connected (primary )?([0-9]+x[0-9]+)(\+\S+).*/{ s//\1: \3 \4 { ForceFullCompositionPipeline = On }, /; H}; ${ g; s/\n//g; s/, $//; p }')\""
The sleep 10
command just adds a 10-seconds delay to ensure that the desktop has fully loaded before running the nvidia=settings --assign
command. You may need to add a larger delay if your desktop takes more time to fully load.
Alternatively, you can save the configuration by clicking Save to X Configuration File button.
Old answer. Try these if the above method doesn't work for you.
What is suggested in the answer you posted is correct for Ubuntu 16.04.
For Ubuntu 18.04 and later versions, you have to change options nvidia_387_drm modeset=1
to options nvidia-drm modeset=1
(the Nvidia driver version is no longer needed).
So what you have to do for Ubuntu 18.04 and later versions is:
Create a file in your /etc/modprobe.d
directory called zz-nvidia-modeset.conf
.
Add the following lines to it:
#enable prime-sync
options nvidia-drm modeset=1
From the terminal run:
sudo update-initramfs -u
Reboot.
To enable the Nvidia adapter, after rebooting, you have to run
sudo prime-select nvidia
then log out and log back in.
Edit: If you are using Gnome, you will have to use another display manager, such as lightdm
, since gdm
does not allow external monitors to work with nomodeset=1
.
To install lightdm
run:
sudo apt install lightdm
After installing lightdm
run
sudo dpkg-reconfigure lightdm
and select it as your display manager in the terminal window that appears.
Best Answer
The solutions above do not work with Ubuntu 20.04 but the problem seems to persist. But the working solution is quite simple:
The original content of nvidia-kms.conf is:
As it says, modeset=0 has to be changed to modeset=1.
I wonder why this is not enabled from the beginning.