Skip to content

Commit b7979bf

Browse files
committed
lib_display: add eglinfo pipeline detection helpers and GPU/CPU hint
Introduce EGLINFO pipeline detection helpers in lib_display.sh to select a working platform (wayland/gbm/device/surfaceless) and print legacy-style details (EGL driver, GL_VENDOR, GL_RENDERER). Also emit an explicit hint indicating whether the selected path is GPU (msm/freedreno/etc.) or CPU (kms_swrast/llvmpipe/etc.) for CI clarity. Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
1 parent effc51a commit b7979bf

1 file changed

Lines changed: 396 additions & 0 deletions

File tree

Runner/utils/lib_display.sh

Lines changed: 396 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,3 +1015,399 @@ weston_force_primary_1080p60_if_not_60() {
10151015

10161016
return "$wf_ret"
10171017
}
1018+
1019+
###############################################################################
1020+
# EGL / GL pipeline introspection (eglinfo parser)
1021+
###############################################################################
1022+
1023+
# Optional: EGLINFO_DEBUG=1 to dump full eglinfo output when a platform fails.
1024+
1025+
egli_pick_platform_flag() {
1026+
EGLINFO="${EGLINFO:-eglinfo}"
1027+
1028+
# NEW: treat missing/unusable eglinfo as a real failure (return 1)
1029+
if ! command -v "$EGLINFO" >/dev/null 2>&1; then
1030+
echo ""
1031+
return 1
1032+
fi
1033+
1034+
# Keep existing behavior: try to detect supported flag from --help.
1035+
# NOTE: we no longer force "|| true" so we can detect a true failure.
1036+
help_out="$("$EGLINFO" --help 2>&1)"
1037+
rc=$?
1038+
1039+
# NEW: if --help truly failed and produced nothing, signal failure
1040+
if [ "$rc" -ne 0 ] && [ -z "${help_out:-}" ]; then
1041+
echo ""
1042+
return 1
1043+
fi
1044+
1045+
if echo "$help_out" | grep -qi -- '--platform'; then
1046+
echo "--platform"
1047+
return 0
1048+
fi
1049+
1050+
if echo "$help_out" | grep -Eqi '(^|[[:space:]])-p([[:space:]]|,|$)'; then
1051+
echo "-p"
1052+
return 0
1053+
fi
1054+
1055+
if echo "$help_out" | grep -Eqi '(^|[[:space:]])-P([[:space:]]|,|$)'; then
1056+
echo "-P"
1057+
return 0
1058+
fi
1059+
1060+
# No platform selection flag supported — not an error
1061+
echo ""
1062+
return 0
1063+
}
1064+
1065+
egli_get_field() {
1066+
key="$1"
1067+
awk -v k="$key" '
1068+
BEGIN { IGNORECASE=1 }
1069+
1070+
function trim(s) {
1071+
gsub(/^[[:space:]]+/, "", s)
1072+
gsub(/[[:space:]]+$/, "", s)
1073+
return s
1074+
}
1075+
1076+
function emit_after_colon(line) {
1077+
sub("^[^:]*:[[:space:]]*", "", line)
1078+
line = trim(line)
1079+
if (line != "") {
1080+
print line
1081+
exit
1082+
}
1083+
}
1084+
1085+
{
1086+
line = $0
1087+
1088+
# 1) Fast-path: key at column 1: "KEY: value"
1089+
if (index(tolower(line), tolower(k ":")) == 1) {
1090+
emit_after_colon(line)
1091+
}
1092+
1093+
# 2) Mesa eglinfo style: "OpenGL ... vendor: freedreno" / "renderer: ..."
1094+
# Callers pass keys like "OpenGL vendor string" or "GL_VENDOR".
1095+
if (tolower(k) ~ /vendor/ && line ~ /^[[:space:]]*OpenGL/ && line ~ / vendor[[:space:]]*:/) {
1096+
emit_after_colon(line)
1097+
}
1098+
if (tolower(k) ~ /renderer/ && line ~ /^[[:space:]]*OpenGL/ && line ~ / renderer[[:space:]]*:/) {
1099+
emit_after_colon(line)
1100+
}
1101+
1102+
# 3) Allow leading whitespace: " OpenGL vendor string: ..."
1103+
if (tolower(line) ~ "^[[:space:]]*" tolower(k) "[[:space:]]*:") {
1104+
emit_after_colon(line)
1105+
}
1106+
}
1107+
'
1108+
}
1109+
1110+
egli_get_first() {
1111+
# $1 = full text, rest = keys (try in order)
1112+
text="$1"
1113+
shift
1114+
1115+
for key in "$@"; do
1116+
val="$(printf '%s\n' "$text" | egli_get_field "$key")"
1117+
if [ -n "$val" ]; then
1118+
printf '%s\n' "$val"
1119+
return 0
1120+
fi
1121+
done
1122+
1123+
printf '%s\n' ""
1124+
return 0
1125+
}
1126+
1127+
egli_classify_pipeline() {
1128+
# Inputs: driver gl_vendor gl_renderer
1129+
d="$1"
1130+
v="$2"
1131+
r="$3"
1132+
1133+
# CPU / software fallbacks (Mesa swrast/llvmpipe/etc.)
1134+
if printf '%s %s %s\n' "$d" "$v" "$r" | grep -Eqi \
1135+
'(llvmpipe|softpipe|swrast|kms_swrast|lavapipe|virgl|swiftshader)'; then
1136+
printf '%s\n' "CPU (software)"
1137+
return 0
1138+
fi
1139+
1140+
# If it’s not obviously software, treat as GPU/hardware.
1141+
printf '%s\n' "GPU (hardware)"
1142+
return 0
1143+
}
1144+
1145+
egli_print_legacy() {
1146+
plat="$1"
1147+
driver="$2"
1148+
gl_vendor="$3"
1149+
gl_renderer="$4"
1150+
1151+
plat_up="$(printf '%s' "$plat" | tr '[:lower:]' '[:upper:]')"
1152+
1153+
log_info "EGLINFO: Pipeline=${plat_up} platform:"
1154+
1155+
[ -n "$driver" ] || driver="(unknown)"
1156+
[ -n "$gl_vendor" ] || gl_vendor="(unknown)"
1157+
[ -n "$gl_renderer" ] || gl_renderer="(unknown)"
1158+
1159+
# Align EXACTLY to your sample log format (no extra indentation)
1160+
log_info "EGLINFO: EGL driver name: $driver"
1161+
log_info "EGLINFO: GL_VENDOR: $gl_vendor"
1162+
log_info "EGLINFO: GL_RENDERER: $gl_renderer"
1163+
}
1164+
1165+
egli_try_one_platform() {
1166+
plat="$1"
1167+
plat_flag="$2"
1168+
1169+
EGLINFO="${EGLINFO:-eglinfo}"
1170+
1171+
if [ -n "$plat_flag" ]; then
1172+
out="$("$EGLINFO" "$plat_flag" "$plat" 2>&1)"
1173+
rc=$?
1174+
else
1175+
out="$(EGL_PLATFORM="$plat" "$EGLINFO" 2>&1)"
1176+
rc=$?
1177+
fi
1178+
1179+
# “Initialized?” heuristic: at least one of these should exist
1180+
egl_vendor="$(printf '%s\n' "$out" | egli_get_field "EGL vendor string")"
1181+
egl_version="$(printf '%s\n' "$out" | egli_get_field "EGL version string")"
1182+
egl_api_ver="$(printf '%s\n' "$out" | egli_get_field "EGL API version")"
1183+
1184+
ok=0
1185+
if [ -n "$egl_vendor" ]; then ok=1; fi
1186+
if [ -n "$egl_version" ]; then ok=1; fi
1187+
if [ -n "$egl_api_ver" ]; then ok=1; fi
1188+
1189+
if [ "$rc" -ne 0 ] || [ "$ok" -eq 0 ]; then
1190+
log_warn "eglinfo platform '$plat' did not initialize cleanly (rc=$rc)."
1191+
if [ "${EGLINFO_DEBUG:-0}" = "1" ]; then
1192+
log_info "---- eglinfo output (platform '$plat') ----"
1193+
printf '%s\n' "$out"
1194+
log_info "---- end eglinfo output ----"
1195+
fi
1196+
return 1
1197+
fi
1198+
1199+
# Driver name
1200+
driver="$(egli_get_first "$out" \
1201+
"EGL driver name" \
1202+
"EGL driver" \
1203+
"Driver name" \
1204+
"Driver")"
1205+
1206+
# GL vendor (prefer explicit GL_VENDOR if present)
1207+
gl_vendor="$(egli_get_first "$out" \
1208+
"GL_VENDOR" \
1209+
"OpenGL ES profile vendor string" \
1210+
"OpenGL vendor string" \
1211+
"OpenGL ES vendor string")"
1212+
1213+
# GL renderer (prefer explicit GL_RENDERER if present)
1214+
gl_renderer="$(egli_get_first "$out" \
1215+
"GL_RENDERER" \
1216+
"OpenGL ES profile renderer string" \
1217+
"OpenGL renderer string" \
1218+
"OpenGL ES renderer string")"
1219+
1220+
# NEW: avoid classification on empty strings
1221+
[ -n "$driver" ] || driver="unknown"
1222+
[ -n "$gl_vendor" ] || gl_vendor="unknown"
1223+
[ -n "$gl_renderer" ] || gl_renderer="unknown"
1224+
1225+
# If we got nothing useful, treat as failure (prevents misleading GPU/CPU label)
1226+
if [ "$driver" = "unknown" ] && [ "$gl_vendor" = "unknown" ] && [ "$gl_renderer" = "unknown" ]; then
1227+
log_warn "eglinfo platform '$plat' returned no driver/vendor/renderer strings; skipping classification."
1228+
return 1
1229+
fi
1230+
1231+
# Print GPU/CPU pipeline type (align to your sample: no extra indentation)
1232+
pipe_kind="$(egli_classify_pipeline "$driver" "$gl_vendor" "$gl_renderer")"
1233+
log_info "EGLINFO: Pipeline type: $pipe_kind"
1234+
1235+
egli_print_legacy "$plat" "$driver" "$gl_vendor" "$gl_renderer"
1236+
return 0
1237+
}
1238+
1239+
display_print_eglinfo_pipeline() {
1240+
# Usage: display_print_eglinfo_pipeline auto|wayland|gbm|device|surfaceless
1241+
mode="${1:-auto}"
1242+
1243+
EGLINFO="${EGLINFO:-eglinfo}"
1244+
if ! command -v "$EGLINFO" >/dev/null 2>&1; then
1245+
log_error "eglinfo not found (EGLINFO='$EGLINFO')"
1246+
return 1
1247+
fi
1248+
1249+
# NOTE: unchanged usage; now egli_pick_platform_flag can return 1
1250+
# but when it does, plat_flag will be empty and caller already checked eglinfo.
1251+
plat_flag="$(egli_pick_platform_flag 2>/dev/null)" || plat_flag=""
1252+
1253+
log_info "---------------- EGLINFO pipeline detection (select one) ----------------"
1254+
1255+
if [ "$mode" = "auto" ]; then
1256+
if [ -n "${WAYLAND_DISPLAY:-}" ]; then
1257+
if egli_try_one_platform "wayland" "$plat_flag"; then
1258+
log_info "---------------- End EGLINFO pipeline detection --------------------------"
1259+
return 0
1260+
fi
1261+
fi
1262+
1263+
if egli_try_one_platform "gbm" "$plat_flag"; then
1264+
log_info "---------------- End EGLINFO pipeline detection --------------------------"
1265+
return 0
1266+
fi
1267+
1268+
if egli_try_one_platform "device" "$plat_flag"; then
1269+
log_info "---------------- End EGLINFO pipeline detection --------------------------"
1270+
return 0
1271+
fi
1272+
1273+
if egli_try_one_platform "surfaceless" "$plat_flag"; then
1274+
log_info "---------------- End EGLINFO pipeline detection --------------------------"
1275+
return 0
1276+
fi
1277+
1278+
log_warn "No working eglinfo platform found (tried wayland/gbm/device/surfaceless)."
1279+
log_info "---------------- End EGLINFO pipeline detection --------------------------"
1280+
return 1
1281+
fi
1282+
1283+
case "$mode" in
1284+
wayland|gbm|device|surfaceless)
1285+
if ! egli_try_one_platform "$mode" "$plat_flag"; then
1286+
log_warn "Requested '$mode' did not work. Trying fallbacks..."
1287+
1288+
if ! egli_try_one_platform "gbm" "$plat_flag"; then
1289+
if ! egli_try_one_platform "device" "$plat_flag"; then
1290+
if ! egli_try_one_platform "surfaceless" "$plat_flag"; then
1291+
if ! egli_try_one_platform "wayland" "$plat_flag"; then
1292+
log_warn "No fallback platforms worked either."
1293+
fi
1294+
fi
1295+
fi
1296+
fi
1297+
fi
1298+
1299+
log_info "---------------- End EGLINFO pipeline detection --------------------------"
1300+
return 0
1301+
;;
1302+
*)
1303+
log_warn "Unknown mode '$mode' (use: auto|wayland|gbm|device|surfaceless). Defaulting to auto."
1304+
display_print_eglinfo_pipeline auto
1305+
return $?
1306+
;;
1307+
esac
1308+
}
1309+
1310+
###############################################################################
1311+
# GPU accel gating (detect-only)
1312+
###############################################################################
1313+
display_is_cpu_renderer() {
1314+
# Usage: display_is_cpu_renderer <mode>
1315+
# Prints EGLINFO block when called (your requirement).
1316+
# Returns: 0 if CPU/software renderer detected, 1 otherwise (GPU or unknown)
1317+
mode="${1:-auto}"
1318+
1319+
# Always print EGLINFO pipeline detection (do NOT redirect)
1320+
display_print_eglinfo_pipeline "$mode" || true
1321+
1322+
EGLINFO="${EGLINFO:-eglinfo}"
1323+
if ! command -v "$EGLINFO" >/dev/null 2>&1; then
1324+
return 1
1325+
fi
1326+
1327+
# NOTE: unchanged usage; now egli_pick_platform_flag can return 1
1328+
plat_flag="$(egli_pick_platform_flag 2>/dev/null)" || plat_flag=""
1329+
1330+
# Run eglinfo and decide CPU/software for one platform.
1331+
# Return 0 if CPU/software, 1 otherwise.
1332+
egli_is_cpu_for_platform() {
1333+
p="$1"
1334+
1335+
if [ -n "$plat_flag" ]; then
1336+
out="$("$EGLINFO" "$plat_flag" "$p" 2>&1)"
1337+
rc=$?
1338+
else
1339+
out="$(EGL_PLATFORM="$p" "$EGLINFO" 2>&1)"
1340+
rc=$?
1341+
fi
1342+
1343+
# Must initialize
1344+
egl_vendor="$(printf '%s\n' "$out" | egli_get_field "EGL vendor string")"
1345+
egl_version="$(printf '%s\n' "$out" | egli_get_field "EGL version string")"
1346+
egl_api_ver="$(printf '%s\n' "$out" | egli_get_field "EGL API version")"
1347+
1348+
ok=0
1349+
if [ -n "$egl_vendor" ]; then ok=1; fi
1350+
if [ -n "$egl_version" ]; then ok=1; fi
1351+
if [ -n "$egl_api_ver" ]; then ok=1; fi
1352+
if [ "$rc" -ne 0 ] || [ "$ok" -eq 0 ]; then
1353+
return 1
1354+
fi
1355+
1356+
driver="$(egli_get_first "$out" \
1357+
"EGL driver name" \
1358+
"EGL driver" \
1359+
"Driver name" \
1360+
"Driver")"
1361+
1362+
gl_vendor="$(egli_get_first "$out" \
1363+
"GL_VENDOR" \
1364+
"OpenGL ES profile vendor string" \
1365+
"OpenGL vendor string" \
1366+
"OpenGL ES vendor string")"
1367+
1368+
gl_renderer="$(egli_get_first "$out" \
1369+
"GL_RENDERER" \
1370+
"OpenGL ES profile renderer string" \
1371+
"OpenGL renderer string" \
1372+
"OpenGL ES renderer string")"
1373+
1374+
# NEW: avoid classification on empty strings
1375+
[ -n "$driver" ] || driver="unknown"
1376+
[ -n "$gl_vendor" ] || gl_vendor="unknown"
1377+
[ -n "$gl_renderer" ] || gl_renderer="unknown"
1378+
1379+
# If we got nothing useful, treat as not-CPU (unknown) rather than mislabel
1380+
if [ "$driver" = "unknown" ] && [ "$gl_vendor" = "unknown" ] && [ "$gl_renderer" = "unknown" ]; then
1381+
return 1
1382+
fi
1383+
1384+
pipe_kind="$(egli_classify_pipeline "$driver" "$gl_vendor" "$gl_renderer")"
1385+
if printf '%s\n' "$pipe_kind" | grep -qi '^CPU'; then
1386+
return 0
1387+
fi
1388+
return 1
1389+
}
1390+
1391+
if [ "$mode" = "auto" ]; then
1392+
# Match display_print_eglinfo_pipeline(auto) preference order.
1393+
if [ -n "${WAYLAND_DISPLAY:-}" ]; then
1394+
if egli_is_cpu_for_platform "wayland"; then return 0; fi
1395+
fi
1396+
if egli_is_cpu_for_platform "gbm"; then return 0; fi
1397+
if egli_is_cpu_for_platform "device"; then return 0; fi
1398+
if egli_is_cpu_for_platform "surfaceless"; then return 0; fi
1399+
return 1
1400+
fi
1401+
1402+
case "$mode" in
1403+
wayland|gbm|device|surfaceless)
1404+
if egli_is_cpu_for_platform "$mode"; then
1405+
return 0
1406+
fi
1407+
return 1
1408+
;;
1409+
*)
1410+
return 1
1411+
;;
1412+
esac
1413+
}

0 commit comments

Comments
 (0)