# Nvidia Optimus + screen tearing + sync to vblank

## Arthanis

I'm using proprietary nvidia-drivers with optimus support, and I notice severe screen tearing (like there is no vertical sync at all), and when I run nvidia-settings, there is no sync to vblank option (to set vertical sync). Is there any way to enable it? If not, does that work using bumblebee/primus ? Thanks in advance.

----------

## Arthanis

Well, here is what I discovered so far:

Xfce4 compositor doesn't support vsync, so no matter if I use bumblebee, primus, intel or nvidia, even though glxgears tells me that vsync is enabled (fps limited to 60), I get screen tearing. So, to that end, I just installed compton and it solved the problem with the intel driver and with primus/bumblebee.

The problem is that, at least here, primus/bumblebee gives me a serious performance hit, so I would like to use nvidia-only. But when I enable nvidia-only, there is no vsync at all. Does anyone know why?

```

claudio@g1310max ~ $ glxgears 

29850 frames in 5.0 seconds = 5969.593 FPS

33478 frames in 5.0 seconds = 6695.498 FPS

```

I also tried enabling triple buffering by adding these entries in my xorg.conf in each Device:

```

Section "Device" 

Identifier   "nvidia" 

Driver   "nvidia" 

BusID   "PCI:1:0:0" 

Option "TripleBuffer" "True"

EndSection 

Section "Device" 

Identifier   "intel" 

Driver   "modesetting" 

BusID   "PCI:0:2:0" 

Option "TripleBuffer" "True"

EndSection 

```

As well as adding in /etc/environment :

```

CLUTTER_PAINT=disable-clipped-redraws:disable-culling

CLUTTER_VBLANK=True

```

And these entries in ~/.nvidia-settings-rc

```

0/SyncToVBlank=1

0/AllowFlipping=1

```

All to no avail. Thanks in advance.

----------

## mf2

I have no idea how NVIDIA Optimus work, but if it uses the standard nvidia driver you will need to export the nvidia-specific env variables:

```

__GL_SYNC_TO_VBLANK=1

__GL_SYNC_DISPLAY_DEVICE="DVI-D-0"

```

I am actually not sure if one needs to put something like "DVI-D-0" (display name by xrandr) or "DFP-0" (display name by nvidia driver) into the __GL_SYNC_DISPLAY_DEVICE variable.

Anyway, you can read more about this in the nvidia driver doc, chapter 11 (should have been installed with the driver into /usr/doc).[/code]

----------

## Arthanis

Thanks for the reply. Well, I tried this at /etc/environment:

```

__GL_SYNC_TO_VBLANK=True

__GL_SYNC_DISPLAY_DEVICE="NVIDIA-0" 

```

As my .xinitrc is the following:

```

xrandr --setprovideroutputsource modesetting NVIDIA-0

xrandr --auto

exec ck-launch-session startxfce4

```

And:

```

xrandr --listproviders

Providers: number : 2

Provider 0: id: 0x1f5 cap: 0x1, Source Output crtcs: 0 outputs: 0 associated providers: 1 name:NVIDIA-0

Provider 1: id: 0x46 cap: 0x2, Sink Output crtcs: 3 outputs: 4 associated providers: 1 name:modesetting

```

[/code]

But taken from nvidia documentation:

 *Quote:*   

> 
> 
> You can use the environment variable __GL_SYNC_DISPLAY_DEVICE to specify to which display device OpenGL should sync. You should set this environment variable to the name of a display device; for example "CRT-1". Look for the line "Connected display device(s):" in your X log file for a list of the display devices present and their names.
> 
> 

 

But when I do it, I get nothing relevant:

```

[    15.693] (II) NVIDIA(0): Creating default Display subsection in Screen section

[    15.693] (**) NVIDIA(0): Option "UseDisplayDevice" "none"

[    15.694] (**) NVIDIA(0): Option "UseDisplayDevice" set to "none"; enabling NoScanout

[    16.044] (--) NVIDIA(0): Valid display device(s) on GeForce GTX 860M at PCI:1:0:0

[    16.044] (WW) NVIDIA(0): Unable to get display device for DPI computation.

[    16.060] (II) modesetting(G0): Output DisplayPort-1-0 has no monitor section

[    16.060] (II) modesetting(G0): Digital Display Input

[    16.060] (II) modesetting(G0): Digital interface is DisplayPort

[    16.076] (II) modesetting(G0): EDID for output DisplayPort-1-0

[    16.079] (WW) modesetting(G0): Option "UseDisplayDevice" is not used

```

Or:

```

grep -ir device /var/log/Xorg.0.log

[    15.564] (**) |   |-->Device "nvidia"

[    15.564] (**) |-->Inactive Device "intel"

[    15.564] (==) Automatically adding devices

[    15.564] (==) Automatically enabling devices

[    15.564] (==) Automatically adding GPU devices

[    15.566] (II) The server relies on udev to provide the list of input devices.

   If no devices become available, reconfigure udev or disable AutoAddDevices.

[    15.566] (II) xfree86: Adding drm device (/dev/dri/card1)

[    15.566] (II) xfree86: Adding drm device (/dev/dri/card0)

[    15.693] (**) NVIDIA(0): Option "UseDisplayDevice" "none"

[    15.694] (**) NVIDIA(0): Option "UseDisplayDevice" set to "none"; enabling NoScanout

[    16.044] (--) NVIDIA(0): Valid display device(s) on GeForce GTX 860M at PCI:1:0:0

[    16.044] (WW) NVIDIA(0): Unable to get display device for DPI computation.

[    16.079] (WW) modesetting(G0): Option "UseDisplayDevice" is not used

[    18.399] (II) config/udev: Adding input device Power Button (/dev/input/event3)

[    18.400] (**) evdev: Power Button: Device: "/dev/input/event3"

[    18.400] (**) Option "config_info" "udev:/sys/devices/LNXSYSTM:00/LNXPWRBN:00/input/input3/event3"

[    18.400] (II) XINPUT: Adding extended input device "Power Button" (type: KEYBOARD, id 6)

[    18.412] (II) config/udev: Adding input device Video Bus (/dev/input/event5)

[    18.412] (**) evdev: Video Bus: Device: "/dev/input/event5"

[    18.412] (**) Option "config_info" "udev:/sys/devices/LNXSYSTM:00/device:00/PNP0A08:00/LNXVIDEO:01/input/input5/event5"

[    18.412] (II) XINPUT: Adding extended input device "Video Bus" (type: KEYBOARD, id 7)

[    18.412] (II) config/udev: Adding input device Video Bus (/dev/input/event4)

[    18.412] (**) evdev: Video Bus: Device: "/dev/input/event4"

[    18.412] (**) Option "config_info" "udev:/sys/devices/LNXSYSTM:00/device:00/PNP0A08:00/device:4d/LNXVIDEO:00/input/input4/event4"

[    18.412] (II) XINPUT: Adding extended input device "Video Bus" (type: KEYBOARD, id 8)

[    18.413] (II) config/udev: Adding input device Power Button (/dev/input/event0)

[    18.413] (**) evdev: Power Button: Device: "/dev/input/event0"

[    18.413] (**) Option "config_info" "udev:/sys/devices/LNXSYSTM:00/device:00/PNP0C0C:00/input/input0/event0"

[    18.413] (II) XINPUT: Adding extended input device "Power Button" (type: KEYBOARD, id 9)

[    18.413] (II) config/udev: Adding input device Lid Switch (/dev/input/event2)

[    18.413] (II) No input driver specified, ignoring this device.

[    18.413] (II) This device may have been added with another device file.

[    18.413] (II) config/udev: Adding input device Sleep Button (/dev/input/event1)

[    18.413] (**) evdev: Sleep Button: Device: "/dev/input/event1"

[    18.413] (**) Option "config_info" "udev:/sys/devices/LNXSYSTM:00/device:00/PNP0C0E:00/input/input1/event1"

[    18.413] (II) XINPUT: Adding extended input device "Sleep Button" (type: KEYBOARD, id 10)

[    18.413] (II) config/udev: Adding drm device (/dev/dri/card1)

[    18.413] (II) config/udev: Adding drm device (/dev/dri/card0)

[    18.413] (II) config/udev: Adding input device HDA Intel HDMI HDMI (/dev/input/event8)

[    18.413] (II) No input driver specified, ignoring this device.

[    18.413] (II) This device may have been added with another device file.

[    18.414] (II) config/udev: Adding input device HDA Intel PCH Mic (/dev/input/event10)

[    18.414] (II) No input driver specified, ignoring this device.

[    18.414] (II) This device may have been added with another device file.

[    18.414] (II) config/udev: Adding input device HDA Intel PCH Front Headphone (/dev/input/event9)

[    18.414] (II) No input driver specified, ignoring this device.

[    18.414] (II) This device may have been added with another device file.

[    18.414] (II) config/udev: Adding input device AT Translated Set 2 keyboard (/dev/input/event6)

[    18.414] (**) evdev: AT Translated Set 2 keyboard: Device: "/dev/input/event6"

[    18.414] (**) Option "config_info" "udev:/sys/devices/platform/i8042/serio0/input/input6/event6"

[    18.414] (II) XINPUT: Adding extended input device "AT Translated Set 2 keyboard" (type: KEYBOARD, id 11)

[    18.414] (II) config/udev: Adding input device SynPS/2 Synaptics TouchPad (/dev/input/event7)

[    18.415] (**) Option "Device" "/dev/input/event7"

[    18.435] (II) synaptics: SynPS/2 Synaptics TouchPad: ignoring touch events for semi-multitouch device

[    18.445] (**) Option "config_info" "udev:/sys/devices/platform/i8042/serio2/input/input12/event7"

[    18.445] (II) XINPUT: Adding extended input device "SynPS/2 Synaptics TouchPad" (type: TOUCHPAD, id 12)

[    18.446] (II) config/udev: Adding input device SynPS/2 Synaptics TouchPad (/dev/input/mouse0)

[    18.446] (**) SynPS/2 Synaptics TouchPad: Ignoring device from InputClass "touchpad ignore duplicates"

```

Any tips on finding the device to sync? Thanks in advance

----------

## Roman_Gruber

http://wiki.gentoo.org/wiki/NVIDIA_Driver_with_Optimus_Laptops

----------

## Arthanis

 *Quote:*   

> 
> 
> http://wiki.gentoo.org/wiki/NVIDIA_Driver_with_Optimus_Laptops
> 
> 

 

Well, I used that guide to get optimus running in first place, but how does this address my issue?

----------

## Xywa

 *Arthanis wrote:*   

> I'm using proprietary nvidia-drivers with optimus support, and I notice severe screen tearing (like there is no vertical sync at all), and when I run nvidia-settings, there is no sync to vblank option (to set vertical sync). Is there any way to enable it? If not, does that work using bumblebee/primus ? Thanks in advance.

 

Hi,

I have the same problem. I used to use bumblebee + primusrum, and there was no tearing (especially in games).

Now I have the proper optimus driver, there is more fps in games, but terrible tearing. The guys who made primus were known about fantastic performance with tearing (in comparation to eg. optirun), so maybe we should ask them how to configure nvidia without bumblebee, so we could have no tearing?

I have (works in Mint):

```
$ cat /etc/environment 

#

# This file is parsed by pam_env module

#

# Syntax: simple "KEY=VAL" pairs on separate lines

#

CLUTTER_PAINT=disable-clipped-redraws:disable-culling

CLUTTER_VBLANK=True
```

```
$ cat .xinitrc 

xrandr --setprovideroutputsource modesetting NVIDIA-0

xrandr --auto

exec startkde
```

```
$ xrandr --listproviders 

Providers: number : 2

Provider 0: id: 0x2b0 cap: 0x1, Source Output crtcs: 2 outputs: 1 associated providers: 1 name:NVIDIA-0

Provider 1: id: 0x45 cap: 0x2, Sink Output crtcs: 2 outputs: 4 associated providers: 1 name:modesetting

```

UPDATE

I have found this:

 *Quote:*   

> When prime is enabled, there is currently no synchronization between the source device producing the pixels and the sink device reading them. I.e., in a typical NVIDIA + Intel configuration, the Intel chip just scans out the shared buffer constantly, without regard to when the pixels are copied into it.
> 
>  *Quote:*   The README mentions this in Chapter 32, "Offloading Graphics Display with RandR 1.4":
> 
> Caveats
> ...

 

https://devtalk.nvidia.com/default/topic/775691/vsync-issue-nvidia-prime-ux32vd-with-gt620-m-/

----------

## arosboro

Hi,

I see ubuntu users have an nvidia-prime package https://github.com/tseliot/nvidia-prime that allows them to switch graphics between intel and nvidia (saving battery) and configure monitors with nvidia-settings.

Is it possible to use something like these binaries in gentoo?

It adds a prime section to nvidia-settings that you can turn on.  My friend uses ubuntu, and it seems he does not have any tearing issues.  He can use hdmi as well, and has 3 monitors working without issue.

----------

## Xywa

Hi,

Any news how to fix tearing on nvidia optimus cards? Any new driver or other solution?

----------

## Xywa

 *Arthanis wrote:*   

> I'm using proprietary nvidia-drivers with optimus support, and I notice severe screen tearing (like there is no vertical sync at all), and when I run nvidia-settings, there is no sync to vblank option (to set vertical sync). Is there any way to enable it? If not, does that work using bumblebee/primus ? Thanks in advance.

 

Looks like tearing with Nvidia Optimus will be fixed in 4.5 kernel:

https://devtalk.nvidia.com/default/topic/775691/linux/vsync-issue-nvidia-prime-ux32vd-with-gt620-m-/4

----------

