Skip to content

Commit 584ab58

Browse files
committed
system.sh: optimize native video detection
If a device platform is unknown platform "native" will be used. Platform native assumes there is a x11 session which supports gl and vulkan. If you want to run from console you can set "force_kms" in retropie.cfg. There is no auto detection. You can not use gles. Add some logic which analyzes the system and sets platform flags according to it. -add helper function get_graphics_platform(): checks enviroment and sets platform flags for video backend. -add helper function get_opengl_target_platform(): tries to get GL and GLES versions from system and sets platform flags for GL or GLES. -add helper function has_render_device(): checks if there is a kmsdrm render note. -add helper function has_video_output_device(): checks if there is a kmsdrm video output device.
1 parent dd26862 commit 584ab58

File tree

1 file changed

+66
-5
lines changed

1 file changed

+66
-5
lines changed

scriptmodules/system.sh

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,66 @@ function get_rpi_video() {
369369
export PKG_CONFIG_PATH="$pkgconfig"
370370
}
371371

372+
function has_video_output_device() {
373+
# check if there is a video output device with a connected display
374+
if [[ -d /sys/class/drm ]]; then
375+
local d
376+
for d in /sys/class/drm/*/ ;
377+
do
378+
[[ -f "$d/status" ]] && [[ $(cat "$d/status") == "connected" ]] && return 0
379+
done
380+
fi
381+
return 1
382+
}
383+
384+
function has_render_device() {
385+
# check if there is a render note
386+
[[ -n "$(ls /dev/dri/render*)" ]] && return 0
387+
return 1
388+
}
389+
390+
function get_graphics_platform() {
391+
case "$(systemctl get-default)" in
392+
multi-user.target)
393+
# for kmsdrm we need a card for video output and a render device for gl/gles acceleration
394+
has_video_output_device && __platform_flags+=(kms)
395+
;;
396+
graphical.target)
397+
__platform_flags+=(x11)
398+
# Only allow wayland if drm-backend.so can be used. Video output device is mandatory.
399+
has_video_output_device && __platform_flags+=(wayland)
400+
;;
401+
esac
402+
}
403+
404+
function get_opengl_target_platform() {
405+
if isPlatform "x11"; then
406+
# glxinfo only runs under x11
407+
! hasPackage "mesa-utils" && aptInstall mesa-utils
408+
409+
local gl_info=$(sudo -u $user DISPLAY=:0 glxinfo -B)
410+
local glcore_ver=$(echo "$gl_info" | grep -oP 'Max core profile version:\s\K.*')
411+
local gl_ver=$(echo "$gl_info" | grep -oP 'Max compat profile version:\s\K.*')
412+
local gles_ver=$(echo "$gl_info" | grep -oP 'Max GLES\[23\] profile version:\s\K.*')
413+
414+
# use $glcore_ver as $gl_ver if version is higher
415+
compareVersions "$glcore_ver" gt "$gl_ver" && gl_ver="$glcore_ver"
416+
if compareVersions "$gles_ver" gt "1.1" && compareVersions "$gl_ver" lt "4.2"; then
417+
compareVersions "$gles_ver" gt "3.1" && __platform_flags+=(gles3 gles31 gles32)
418+
__platform_flags+=(gles)
419+
else
420+
compareVersions "$gl_ver" gt "2.0" && __platform_flags+=(gl2)
421+
__platform_flags+=(gl)
422+
fi
423+
else
424+
# Fallback for other platforms
425+
# Use GL for x86. Most x86 platforms have better GL support.
426+
# Use GLES for arm. Most arm platforms have better GLES support.
427+
isPlatform "x86" && __platform_flags+=(gl) || __platform_flags+=(gles)
428+
isPlatform "kms" && ! has_render_device && __platform_flags+=(softpipe)
429+
fi
430+
}
431+
372432
function get_platform() {
373433
local architecture="$(uname --machine)"
374434
if [[ -z "$__platform" ]]; then
@@ -626,14 +686,15 @@ function platform_tinker() {
626686

627687
function platform_native() {
628688
__default_cpu_flags="-march=native"
629-
__platform_flags+=(gl vulkan)
689+
# add x86 platform flag for x86/x86_64 archictures.
690+
[[ "$__platform_arch" =~ (i386|i686|x86_64) ]] && __platform_flags+=(x86)
691+
# get native video platform flags
630692
if [[ "$__has_kms" -eq 1 ]]; then
631-
__platform_flags+=(kms)
693+
__platform_flags+=(kms gl vulkan)
632694
else
633-
__platform_flags+=(x11)
695+
get_graphics_platform
696+
get_opengl_target_platform
634697
fi
635-
# add x86 platform flag for x86/x86_64 archictures.
636-
[[ "$__platform_arch" =~ (i386|i686|x86_64) ]] && __platform_flags+=(x86)
637698
}
638699

639700
function platform_armv7-mali() {

0 commit comments

Comments
 (0)