-
Notifications
You must be signed in to change notification settings - Fork 3
/
dgpu
executable file
·30 lines (30 loc) · 1.22 KB
/
dgpu
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
#!/usr/bin/env -S sh -eu
# This does basically the same thing as prime-run in Arch's nvidia-prime
# package, but does so more vendor-agnostically and carefully.
providers=$(xrandr --listproviders)
if printf %s\\n "$providers" | grep -Eqi 'nvidia-[0-9]'; then
# It turns out that it is no longer okay to export the prime offload
# variables when running NVidia-as-primary; this has recently started
# crashing Plasma.
exec "$@"
elif printf %s\\n "$providers" | grep -Eqi 'nvidia-g[0-9]'; then
export __NV_PRIME_RENDER_OFFLOAD=1
export __GLX_VENDOR_LIBRARY_NAME=nvidia
export __VK_LAYER_NV_optimus=NVIDIA_only
exec "$@"
# This doesn't account for the possiblity that an AMD GPU is integrated.
elif printf %s\\n "$providers" | grep -qi radeon; then
export DRI_PRIME=1
exec "$@"
# I figure it's safer to fail if a command needs a dGPU and it's not there
# for some reason, than for it to start on the iGPU and run like molasses.
# But if you do want to run the command anyways, set DGPU_NOFAIL.
else
if [ "${DGPU_NOFAIL:-}" ]; then
exec "$@"
else
notify-send "Discrete GPU Unavailable" "Can't run $*"
printf "Discrete GPU unavailable; can't run %s\n" "$*" >&2
exit 1
fi
fi