mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
fix(gamescope): default images under the frame limiter, refresh follows the panel
With Steam's Frame Limit on, gamescope forces FIFO while the WSI layer always hands the driver MAILBOX, so a game with the eight images the app asks for could queue up to seven frames ahead of the screen. While the limiter forces FIFO the layer now uses its default of 3 images; DXVK and VKD3D-Proton already recreate their swapchain when the limiter changes, other apps are asked to with VK_SUBOPTIMAL_KHR (0119). -r fixed gamescope's pacing and limiter rate for the whole session, so a panel switched to another mode kept the old rate until the next session. With GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST=1 the rate the host compositor reports replaces it, and Steam gets the display information again (0120). The session sets it whenever it passes -r.
This commit is contained in:
1 parent
73daaf7adc
commit
c4ade69eb3
6 files changed
+166
-3
No files matched your search
@@ -96,8 +96,7 @@ running AIO Graphics Test uncapped, Xwayland used 24-32% of a core and the game'
|
||||
present thread sat about half idle.
|
||||
|
||||
The patch can keep the result for `DROIDDECK_WSI_BYPASS_CHECK_MS` milliseconds. Unset
|
||||
or 0 keeps the per-present check; the app sets 100 only in Performance mode and 0
|
||||
otherwise. With 100, a window resize or a flip/obscure change is seen up to 100 ms
|
||||
or 0 keeps the per-present check; the app sets 100. With 100, a window resize or a flip/obscure change is seen up to 100 ms
|
||||
later than before; surface creation and capability queries still check every time.
|
||||
|
||||
## 0118 Wayland: preserve signed plane positions
|
||||
@@ -121,3 +120,34 @@ The old component lost the image in Fill and magnification. The tested executabl
|
||||
matches the pinned p14 archive and the locally assembled APK. Hardware checks used
|
||||
native Gamescope properties; the physical Back+LB shortcut was not independently
|
||||
confirmed. The original APK and runtime were restored after validation.
|
||||
|
||||
## 0119 WSI: default image count while the frame limiter runs
|
||||
|
||||
The app sets `GAMESCOPE_WSI_MIN_IMAGE_COUNT=8` so an uncapped game keeps drawing while
|
||||
gamescope turns its buffers around. With Steam's Frame Limit on, gamescope forces FIFO,
|
||||
and the layer always hands the driver MAILBOX, so a game with eight images could queue
|
||||
up to seven frames inside gamescope before it blocked: each one adds a frame of input
|
||||
latency at the limited rate.
|
||||
|
||||
While the limiter forces FIFO, the layer now reports and enforces its default minimum
|
||||
of 3 images instead of the raised count; with the limiter off it uses the raised count
|
||||
as before. DXVK and VKD3D-Proton already recreate their swapchain when the limiter
|
||||
changes (the layer returns `VK_ERROR_OUT_OF_DATE_KHR`), so their image count follows
|
||||
the Quick Access menu. Other apps keep their swapchain on a limiter change; they now
|
||||
get `VK_SUBOPTIMAL_KHR` while their image count no longer matches, unless the layer
|
||||
marks them as not taking it (`NoSuboptimal`).
|
||||
|
||||
## 0120 Wayland: nested refresh follows the host
|
||||
|
||||
`-r` fixes the refresh gamescope paces at, and the frame limiter and Steam's Frame Limit
|
||||
slider use the same value. The app passes the panel refresh at session start, so a
|
||||
panel switched to another mode during the session (for example in the device's own
|
||||
quick settings) left gamescope pacing at the old rate until the next session; only the
|
||||
reported output refresh changed.
|
||||
|
||||
With `GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST=1`, a refresh the host compositor reports
|
||||
through presentation feedback replaces the `-r` value, so pacing and the limiter switch
|
||||
with the panel. `-r` still sets the starting rate, which avoids gamescope assuming
|
||||
60 Hz until the first frame is shown. When the refresh changes, gamescope also sends
|
||||
its `gamescope_control` display information to Steam again; Steam otherwise reads it
|
||||
only when it binds.
|
||||
@@ -0,0 +1,59 @@
|
||||
diff --git a/layer/VkLayer_FROG_gamescope_wsi.cpp b/layer/VkLayer_FROG_gamescope_wsi.cpp
|
||||
index ea4ba84..46d086c 100644
|
||||
--- a/layer/VkLayer_FROG_gamescope_wsi.cpp
|
||||
+++ b/layer/VkLayer_FROG_gamescope_wsi.cpp
|
||||
@@ -201,6 +201,13 @@ namespace GamescopeWSILayer {
|
||||
return s_minImageCount;
|
||||
}
|
||||
|
||||
+ // The raised count keeps an uncapped game drawing while gamescope turns its buffers around.
|
||||
+ // Under the frame limiter's FIFO the extra images only queue frames ahead of the screen,
|
||||
+ // so a limited swapchain gets the default count.
|
||||
+ static uint32_t getMinImageCount(bool forcingFifo) {
|
||||
+ return forcingFifo ? std::min(getMinImageCount(), 3u) : getMinImageCount();
|
||||
+ }
|
||||
+
|
||||
static bool getEnsureMinImageCount() {
|
||||
static bool s_ensureMinImageCount = []() -> bool {
|
||||
if (auto ensure = parseEnv<bool>("GAMESCOPE_WSI_ENSURE_MIN_IMAGE_COUNT")) {
|
||||
@@ -984,7 +991,7 @@ namespace GamescopeWSILayer {
|
||||
|
||||
pSurfaceCapabilities->currentExtent = rect->extent;
|
||||
}
|
||||
- pSurfaceCapabilities->minImageCount = getMinImageCount();
|
||||
+ pSurfaceCapabilities->minImageCount = getMinImageCount(gamescopeIsForcingFifo(gamescopeSurface->waylandObjects));
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
@@ -1027,7 +1034,7 @@ namespace GamescopeWSILayer {
|
||||
|
||||
pSurfaceCapabilities->surfaceCapabilities.currentExtent = rect->extent;
|
||||
}
|
||||
- pSurfaceCapabilities->surfaceCapabilities.minImageCount = getMinImageCount();
|
||||
+ pSurfaceCapabilities->surfaceCapabilities.minImageCount = getMinImageCount(gamescopeIsForcingFifo(gamescopeSurface->waylandObjects));
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
@@ -1305,7 +1312,7 @@ namespace GamescopeWSILayer {
|
||||
|
||||
uint32_t minImageCount = swapchainInfo.minImageCount;
|
||||
if (getEnsureMinImageCount())
|
||||
- minImageCount = std::max(getMinImageCount(), minImageCount);
|
||||
+ minImageCount = std::max(getMinImageCount(gamescopeIsForcingFifo(gamescopeSurface->waylandObjects)), minImageCount);
|
||||
swapchainInfo.minImageCount = minImageCount;
|
||||
|
||||
fprintf(stderr, "[Gamescope WSI] Creating swapchain for xid: 0x%0x - oldSwapchain: %p - provided minImageCount: %u - minImageCount: %u - format: %s - colorspace: %s - flip: %s\n",
|
||||
@@ -1627,6 +1634,13 @@ namespace GamescopeWSILayer {
|
||||
continue;
|
||||
}
|
||||
|
||||
+ // Other apps keep their swapchain when the limiter changes; ask them to recreate it so
|
||||
+ // the image count follows the limiter as well.
|
||||
+ if (!frameLimiterAware && gamescopeSwapchain->forceFifo != forceFifo &&
|
||||
+ getMinImageCount(true) != getMinImageCount(false) &&
|
||||
+ !(gamescopeSurface->flags & GamescopeLayerClient::Flag::NoSuboptimal))
|
||||
+ UpdateSwapchainResult(VK_SUBOPTIMAL_KHR);
|
||||
+
|
||||
const bool canBypass = gamescopeSurface->canBypassXWaylandAtPresent(gamescopeSwapchain->isHdrColorspace);
|
||||
if (canBypass != gamescopeSwapchain->isBypassingXWayland) {
|
||||
if (canBypass) {
|
||||
@@ -0,0 +1,63 @@
|
||||
diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp
|
||||
index 40164ba..fa6060e 100644
|
||||
--- a/src/Backends/WaylandBackend.cpp
|
||||
+++ b/src/Backends/WaylandBackend.cpp
|
||||
@@ -1698,6 +1698,22 @@ namespace gamescope
|
||||
}
|
||||
}
|
||||
|
||||
+ // -r sets the refresh gamescope starts with. With GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST=1 a refresh
|
||||
+ // the host compositor reports later replaces it, so pacing and the frame limiter follow a panel
|
||||
+ // switched to another mode during the session.
|
||||
+ static void FollowHostRefresh( int32_t nRefreshmHz )
|
||||
+ {
|
||||
+ static const bool s_bFollow = []
|
||||
+ {
|
||||
+ const char *pszFollow = getenv( "GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST" );
|
||||
+ return pszFollow && atoi( pszFollow ) != 0;
|
||||
+ }();
|
||||
+ if ( !s_bFollow || !g_nNestedRefresh || g_nNestedRefresh == nRefreshmHz )
|
||||
+ return;
|
||||
+ xdg_log.infof( "Nested refresh follows the host: %.3fhz", ConvertmHzToHz( (float) nRefreshmHz ) );
|
||||
+ g_nNestedRefresh = nRefreshmHz;
|
||||
+ }
|
||||
+
|
||||
void CWaylandPlane::UpdateVRRRefreshRate()
|
||||
{
|
||||
if ( m_pParent )
|
||||
@@ -1724,6 +1740,7 @@ namespace gamescope
|
||||
// TODO(strategy): We should pick the largest refresh rate.
|
||||
xdg_log.infof( "Changed refresh to: %.3fhz", ConvertmHzToHz( (float) nLargestRefreshRateMhz ) );
|
||||
g_nOutputRefresh = nLargestRefreshRateMhz;
|
||||
+ FollowHostRefresh( nLargestRefreshRateMhz );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1798,6 +1815,7 @@ namespace gamescope
|
||||
{
|
||||
xdg_log.infof( "Changed refresh to: %.3fhz", ConvertmHzToHz( (float) nRefresh ) );
|
||||
g_nOutputRefresh = nRefresh;
|
||||
+ FollowHostRefresh( nRefresh );
|
||||
}
|
||||
|
||||
m_pConnector->SetHostCompositorIsCurrentlyVRR( false );
|
||||
diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
|
||||
index 6c9299d..5fb9086 100644
|
||||
--- a/src/steamcompmgr.cpp
|
||||
+++ b/src/steamcompmgr.cpp
|
||||
@@ -9254,6 +9254,15 @@ void update_vrr_atoms(xwayland_ctx_t *root_ctx, bool force, bool* needs_flush =
|
||||
g_nCurrentRefreshRate_CachedValue = g_nOutputRefresh;
|
||||
if (needs_flush)
|
||||
*needs_flush = true;
|
||||
+
|
||||
+ // Steam reads the display's refresh rates from gamescope_control when it binds; send them again.
|
||||
+ if ( !force )
|
||||
+ {
|
||||
+ wlserver_lock();
|
||||
+ for ( const auto &control : wlserver.gamescope_controls )
|
||||
+ wlserver_send_gamescope_control( control );
|
||||
+ wlserver_unlock();
|
||||
+ }
|
||||
}
|
||||
|
||||
// Don't update this in-sync with DRM vrr usage.
|
||||
@@ -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
|
||||
|
||||
@@ -18,16 +18,19 @@ class SessionPacingTest(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
env = dict(os.environ, XDG_RUNTIME_DIR=directory, BL_REFRESH=str(refresh),
|
||||
BL_MANGOAPP='0', BL_FPS='0', DROIDDECK_GAME_FRAME_LIMIT='0')
|
||||
env.pop('GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST', None)
|
||||
env.update(overrides)
|
||||
script = '''
|
||||
set -u
|
||||
mode=steam
|
||||
pipewire_stub() { return 1; }
|
||||
run_gamescope() { printf 'ARG:%s\\n' "$@"; }
|
||||
run_gamescope() { printf 'ARG:%s\\n' "$@"; printf 'FOLLOW:%s\\n' "${GAMESCOPE_NESTED_REFRESH_FOLLOWS_HOST:-}"; }
|
||||
''' + block
|
||||
result = subprocess.run(['bash', '-c', script], env=env, capture_output=True,
|
||||
text=True, timeout=5)
|
||||
self.assertEqual(0, result.returncode, result.stderr)
|
||||
self.follow = [line.removeprefix('FOLLOW:') for line in result.stdout.splitlines()
|
||||
if line.startswith('FOLLOW:')]
|
||||
return [line.removeprefix('ARG:') for line in result.stdout.splitlines()
|
||||
if line.startswith('ARG:')]
|
||||
|
||||
@@ -38,6 +41,12 @@ run_gamescope() { printf 'ARG:%s\\n' "$@"; }
|
||||
self.assertEqual(str(refresh), args[args.index('-r') + 1])
|
||||
self.assertIn('-e', args)
|
||||
|
||||
def test_gamescope_follows_the_panel_after_the_starting_rate(self):
|
||||
self.launch(144)
|
||||
self.assertEqual(['1'], self.follow)
|
||||
self.launch(0)
|
||||
self.assertEqual([''], self.follow)
|
||||
|
||||
def test_retired_cap_variables_do_not_override_the_display_rate(self):
|
||||
for performance in ('0', '1'):
|
||||
with self.subTest(performance=performance):
|
||||
|
||||
Reference in new issue
Block a user