summaryrefslogtreecommitdiff
path: root/content/posts/optimus-void.md
blob: 6ae889cafbafc7e2e5195388177d8f51117e7458 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
title: "Using Optimus on Void or Non Systemd Distros"
date: 2019-09-13T12:10:56+05:30
description: This article is for those who are a victim of laptop vendors but want to squeeze out maximum performance of their machine.
draft: false
---

## What is optimus technology?
According to gentoo wiki
> NVIDIA Optimus is a proprietary technology that seamlessly switches between two GPUs. It is typically used on systems that have an integrated Intel GPU and a discrete NVIDIA GPU. The main benefit of using NVIDIA Optimus is to extend battery life by providing maximum GPU performance only when needed.

There is a great wiki about using bumblebee(not transformer) on void linux but bumblebee’s project last commit was in 2013 and it doesn’t support vulkan, so no luck for linux gamers. A better way is to use a utility like nvidia-prime which is available for ubuntu or optimus-manager which is available for arch-based distros(available in AUR). Sadly, these projects require systemd as a init system. There is only one project which uses shell script and partly depends on systemd but is pretty hackable - [nvidia-xrun](https://github.com/Witko/nvidia-xrun).

## Problem on void
libglvnd is broken in void repos which makes it hard to have multiple drivers from different vendors to coexist on the same filesystem. This results in having either openGL libraries from mesa or nvidia.

## The Hack
Install nvidia openGL libraries in /opt directory and point nvidia-xrun to use them. This is just a workaround of libglvnd.

First of all install these packages:
- nvidia-dkms - for kernel modules
- libGL libEGL - mesa drivers
- xrandr xorg - display server
- any wm/de

Create a file /etc/modprobe.d/nvidia.conf for blacklisting nvidia kernel modules so that they won’t be loaded at boot. Add the following text:
```
blacklist nvidia
blacklist nvidia-drm
blacklist nvidia-modeset
blacklist nvidia-uv
blacklist nouveau
```

Next create some directories
```shell
$ sudo mkdir /opt/nvidia
$ sudo mkdir -p /opt/nvidia/fakeroot/usr/lib
$ sudo mkdir -p /opt/nvidia/fakeroot/usr/lib32
$ sudo mkdir /etc/X11/nvidia
```

Now we have to create a fakeroot directory with nvidia openGL libraries
```shell
$ sudo ln -s /opt/nvidia/fakeroot/usr/lib /opt/nvidia/fakeroot/lib
$ sudo ln -s /opt/nvidia/fakeroot/usr/lib32 /opt/nvidia/fakeroot/lib32
$ sudo chmod 755 -R /opt/nvidia/fakeroot
$ xbps-install --rootdir /opt/nvidia/fakeroot --repository https://alpha.de.repo.voidlinux.org/current --repository https://alpha.de.repo.voidlinux.org/current/nonfree --repository https://alpha.de.repo.voidlinux.org/current/multilib --repository https://alpha.de.repo.voidlinux.org/current/multilib/nonfree --yes --sync nvidia nvidia-libs nvidia-libs-32bit
```

Next clone my repo and move the scripts to respective location
```shell
$ git clone https://github.com/fd0e/optimus-hack.git
$ cd optimus-hack/
$ sudo cp -r xorg.conf xorg.conf.d /etc/X11/nvidia/
$ sudo cp run.sh /opt/nvidia/
```

There is also off.sh which ensures that GPU is off. Run this as root at boot.

Also add these lines in your ~/.xinitrc.
```shell
# load additional configs
if [ "$2" = "nvidia" ]; then
	XINIT_D="/etc/X11/nvidia/xinit/xinitrc.d"
else
	XINIT_D="/etc/X11/xinit/xinitrc.d"
fi

if [ -d "$XINIT_D" ]; then
	for f in "$XINIT_D/?*.sh" ; do
		[ -x "$f" ] && . "$f"
	done
	unset f
fi
unset XINIT_D

# additional nvidia specific settings
if [ "$2" = "nvidia" ]; then	
	xrandr --setprovideroutputsource modesetting NVIDIA-0
	xrandr --auto
fi
```

Now close your X session and run /opt/nvidia/run.sh.

And boom! Your X session is now running on nvidia opengl libraries.

## Troubleshooting
If steam complains about missing libGL. Run steam using this command
```shell
$ STEAM_RUNTIME_PREFER_HOST_LIBRARIES=0 steam
```

## Conclusion
I don’t recommend using this method but this is the only thing that worked for me.

See this article for more details - [here](https://www.ifnull.org/articles/void_optimus_nvidia_intel/#disqus_thread)