nvidia-xrun solution on hybrid graphic + tearing free

This is a post on setting up nvidia drivers on laptop with hybrid graphic cards.

config:

- OS: Archlinux
- Graphic: nvidia GeForce 960m + Intel HD Graphics 530
- i3 as window manager
- startx  (xorg-xinit)

packages to install:

- nvidia
- bbswitch
- nvidia-xrun or nvidia-xrun-git (AUR)

Before setup /etc/X11/nvidia-xorg.conf.d/30-nvidia.conf

Section "Device"
    Identifier "nvidia"
    Driver "nvidia"
    BusID "PCI:1:0:0"
EndSection

Make sure the BusID matches the result of

$ lspci | grep -i nvidia | awk '{print $1}'

Run Window manager with nvidia-xrun

In my case, I simply modified my .xinitrc file into a shell script and put it somewhere in PATH

it’s something like this:

xinit_i3

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/sh

# fcitx input
export XIM=fcitx
export XIM_PROGRAM=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS=@im=fcitx
export GTK_IM_MODULE=fcitx
fcitx -d 

# swap caps
setxkbmap -option caps:swapescape

# some variables

export TERMINAL="st"
export BROWSER="firefox"
export EDITOR=nvim

# background
fehbg &
xset r rate 300 50 
xrandr --dpi 130


# exec dwm
# prime-offload
exec i3

Now intead of using startx, use command nvidia-xrun xinit_i3 to start X with nvidia graphic card.

Avoid Screen Tearing

for intel graphic only, screen tearing can be avoided by adding or modifying this file:

/etc/X11/xorg.conf.d/20-intel.conf
----------------------------------
Section "Device"
  Identifier "Intel Graphics"
  Driver "intel"
  Option "TearFree" "true"
EndSection

For nvidia, we need to set the parameter modeset of module nvidia_drm to 1.

Sadly, this parameter can not be modified in runtime, which mean the vsync feature can only be tweaked upon loading the nvidia_drm module.

nvidia-xrun loads the nvidia related modules when they are unloaded yet. So modify the nvidia-xrun config file:

1
2
3
4
/etc/default/nvidia-xrun
---------------------------------
# CHANGE THE LINE "MODULES_LOAD" into:
MODULES_LOAD=(nvidia nvidia_uvm nvidia_modeset "nvidia_drm modeset=1")

Now there is still a problem: before calling nvidia-xrun, the nvidia* modules has already been loaded by OS without the modeset parameter, so the nvidia-xrun will not do anything to the modules.

So there are 2 ways to deal with this

1.add something to modprob config: so that the modeset=1 parameter will be set when loading nvidia_drm.

/lib/modprobe.d/nvidia-drm-modeset.conf
---------------------------------------
options nvidia-drm modeset=1

2.the hacky but easy way: edit the nvidia-xrun script, so that it tries to unload the preloaded modules first, then loads the modules itself with correct parameter.

/usr/bin/nvidia-xrun (PARTIAL)

# >>> unload the preloaded modules first. <<<
unload_modules
load_modules
execute ${COMMAND}
unload_modules

REF

https://wiki.archlinux.org/index.php/NVIDIA
https://wiki.archlinux.org/index.php/NVIDIA_Optimus
https://wiki.archlinux.org/index.php/Nvidia-xrun

Nov 18, 2020


[+] click to leave a comment [+]
the comment system on this blog works via email. The button
below will generate a mailto: link based on this page's url 
and invoke your email client - please edit the comment there!

[optional] even better, encrypt the email with my public key

- don't modify the subject field
- specify a nickname, otherwise your comment will be shown as   
  anonymous
- your email address will not be disclosed
- you agree that the comment is to be made public.
- to take down a comment, send the request via email.

>> SEND COMMENT <<




Fun with Image Maps and SVGs via benji February 20, 2024

Over the past few weeks I've been playing around with making some images on my website interactive. My "informatics" class in high school taught us some basic HTML. By basic I mean in notepad and writing everything by hand, saving to a...

Goblin Week 2024 via Helvetica Blanc January 26, 2024

It snuck up on me, but I managed to draw my little goblins to celebrate the week! I love my children - they're like awful Pikmin. I've uploaded the whole parade as a print, as well as individual prints for each goblin. There's something very fu…

How to trust gpg keys via Travis Shears Personal Site October 27, 2023

After moving some GPG keys to a new computer I kept getting these trust warnings. It is NOT certain that the key belongs to the person named in the user ID.If you * really * know what you are doing, you may answer the next question with yes. Use this key a…

Generated by openring from webring