mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +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
@@ -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")
|
||||
|
||||
@@ -258,7 +258,7 @@
|
||||
<string name="mode_ratio_auto">Auto uses at least 16:9.</string>
|
||||
<string name="mode_fps">Frame limit</string>
|
||||
<string name="mode_performance">Performance mode</string>
|
||||
<string name="mode_performance_hint">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.</string>
|
||||
<string name="mode_performance_hint">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.</string>
|
||||
<string name="mode_fps_note">Caps the whole session. The display switches to a refresh rate the cap divides evenly.</string>
|
||||
<string name="mode_hdr">HDR</string>
|
||||
<string name="mode_hdr10">HDR10 output</string>
|
||||
|
||||
@@ -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