diff --git a/gamescope-session/usr/share/gamescope-session-plus/gamescope-session-plus b/gamescope-session/usr/share/gamescope-session-plus/gamescope-session-plus index 3594863..5e027b9 100755 --- a/gamescope-session/usr/share/gamescope-session-plus/gamescope-session-plus +++ b/gamescope-session/usr/share/gamescope-session-plus/gamescope-session-plus @@ -1,21 +1,14 @@ #!/bin/bash +set -x + +SYS_ID="$(cat /sys/devices/virtual/dmi/id/product_name)" + declare -r CLIENT=$1 declare -r CLIENT_CONFIG_DIR_USR=/usr/share/gamescope-session-plus/sessions.d declare -r CLIENT_CONFIG_DIR_ETC=/etc/gamescope-session-plus/sessions.d declare -r CLIENT_CONFIG_DIR_LOCAL="${XDG_CONFIG_HOME:-$HOME/.config}/gamescope-session-plus/sessions.d" -# Reset power-profiles-daemon/TuneD to balanced if the current profile is power save, this allows desktop control without greatly harming gaming performance. -if command -v tuned-adm > /dev/null; then - if grep -qz "powersave" <<< "$(tuned-adm active)"; then - tuned-adm profile balanced - fi -elif command -v powerprofilesctl > /dev/null; then - if grep -qz "power-saver" <<< "$(powerprofilesctl get)"; then - powerprofilesctl set balanced - fi -fi - # default empty session recovery function short_session_recover() { : @@ -26,8 +19,24 @@ post_gamescope_start() { : } +# default empty function to run after client exits +post_client_shutdown() { + : +} + +get_gamescope_binary() { + if [ -n "$GAMESCOPE_BIN" ]; then + echo $GAMESCOPE_BIN + elif /usr/libexec/gamescope-sdl-workaround && command -v /usr/bin/gamescope-legacy > /dev/null; then + # GPUs that require the SDL backend + echo "/usr/bin/gamescope-legacy" + else + echo "/usr/bin/gamescope" + fi +} + gamescope_has_option() { - if (gamescope --help 2>&1 | grep -e "$1" > /dev/null); then + if ($(get_gamescope_binary) --help 2>&1 | grep -e "$1" > /dev/null); then return 0 fi @@ -40,6 +49,15 @@ gamescope_has_option() { export INTEL_DEBUG=norbc export mesa_glthread=true +# This should be used by default by gamescope. Cannot hurt to force it anyway. +# Reported better framelimiting with this enabled +if /usr/libexec/gamescope-sdl-workaround; then + # Skip on legacy hardware + export ENABLE_GAMESCOPE_WSI=0 +else + export ENABLE_GAMESCOPE_WSI=1 +fi + # Force Qt applications to run under xwayland export QT_QPA_PLATFORM=xcb @@ -72,6 +90,11 @@ touch "$GAMESCOPE_PATCHED_EDID_FILE" # and Gamescope will use for now. export GAMESCOPE_NV12_COLORSPACE=k_EStreamColorspace_BT601 +# Workaround older versions of vkd3d-proton setting this +# too low (desc.BufferCount), resulting in symptoms that are potentially like +# swapchain starvation. +export VKD3D_SWAPCHAIN_LATENCY_FRAMES=3 + # Initially write no_display to our config file # so we don't get mangoapp showing up before Steam initializes # on OOBE and stuff. @@ -95,14 +118,6 @@ export GAMESCOPE_LIMITER_FILE=$(mktemp /tmp/gamescope-limiter.XXXXXXXX) # Temporary crutch until dummy plane interactions / etc are figured out export GAMESCOPE_DISABLE_ASYNC_FLIPS=1 -# Make Qt apps use the styling and behaviour of the desktop session -# This fixes some missing icons and unreadable text with Qt desktop apps in gamescope -if [[ ${BASE_IMAGE_NAME} == 'silverblue' ]]; then - export QT_QPA_PLATFORM_THEME=gtk2 -else - export QT_QPA_PLATFORM_THEME=kde -fi - ulimit -n 524288 # Source device quirks if exists @@ -191,21 +206,11 @@ if [ -z "$GAMESCOPECMD" ]; then ADAPTIVE_SYNC_OPTION="--adaptive-sync" fi - FORCE_COMPOSITION_OPTION="" - if [ -n "$FORCE_COMPOSITION" ]; then - FORCE_COMPOSITION_OPTION="--force-composition" - fi - PANEL_TYPE_OPTION="" if [ -n "$PANEL_TYPE" ] && gamescope_has_option "--force-panel-type"; then PANEL_TYPE_OPTION="--force-panel-type $PANEL_TYPE" fi - BYPASS_STEAM_RESOLUTION_OPTION="" - if [ ! -n "$DONT_BYPASS_RESOLUTION" ] && gamescope_has_option "--bypass-steam-resolution"; then - BYPASS_STEAM_RESOLUTION_OPTION="--bypass-steam-resolution" - fi - CUSTOM_REFRESH_RATES_OPTION="" if [ -n "$CUSTOM_REFRESH_RATES" ] && gamescope_has_option "--custom-refresh-rates"; then CUSTOM_REFRESH_RATES_OPTION="--custom-refresh-rates $CUSTOM_REFRESH_RATES" @@ -217,36 +222,28 @@ if [ -z "$GAMESCOPECMD" ]; then BACKEND_OPTION="--backend $BACKEND" fi - DISABLE_TOUCH_CLICK_OPTION="" - if [ -n "$DISABLE_TOUCH_CLICK" ] && gamescope_has_option "--disable-touch-click"; then - DISABLE_TOUCH_CLICK_OPTION="--disable-touch-click" - fi + HDR_OPTIONS="" + if [ "$ENABLE_GAMESCOPE_HDR" == "1" ] && [ "$ENABLE_GAMESCOPE_WSI" == "1" ] && gamescope_has_option "--hdr-enabled" && gamescope_has_option "--hdr-itm-enable"; then + HDR_OPTIONS="--hdr-enabled --hdr-itm-enable" + export ENABLE_HDR_WSI=1 + export DXVK_HDR=1 + fi - MURA_OPTION="" - if [ -n "$MURA" ] && gamescope_has_option "--mura-map"; then - MURA_OPTION="--mura-map $MURA" - fi + if [ -n "$GAMESCOPE_HDR_NITS" ] && gamescope_has_option "--hdr-itm-sdr-nits" && gamescope_has_option "--hdr-sdr-content-nits"; then + HDR_OPTIONS="$HDR_OPTIONS --hdr-itm-sdr-nits $GAMESCOPE_HDR_NITS --hdr-sdr-content-nits $GAMESCOPE_HDR_NITS" + fi - TOUCH_GESTURES_OPTION="" - if [ -n "$TOUCH_GESTURES" ] && gamescope_has_option "--touch-gestures"; then - TOUCH_GESTURES_OPTION="--touch-gestures" - fi - - GAMESCOPECMD="/usr/bin/gamescope \ + GAMESCOPECMD="$(get_gamescope_binary) \ $CURSOR \ $RESOLUTION \ $INTERNAL_RESOLUTION \ - $DRM_MODE_OPTION \ $ORIENTATION_OPTION \ + $DRM_MODE_OPTION \ $ADAPTIVE_SYNC_OPTION \ - $FORCE_COMPOSITION_OPTION \ $PANEL_TYPE_OPTION \ - $BYPASS_STEAM_RESOLUTION_OPTION \ $CUSTOM_REFRESH_RATES_OPTION \ $BACKEND_OPTION \ - $DISABLE_TOUCH_CLICK_OPTION \ - $MURA_OPTION \ - $TOUCH_GESTURES_OPTION \ + $HDR_OPTIONS \ --prefer-output $OUTPUT_CONNECTOR \ --xwayland-count $XWAYLAND_COUNT \ --default-touch-mode $TOUCH_MODE \ @@ -266,7 +263,7 @@ fi # Attempt to fallback to a desktop session if something goes wrong too many times short_session_tracker_file="/tmp/chimeraos-short-session-tracker" short_session_duration=60 -short_session_count_before_reset=3 +short_session_count_before_reset=5 SECONDS=0 short_session_count=$(wc <"$short_session_tracker_file" -l) @@ -281,30 +278,18 @@ if [[ "$short_session_count" -ge "$short_session_count_before_reset" ]]; then exit 1 fi -# Log rotate the last session -if [ -f "${HOME}"/.${CLIENT}-stdout.log ]; then - cp "${HOME}"/.${CLIENT}-stdout.log "${HOME}"/.${CLIENT}-stdout.log.old -fi -if [ -f "${HOME}"/.gamescope-stdout.log ]; then - cp "${HOME}"/.gamescope-stdout.log "${HOME}"/.gamescope-stdout.log.old -fi -if [ -f "${HOME}"/.gamescope-cmd.log ]; then - cp "${HOME}"/.gamescope-cmd.log "${HOME}"/.gamescope-cmd.log.old -fi - -# Start gamescope compositor, log it's output and background it -echo $GAMESCOPECMD >"${HOME}"/.gamescope-cmd.log -$GAMESCOPECMD >"${HOME}"/.gamescope-stdout.log 2>&1 & +# Start gamescope compositor and background it +$GAMESCOPECMD & gamescope_pid="$!" -if read -r -t 15 response_x_display response_wl_display <> "$socket"; then +if read -r -t 3 response_x_display response_wl_display <>"$socket"; then export DISPLAY="$response_x_display" export GAMESCOPE_WAYLAND_DISPLAY="$response_wl_display" # We're done! else echo "gamescope failed" >>"$short_session_tracker_file" kill -9 "$gamescope_pid" - wait + wait -n "$gamescope_pid" exit 1 # Systemd or Session manager will have to restart session fi @@ -320,18 +305,16 @@ fi # If we have mangoapp binary start it if command -v mangoapp >/dev/null; then (while true; do - mangoapp >"${HOME}"/.mangoapp-stdout.log 2>&1 + mangoapp done) & fi -# Start discover-overlay if discord is installed -if command -v discover-overlay > /dev/null && grep -q "com.discordapp.Discord" <<< $(/usr/bin/flatpak list --app --columns=application); then - env DISPLAY=:0 discover-overlay 2>&1 & -fi - -# If the Sunshine service is enabled, restart it -if systemctl is-enabled --user sunshine.service; then - systemctl restart --user sunshine.service 2>&1 & +# Handle Galileo Mura Correction +# This is applied here and not in device-quirks because it must be called after gamescope has started. +if [[ ":Galileo:" =~ ":$SYS_ID:" ]]; then + if command -v galileo-mura-setup > /dev/null; then + galileo-mura-setup & + fi fi # For compatibility with older user configuration overrides @@ -340,7 +323,7 @@ if [ -n "$STEAMCMD" ]; then fi # Start client application -$CLIENTCMD >"${HOME}/.${CLIENT}-stdout.log" 2>&1 +$CLIENTCMD if [[ "$SECONDS" -lt "$short_session_duration" ]]; then echo "${CLIENT} failed" >>"$short_session_tracker_file" @@ -348,6 +331,8 @@ else rm "$short_session_tracker_file" fi +post_client_shutdown + # When the client exits, kill gamescope nicely kill $gamescope_pid @@ -390,4 +375,4 @@ for job in $(jobs -p); do ps -p "$job" >&2 fi kill -9 "$job" -done +done \ No newline at end of file