Skip to content
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
10 changes: 6 additions & 4 deletions tools/aurora-sep/recipes/mesa-m3/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
# the exact j613-25g83-hal200 token, firmware26.6.2 handoff and runtime HAL200/USC3.
# The J615 shares that profile experimentally: the session hook admits it only
# with /chosen asahi,j615-25g83-experimental="1" (share/mesa-m3/native25-boards).
# Where /opt/mesa-m3 is not used, Hyprland sessions on J613, J615 and J516S keep
# a system Mesa in /usr that mesa-m3-system-check admits, not software rendering.
# The package builds both sources sequentially and checks compiler definitions,
# generated kernels, queue sandbox behavior, TLS loading and native MRT clears.
# No profile selection substitutes another Mac's firmware or calibration.
pkgname=mesa-m3
pkgver=26.1.4.m3.2
pkgrel=8
pkgrel=9
_commit=7ff89a4da387bd561b78efd5f09c98ca8ae18538
pkgdesc="Mesa in /opt/mesa-m3 for the M3 Pro (G15S) and M3 (G15G) GPUs; used by uwsm sessions on T6030, and on T8122 when opted in"
arch=('aarch64')
Expand Down Expand Up @@ -85,7 +87,7 @@ sha256sums=('7ed24969985dce91f089d34dbe1c55cbcb8c95765e3e5bc0f268d27fbead2222'
'10abda78df16e650a77443f50cc46a15e418c42d4d9680c6a61616b232c9bdef'
'6c98fab6f9d70449bd7f5258c34eac773836908e060ce5bef86dc5b0ce595e61'
'826016665cd0424a614b67add921c0c79c3c698a4d104ea5712518449b75f27c'
'9cbc38f4bee27ab72d4a288f2741ab1eeb70112ca473a5c98a9695cdfcbe56f7'
'8abf5fcf736b24dad81ffe6a10e137ded8727c004f17d9d723c27e04141b717f'
'6144af8b2e0f04ea615e8c4149e69c45ac49e630c46b2a58f0d1095d977798b2'
'530948fc1a124de21c030a497e2ef5351742ba4ad4653484fe30fd1697ad7141'
'644cf4a5ab57b7badec75843e2899b68d41490c4851d6885227180d6090c25ea'
Expand All @@ -94,10 +96,10 @@ sha256sums=('7ed24969985dce91f089d34dbe1c55cbcb8c95765e3e5bc0f268d27fbead2222'
'04fae9bf32a09a574b6ed9ab9d7afb97340df252b9269ed789303e8561a61a21'
'96c3101c15c73d26cd3086bc8ac4e8eb35d42300d495ca0ffd2bd03960ef3332'
'9c7c3050d3ec15fce80a6e59d099567b396f1844a43695aa4377e02ac696f566'
'2a15cfdbc160b78e5a3a8e99d5898d40a54db28592f1a4ce04a600990a731f87'
'17a3c74a34681cb202767de73cfbe62c3bcbb93a16093cd058eaa955cd8776ea'
'7eaae7de828e15208fccc84db2b910f38bb1288176419f7af7f4675b5c542ce4'
'c888e9dce99e8379aa21e9c5895cbe1b7e879a9319bca144193eddc66f9d4051'
'e80947130044c2dc3671c24c7bff4f523dcc033f7e96f71e334d89a663e2742e')
'6ea402187cd93305315e7a0fae0012eaead15083916985b1e32ee1cc6cf9469c')

# The qualified M3 Pro build's generated kernel files and libclc. build() stops
# when one of ours differs. libagx_shaders.c is compared through kernel-digest.py:
Expand Down
5 changes: 3 additions & 2 deletions tools/aurora-sep/recipes/mesa-m3/mesa-m3-session-confirm
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/sh
# SPDX-License-Identifier: MIT
# mesa-m3-session-confirm [--settle SECONDS]: write the success marker of this
# boot's login with /opt/mesa-m3, but only on live evidence that its
# compositor is up and serving. Run by mesa-m3-session-confirm.service after
# boot's login with /opt/mesa-m3 (or with the system Mesa that the session hook
# admitted automatically), but only on live evidence that its compositor is up
# and serving. Run by mesa-m3-session-confirm.service after
# graphical-session.target (reaching the target alone proves nothing).
#
# The attempt (${XDG_STATE_HOME:-~/.local/state}/mesa-m3/attempt, written by
Expand Down
170 changes: 115 additions & 55 deletions tools/aurora-sep/recipes/mesa-m3/mesa-m3-session-env
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@
# search failed)
# gpu-fault the kernel log shows an M3 GPU or display fault this boot
# (on a T8122 also a failed first-job verdict of its start)
# previous-failed a login with /opt/mesa-m3 earlier this boot has no success
# marker: its compositor was not seen alive and answering
# on its Wayland socket after the settle time (see
# previous-failed a login with /opt/mesa-m3 (or with the system Mesa admitted
# automatically) earlier this boot has no success marker:
# its compositor was not seen alive and answering on its
# Wayland socket after the settle time (see
# mesa-m3-session-confirm.service). The attempt and the
# marker are in ${XDG_STATE_HOME:-~/.local/state}/mesa-m3,
# which a logout does not clear (/run/user/<uid> can go
Expand All @@ -60,20 +61,38 @@
# M1, M2, the M3 Max and anything else are left alone.
#
# When it does not use /opt/mesa-m3 but an M3 render node is there and this
# user can open it, the system Mesa would be refused by the kernel (it is not
# M3-aware), and a compositor that renders through an EGL device on that node
# user can open it, a system Mesa that is not M3-aware would be refused by the
# kernel, and a compositor that renders through an EGL device on that node
# (Hyprland) would stop at start. For every inactive reason except user-setup
# it therefore exports LIBGL_ALWAYS_SOFTWARE=1 (and MESA_M3_FALLBACK=software,
# which marks it as this hook's): the session renders in software. For
# user-setup it exports nothing: the session's own Mesa setup, which it uses,
# decides. The state file says which (fallback=software|none).
#
# A file opt-out (/etc/mesa-m3/disable or the user's mesa-m3/disable) on a
# J613 (T8122) or a J516S (T6030) is the exception: when the same node,
# display, kernel-log, user-setup and same-boot attempt checks pass and
# mesa-m3-system-check admits /usr, the session keeps system Mesa
# (fallback=none, no new attempt). The whole check runs in its own sh and is
# refused after 20 seconds. mesa_m3=off stays on the software fallback.
# A system Mesa on /usr that drives the GPU natively is the exception, on a
# J613 or J615 (T8122, the 13- and 15-inch M3 Air) or a J516S (T6030) in a
# Hyprland session. It is checked only where the gate above ends inactive,
# except not-supported and user-setup (the session's own Mesa setup still
# decides): an active /opt/mesa-m3 is never replaced. When the node, display,
# kernel-log, user-setup (--system-provider) and same-boot attempt checks pass
# and mesa-m3-system-check admits /usr, the session keeps the system Mesa
# (fallback=none) instead of the software fallback. The whole check runs in
# its own sh and is refused after 20 seconds. mesa_m3=off and nomodeset refuse
# it, and any refusal leaves the gate's decision and its fallback exactly as
# above. Its state:
# system-mesa no opt-out: the system Mesa was admitted automatically.
# Its attempt is recorded first, as for active, so a login
# whose compositor is not confirmed (mesa-m3-session-confirm)
# turns the next login of this boot into the software
# fallback instead of a login loop. When the attempt
# cannot be written, the gate's decision and fallback
# stay, and the detail says the attempt was not recorded.
# opt-out a file opt-out (/etc/mesa-m3/disable or the user's
# mesa-m3/disable) whose system Mesa was admitted: as
# before, no new attempt.
# Without a file opt-out, the 25G83 native profile stays on its own gate: an
# /etc/mesa-m3/t8122-profile selection, or a node with the
# apple,j613-25g83-gpu-handoff property, is not admitted automatically.
#
# Each login writes /run/user/<uid>/mesa-m3-session.state (atomically, 0644,
# key=value lines, first line schema=aurora.mesa-m3-session/2) and logs one
Expand Down Expand Up @@ -255,13 +274,14 @@ mesa_m3_gate() {
# opt-out uses before it will leave the system Mesa in place.
_mm3_klog=$(_mm3_kernel_log) || { echo "$_mm3_klog"; return 1; }

# A login that chose /opt/mesa-m3 earlier this boot must have a success
# marker bound to it (same boot_id, session_id and hook_run_id), written by
# mesa-m3-session-confirm.service only after its compositor was alive and
# answering on its Wayland socket after the settle time. Otherwise this
# A login that chose /opt/mesa-m3 (or the system Mesa automatically) earlier
# this boot must have a success marker bound to it (same boot_id,
# session_id and hook_run_id), written by mesa-m3-session-confirm.service
# only after its compositor was alive and answering on its Wayland socket
# after the settle time. Otherwise this
# login stays off it: no login loop when the compositor cannot run on it.
if ! _mm3_legacy_attempt_clear "$_mm3_root"; then
echo "previous-failed the last login with /opt/mesa-m3 this boot (hook_run_id ${_mm3_v:-unknown}) has no success marker: its compositor was not seen alive and answering, so this login renders in software; to try the GPU again: rm $_mm3_att, then log out and in (or reboot)"
echo "previous-failed the last GPU login this boot (hook_run_id ${_mm3_v:-unknown}) has no success marker: its compositor was not seen alive and answering, so this login renders in software; to try the GPU again: rm $_mm3_att, then log out and in (or reboot)"
return 1
fi

Expand Down Expand Up @@ -361,9 +381,9 @@ _mm3_kernel_log() {
return 0
}

# Return 0 when this boot has no unmatched /opt/mesa-m3 attempt. Return 1
# when an attempt for this boot_id has no success marker bound to its
# hook_run_id and session_id. Never creates, deletes or rewrites either file.
# Return 0 when this boot has no unmatched attempt (of /opt/mesa-m3 or of an
# automatic system Mesa). Return 1 when an attempt for this boot_id has no
# success marker bound to its hook_run_id and session_id. Never creates, deletes or rewrites either file.
# On failure, _mm3_att and _mm3_v are the attempt path and its hook_run_id.
_mm3_legacy_attempt_clear() {
_mm3_att="$1${XDG_STATE_HOME:-$HOME/.local/state}/mesa-m3/attempt"
Expand All @@ -385,27 +405,33 @@ _mm3_legacy_attempt_clear() {
return 0
}

# File opt-out on J613/T8122 or J516S/T6030 may keep the system Mesa. Prints
# one detail line and returns 0 only when every check below passes. A helper
# exit of 0 is not enough on its own. Does not write an attempt or touch a
# marker. mesa_m3=off is not a file opt-out.
# The system Mesa on J613 or J615 (T8122) or J516S (T6030), automatically or
# after a file opt-out. Prints one detail line and returns 0 only when every
# check below passes. A helper exit of 0 is not enough on its own. Does not
# write an attempt or touch a marker (the caller records an automatic one).
# mesa_m3=off and nomodeset refuse it; mesa_m3=off is not a file opt-out.
_mm3_system_admit() {
case ${XDG_CURRENT_DESKTOP:-} in Hyprland|hyprland) ;; *) return 1 ;; esac
_mm3_cmdline=$(cat "$1/proc/cmdline" 2>/dev/null) || return 1
case " $_mm3_cmdline " in
*" mesa_m3=off "*|*" nomodeset "*) return 1 ;;
esac
_mm3_auto=0
if [ ! -e "$1/etc/mesa-m3/disable" ] &&
[ ! -e "$1${XDG_CONFIG_HOME:-$HOME/.config}/mesa-m3/disable" ]; then
return 1
# Automatic: an explicit 25G83 native profile selection keeps its gate.
_mm3_auto=1
[ ! -e "$1/etc/mesa-m3/t8122-profile" ] || return 1
fi
_mm3_dt=$(tr '\0' '\n' 2>/dev/null < "$1/proc/device-tree/compatible")
_mm3_soc=$(_mm3_soc_of "$1")
_mm3_chip=
_mm3_identity=$(printf '%s\n' "$_mm3_dt" | grep -E '^apple,j')
_mm3_socs=$(printf '%s\n' "$_mm3_dt" | grep -E '^apple,t')
# Exactly one board and one SoC compatible. The 13-inch (J613) and 15-inch
# (J615) M3 Air pass the same T8122 checks; mesa-m3-system-check repeats them.
case "$_mm3_soc:$_mm3_identity:$_mm3_socs" in
t8122:apple,j613:apple,t8122) _mm3_chip=t8122 ;;
t8122:apple,j613:apple,t8122 | t8122:apple,j615:apple,t8122) _mm3_chip=t8122 ;;
t6030:apple,j516s:apple,t6030) _mm3_chip=t6030 ;;
*) return 1 ;;
esac
Expand All @@ -422,6 +448,10 @@ _mm3_system_admit() {
_mm3_drv=$(basename "$(readlink -f "$_mm3_node/device/driver" 2>/dev/null)" 2>/dev/null)
[ "$_mm3_drv" = asahi ] || return 1
tr '\0' '\n' 2>/dev/null < "$_mm3_node/device/of_node/compatible" | grep -qx "apple,agx-$_mm3_chip" || return 1
# A node handed off for the 25G83 firmware belongs to the native profile.
if [ "$_mm3_auto" -eq 1 ] && [ -e "$_mm3_node/device/of_node/apple,j613-25g83-gpu-handoff" ]; then
return 1
fi
_mm3_dev="$1/dev/dri/${_mm3_node##*/}"
[ -r "$_mm3_dev" ] && [ -w "$_mm3_dev" ] || return 1
_mm3_dcp=$(_mm3_native_display "$1" "$_mm3_chip") || return 1
Expand All @@ -448,7 +478,7 @@ _mm3_system_admit() {
timeout -k 2 5 env -i PATH=/usr/bin:/bin "$_mm3_helper" \
"/dev/dri/${_mm3_node##*/}" "$_mm3_chip" >/dev/null 2>&1
[ "$?" -eq 0 ] || return 1
printf '%s\n' "system Mesa on /usr admits /dev/dri/${_mm3_node##*/} ($_mm3_chip); /opt/mesa-m3 stays inactive"
printf '%s\n' "system Mesa on /usr admits /dev/dri/${_mm3_node##*/} ($_mm3_chip, $_mm3_identity); /opt/mesa-m3 stays inactive"
}

# _mm3_system_admit in its own sh, under one timeout for the whole check. A
Expand All @@ -461,18 +491,24 @@ _mm3_system_admit_bounded() {
sh "$_mm3_self" "${1:-}" "$_mm3_p"
}

# _mm3_state ROOT DECISION REASON DETAIL FALLBACK: write the state file and the journal
# line. A value holding a newline or carriage return is refused.
_mm3_state() {
# _mm3_login_ids ROOT: this login's uid, session id and boot id, as the state
# file and the attempt record them.
_mm3_login_ids() {
_mm3_uid=$(id -u)
_mm3_sid=${XDG_SESSION_ID:-}
[ -n "$_mm3_sid" ] || _mm3_sid=$(loginctl show-user "$_mm3_uid" -p Display --value 2>/dev/null)
_mm3_boot=
[ -r "$1/proc/sys/kernel/random/boot_id" ] && IFS= read -r _mm3_boot < "$1/proc/sys/kernel/random/boot_id"
}

# _mm3_state ROOT DECISION REASON DETAIL FALLBACK: write the state file and the journal
# line. A value holding a newline or carriage return is refused.
_mm3_state() {
_mm3_login_ids "$1"
_mm3_inv=$(systemctl show -p InvocationID --value "user@$_mm3_uid.service" 2>/dev/null)
_mm3_ver=
[ -r "$1$_mm3_p/share/mesa-m3/package-version" ] &&
IFS= read -r _mm3_ver < "$1$_mm3_p/share/mesa-m3/package-version"
_mm3_boot=
[ -r "$1/proc/sys/kernel/random/boot_id" ] && IFS= read -r _mm3_boot < "$1/proc/sys/kernel/random/boot_id"
_mm3_cr=$(printf '\r')
_mm3_nl='
'
Expand Down Expand Up @@ -501,7 +537,8 @@ _mm3_state() {
return 1
}

# _mm3_attempt ROOT: record that this login uses /opt/mesa-m3, in
# _mm3_attempt ROOT: record that this login uses /opt/mesa-m3 (or the system
# Mesa admitted automatically), in
# ${XDG_STATE_HOME:-~/.local/state}/mesa-m3/attempt (kept across a logout; a
# later boot's gate ignores it by boot_id). It counts as failed until
# mesa-m3-session-confirm.service writes a success marker beside it with the
Expand Down Expand Up @@ -533,7 +570,47 @@ mesa_m3_session_env() {
[ -r /proc/sys/kernel/random/uuid ] && IFS= read -r _mm3_run < /proc/sys/kernel/random/uuid
_mm3_run=${_mm3_run:-unknown}
[ "${_mm3_decision%% *}" = not-supported ] || export MESA_M3_HOOK_RUN_ID="$_mm3_run"
if [ "$_mm3_on" -eq 0 ]; then
# The system Mesa only where the gate ends inactive (see the header): never
# instead of an active /opt/mesa-m3, and not where this is neither a T6030
# nor a T8122 or the session's own Mesa setup chose. A refusal leaves the
# gate's decision and fallback as they were.
_mm3_admitted=0
_mm3_extra=
if [ "$_mm3_on" -ne 0 ]; then
case ${_mm3_decision%% *} in
not-supported | user-setup) ;;
*)
_mm3_sys=$(_mm3_system_admit_bounded "${1:-}")
[ "$?" -ne 0 ] || _mm3_admitted=1 ;;
esac
fi
# Automatic: the attempt comes first. Without it no unconfirmed login could
# send the next one to software, so a failed write keeps the fallback.
if [ "$_mm3_admitted" -eq 1 ] && [ "${_mm3_decision%% *}" != opt-out ]; then
_mm3_login_ids "${1:-}"
if ! _mm3_attempt "${1:-}"; then
_mm3_admitted=0
_mm3_extra="; system Mesa admitted, but its attempt not recorded in ${XDG_STATE_HOME:-$HOME/.local/state}/mesa-m3, so this login keeps the fallback"
fi
fi
if [ "$_mm3_admitted" -eq 1 ]; then
# Only the pair this hook itself exports. Anything else in the
# environment, including a user's own LIBGL_ALWAYS_SOFTWARE without
# this marker, stays.
if [ "${LIBGL_ALWAYS_SOFTWARE:-}" = 1 ] && [ "${MESA_M3_FALLBACK:-}" = software ]; then
unset LIBGL_ALWAYS_SOFTWARE
unset MESA_M3_FALLBACK
fi
if [ "${_mm3_decision%% *}" = opt-out ]; then
# A file opt-out: as before, no new attempt.
_mm3_state "${1:-}" inactive opt-out "${_mm3_decision#* }; $_mm3_sys" none
else
# Automatic: its attempt is already recorded, so a compositor that
# is not confirmed sends the next login of this boot to the
# software fallback instead of looping.
_mm3_state "${1:-}" inactive system-mesa "$_mm3_sys; the /opt/mesa-m3 gate said: $_mm3_decision" none
fi
elif [ "$_mm3_on" -eq 0 ]; then
case ":${LD_LIBRARY_PATH:-}:" in
*":$_mm3_p/lib:"*) ;;
*) export LD_LIBRARY_PATH="$_mm3_p/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" ;;
Expand Down Expand Up @@ -562,44 +639,27 @@ mesa_m3_session_env() {
_mm3_attempt "${1:-}"
else
# Never the system Mesa on an M3 render node it can open (Hyprland
# would stop at start), except where this session's own setup chose,
# or a file opt-out whose system-Mesa handoff passed.
# would stop at start), except where this session's own setup chose.
_mm3_fb=none
_mm3_detail=${_mm3_decision#* }
_mm3_admitted=0
if [ "${_mm3_decision%% *}" = opt-out ]; then
_mm3_sys=$(_mm3_system_admit_bounded "${1:-}")
if [ "$?" -eq 0 ]; then
_mm3_admitted=1
_mm3_detail="$_mm3_detail; $_mm3_sys"
# Only the pair this hook itself exports. Anything else in the
# environment, including a user's own LIBGL_ALWAYS_SOFTWARE
# without this marker, stays.
if [ "${LIBGL_ALWAYS_SOFTWARE:-}" = 1 ] && [ "${MESA_M3_FALLBACK:-}" = software ]; then
unset LIBGL_ALWAYS_SOFTWARE
unset MESA_M3_FALLBACK
fi
fi
fi
if [ "$_mm3_admitted" -eq 0 ] && [ "${_mm3_decision%% *}" != user-setup ] && _mm3_node_open "${1:-}"; then
if [ "${_mm3_decision%% *}" != user-setup ] && _mm3_node_open "${1:-}"; then
export LIBGL_ALWAYS_SOFTWARE=1
export MESA_M3_FALLBACK=software
_mm3_fb=software
fi
_mm3_state "${1:-}" inactive "${_mm3_decision%% *}" "$_mm3_detail" "$_mm3_fb"
_mm3_state "${1:-}" inactive "${_mm3_decision%% *}" "${_mm3_decision#* }$_mm3_extra" "$_mm3_fb"
fi
}

if [ -z "${MESA_M3_SESSION_ENV_NO_RUN:-}" ]; then
mesa_m3_session_env
unset -f mesa_m3_gate mesa_m3_session_env _mm3_init _mm3_state _mm3_node_open _mm3_attempt \
_mm3_soc_of _mm3_25g83_board _mm3_native_display _mm3_kernel_log \
_mm3_legacy_attempt_clear _mm3_system_admit _mm3_system_admit_bounded
_mm3_legacy_attempt_clear _mm3_system_admit _mm3_system_admit_bounded _mm3_login_ids
fi
unset _mm3_root _mm3_p _mm3_nodes _mm3_node _mm3_n _mm3_drv _mm3_dcp _mm3_c _mm3_dev _mm3_f _mm3_v \
_mm3_val _mm3_ifs _mm3_d _mm3_out _mm3_rc _mm3_decision _mm3_on \
_mm3_so _mm3_uid _mm3_sid _mm3_inv _mm3_ver _mm3_boot _mm3_cr _mm3_nl \
_mm3_body _mm3_kv _mm3_dir _mm3_tmp _mm3_fb _mm3_run _mm3_att _mm3_ok _mm3_faults _mm3_ign _mm3_igd \
_mm3_soc _mm3_name _mm3_dt _mm3_base _mm3_profile _mm3_requested _mm3_files _mm3_gate_ifs _mm3_board _mm3_note \
_mm3_klog _mm3_sys _mm3_admitted _mm3_detail _mm3_helper _mm3_chip _mm3_identity _mm3_socs _mm3_cmdline \
_mm3_self
_mm3_self _mm3_auto _mm3_extra
Loading