From 35e0f31a74d4e7b07c99052b453072ddb27558d7 Mon Sep 17 00:00:00 2001 From: Jeena Date: Mon, 19 Oct 2026 13:30:52 +0000 Subject: [PATCH] emu: pin windowed mode to the integrated GPU The discrete card now runs continuous AI inference, so the emulator must not claim GL/Vulkan contexts on it. In windowed mode the emulator uses the host GL/Vulkan stack, and the default GLVND selection picks the discrete card on this machine. The script now discovers the first display device whose driver is not nvidia and pins the emulator process to it (Mesa GLX/EGL + DRI_PRIME + the Intel Vulkan ICD). Headless (the default) needs no change: it always ran on swiftshader, strictly software, and never touched any GPU. --- scripts/start-emulator.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/scripts/start-emulator.sh b/scripts/start-emulator.sh index fdb9af7..ca36d46 100755 --- a/scripts/start-emulator.sh +++ b/scripts/start-emulator.sh @@ -76,6 +76,41 @@ if [ -e /dev/kvm ]; then echo "/dev/kvm found — hardware acceleration on" fi +# Pin the emulator process to the integrated GPU so the discrete card stays free +# for AI inference (windowed mode uses the host GL/Vulkan stack; headless runs on +# swiftshader — pure software — and never touches any GPU at all). Discovered +# from the PCI tree: first display device NOT driven by the nvidia driver. +IGPU="" +for dev in /sys/bus/pci/devices/*; do + class=$(cat "$dev/class" 2>/dev/null) || continue + case "$class" in + 0x0300*|0x0380*) ;; # VGA / display controller + *) continue ;; + esac + if [ "$(basename "$(readlink "$dev/driver" 2>/dev/null)")" = nvidia ]; then continue; fi + IGPU=$(basename "$dev") + break +done +if [ -n "$IGPU" ]; then + # Mesa GL/GLES: force the Mesa vendors, then the Intel render device. + export __GLX_VENDOR_LIBRARY_NAME=mesa + export __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json + export DRI_PRIME="pci-${IGPU//./_}" + # Vulkan: restrict the loader to the iGPU's ICD (both var names — loader + # version differences). + for icd in /usr/share/vulkan/icd.d/intel_icd.x86_64.json \ + /usr/share/vulkan/icd.d/Intel_icd.x86_64.json; do + if [ -f "$icd" ]; then + export VK_ICD_FILENAMES="$icd" + export VK_DRIVER_FILES="$icd" + break + fi + done + echo "GPU pinned to iGPU $IGPU (Mesa/Intel env) — dGPU untouched" +else + echo "no iGPU found — leaving GPU selection to the driver (dGPU may be used)" +fi + # --- build combined adb vendor-keys file ------------------------------------ # The TV system image is a user build: adb push to /data/misc/adb/adb_keys is # blocked, so remote keys are trusted via ADB_VENDOR_KEYS at launch instead.