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.