Unverified Commit 8ffc3bf8 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

feat: GPU passthrough

* feat: GPU passthrough
parent c2edb081
Loading
Loading
Loading
Loading
+34 −2
Original line number Diff line number Diff line
@@ -3,15 +3,47 @@ set -Eeuo pipefail

# Docker environment variables

: ${GPU:='N'}           # GPU passthrough
: ${DISPLAY:='none'}    # Display type

case "${DISPLAY,,}" in
  vnc)
    if [[ "$GPU" != [Yy1]* ]] || [[ "$ARCH" != "amd64" ]]; then
      DISPLAY_OPTS="-nographic -vga std -vnc :0"
    else
      DISPLAY_OPTS="-vga std -vnc :0"
    fi
    ;;
  *)
    if [[ "$GPU" != [Yy1]* ]] || [[ "$ARCH" != "amd64" ]]; then
      DISPLAY_OPTS="-nographic -display none"
    else
      DISPLAY_OPTS=""
    fi
    ;;
esac

if [[ "$GPU" != [Yy1]* ]] || [[ "$ARCH" != "amd64" ]]; then
  return 0
fi

DISPLAY_OPTS="$DISPLAY_OPTS -display egl-headless,rendernode=/dev/dri/renderD128"
DISPLAY_OPTS="$DISPLAY_OPTS -device virtio-vga,id=video0,max_outputs=1,bus=pcie.0,addr=0x1"

[ ! -d /dev/dri ] && mkdir -m 755 /dev/dri

if [ ! -c /dev/dri/card0 ]; then
  mknod /dev/dri/card0 c 226 0
fi

if [ ! -c /dev/dri/renderD128 ]; then
  mknod /dev/dri/renderD128 c 226 128
fi

chmod 666 /dev/dri/card0
chmod 666 /dev/dri/renderD128

addPackage "xserver-xorg-video-intel" "Intel GPU drivers"
addPackage "qemu-system-modules-opengl" "OpenGL module"

return 0
+22 −0
Original line number Diff line number Diff line
@@ -32,4 +32,26 @@ VERS=$(qemu-system-x86_64 --version | head -n 1 | cut -d '(' -f 1)
STORAGE="/storage"
[ ! -d "$STORAGE" ] && error "Storage folder ($STORAGE) not found!" && exit 13

# Helper functions

addPackage () {

  local pkg=$1
  local desc=$2

  if apt-mark showinstall | grep -qx "$pkg"; then
    return 0
  fi

  info "Installing $desc..."

  export DEBCONF_NOWARNINGS="yes"
  export DEBIAN_FRONTEND="noninteractive"

  apt-get -qq update
  apt-get -qq --no-install-recommends -y install "$pkg" > /dev/null

  return 0
}

return 0