Skip to content
Snippets Groups Projects

Add Linux wrapper tweak for hybrid gpu systems

Closed Xenhat Hex requested to merge xenhat/features/multi-gpu into main
1 file
+ 53
0
Compare changes
  • Side-by-side
  • Inline
@@ -105,6 +105,59 @@ else
echo "Please install wine to enable full voice functionality."
fi
# Multiple GPU support
#TODO: check if running on battery?
if [[ -z "$AL_NO_OFFLOAD" ]]; then
_fallback_to_lspci=0
if [[ -d /sys/class/drm/card1 ]]; then
# The system registered more than one GPU
# TODO: Test if this folder disappears after disconnecting an eGPU
if [[ -f /sys/class/drm/card1/device/vendor ]]; then
# We have more than one display adapter and it exposes its vendor info
# Check if this indeed the non-primary gpus
if [[ $(</sys/class/drm/card1/device/boot_vga) == 0 ]]; then
if [[ "$(< /sys/class/drm/card1/device/vendor)" == "0x10de" ]]; then
# NVIDIA GPU
export __NV_PRIME_RENDER_OFFLOAD=1
export __GLX_VENDOR_LIBRARY_NAME=nvidia
else
echo >&2 'Warning: unknown secondary GPU vendor, please report the following to the Alchemy Viewer support Discord server:'
echo >&2 "Secondary (drm/card1) GPU vendor is '$(/sys/class/drm/card1/device/vendor)'"
fi
else
echo >&2 'Warning: Secondary GPU is the boot GPU! How to handle? Please report to the Alchemy Viewer support Discord server.'
fi
else
echo >&2 "Secondary GPU does not expose its vendor!"
_fallback_to_lspci=1
fi
if [[ "$_fallback_to_lspci" == 1 ]]; then
if ! command -v lspci; then
echo >&2 "Warning: lspci not found. automatic display adapter selection will not work."
else
vga_adapters=$(lspci -nn | grep '\[03')
adapters_count=$(wc -l <<< "$vga_adapters")
if [[ $adapters_count -gt 1 ]]; then
echo 'Multiple graphics adapters detected, attempting to select the best one.'
# TODO: Stuff DRI_PRIME=1 somewhere in there for machines with AMD discrete gpus + integrated graphics
if [[ "${vga_adapters}" =~ "10de" ]] && [[ "${vga_adapters}" =~ "Advanced Micro Devices, Inc" ]]; then
export __NV_PRIME_RENDER_OFFLOAD=1
export __GLX_VENDOR_LIBRARY_NAME=nvidia
else
# if [[ "${vga_adapters}" =~ "Intel" ]]; then
echo >&2 'Warning: Auto-select does not know what to do with your current configuration.'
echo >&2 'Please send the following output to the Alchemy Viewer support Discord server:'
echo >&2 "======"
echo >&2 "$vga_adapters"
echo >&2 "======"
fi
fi
fi
fi
fi
#TODO: gracefully fail if the GPU is stuck sleeping. It can happen.
fi
# Run the program.
# Don't quote $LL_WRAPPER because, if empty, it should simply vanish from the
# command line. But DO quote "${ARGS[@]}": preserve separate args as
Loading