mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 22:36:00 +00:00
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.
This commit is contained in:
1 parent
78f95c5a0c
commit
1b3814a587
3 files changed
+40
-1
No files matched your search
@@ -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)"
|
||||
|
||||
Reference in new issue
Block a user