diff --git a/misc/passthrough.func b/misc/passthrough.func index 43c96beb..aaae1e70 100644 --- a/misc/passthrough.func +++ b/misc/passthrough.func @@ -234,3 +234,115 @@ nvidia_handle_passthrough() { msg_warn "Skipped NVIDIA passthrough by user choice." fi } +# ------------------------------------------------------------------------------ +# Hardware acceleration setup inside container (Intel/AMD via VAAPI) +# Debian 12 (bookworm), Debian 13 (trixie), Ubuntu 24.04 (noble) +# Usage: hwaccel_setup_in_ct [--nonfree-intel] +# ------------------------------------------------------------------------------ +hwaccel_setup_in_ct() { + local CTTYPE="$1" NONFREE=0 + [[ "$2" == "--nonfree-intel" ]] && NONFREE=1 + + local ID VERSION_CODENAME + if [[ -r /etc/os-release ]]; then . /etc/os-release; fi + ID="${ID:-debian}" + VERSION_CODENAME="${VERSION_CODENAME:-bookworm}" + + msg_info "Setting up VAAPI userland for ${ID^} ($VERSION_CODENAME)" + + case "$ID" in + debian | ubuntu) + if ((NONFREE)) && [[ "$VERSION_CODENAME" =~ (trixie|noble) ]]; then + # Debian 13 / Ubuntu 24.04 — enable non-free Intel media (Debian deb822) + if [[ "$VERSION_CODENAME" == "trixie" ]]; then + cat >/etc/apt/sources.list.d/non-free.sources <<'SRC' +Types: deb deb-src +URIs: http://deb.debian.org/debian +Suites: trixie +Components: non-free non-free-firmware + +Types: deb deb-src +URIs: http://deb.debian.org/debian-security +Suites: trixie-security +Components: non-free non-free-firmware + +Types: deb deb-src +URIs: http://deb.debian.org/debian +Suites: trixie-updates +Components: non-free non-free-firmware +SRC + fi + + $STD apt-get update + $STD apt-get install -y \ + intel-media-va-driver-non-free \ + ocl-icd-libopencl1 \ + mesa-opencl-icd \ + mesa-va-drivers \ + libvpl2 \ + vainfo \ + intel-gpu-tools + else + $STD apt-get update + $STD apt-get install -y \ + va-driver-all \ + ocl-icd-libopencl1 \ + mesa-opencl-icd \ + mesa-va-drivers \ + vainfo \ + intel-gpu-tools + fi + ;; + *) + msg_warn "Unsupported distro ($ID $VERSION_CODENAME) – skipping VAAPI setup." + return 0 + ;; + esac + + if [[ "$CTTYPE" == "0" ]]; then + $STD adduser "$(id -un)" video || true + $STD adduser "$(id -un)" render || true + fi + + msg_ok "VAAPI userland ready" +} + +# ------------------------------------------------------------------------------ +# NVIDIA userland inside container +# Debian 12/13, Ubuntu 24.04 +# Usage: nvidia_setup_in_ct +# ------------------------------------------------------------------------------ +nvidia_setup_in_ct() { + local CTTYPE="$1" + + local ID VERSION_CODENAME + if [[ -r /etc/os-release ]]; then . /etc/os-release; fi + ID="${ID:-debian}" + VERSION_CODENAME="${VERSION_CODENAME:-bookworm}" + + msg_info "Installing NVIDIA userland on ${ID^} ($VERSION_CODENAME)" + + case "$ID" in + debian | ubuntu) + $STD apt-get update + $STD apt-get install -y \ + nvidia-driver \ + nvidia-utils \ + libnvidia-encode1 \ + libcuda1 || { + msg_error "Failed to install NVIDIA packages" + return 1 + } + ;; + *) + msg_warn "Unsupported distro ($ID $VERSION_CODENAME) – skipping NVIDIA setup." + return 0 + ;; + esac + + if [[ "$CTTYPE" == "0" ]]; then + $STD adduser "$(id -un)" video || true + fi + + msg_ok "NVIDIA userland ready" +}