5

I installed Ubuntu 19.04 on my PC:

  • INTEL i7 8700k
  • NVIDIA Gigabyte GeForce GTX 1080 Ti AORUS Waterforce @NVIDIA-driver-418
  • Monitor ASUS PB287Q @3840x2160 Pixel

At the very beginning of using Ubuntu I noticed this annoying screen tearing. I thought that is was only in Firefox, but when I shook the window I saw a horizontal line that broke the window in two parts (the tearing). It happens in every kind of window or application. I read a lot and this is what I have done so far:

  • Enable fractional scaling, because I couldn't read at 100% and it killed me at 200%.
    I set it to 150 %: gsettings set org.gnome.mutter experimental-features "['x11-randr-fractional-scaling']"
  • ForceFullCompositionPipeline to On. First in nvidia-settings, later in /usr/share/X11/xorg.conf.d/10-nvidia.conf, because I noticed that a reboot or a shutdown will reset the setting.

Output of nvidia-settings -q CurrentMetaMode:

Attribute 'CurrentMetaMode' (EST:1.0): id=50, switchable=yes, source=RandR ::
  DPY-7: nvidia-auto-select @5120x2880 +0+0
  {Transform=(1.333328,0.000000,0.000000,0.000000,1.333328,0.000000,0.000000,0.
  000000,1.000000), ViewPortIn=5120x2880, ViewPortOut=3840x2160+0+0,
  ResamplingMethod=Bilinear, ForceCompositionPipeline=On,
  ForceFullCompositionPipeline=On}

I attached my 10-nvidia.conf. It is very strange that if I fire this, the tearing is immediately fixed, but I need to reapply it from time to time even if I set up my 10-nvidia.conf:

sudo nvidia-settings --assign CurrentMetaMode="nvidia-auto-select
  @5120x2880 +0+0 { ViewPortIn=5120x2880, ViewPortOut=3840x2160+0+0,
  ResamplingMethod=Bilinear, ForceCompositionPipeline=On,
  ForceFullCompositionPipeline=On }"

1 Answers1

3

I guess I finally found a solution for myself. With the steps below I was able to get a tearing free experience and setting up my HiDPI display to get readable content. I wanted to avoid GNOME scaling mode under settings and display devices (see issues below between GNOME and NVIDIA) and to solve the scaling by setting up the DPI correctly. It didn't work out the way I imagined it would (the DPI scaling, tearing is fixed), however I am looking for your feedback. Maybe it can be made to work after all.

I had to deal with the following problems:

  • After installation of Ubuntu, I was unable to read anything on my display. Using a 4k display at 28" needed a HiDPI setup without using binoculars.
  • Setting up a scaling in Gnome Settings Menu to 200 was too much and 100 not acceptable. Fractional Scaling was OK.
  • Next thing was the tearing. Everything felt choppy and all windows had this horizontal line of doom. So I set up a 10-nvidia.conf.
  • 10-nvidia.conf only fixed it partly as from time to time after a restart or a shutdown the tearing was back.
  • Gnome Scaling and the NVIDIA driver interfered with each other.
    • I noticed that my screen went black for some seconds when I opened nvidia-settings.
    • Flameshot (the screenshot App) was not working as the screen went black when I tried to take a screenshot. Hitting Esc to end the "take screenshot" action made the screen appear again.
    • I wanted to use a icc-color-profile for my monitor and sometimes it was applied and sometimes not. I noticed the slight change in color.
  • When I applied a scaling in Gnome Settings, I noticed that ViewPortIn in nvidia-settings changed to 5120x2880 even if I have 3840x2160. This is related to how DPI scaling is done in Gnome (correct me if I am wrong). Interestingly if I changed ViewPortIn to 3840x2160 (equal to scaling 100 %) Flameshot was working again.
  • Nightmode was not working, as soon as it got activated it was disabled by just launching the file manager or it happened because of other random reasons.

However with all those problems in mind I wanted to set everything back to default and start over again.

  • I removed everything in 10-nvidia.conf except the initial Section "OutputClass"
  • I executed sudo nvidia-settings navigated to "X Server Display Configuration", selected "Configuration" and chose "Disabled". I confirmed the dialog and chose to apply as much as it can. I did the same with nvidia-settings afterwards (executed without root after closing NVIDIA settings), to be safe.
  • Back in Gnome settings I selected a scaling of 100 % and executed gsettings reset org.gnome.mutter experimental-features to disable fractional scaling.

A reboot and several google requests later, I wanted to have a setup that would avoid Gnome's Scaling and doing all that DPI stuff in the NVIDIA driver.


Setting up 10-nvidia.conf:
I got the basics for that file by opening nvidia-settings -> "X Server Display Configuration" -> "Save to X Configuration File" -> "Show preview..." and copying all that stuff.
With sudo gedit /usr/share/X11/xorg.conf.d/10-nvidia.conf I pasted the sections of "Show preview..." to the existing content. DO NOT REPLACE.

I then added/edited the following content (don't copy and paste my file:):

  • To actually fix tearing, that is the magic [reference]:
    Option "metamodes" "nvidia-auto-select +0+0 {ForceCompositionPipeline=On}"
  • I then wanted to set up DPI scaling:
    Option "DPI" "161 x 158"
    I thought that if I set it up correctly, I would get a correct DPI scaling by doing this:
    • It is very likely that xdpyinfo | grep -B2 resolution will output resolution: 96x96 dots per inch, but that is not actually the correct DPI. With whtyger's post I calculated my DPI:
      randr | grep -w connected DP-4 connected primary 3840x2160+0+0 (normal left inverted right x axis y axis) 621mm x 341mm
    • The calculation:
      x = 62,1 cm
      y = 34,1 cm

      x = 62,1 cm / 2,54 = 24,4488 size in inches
      y = 34,1 cm / 2,54 = 13,4252 size in inches

      x = 3860 px / 24,4 inches = 158,1972 DPI
      y = 2160 px / 13,4 inches = 161,1940 DPI
    • Unfortunately either I forgot something or my way to apply a proper DPI scaling is not working. However I still had to pinch my eyes together (small font size).
    • I executed xrandr --dpi 144 to set DPI scaling to 144 %. The PC didn't react after the command. Strg + Alt + F1 brought me to login screen and I was able to log in again where I got my 144 DPI. However it didn't changed the scaling factor of UI elements.
    • I still didn't want to use GNOME scaling and so I used GNOME Tweak Tool to increase Font scaling. With the formula desired_DPI / 96 I got my 1,50 scaling factor (144 DPI / 96). Most desktop and application elements are readable now and I avoid using the GNOME scaling mode under display devices.
    • I added Option "Composite" "Enable" and hoped to get a better performance with no tearing. With the magic fix in place, I didn't notice any better performance as the tearing is already fixed with ForceCompositionPipeline
    • with sudo nvidia-settings I navigated to "OpenGL Settings" and disabled "Sync to VBlank" and activated "Allow Flipping".


Final thoughts:

The overall feeling is much better and tearing is dead. However I still can not believe that a 60 Hz is that slow. So when I shake windows like crazy hell, I still see a lot of ghosting of the window. I am able to use Flameshot again! If I use nightmode and I start nvidia-settings, the nightmode ends as something interfere with that mode. Luckily Windows is fighting the same battle.
I hope that I didn't write too much and that I could help one or the other with his problem. I am looking forward to feedback.


References:
How to Enable Fractional Scaling in Ubuntu 19.04
How to Handle a Hi-Dpi Screen in Linux
How to find and change the screen DPI?
GNOME Tweak Tool
HiDPI
Nvidia proprietary driver DPI settings
Xorg
Screen tearing with a newer nVidia GPU


10-nvidia.conf - DO NOT COPY/PASTE:

Section "OutputClass"
    Identifier "nvidia"
    MatchDriver "nvidia-drm"
    Driver "nvidia"
    Option "AllowEmptyInitialConfiguration"
    ModulePath "/usr/lib/x86_64-linux-gnu/nvidia-418/xorg"
EndSection

Section "Module"
    Load           "dbe"
    Load           "extmod"
    Load           "type1"
    Load           "freetype"
    Load           "glx"
EndSection

Section "Monitor"
    # HorizSync source: edid, VertRefresh source: edid
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "Ancor Communications Inc ASUS PB287Q"
    HorizSync       24.0 - 160.0
    VertRefresh     30.0 - 80.0
    Option         "DPMS"
    Option         "DPI" "161 x 158"
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BoardName      "GeForce GTX 1080 Ti"
    Option         "UseEdidDpi" "False"
    Option         "DPI" "161 x 158"
    EndSection

Section "Screen"
    Identifier     "Screen0"
    Device         "Device0"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "Stereo" "0"
    Option         "nvidiaXineramaInfoOrder" "DFP-7"
    Option         "metamodes" "nvidia-auto-select +0+0 {ForceCompositionPipeline=On}"
    Option         "SLI" "Off"
    Option         "MultiGPU" "Off"
    Option         "BaseMosaic" "off"
    SubSection     "Display"
        Depth       24
        Modes       "3840x2160"
    EndSubSection
EndSection

Section "Extensions"
    Option         "Composite" "Enable"
EndSection