mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
perf(gamescope): skip the repeated window lookup and wake on host events (#1672)
The WSI layer sends override_window_content on every present, and gamescope walked the X tree to the top-level window (a blocking XQueryTree round trip per level, under the wlserver lock) before noticing the same swapchain already overrides it. A swapchain repeating the same window now skips the walk for 100 ms (0121). Backport of upstream gamescope 2962992 by Matthew Schwartz: the nested Wayland backend's input thread reads the host display, but steamcompmgr does not watch that fd, so buffer releases and presentation feedback could wait up to one refresh for its next poll; the input thread now wakes it after each read (0122). Pins gamescope-3.16.29-p17, the archive that was A/B-tested on the device. PATCHES.md also describes the p16 change to 0120.
This commit is contained in:
1 parent
0f839bef5d
commit
b5cc6dd185
4 files changed
+96
-2
No files matched your search
@@ -156,3 +156,28 @@ A host mode switch can report a passing rate for a few frames (72 Hz between 144
|
||||
120 Hz on the AYANEO Pocket FIT), so with following on a new rate is taken once it has
|
||||
been reported for 300 ms. Without the variable the reported rate is taken at once, as
|
||||
upstream does.
|
||||
|
||||
The rate comes from the feedback of a frame gamescope presents, so with nothing moving
|
||||
on screen no feedback arrived and the old rate stayed. With following on, gamescope
|
||||
presents once when the host's `wl_output` mode changes (DroidDeck's compositor sends
|
||||
the new mode) and keeps presenting while a new rate is pending (since p16).
|
||||
|
||||
## 0121 Xwayland: skip the X tree walk for a repeated window override
|
||||
|
||||
The WSI layer sends `override_window_content` on every present of an X11 swapchain.
|
||||
gamescope first walked from that window to its top-level window with `XQueryTree`, one
|
||||
blocking X round trip per level under the wlserver lock, and only then noticed that the
|
||||
same swapchain already overrides that window. At thousands of frames per second that is
|
||||
thousands of round trips to Xwayland every second.
|
||||
|
||||
The override now remembers the window it was asked for. When the same swapchain and
|
||||
surface ask for the same window again within 100 ms, the request returns at once; after
|
||||
100 ms the walk runs again, so a window that moved to another top level is still found.
|
||||
|
||||
## 0122 Wayland: wake steamcompmgr after reading host events
|
||||
|
||||
Backport of upstream commit 2962992 by Matthew Schwartz (ValveSoftware/gamescope).
|
||||
The nested Wayland backend's input thread reads the host display, but steamcompmgr
|
||||
does not watch that file descriptor, so buffer releases and presentation feedback
|
||||
queued by that read could wait up to one refresh for steamcompmgr's next poll. The
|
||||
input thread now wakes steamcompmgr after each read.
|
||||
@@ -0,0 +1,55 @@
|
||||
diff --git a/src/wlserver.cpp b/src/wlserver.cpp
|
||||
index 9a027a2..e6d8e31 100644
|
||||
--- a/src/wlserver.cpp
|
||||
+++ b/src/wlserver.cpp
|
||||
@@ -98,6 +98,8 @@ struct wlserver_content_override {
|
||||
uint32_t x11_window;
|
||||
struct wl_listener surface_destroy_listener;
|
||||
struct wl_resource *gamescope_swapchain;
|
||||
+ uint32_t requested_window;
|
||||
+ uint64_t ulCheckedNs;
|
||||
};
|
||||
|
||||
std::mutex g_wlserver_xdg_shell_windows_lock;
|
||||
@@ -800,6 +802,20 @@ static void gamescope_swapchain_destroy_co( struct wl_resource *resource );
|
||||
|
||||
void gamescope_xwayland_server_t::handle_override_window_content( struct wl_client *client, struct wl_resource *gamescope_swapchain_resource, struct wlr_surface *surface, uint32_t x11_window )
|
||||
{
|
||||
+ // The WSI layer sends this on every present. Finding the top level walks the X tree with a
|
||||
+ // round trip per level, so a swapchain repeating the same window skips it for 100 ms.
|
||||
+ const uint64_t ulNow = get_time_in_nanos();
|
||||
+ if ( gamescope_swapchain_resource )
|
||||
+ {
|
||||
+ for ( const auto &[ window, existing ] : content_overrides )
|
||||
+ {
|
||||
+ if ( existing->gamescope_swapchain == gamescope_swapchain_resource && existing->surface == surface &&
|
||||
+ existing->requested_window == x11_window && ulNow - existing->ulCheckedNs < 100'000'000ul )
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ const uint32_t requested_window = x11_window;
|
||||
x11_window = x11_find_toplevel_for_xid( this->ctx->dpy, x11_window );
|
||||
|
||||
wlserver_x11_surface_info *x11_surface = lookup_x11_surface_info_from_xid( this, x11_window );
|
||||
@@ -813,7 +829,11 @@ void gamescope_xwayland_server_t::handle_override_window_content( struct wl_clie
|
||||
|
||||
if ( content_overrides.count( x11_window ) ) {
|
||||
if ( content_overrides[x11_window]->gamescope_swapchain == gamescope_swapchain_resource )
|
||||
+ {
|
||||
+ content_overrides[x11_window]->requested_window = requested_window;
|
||||
+ content_overrides[x11_window]->ulCheckedNs = ulNow;
|
||||
return;
|
||||
+ }
|
||||
#ifdef GAMESCOPE_SWAPCHAIN_DEBUG
|
||||
wl_log.infof( "handle_override_window_content: (2) DESTROYING x11_window: 0x%x old_swapchain: %p new_swapchain: %p", x11_window, content_overrides[x11_window]->gamescope_swapchain, gamescope_swapchain_resource );
|
||||
#endif
|
||||
@@ -830,6 +850,8 @@ void gamescope_xwayland_server_t::handle_override_window_content( struct wl_clie
|
||||
co->surface = surface;
|
||||
co->x11_window = x11_window;
|
||||
co->gamescope_swapchain = gamescope_swapchain_resource;
|
||||
+ co->requested_window = requested_window;
|
||||
+ co->ulCheckedNs = ulNow;
|
||||
co->surface_destroy_listener.notify = content_override_handle_surface_destroy;
|
||||
wl_signal_add( &surface->events.destroy, &co->surface_destroy_listener );
|
||||
content_overrides[ x11_window ] = co;
|
||||
@@ -0,0 +1,14 @@
|
||||
diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp
|
||||
index 1b85e63..370661d 100644
|
||||
--- a/src/Backends/WaylandBackend.cpp
|
||||
+++ b/src/Backends/WaylandBackend.cpp
|
||||
@@ -2977,6 +2977,9 @@ namespace gamescope
|
||||
LogDisplayError( "Failed to read events on input thread", m_pBackend->GetDisplay() );
|
||||
abort();
|
||||
}
|
||||
+
|
||||
+ // Reading also queues releases and presentation feedback for steamcompmgr.
|
||||
+ nudge_steamcompmgr();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
GAMESCOPE_REPO=Droid-Deck/DroidDeck-Components
|
||||
GAMESCOPE_TAG=gamescope-3.16.29-p16
|
||||
GAMESCOPE_SHA256=8ae783d730d910de9a44ddb98dd567643e9cf7987f16ef261fe08cd2c4a7ba5c
|
||||
GAMESCOPE_TAG=gamescope-3.16.29-p17
|
||||
GAMESCOPE_SHA256=18e2b65407c5775301abdbc9f0db7df6b0e653923afcebdaa0f1ea3b9d5d5bb4
|
||||
Reference in new issue
Block a user