From 1b3814a5876788962141d1a53c4ffcd8cc367c9c Mon Sep 17 00:00:00 2001
From: The412Banner <205237651+The412Banner@users.noreply.github.com>
Date: Mon, 26 Oct 2026 09:16:05 -0400
Subject: [PATCH] Hold games to the frame limit in Performance mode (#1609)
A frame limit only paced what reached the screen: a game without vsync
kept drawing hundreds of frames a second that were thrown away (AIO at
a 60 fps limit drew 155 to 2,446 fps), so the limit saved no power.
With Performance mode on and a frame limit set, the session now sets
gamescope's per-game limit over gamescope_control (gamescopectl
debug_set_fps_limit). gamescope's limiter then has its WSI layer hold
Vulkan games, DXVK and VKD3D included, to the limit. gamescope's own
--framerate-limit option is reset on its first frame in 3.16.29, and
Steam resets the per-game limit while it starts, so the session watches
gamescope's limiter state file and sets the limit again whenever it is
off (a once-a-second check with shell builtins, no process started).
With Performance mode off, a limit paces the screen only, as before.
The session also gives gamescope a fixed limiter state file path, so
gamescope stops leaving a new one behind on every start, and removes
the old ones.
Device-proven on the AYANEO Pocket FIT (Turnip, AIO D3D11, 45 s runs on
battery, three runs each): at a 60 fps limit the game held exactly
60.0 fps and the device drew 7.08 W instead of 9.45 W, with 1.3 instead
of 2.6 busy cores and 5 instead of 11 % GPU load. No limit: unchanged.
---
.../launcher/session/SessionService.kt | 2 +
app/src/main/res/values/strings.xml | 2 +-
.../overlay/usr/local/bin/droiddeck-session | 37 +++++++++++++++++++
3 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt
index b49e6392d8..c81c1831c0 100644
--- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt
+++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt
@@ -483,6 +483,8 @@ class SessionService : Service() {
val windowCheckMs = if (SessionState.performanceMode) 100 else 0
guest.add("DROIDDECK_WSI_BYPASS_CHECK_MS=$windowCheckMs")
guest.add("WINE_OFFSCREEN_CHECK_MS=$windowCheckMs")
+ // With a frame limit, gamescope's limiter also holds the games to it instead of only pacing the screen.
+ guest.add("DROIDDECK_GAME_FRAME_LIMIT=" + (if (SessionState.performanceMode) 1 else 0))
if (SessionPrefs.compositorFpsLimit(SessionState.fpsLimit, SessionState.performanceMode) == SessionPrefs.FPS_UNPACED) {
// gamescope turns buffers around slower than an unpaced game draws; more images keep it drawing.
guest.add("GAMESCOPE_WSI_MIN_IMAGE_COUNT=8")
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 03204a9ffa..6de9cdb354 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -258,7 +258,7 @@
Auto uses at least 16:9.
Frame limit
Performance mode
- With no frame limit, games run as fast as they can: frames go back to the game without waiting for the screen. With a frame limit, frames stay paced to it. Either way, gamescope and Wine skip repeated window checks. Uses more power and runs warmer without a limit. Applies next session.
+ With no frame limit, games run as fast as they can: frames go back to the game without waiting for the screen. With a frame limit, games are held to it instead of drawing frames the screen never shows. Either way, gamescope and Wine skip repeated window checks. Uses more power and runs warmer without a limit. Applies next session.
Caps the whole session. The display switches to a refresh rate the cap divides evenly.
HDR
HDR10 output
diff --git a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session
index bc3febb332..755a9fce89 100755
--- a/tools/linuxfs/overlay/usr/local/bin/droiddeck-session
+++ b/tools/linuxfs/overlay/usr/local/bin/droiddeck-session
@@ -70,6 +70,31 @@ steam_update_stuck() {
[ "$steam_updates" -ge 3 ]
}
+# gamescope's --framerate-limit lasts only until its first frame, which recomputes the limit
+# from the per-app value set over gamescope_control, and Steam resets that value to 0 while it
+# starts. Watch gamescope's limiter state file (first byte 1 = limiter on) and set the value
+# again whenever it is off; the limiter then makes the WSI layer hold Vulkan games (DXVK and
+# VKD3D included) to it. Shell builtins only, so the once-a-second check starts no process.
+hold_games_to_frame_limit() {
+ local fps=$1 file=$2 parent=$3 state sent=0 nap napfd=
+ command -v gamescopectl >/dev/null || { echo "== gamescope: no gamescopectl, the frame limit paces the screen only"; return 0; }
+ nap=$(mktemp -u "${XDG_RUNTIME_DIR:-/tmp}/droiddeck-nap.XXXXXX") && mkfifo "$nap" 2>/dev/null \
+ && exec {napfd}<>"$nap"; rm -f "$nap"
+ while kill -0 "$parent" 2>/dev/null; do
+ if [ -f "$file" ]; then
+ state=
+ IFS= read -r -n1 -d '' state < "$file"
+ if [ "$state" != $'\x01' ] && gamescopectl debug_set_fps_limit "$fps" >/dev/null 2>&1; then
+ sent=$((sent + 1))
+ if [ "$sent" = 1 ]; then echo "== gamescope: games held to $fps fps"
+ elif [ "$sent" -le 4 ]; then echo "== gamescope: the frame limit was reset, set it again"
+ fi
+ fi
+ fi
+ if [ -n "$napfd" ]; then read -r -t 1 -u "$napfd" _; else sleep 1; fi
+ done
+}
+
run_gamescope() (
local status_file child_status compositor_status
status_file=$(mktemp "${XDG_RUNTIME_DIR:-/tmp}/droiddeck-steam-exit.XXXXXX") || exit 73
@@ -238,6 +263,13 @@ if [ -z "${BL_INSIDE:-}" ]; then
fi
if [ "${BL_FPS:-0}" -gt 0 ]; then
args+=(-r "$BL_FPS")
+ # -r alone only paces what reaches the screen: a game without vsync keeps drawing
+ # hundreds of frames that are thrown away. Performance mode also holds the games to it.
+ if [ "${DROIDDECK_GAME_FRAME_LIMIT:-0}" = 1 ]; then
+ game_frame_limit=$BL_FPS
+ else
+ echo "== gamescope: frame limit $BL_FPS paces the screen only"
+ fi
elif [ "${BL_REFRESH:-0}" -gt 0 ]; then
args+=(-r "$BL_REFRESH")
fi
@@ -258,6 +290,11 @@ if [ -z "${BL_INSIDE:-}" ]; then
echo "== gamescope: mangoapp on ($(command -v mangoapp), config $MANGOHUD_CONFIGFILE)"
fi
export BL_INSIDE=1
+ # A fixed path: left to itself gamescope creates a new limiter state file on every start.
+ rm -f "${XDG_RUNTIME_DIR:-/tmp}"/gamescope-limiter-*
+ export GAMESCOPE_LIMITER_FILE="${XDG_RUNTIME_DIR:-/tmp}/droiddeck-gamescope-limiter"
+ rm -f "$GAMESCOPE_LIMITER_FILE"
+ [ -n "${game_frame_limit:-}" ] && hold_games_to_frame_limit "$game_frame_limit" "$GAMESCOPE_LIMITER_FILE" $$ &
if [ "$mode" = steam ]; then
if /usr/local/bin/droiddeck-pipewire start; then
eval "$(/usr/local/bin/droiddeck-pipewire env)"