netbrain / zwift

Easily zwift on linux
The Unlicense
241 stars 27 forks source link

Provide a way to choose gpu? #153

Open netbrain opened 1 month ago

netbrain commented 1 month ago

NixOs nvidia-container-toolkit have been broken for some time now, atleast on my machine.

So when running zwift i get

❯ DEBUG=1 zwift 
+ [[ -f /home/netbrain/.config/zwift/config ]]
+ ZWIFT_CONFIG_FLAG='--env-file /home/netbrain/.config/zwift/config'
+ source /home/netbrain/.config/zwift/config
++ ZWIFT_USERNAME=xxx
++ ZWIFT_PASSWORD=xxx
++ ZWIFT_GID=1000
++ ZWIFT_UID=1000
+ [[ -f /home/netbrain/.config/zwift/netbrain-config ]]
+ [[ ! -z '' ]]
+ WINDOW_MANAGER=Other
+ IMAGE=docker.io/netbrain/zwift
+ VERSION=latest
+ NETWORKING=bridge
+ ZWIFT_UID=1000
+ ZWIFT_GID=1000
+ '[' '!' ']'
++ command -v podman
+ '[' -x '' ']'
+ CONTAINER_TOOL=docker
+ '[' docker == podman ']'
+ LOCAL_UID=1000
+ CONTAINER_UID=1000
+ CONTAINER_GID=1000
+ case "$XDG_SESSION_TYPE" in
+ WINDOW_MANAGER=Wayland
+ '[' Wayland = Wayland ']'
+ '[' -z ']'
+ WINDOW_MANAGER=XWayland
++ id -u
+ '[' 1000 -ne 1000 ']'
+ [[ ! -n '' ]]
++ curl -s https://raw.githubusercontent.com/netbrain/zwift/master/zwift.sh
++ sha256sum
++ awk '{print $1}'
+ REMOTE_SUM=732988328e5b86a1174a828a9915f225b024b235d625867a8d2fc092dc09b76f
++ sha256sum /home/netbrain/.local/bin/zwift
++ awk '{print $1}'
+ THIS_SUM=732988328e5b86a1174a828a9915f225b024b235d625867a8d2fc092dc09b76f
+ '[' 732988328e5b86a1174a828a9915f225b024b235d625867a8d2fc092dc09b76f = 732988328e5b86a1174a828a9915f225b024b235d625867a8d2fc092dc09b76f ']'
+ echo 'You are running latest zwift.sh 👏'
You are running latest zwift.sh 👏
+ [[ ! -n '' ]]
+ docker pull docker.io/netbrain/zwift:latest
latest: Pulling from netbrain/zwift
Digest: sha256:dbe6ed2ac21eff667ad277bc42c2c66e6fb06fa2341a5ebc125b28ed7c8e5b55
Status: Image is up to date for netbrain/zwift:latest
docker.io/netbrain/zwift:latest
+ GENERAL_FLAGS=(-d --rm --privileged --network $NETWORKING --name zwift-$USER --security-opt label=disable --hostname $HOSTNAME -e DISPLAY=$DISPLAY -e ZWIFT_UID=$CONTAINER_UID -e ZWIFT_GID=$CONTAINER_GID -e PULSE_SERVER=/run/user/$CONTAINER_UID/pulse/native -v zwift-$USER:/home/user/.wine/drive_c/users/user/Documents/Zwift -v /run/user/$LOCAL_UID/pulse:/run/user/$CONTAINER_UID/pulse)
+ [[ -f /proc/driver/nvidia/version ]]
+ [[ docker == \p\o\d\m\a\n ]]
+ VGA_DEVICE_FLAG=--gpus=all
+ [[ -n unix:path=/run/user/1000/bus ]]
+ [[ unix:path=/run/user/1000/bus =~ ^unix:path=([^,]+) ]]
+ DBUS_UNIX_SOCKET=/run/user/1000/bus
+ [[ -n /run/user/1000/bus ]]
+ DBUS_CONFIG_FLAGS=(-e DBUS_SESSION_BUS_ADDRESS=$(echo $DBUS_SESSION_BUS_ADDRESS | sed 's/'$LOCAL_UID'/'$CONTAINER_UID'/') -v $DBUS_UNIX_SOCKET:$(echo $DBUS_UNIX_SOCKET | sed 's/'$LOCAL_UID'/'$CONTAINER_UID'/'))
++ echo unix:path=/run/user/1000/bus
++ sed s/1000/1000/
++ echo /run/user/1000/bus
++ sed s/1000/1000/
+ '[' XWayland == Wayland ']'
+ '[' XWayland == XWayland ']'
+ '[' -z ']'
+ WM_FLAGS=(-v /tmp/.X11-unix:/tmp/.X11-unix)
+ '[' XWayland == XOrg ']'
+ '[' docker == podman ']'
++ docker run -d --rm --privileged --network bridge --name zwift-netbrain --security-opt label=disable --hostname netwrk -e DISPLAY=:0 -e ZWIFT_UID=1000 -e ZWIFT_GID=1000 -e PULSE_SERVER=/run/user/1000/pulse/native -v zwift-netbrain:/home/user/.wine/drive_c/users/user/Documents/Zwift -v /run/user/1000/pulse:/run/user/1000/pulse --env-file /home/netbrain/.config/zwift/config --gpus=all -e DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus -v /run/user/1000/bus:/run/user/1000/bus -v /tmp/.X11-unix:/tmp/.X11-unix docker.io/netbrain/zwift:latest
docker: Error response from daemon: could not select device driver "" with capabilities: [[gpu]].
+ CONTAINER=9d5d178211d9686800c5feca421528be6b885cd8558765c2f51bf7fc903300d2
+ '[' 125 -ne 0 ']'
+ msgbox error 'Error can'\''t run zwift, check variables!' 10
+ TYPE=error
+ MSG='Error can'\''t run zwift, check variables!'
+ TIMEOUT=10
+ RED='\033[0;31m'
+ NC='\033[0m'
+ BOLD='\033[1m'
+ UNDERLINE='\033[4m'
+ case $1 in
+ echo -e '\033[0;31m\033[1m\033[4mError - Error can'\''t run zwift, check variables!\033[0m'
Error - Error can't run zwift, check variables!
+ '[' 10 -eq 0 ']'
+ sleep 10
+ exit 0

However as i have a laptop with dual video cards (nvidia/intel) if i run the docker command without the --gpus=all it will choose to run on my intel card instead, and work just fine albeit with less framerate.

So this got me thinking, maybe we should provide a way to choose which graphics system to try to run the container with?

WDYT @sHedC ?

sHedC commented 1 month ago

At the moment it checks if you have an NVidia driver installed then uses that, else it just uses /dev/dri. So skipping hte Nvidia card is easy by variable then selecting the dri card could be done maybe with switcheroo (in the container?)

Maybe install switcheroo in the container and see if it can be used to select the GPU with everything passed through.

NVidia drivers on linux are still not great and not good under wayland yet although better.