Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to choose gpu? #153

Open
netbrain opened this issue Aug 12, 2024 · 6 comments
Open

Provide a way to choose gpu? #153

netbrain opened this issue Aug 12, 2024 · 6 comments

Comments

@netbrain
Copy link
Owner

netbrain commented Aug 12, 2024

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
Copy link
Collaborator

sHedC commented Aug 12, 2024

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.

@RuneRoven
Copy link

RuneRoven commented Oct 26, 2024

I found a fix for this for now if you have the nvidia container toolkit working and dual GPUs.
in the zwift.sh just add:
-e __GLX_VENDOR_LIBRARY_NAME=nvidia
-e __NV_PRIME_RENDER_OFFLOAD=1
in the general flags. This will set the GPU for the current shell. Works fine for me with proprietary drivers.
For the open drivers there other environment variables to use

# Define Base Container Parameters
GENERAL_FLAGS=(
    --rm
    --privileged
    --network $NETWORKING
    --name zwift-$USER
    --security-opt label=disable
    --hostname $HOSTNAME

    -e __GLX_VENDOR_LIBRARY_NAME=nvidia 
    -e __NV_PRIME_RENDER_OFFLOAD=1
    -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
)

@netbrain
Copy link
Owner Author

I take it your are running dual GPU system?

@RuneRoven
Copy link

Yes, that is correct. Struggled for a while to get the Nvidia driver to work fully in my system but once i got the nvidia container toolkit running i was able to find a quite easy solution that don't require rebuilding the docker image. If not having the env flags set wine starts with the primary gpu which in my case is the built in intel.

@netbrain
Copy link
Owner Author

-e __GLX_VENDOR_LIBRARY_NAME=nvidia 
-e __NV_PRIME_RENDER_OFFLOAD=1

Should probably be documented in the readme somrwhere, or maybe even just always included as flags when a Nvidia card is detected in Zwift.sh

@RuneRoven
Copy link

i guess you could add it as optional env so one could add it in the settings file and let the run script include it if it is in the settings file so it not affects anything else. These are also only valid if you have the proprietary drivers from nvidia and not the open drivers for the newer gpus. for the open driver there are different env to use..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants