mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 14:26:00 +00:00
feat: Steam's Frame Limit decides; gamescope and the limit follow the refresh rate (#1650)
Remove the Performance mode switch. The session always runs the way Performance mode did: replaced buffers go back to the game at once (except while mirroring to glasses), gamescope's WSI layer and winex11 reuse their per-present window checks, and games get eight swapchain images while uncapped. Steam's Frame Limit in the Quick Access menu is the only limit. gamescope 3.16.29-p15 (p14 plus two patches): - 0119: with the Frame Limit on, gamescope forces FIFO while the WSI layer hands the driver MAILBOX, so a game with eight images could queue up to seven frames ahead of the screen. While the limiter forces FIFO the layer uses its default of 3 images; DXVK and VKD3D-Proton recreate their swapchain when the limiter changes, other apps are asked to with VK_SUBOPTIMAL_KHR. - 0120: -r fixed gamescope's pacing and limiter rate for the whole session. With GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST=1 a rate the host has reported for 300 ms replaces it (a switch from 144 to 120 Hz passes through 72 Hz for a few frames), and Steam gets the display information again. The session sets it whenever it passes -r. Steam keeps its Frame Limit as the client setting gamescope_app_target_framerate and offers the values gamescope's display state lists. After a refresh change, a limit the new rate does not offer (72 at 120 Hz) left the slider on its first value while the game kept the old limit. The Steam helper watches the offered values and, once they settle, keeps the limit when it is still offered and moves it to the highest value otherwise, through Steam's own setting so the slider shows it. Steam's webpack does not expose its module cache, so the gamescope service is found by the calls its module makes, and the helper retries the install every 10 s until Steam is ready. The session window asks for the fastest mode the peak refresh setting allows and chose again only when the display changed, so after it had asked for 60 Hz, raising Android's refresh setting left the display, gamescope and the limit at 60. It now also chooses again when peak_refresh_rate or min_refresh_rate changes.
This commit is contained in:
1 parent
0e9a31ccfe
commit
4c7e59ed8b
52 files changed
+466
-133
No files matched your search
@@ -238,6 +238,8 @@ if [ -z "${BL_INSIDE:-}" ]; then
|
||||
fi
|
||||
if [ "${BL_REFRESH:-0}" -gt 0 ]; then
|
||||
args+=(-r "$BL_REFRESH")
|
||||
# -r is the starting rate; gamescope follows the panel when it switches modes later.
|
||||
export GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST=1
|
||||
fi
|
||||
[ "$mode" = steam ] && [ "${BL_STEAM_UI:-}" != desktop ] && args+=(-e)
|
||||
if [ "$mode" = steam ] && [ "${BL_XWAYLAND_COUNT:-2}" -gt 1 ]; then
|
||||
|
||||
@@ -241,6 +241,74 @@ TOUR_JS = r"""
|
||||
return "off";
|
||||
})()
|
||||
"""
|
||||
# Steam keeps the Quick Access Frame Limit as the client setting gamescope_app_target_framerate
|
||||
# (CMsgClientSettings field 21002) and offers the values gamescope's display state lists in
|
||||
# active_display_info.supported_frame_rates. When the panel's refresh rate changes, a remembered
|
||||
# limit that is not one of the new values leaves the slider on its first value while the game runs
|
||||
# at the old limit. The limit is kept when it is still offered and moved to the highest value
|
||||
# otherwise. Choices are read once they have been unchanged for a moment, since a mode switch can
|
||||
# report a passing rate first.
|
||||
FRAME_LIMIT_JS = r"""
|
||||
(() => {
|
||||
if (window.__droiddeckFrameLimit) return "present";
|
||||
const settings = window.settingsStore;
|
||||
let service = null;
|
||||
try {
|
||||
// Steam's webpack does not expose its module cache; the gamescope service client is found by
|
||||
// the calls its module makes and loaded by id.
|
||||
let require;
|
||||
window.webpackChunksteamui.push([[Symbol("droiddeck-frame-limit")], {}, r => { require = r; }]);
|
||||
for (const id of Object.keys(require.m || {})) {
|
||||
const source = String(require.m[id]);
|
||||
if (!source.includes("SetBlurParams") || !source.includes("RegisterForNotifyStateChanged")) continue;
|
||||
let exports;
|
||||
try { exports = require(id); } catch (e) { continue; }
|
||||
if (!exports || typeof exports !== "object") continue;
|
||||
service = Object.values(exports).find(value => value && typeof value.GetState === "function" &&
|
||||
typeof value.RegisterForNotifyStateChanged === "function" && typeof value.SetBlurParams === "function");
|
||||
if (service) break;
|
||||
}
|
||||
} catch (e) {
|
||||
service = null;
|
||||
}
|
||||
if (!service || !settings?.clientSettings || typeof SteamClient.Settings?.SetSetting !== "function") return "unavailable";
|
||||
const self = { choices: null, timer: null };
|
||||
const write = value => {
|
||||
const bytes = [];
|
||||
for (let n of [21002 * 8, value]) {
|
||||
while (n > 127) { bytes.push((n & 127) | 128); n = Math.floor(n / 128); }
|
||||
bytes.push(n);
|
||||
}
|
||||
SteamClient.Settings.SetSetting(btoa(String.fromCharCode(...bytes)));
|
||||
};
|
||||
self.check = async () => {
|
||||
let rates;
|
||||
try {
|
||||
const reply = await service.GetState({});
|
||||
if (!reply.BSuccess()) return;
|
||||
rates = reply.Body().toObject().state?.active_display_info?.supported_frame_rates;
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
if (!Array.isArray(rates) || rates.length === 0) return;
|
||||
const choices = rates.join(",");
|
||||
if (choices === self.choices) return;
|
||||
self.choices = choices;
|
||||
const current = settings.clientSettings;
|
||||
if (!current.gamescope_enable_app_target_framerate || rates.includes(current.gamescope_app_target_framerate)) return;
|
||||
write(Math.max(...rates));
|
||||
};
|
||||
self.schedule = () => {
|
||||
clearTimeout(self.timer);
|
||||
self.timer = setTimeout(self.check, 1500);
|
||||
};
|
||||
self.subscription = service.RegisterForNotifyStateChanged(self.schedule);
|
||||
self.interval = setInterval(self.schedule, 5000);
|
||||
self.schedule();
|
||||
window.__droiddeckFrameLimit = self;
|
||||
return "installed";
|
||||
})()
|
||||
"""
|
||||
FILE_BINDING = "droiddeckOpenFileDialog"
|
||||
FILE_JS = r"""
|
||||
(() => {
|
||||
@@ -680,6 +748,8 @@ class Helper:
|
||||
self.chooser = None
|
||||
self.controls_state = None
|
||||
self.controls_installed = False
|
||||
self.frame_limit_state = None
|
||||
self.frame_limit_retry = 0
|
||||
|
||||
def sync_controls(self):
|
||||
try:
|
||||
@@ -702,6 +772,19 @@ class Helper:
|
||||
except (OSError, ValueError, TypeError):
|
||||
pass
|
||||
|
||||
def sync_frame_limit(self):
|
||||
# Steam can still be loading its settings and gamescope state when the helper attaches.
|
||||
if self.frame_limit_state in ("installed", "present") or time.monotonic() < self.frame_limit_retry:
|
||||
return
|
||||
try:
|
||||
state = self.page.evaluate(FRAME_LIMIT_JS)
|
||||
except RuntimeError as e:
|
||||
state = "failed (%s)" % e
|
||||
if state != self.frame_limit_state:
|
||||
say("frame limit sync: %s" % state)
|
||||
self.frame_limit_state = state
|
||||
self.frame_limit_retry = time.monotonic() + 10
|
||||
|
||||
def open_chooser(self, payload):
|
||||
try:
|
||||
request = json.loads(payload)
|
||||
@@ -801,6 +884,8 @@ class Helper:
|
||||
self.page = page
|
||||
self.controls_state = None
|
||||
self.controls_installed = False
|
||||
self.frame_limit_state = None
|
||||
self.frame_limit_retry = 0
|
||||
self.sync_controls()
|
||||
return True
|
||||
|
||||
@@ -956,6 +1041,7 @@ class Helper:
|
||||
self.ensure_tools()
|
||||
while True:
|
||||
self.sync_controls()
|
||||
self.sync_frame_limit()
|
||||
sources = [self.page.ws] + ([watcher] if watcher.fileno() >= 0 else [])
|
||||
if self.chooser is not None:
|
||||
sources.append(self.chooser[1].stdout)
|
||||
|
||||
Reference in new issue
Block a user