Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize native video detection #3686

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions scriptmodules/supplementary/emulationstation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,12 @@ function build_emulationstation() {
isPlatform "mesa" && params+=(-DGL=On)
# force GLESv1 on videocore due to performance issue with GLESv2
isPlatform "videocore" && params+=(-DUSE_GLES1=On)
elif isPlatform "x11"; then
if isPlatform "gles"; then
params+=(-DGLES=On)
local gles_ver=$(sudo -u $user glxinfo -B | grep -oP 'Max GLES[23] profile version:\s\K.*')
compareVersions $gles_ver lt 2.0 && params+=(-DUSE_GLES1=On)
else
params+=(-DGL=On)
local gl_ver=$(sudo -u $user glxinfo -B | grep -oP 'Max compat profile version:\s\K.*')
compareVersions $gl_ver gt 2.0 && params+=(-DUSE_GL21=On)
fi
elif isPlatform "gles"; then
params+=(-DGLES=On)
! isPlatform "gles2" && params+=(-DUSE_GLES1=On)
elif isPlatform "gl"; then
params+=(-DGL=On)
isPlatform "gl2" && params+=(-DUSE_GL21=On)
fi
if isPlatform "dispmanx"; then
params+=(-DOMX=On)
Expand Down
71 changes: 66 additions & 5 deletions scriptmodules/system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,66 @@ function get_rpi_video() {
export PKG_CONFIG_PATH="$pkgconfig"
}

function has_video_output_device() {
# check if there is a video output device with a connected display
if [[ -d /sys/class/drm ]]; then
local d
for d in /sys/class/drm/*/ ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing local declaration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

do
[[ -f "$d/status" ]] && [[ $(cat "$d/status") == "connected" ]] && return 0
done
fi
return 1
}

function has_render_device() {
# check if there is a render note
[[ -n "$(ls /dev/dri/render*)" ]] && return 0
return 1
}

function get_graphics_platform() {
case "$(systemctl get-default)" in
multi-user.target)
# for kmsdrm we need a card for video output and a render device for gl/gles acceleration
has_video_output_device && __platform_flags+=(kms)
;;
graphical.target)
__platform_flags+=(x11)
# Only allow wayland if drm-backend.so can be used. Video output device is mandatory.
has_video_output_device && __platform_flags+=(wayland)
;;
esac
}

function get_opengl_target_platform() {
if isPlatform "x11"; then
# glxinfo only runs under x11
! hasPackage "mesa-utils" && aptInstall mesa-utils

local gl_info=$(sudo -u $user DISPLAY=:0 glxinfo -B)
local glcore_ver=$(echo "$gl_info" | grep -oP 'Max core profile version:\s\K.*')
local gl_ver=$(echo "$gl_info" | grep -oP 'Max compat profile version:\s\K.*')
local gles_ver=$(echo "$gl_info" | grep -oP 'Max GLES\[23\] profile version:\s\K.*')

# use $glcore_ver as $gl_ver if version is higher
compareVersions "$glcore_ver" gt "$gl_ver" && gl_ver="$glcore_ver"
if compareVersions "$gles_ver" gt "1.1" && compareVersions "$gl_ver" lt "4.2"; then
compareVersions "$gles_ver" gt "3.1" && __platform_flags+=(gles3 gles31 gles32)
__platform_flags+=(gles)
else
compareVersions "$gl_ver" gt "2.0" && __platform_flags+=(gl2)
__platform_flags+=(gl)
fi
else
# Fallback for other platforms
# Use GL for x86. Most x86 platforms have better GL support.
# Use GLES for arm. Most arm platforms have better GLES support.
isPlatform "x86" && __platform_flags+=(gl) || __platform_flags+=(gles)
isPlatform "kms" && ! has_render_device && __platform_flags+=(softpipe)
fi
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this is needed as a standalone function. This PR relies too much on "something && something &&" and it isn't that readable imho.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it into platform_native() and removed get_native_video.sh.

get_graphics_platform really just checks if there is a lvds/hdmi/lcd display controller with a kms driver which can be used to output something. On arm platforms display controller and gpus can be separate devices. Display controllers are kms devices and gpus are kms render only (kmsro) devices. With get_opengl_target_platform we check capabilities of the render device.

function get_platform() {
local architecture="$(uname --machine)"
if [[ -z "$__platform" ]]; then
Expand Down Expand Up @@ -626,14 +686,15 @@ function platform_tinker() {

function platform_native() {
__default_cpu_flags="-march=native"
__platform_flags+=(gl vulkan)
# add x86 platform flag for x86/x86_64 archictures.
[[ "$__platform_arch" =~ (i386|i686|x86_64) ]] && __platform_flags+=(x86)
# get native video platform flags
if [[ "$__has_kms" -eq 1 ]]; then
__platform_flags+=(kms)
__platform_flags+=(kms gl vulkan)
else
__platform_flags+=(x11)
get_graphics_platform
get_opengl_target_platform
fi
# add x86 platform flag for x86/x86_64 archictures.
[[ "$__platform_arch" =~ (i386|i686|x86_64) ]] && __platform_flags+=(x86)
}

function platform_armv7-mali() {
Expand Down