Skip to content

Commit

Permalink
Remove GLX component. Always use VirtualGL rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
robballantyne committed Mar 11, 2024
1 parent 963d076 commit 1b0271b
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 278 deletions.
8 changes: 0 additions & 8 deletions build/COPY_ROOT/opt/ai-dock/bin/preflight.d/30-steam.sh

This file was deleted.

16 changes: 13 additions & 3 deletions build/COPY_ROOT/opt/ai-dock/bin/supervisor-kasmvnc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,22 @@ function start() {
fuser -k -SIGKILL ${LISTEN_PORT}/tcp > /dev/null 2>&1 &
wait -n

printf "Starting ${SERVICE_NAME}...\n"
/usr/bin/python3 /opt/ai-dock/fastapi/logviewer/main.py \
-p $LISTEN_PORT \
-r 5 \
-s "${SERVICE_NAME}" \
-t "Preparing ${SERVICE_NAME}" &
fastapi_pid=$!

until [ -S "/tmp/.X11-unix/X${DISPLAY/:/}" ]; do
printf "Waiting for X11 socket...\n"
while [[ -f /run/workspace_sync || -f /run/container_config || ! -S /run/dbus/system_bus_socket || ! -S "/tmp/.X11-unix/X${DISPLAY/:/}" ]]; do
printf "Waiting for X11 and container provisioning...\n"
sleep 1
done

kill $fastapi_pid &
wait -n

printf "Starting ${SERVICE_NAME}...\n"
source /opt/ai-dock/etc/environment.sh
sudo cp -f /usr/share/kasmvnc/kasmvnc_defaults.yaml.template \
/usr/share/kasmvnc/kasmvnc_defaults.yaml
Expand Down
27 changes: 15 additions & 12 deletions build/COPY_ROOT/opt/ai-dock/bin/supervisor-selkies-gstreamer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,23 @@ function start() {

fuser -k -SIGKILL ${LISTEN_PORT}/tcp > /dev/null 2>&1 &
wait -n
printf "Starting ${SERVICE_NAME}...\n"

/usr/bin/python3 /opt/ai-dock/fastapi/logviewer/main.py \
-p $LISTEN_PORT \
-r 5 \
-s "${SERVICE_NAME}" \
-t "Preparing ${SERVICE_NAME}" &
fastapi_pid=$!

until [[ -S /run/dbus/system_bus_socket ]]; do
printf "Waiting for dbus socket...\n"
while [[ -f /run/workspace_sync || -f /run/container_config || ! -S /run/dbus/system_bus_socket || ! -S "/tmp/.X11-unix/X${DISPLAY/:/}" ]]; do
printf "Waiting for X11 and container provisioning...\n"
sleep 1
done

until [ -S "/tmp/.X11-unix/X${DISPLAY/:/}" ]; do
printf "Waiting for X11 socket...\n"
sleep 1
done
kill $fastapi_pid &
wait -n

printf "Starting ${SERVICE_NAME}...\n"
source /opt/ai-dock/etc/environment.sh

sudo mkdir -pm755 /dev/input
Expand All @@ -73,10 +79,7 @@ function start() {
# Start the selkies-gstreamer WebRTC HTML5 remote desktop application

source /opt/gstreamer/gst-env
xmode="$(cat /tmp/.X-mode)"
if [[ $xmode == "proxy" ]]; then
selkies-gstreamer-resize ${SIZEW}x${SIZEH}
fi
selkies-gstreamer-resize ${SIZEW}x${SIZEH}

if [[ ${ENABLE_COTURN,,} == "true" ]]; then
export TURN_HOST="${TURN_HOST:-${EXTERNAL_IP_ADDRESS}}"
Expand All @@ -85,7 +88,7 @@ function start() {
export TURN_PASSWORD="${COTURN_PASSWORD:-password}"
fi

export LD_PRELOAD /usr/local/lib/selkies-js-interposer/joystick_interposer.so${LD_PRELOAD:+:${LD_PRELOAD}}
export LD_PRELOAD=/usr/local/lib/selkies-js-interposer/joystick_interposer.so${LD_PRELOAD:+:${LD_PRELOAD}}

selkies-gstreamer \
--enable_basic_auth=false \
Expand Down
87 changes: 3 additions & 84 deletions build/COPY_ROOT/opt/ai-dock/bin/supervisor-x-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ function cleanup() {

function start() {
source /opt/ai-dock/etc/environment.sh

# Hardcode VIDEO_PORT: Users are breaking host machines!!
export VIDEO_PORT=DFP
env-store VIDEO_PORT

if [[ ${SERVERLESS,,} = "true" ]]; then
printf "Refusing to start $SERVICE_NAME in serverless mode\n"
Expand All @@ -36,24 +32,16 @@ function start() {
sudo mkdir -pm700 /tmp/runtime-user
sudo chown $(id -u):$(id -u) /tmp/runtime-user

if [[ $XPU_TARGET == "NVIDIA_GPU" && $(is_nvidia_capable) == "true" ]]; then
printf "Starting NVIDIA X server...\n"
export X_PROXY=false
env-store X_PROXY
if [[ $XPU_TARGET == "NVIDIA_GPU" && $(is_nvidia_capable) == "true" && ${ACCEPT_NVIDIA_LICENSE,,} != "false" ]]; then
printf "Installing NVIDIA drivers...\n"
start_nvidia
else
printf "Starting proxy X server...\n"
export X_PROXY=forced
env-store X_PROXY
start_proxy
fi
}

function start_nvidia() {
# Mostly copied from https://github.com/selkies-project/docker-nvidia-glx-desktop

# This symbolic link enables running Xorg inside a container with `-sharevts`
sudo ln -snf /dev/ptmx /dev/tty7

# Check if nvidia display drivers are present - Download if not
if ! which nvidia-xconfig /dev/null 2>&1; then
Expand All @@ -80,77 +68,8 @@ function start_nvidia() {
sudo rm -rf /tmp/NVIDIA* && cd ~
fi
fi

# Allow starting Xorg from a pseudoterminal instead of strictly on a tty console
if [ ! -f /etc/X11/Xwrapper.config ]; then
echo -e "allowed_users=anybody\nneeds_root_rights=yes" | sudo tee /etc/X11/Xwrapper.config > /dev/null
fi
if grep -Fxq "allowed_users=console" /etc/X11/Xwrapper.config; then
sudo sed -i "s/allowed_users=console/allowed_users=anybody/;$ a needs_root_rights=yes" /etc/X11/Xwrapper.config
fi

# Remove existing Xorg configuration
if [ -f "/etc/X11/xorg.conf" ]; then
sudo rm -f "/etc/X11/xorg.conf"
fi

# Get first GPU device if all devices are available or `NVIDIA_VISIBLE_DEVICES` is not set
if [ "$NVIDIA_VISIBLE_DEVICES" == "all" ] || [ -z "$NVIDIA_VISIBLE_DEVICES" ]; then
export GPU_SELECT="$(sudo nvidia-smi --query-gpu=uuid --format=csv | sed -n 2p)"
# Get first GPU device out of the visible devices in other situations
else
export GPU_SELECT="$(sudo nvidia-smi --id=$(echo "$NVIDIA_VISIBLE_DEVICES" | cut -d ',' -f1) --query-gpu=uuid --format=csv | sed -n 2p)"
if [ -z "$GPU_SELECT" ]; then
export GPU_SELECT="$(sudo nvidia-smi --query-gpu=uuid --format=csv | sed -n 2p)"
fi
fi

# Test whether we have a GPU and display drivers. If not we fall back to Xvfb proxy and hope we have /dev/dri
if [ -z "$GPU_SELECT" ] || ! which nvidia-xconfig > /dev/null 2>&1; then
echo "No NVIDIA GPUs detected or nvidia-container-toolkit not configured. Starting X proxy."
nv_capable=false
fi

if [[ $nv_capable != "false" ]]; then
# Setting `VIDEO_PORT` to none disables RANDR/XRANDR, do not set this if using datacenter GPUs
if [ "${VIDEO_PORT,,}" = "none" ]; then
export CONNECTED_MONITOR="--use-display-device=None"
# The X server is otherwise deliberately set to a specific video port despite not being plugged to enable RANDR/XRANDR, monitor will display the screen if plugged to the specific port
else
export CONNECTED_MONITOR="--connected-monitor=${VIDEO_PORT}"
fi

# Bus ID from nvidia-smi is in hexadecimal format, should be converted to decimal format which Xorg understands, required because nvidia-xconfig doesn't work as intended in a container
HEX_ID="$(sudo nvidia-smi --query-gpu=pci.bus_id --id="$GPU_SELECT" --format=csv | sed -n 2p)"
IFS=":." ARR_ID=($HEX_ID)
unset IFS
BUS_ID="PCI:$((16#${ARR_ID[1]})):$((16#${ARR_ID[2]})):$((16#${ARR_ID[3]}))"
# A custom modeline should be generated because there is no monitor to fetch this information normally
export MODELINE="$(cvt -r "${SIZEW}" "${SIZEH}" "${REFRESH}" | sed -n 2p)"
# Generate /etc/X11/xorg.conf with nvidia-xconfig
sudo nvidia-xconfig --virtual="${SIZEW}x${SIZEH}" --depth="$CDEPTH" --mode="$(echo "$MODELINE" | awk '{print $2}' | tr -d '\"')" --allow-empty-initial-configuration --no-probe-all-gpus --busid="$BUS_ID" --no-multigpu --no-sli --no-base-mosaic --only-one-x-screen ${CONNECTED_MONITOR}
# Guarantee that the X server starts without a monitor by adding more options to the configuration
sudo sed -i '/Driver\s\+"nvidia"/a\ Option "ModeValidation" "NoMaxPClkCheck, NoEdidMaxPClkCheck, NoMaxSizeCheck, NoHorizSyncCheck, NoVertRefreshCheck, NoVirtualSizeCheck, NoExtendedGpuCapabilitiesCheck, NoTotalSizeCheck, NoDualLinkDVICheck, NoDisplayPortBandwidthCheck, AllowNon3DVisionModes, AllowNonHDMI3DModes, AllowNonEdidModes, NoEdidHDMI2Check, AllowDpInterlaced"\n Option "HardDPMS" "False"' /etc/X11/xorg.conf
# Add custom generated modeline to the configuration
sudo sed -i '/Section\s\+"Monitor"/a\ '"$MODELINE" /etc/X11/xorg.conf
# Prevent interference between GPUs, add this to the host or other containers running Xorg as well
echo -e "Section \"ServerFlags\"\n Option \"AutoAddGPU\" \"false\"\nEndSection" | sudo tee -a /etc/X11/xorg.conf > /dev/null

# Run Xorg server with required extensions
echo "xorg" > /tmp/.X-mode
/usr/bin/Xorg vt7 -noreset -novtswitch -sharevts -dpi "${DPI}" +extension "GLX" +extension "RANDR" +extension "RENDER" +extension "MIT-SHM" "${DISPLAY}"

# If everything is working as expected we won't reach this - But if we do we can still have a display
export X_PROXY=forced
env-store X_PROXY
printf "Starting proxy X server (NVIDIA Failure)...\n"
start_proxy
else
export X_PROXY=forced
env-store X_PROXY
printf "Starting proxy X server (No NVIDIA driver)...\n"
start_proxy
fi
start_proxy
}

# If /dev/dri is not available in te container we will have no HW accel
Expand Down
21 changes: 0 additions & 21 deletions build/COPY_ROOT_EXTRA/opt/ai-dock/bin/build/layer1/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,6 @@ apt-get install --install-recommends -y \
libreoffice-plasma \
libreoffice-style-breeze

# Steam
export GE_PROTON_VERSION="$(curl -fsSL "https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases/latest" | jq -r '.tag_name')"
env-store GE_PROTON_VERSION
mkdir -p /opt/proton
wget -c "https://github.com/GloriousEggroll/proton-ge-custom/releases/download/${GE_PROTON_VERSION}/${GE_PROTON_VERSION}.tar.gz" -O - | tar xz -C /opt/proton
proton_dir="/opt/proton/${GE_PROTON_VERSION}"
cp /opt/ai-dock/share/proton/*.vdf "${proton_dir}"
sed -i "s#PROTON_NAME#${GE_PROTON_VERSION}#g" "${proton_dir}/compatibilitytool.vdf"

dpkg-divert --add /usr/games/steam
$APT_INSTALL \
steam-installer \
libpipewire-0.3-0:i386 \
libxcb-res0:i386 \
libgtk2.0-0:i386
cp -f /opt/ai-dock/share/steam/bin/steam /usr/games/steam
chmod +x /usr/games/steam
cp -f /opt/ai-dock/share/steam/bin/steam-native /usr/bin/steam-native
chmod +x /usr/bin/steam-native
ln -sf /usr/games/steam /usr/bin/steam

# Graphics utils
apt-get update
$APT_INSTALL \
Expand Down

This file was deleted.

This file was deleted.

118 changes: 0 additions & 118 deletions build/COPY_ROOT_EXTRA/opt/ai-dock/share/steam/bin/steam

This file was deleted.

11 changes: 0 additions & 11 deletions build/COPY_ROOT_EXTRA/opt/ai-dock/share/steam/bin/steam-native

This file was deleted.

Loading

0 comments on commit 1b0271b

Please sign in to comment.