From 38926b315727bb2de7539b1ebb1cfebe838895c7 Mon Sep 17 00:00:00 2001 From: The412Banner <205237651+The412Banner@users.noreply.github.com> Date: Sun, 25 Oct 2026 16:29:26 -0400 Subject: [PATCH] feat: Performance mode puts frame pacing and per-frame window-check fixes behind one switch (#1563) Adds a Performance mode switch under Mode settings > Frame rate, off by default and stored per mode like the frame limit. Off keeps today's behaviour. On: - with no frame limit, the compositor hands buffers back to the game as soon as they are replaced instead of once per refresh, and gamescope's WSI layer is asked for at least 8 swapchain images; a chosen frame limit still paces - DROIDDECK_WSI_BYPASS_CHECK_MS=100 lets gamescope's WSI layer reuse its present-time Xwayland bypass check (patch 0117, gamescope-3.16.29-p13); WINE_OFFSCREEN_CHECK_MS=100 does the same for winex11 once a DroidDeck-Proton release carries that fix. Off sets both to 0. The gamescope pack now ships the patched WSI layer and SessionFiles stages it over the runtime's stock copy. Two per-game options, off by default: PROTON_DXVK_D3D8 and WINE_D3D_CONFIG renderer=vulkan|gl. AIO Graphics Test on an AYANEO Pocket FIT (Adreno 750), off -> on: Vulkan 204 -> 1787, OpenGL 296 -> 2169, D3D12 308 -> 3563, D3D11 1133 -> 2874, D3D9 1253 -> 3098 fps; DiRT Showdown 92.2 -> 93.4 (GPU-bound). --- app/src/main/cpp/waylandcomp/src/compositor.c | 4 +- .../cpp/waylandcomp/src/waylandcomp_jni.c | 2 + .../droiddeck/launcher/FrontEndActivity.kt | 5 +- .../com/droiddeck/launcher/SessionActivity.kt | 10 ++-- .../launcher/core/GameEnvironmentOptions.kt | 2 + .../launcher/session/SessionFiles.kt | 2 + .../launcher/session/SessionPrefs.kt | 18 +++++- .../launcher/session/SessionService.kt | 10 ++++ .../launcher/session/SessionState.kt | 3 + .../launcher/session/SettingsReset.kt | 2 +- .../launcher/ui/ModeSettingsDialog.kt | 4 ++ app/src/main/res/values/strings.xml | 4 ++ .../launcher/session/PerformanceModeTest.kt | 42 ++++++++++++++ tools/gamescope/PATCHES.md | 14 +++++ tools/gamescope/build-in-arch.sh | 6 +- .../0117-wsi-cache-present-bypass-check.patch | 55 +++++++++++++++++++ tools/gamescope/release.env | 4 +- 17 files changed, 176 insertions(+), 11 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/session/PerformanceModeTest.kt create mode 100644 tools/gamescope/patches/0117-wsi-cache-present-bypass-check.patch diff --git a/app/src/main/cpp/waylandcomp/src/compositor.c b/app/src/main/cpp/waylandcomp/src/compositor.c index 562a83a750..0718623cfa 100644 --- a/app/src/main/cpp/waylandcomp/src/compositor.c +++ b/app/src/main/cpp/waylandcomp/src/compositor.c @@ -264,6 +264,8 @@ static struct wl_event_source *g_fallback_timer; static int g_fallback_armed; volatile int g_fps_limit; +/* fps limit -1 (Performance mode without a limit): replaced buffers go back to the client at once instead of once per refresh. */ +volatile int g_release_unpaced; volatile int g_hide_shell; @@ -371,7 +373,7 @@ static int on_release_timer(int fd, uint32_t mask, void *data) { static void release_buffer(struct surface *s, struct wl_resource *buffer, int64_t since_ns) { const int limit = g_fps_limit; const int64_t interval = limit > 0 ? 1000000000LL / limit : g_refresh_ns; - if (interval <= 0 || g_release_timer_fd < 0) { wl_buffer_send_release(buffer); perf_note_release(since_ns); return; } + if (g_release_unpaced || interval <= 0 || g_release_timer_fd < 0) { wl_buffer_send_release(buffer); perf_note_release(since_ns); return; } int64_t now = now_ns(); int64_t at = s->next_release_ns + interval; int64_t latest = now + interval * (int64_t)(s->releases_pending + 1); diff --git a/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c index 16e42d1b5d..e6bb03027c 100644 --- a/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c +++ b/app/src/main/cpp/waylandcomp/src/waylandcomp_jni.c @@ -34,6 +34,7 @@ extern unsigned droiddeck_stream_frames(void); extern void droiddeck_wayland_output_resized(void); extern void droiddeck_wayland_set_output_refresh_rate(int mhz); extern volatile int g_fps_limit; +extern volatile int g_release_unpaced; extern volatile int g_hide_shell; extern volatile int g_zero_copy; extern volatile unsigned g_zero_copy_last; @@ -574,6 +575,7 @@ Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetLookName(JNIEnv * JNIEXPORT void JNICALL Java_com_droiddeck_launcher_wayland_WaylandCompositor_nativeSetFpsLimit(JNIEnv *env, jclass clazz, jint fps) { g_fps_limit = fps > 0 ? fps : 0; + g_release_unpaced = fps < 0; __android_log_print(ANDROID_LOG_INFO, TAG, "fps limit %d", fps); } diff --git a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt index 9e8d2f50a8..0d59c8da9d 100644 --- a/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/FrontEndActivity.kt @@ -392,6 +392,7 @@ class FrontEndActivity : ComponentActivity() { private var appScale by mutableStateOf(com.droiddeck.launcher.core.AppUiPrefs.DEFAULT_SCALE) private var hdrOn by mutableStateOf(false) private var fpsLimit by mutableStateOf(0) + private var performanceMode by mutableStateOf(false) private var upscaler by mutableStateOf(0) private var upscaleSharpness by mutableStateOf(75) private var hdrReason by mutableStateOf(null) @@ -1711,7 +1712,7 @@ class FrontEndActivity : ComponentActivity() { ModeSettings( mode = mode, resolution = resolution, panelSize = com.droiddeck.launcher.session.SessionDisplay.panelSize(this), - hdr = hdrOn, hdrReason = hdrReason, fpsLimit = fpsLimit, + hdr = hdrOn, hdrReason = hdrReason, fpsLimit = fpsLimit, performanceMode = performanceMode, upscaler = upscaler, upscaleSharpness = upscaleSharpness, gpuDrivers = drivers.summary(), touchMode = touchMode, @@ -1778,6 +1779,7 @@ class FrontEndActivity : ComponentActivity() { onHdr = { on -> SessionPrefs.setHdr(this, mode, on); hdrOn = on }, onGpuDrivers = { openComponents(focusContent = true, tab = com.droiddeck.launcher.ui.GPU_TAB) }, onFpsLimit = { fps -> SessionPrefs.setFpsLimit(this, mode, fps); fpsLimit = fps }, + onPerformanceMode = { on -> SessionPrefs.setPerformanceMode(this, mode, on); performanceMode = on }, onUpscaler = { m -> SessionPrefs.setUpscaler(this, m); upscaler = m }, onUpscaleSharpness = { pct -> SessionPrefs.setUpscaleSharpness(this, pct); upscaleSharpness = pct }, onTouch = { t -> SessionPrefs.setTouchMode(this, t); touchMode = t }, @@ -2029,6 +2031,7 @@ class FrontEndActivity : ComponentActivity() { loadBootMovie() hdrOn = SessionPrefs.hdr(this, mode) fpsLimit = SessionPrefs.fpsLimit(this, mode) + performanceMode = SessionPrefs.performanceMode(this, mode) upscaler = SessionPrefs.upscaler(this) upscaleSharpness = SessionPrefs.upscaleSharpness(this) hdrReason = com.droiddeck.launcher.wayland.HdrSupport.probe(this).reason diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 9a5b1ddc93..2740c71248 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -477,9 +477,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { com.droiddeck.launcher.gpu.SteamVrHealth.begin(this, SessionState.sessionId) window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) if (!SessionState.running) { - SessionState.fpsLimit = SessionPrefs.fpsLimit( - this, SessionPrefs.prefMode(intent.getStringExtra(SessionService.EXTRA_MODE) ?: SessionService.MODE_STEAM), - ) + val prefMode = SessionPrefs.prefMode(intent.getStringExtra(SessionService.EXTRA_MODE) ?: SessionService.MODE_STEAM) + SessionState.fpsLimit = SessionPrefs.fpsLimit(this, prefMode) + SessionState.performanceMode = SessionPrefs.performanceMode(this, prefMode) } applyOutputPacing() if (!SessionState.running) SessionState.followScreen = followChoice() @@ -1851,7 +1851,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { private fun mirrorRefreshLimit(): Int = GlassesRendering.mirrorRefreshLimit(glassesSettings, glasses, glassesScreen != null) - private fun outputFpsLimit(): Int = GlassesRendering.fpsLimit(SessionState.fpsLimit, mirrorRefreshLimit()) + private fun outputFpsLimit(): Int = SessionPrefs.compositorFpsLimit( + GlassesRendering.fpsLimit(SessionState.fpsLimit, mirrorRefreshLimit()), SessionState.performanceMode, + ) private fun applyOutputPacing() { Log.i(TAG, "perf: " + PerfMode.apply(this, outputFpsLimit(), mirrorRefreshLimit())) diff --git a/app/src/main/java/com/droiddeck/launcher/core/GameEnvironmentOptions.kt b/app/src/main/java/com/droiddeck/launcher/core/GameEnvironmentOptions.kt index 3ad45c1fa6..e339f38df1 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/GameEnvironmentOptions.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/GameEnvironmentOptions.kt @@ -14,6 +14,8 @@ object GameEnvironmentOptions { Option("MESA_SHADER_CACHE_MAX_SIZE", "1G", R.string.game_env_cache_size, Type.CHOICE, listOf("512M", "1G", "2G", "4G")), Option("PROTON_LOG", "1", R.string.game_env_proton_log, Type.TOGGLE, listOf("0", "1")), Option("PROTON_USE_WINED3D", "1", R.string.game_env_wined3d, Type.TOGGLE, listOf("0", "1")), + Option("PROTON_DXVK_D3D8", "1", R.string.game_env_dxvk_d3d8, Type.TOGGLE, listOf("0", "1")), + Option("WINE_D3D_CONFIG", "renderer=vulkan", R.string.game_env_wined3d_renderer, Type.CHOICE, listOf("renderer=vulkan", "renderer=gl")), Option("PROTON_USE_XALIA", "0", R.string.game_env_xalia, Type.TOGGLE, listOf("0", "1")), Option("PROTON_NO_NTSYNC", "1", R.string.game_env_no_ntsync, Type.TOGGLE, listOf("0", "1")), Option("PROTON_NO_ESYNC", "1", R.string.game_env_no_esync, Type.TOGGLE, listOf("0", "1")), diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt index 2991b559c5..958aa2df52 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionFiles.kt @@ -142,6 +142,8 @@ object SessionFiles { } + listOf("libvulkan-thunk.so", "libwebkitinput.so").map { "x86_64/$it" to "usr/local/lib/droiddeck-fex/x86_64/$it" } val optional = (arrayOf( "usr/local/bin/gamescope" to "usr/local/bin/gamescope", + // The gamescope pack carries its own WSI layer (patch 0117); it replaces the runtime's stock copy. + "usr/lib/libVkLayer_FROG_gamescope_wsi_aarch64.so" to "usr/lib/libVkLayer_FROG_gamescope_wsi_aarch64.so", "usr/local/lib/droiddeck/uruntime" to "usr/local/lib/droiddeck/uruntime", "usr/local/lib/droiddeck-pipewire.tzst" to "usr/local/lib/droiddeck-pipewire.tzst", "usr/local/share/licenses/uruntime/LICENSE" to "usr/local/share/licenses/uruntime/LICENSE", diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index 9756aa0515..975ca45905 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -875,7 +875,7 @@ object SessionPrefs { prefs(context).edit().putBoolean("hdr.$mode", on).apply() } - fun fpsLimit(context: Context, mode: String): Int = prefs(context).getInt("fpsLimit.$mode", 0) + fun fpsLimit(context: Context, mode: String): Int = prefs(context).getInt("fpsLimit.$mode", 0).coerceAtLeast(0) fun setFpsLimit(context: Context, mode: String, fps: Int) { prefs(context).edit().putInt("fpsLimit.$mode", fps.coerceAtLeast(0)).apply() @@ -886,6 +886,22 @@ object SessionPrefs { fun fpsLimitChoices(context: Context): List> = fpsLimitChoices.map { (fps, label) -> fps to if (fps == 0) context.getString(R.string.frame_gen_off) else label } + /** + * Performance mode: without a frame limit, buffers go back to the game as soon as they are replaced + * instead of once per refresh, and gamescope's WSI layer and winex11 reuse their per-present window checks. + */ + fun performanceMode(context: Context, mode: String): Boolean = prefs(context).getBoolean("performanceMode.$mode", false) + + fun setPerformanceMode(context: Context, mode: String, on: Boolean) { + prefs(context).edit().putBoolean("performanceMode.$mode", on).apply() + } + + /** Compositor frame limit that releases buffers to the game unpaced. */ + const val FPS_UNPACED = -1 + + /** The limit handed to the compositor: Performance mode without a limit is unpaced, a chosen limit still paces. */ + fun compositorFpsLimit(limit: Int, performanceMode: Boolean): Int = if (performanceMode && limit <= 0) FPS_UNPACED else limit + val upscalerChoices = listOf( 0 to "Linear", 2 to "Nearest", 4 to "AMD FSR 1", 3 to "Snapdragon GSR", 8 to "Snapdragon GSR (quality)", 7 to "NVIDIA NIS", 6 to "Sharpen only", diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 363993c713..630feeb921 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -475,6 +475,16 @@ class SessionService : Service() { Log.i(TAG, "hdr: gamescope --hdr-enabled, DXVK_HDR=1") } guest.add("BL_FPS=" + SessionState.fpsLimit) + // gamescope's WSI layer and winex11 reuse their per-present window checks for this long; 0 checks on every present. + val windowCheckMs = if (SessionState.performanceMode) 100 else 0 + guest.add("DROIDDECK_WSI_BYPASS_CHECK_MS=$windowCheckMs") + guest.add("WINE_OFFSCREEN_CHECK_MS=$windowCheckMs") + 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") + guest.add("GAMESCOPE_WSI_ENSURE_MIN_IMAGE_COUNT=1") + } + Log.i(TAG, "performance mode " + (if (SessionState.performanceMode) "on" else "off") + ", frame limit " + SessionState.fpsLimit) guest.add("BL_REFRESH=" + Math.round(SessionState.refreshHz)) guest.add("BL_LOG=" + sessionLog.path) guest.add("BL_DEBUG_DIR=" + sessionDir.path) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionState.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionState.kt index 6bdece304d..4b57a10689 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionState.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionState.kt @@ -104,6 +104,9 @@ object SessionState { @Volatile var fpsLimit: Int = 0 + @Volatile + var performanceMode = false + @Volatile var firstFrameSeen = false diff --git a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt index 62222ed3ef..c933229a88 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt @@ -29,7 +29,7 @@ object SettingsReset { ) internal val SESSION_PREFIXES = listOf( - "resolutionCap.", "displayResolution.", "customRes.", "hdr.", "fpsLimit.", "suspendPolicy.", + "resolutionCap.", "displayResolution.", "customRes.", "hdr.", "fpsLimit.", "performanceMode.", "suspendPolicy.", ) private val STEAM_TOUCH_KEYS = listOf("feedback", "autoFade", "gyro", "shake") diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt b/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt index 8e83598386..393971446e 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ModeSettingsDialog.kt @@ -60,6 +60,7 @@ class ModeSettings( val hdrReason: String?, val gpuDrivers: String? = null, val fpsLimit: Int = 0, + val performanceMode: Boolean = false, val upscaler: Int = 0, val upscaleSharpness: Int = 75, val touchMode: String, @@ -116,6 +117,7 @@ class ModeSettingsActions( val onHdr: (Boolean) -> Unit, val onGpuDrivers: () -> Unit = {}, val onFpsLimit: (Int) -> Unit = {}, + val onPerformanceMode: (Boolean) -> Unit = {}, val onUpscaler: (Int) -> Unit = {}, val onUpscaleSharpness: (Int) -> Unit = {}, val onTouch: (String) -> Unit, @@ -241,6 +243,8 @@ fun ModeSheetRows(s: ModeSettings, a: ModeSettingsActions, tab: String, extras: ) } SettingsGroup(stringResource(R.string.display_frame_rate)) { + ToggleRow(host, "performance", stringResource(R.string.mode_performance), stringResource(R.string.mode_performance_hint), + s.performanceMode, onChange = a.onPerformanceMode) ChoiceRow(host, "fps", stringResource(R.string.mode_fps), stringResource(R.string.common_applies_next_session), SessionPrefs.fpsLimitChoices(LocalContext.current), s.fpsLimit, note = stringResource(R.string.mode_fps_note), onPick = a.onFpsLimit) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1ca16f9100..a0d9672c4d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -85,6 +85,8 @@ VKD3D options for D3D12. nodxr disables ray tracing; use only for a game that needs it. Set to 1 for a Proton diagnostic log. Logging can reduce performance and use storage. Set to 1 to use OpenGL-based WineD3D instead of DXVK for D3D9–11 compatibility testing. + Renderer for DirectDraw, Direct3D 1-7 and games run with WineD3D. Vulkan skips the OpenGL-on-Zink path and is much faster for old DirectDraw and Direct3D 7 games on Adreno. + Set to 1 to run Direct3D 8 through DXVK instead of WineD3D. Faster in AIO Graphics Test\'s Direct3D 8 test on Adreno. Set to 1 to keep this game off ntsync (droiddeck-ntsync or a kernel driver); it uses droiddeck-esync where a pack exists, otherwise droiddeck-fsync. Set to 1 to turn droiddeck-esync off for this game; it uses droiddeck-fsync instead, or droiddeck-ntsync where fsync is off too. Set to 1 to keep this game off droiddeck-fsync; it uses droiddeck-esync where a pack exists, otherwise droiddeck-ntsync. @@ -254,6 +256,8 @@ Set by the custom resolution. Auto uses at least 16:9. Frame limit + Performance mode + 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. Caps the whole session. The display switches to a refresh rate the cap divides evenly. HDR HDR10 output diff --git a/app/src/test/java/com/droiddeck/launcher/session/PerformanceModeTest.kt b/app/src/test/java/com/droiddeck/launcher/session/PerformanceModeTest.kt new file mode 100644 index 0000000000..f59157c3be --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/session/PerformanceModeTest.kt @@ -0,0 +1,42 @@ +package com.droiddeck.launcher.session + +import android.content.Context +import org.junit.Assert.* +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [33]) +class PerformanceModeTest { + private val app get() = RuntimeEnvironment.getApplication() + private val session get() = app.getSharedPreferences("session", Context.MODE_PRIVATE) + + @Before fun clear() { session.edit().clear().commit() } + + @Test fun offByDefaultAndPerMode() { + assertFalse(SessionPrefs.performanceMode(app, SessionService.MODE_STEAM)) + SessionPrefs.setPerformanceMode(app, SessionService.MODE_STEAM, true) + assertTrue(SessionPrefs.performanceMode(app, SessionService.MODE_STEAM)) + assertFalse(SessionPrefs.performanceMode(app, SessionService.MODE_DESKTOP)) + } + + @Test fun offKeepsTodaysPacing() { + assertEquals(0, SessionPrefs.compositorFpsLimit(0, false)) + assertEquals(60, SessionPrefs.compositorFpsLimit(60, false)) + } + + @Test fun onWithoutALimitIsUnpacedAndAChosenLimitStillPaces() { + assertEquals(SessionPrefs.FPS_UNPACED, SessionPrefs.compositorFpsLimit(0, true)) + assertEquals(60, SessionPrefs.compositorFpsLimit(60, true)) + } + + @Test fun anOldUncappedFrameLimitReadsAsOff() { + session.edit().putInt("fpsLimit.steam", -1).commit() + assertEquals(0, SessionPrefs.fpsLimit(app, SessionService.MODE_STEAM)) + assertFalse(SessionPrefs.fpsLimitChoices.any { it.first < 0 }) + } +} diff --git a/tools/gamescope/PATCHES.md b/tools/gamescope/PATCHES.md index a34e97e356..ab53e5ad99 100644 --- a/tools/gamescope/PATCHES.md +++ b/tools/gamescope/PATCHES.md @@ -85,3 +85,17 @@ the patched component retained 1/20, then 0 after destruction. The unassigned control retained 20/20 and then 0. In Backpack Battles, two batches of ten touch drags leaked 188 and 197 SHM descriptors before the fix; the same batches added zero after the fix (112 total descriptors before and after each batch). + +## 0117 WSI: cache the present-time Xwayland bypass check + +`QueuePresentKHR` in the WSI layer calls `canBypassXWayland` for every swapchain on +every present. Each call makes several synchronous X requests (window geometry, +`_WINE_ALLOW_FLIP`, parent window, a child-window scan, the toplevel window). At +high frame rates that is thousands of round trips a second: on an AYANEO Pocket FIT +running AIO Graphics Test uncapped, Xwayland used 24-32% of a core and the game's +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 +later than before; surface creation and capability queries still check every time. diff --git a/tools/gamescope/build-in-arch.sh b/tools/gamescope/build-in-arch.sh index 2853e593ab..79d4fd8692 100755 --- a/tools/gamescope/build-in-arch.sh +++ b/tools/gamescope/build-in-arch.sh @@ -49,7 +49,11 @@ tar --use-compress-program=unzstd -xf "$PKG" -C out --strip-components=2 usr/bin mv out/gamescope out/usr/local/bin/gamescope chmod 755 out/usr/local/bin/gamescope strip --strip-unneeded out/usr/local/bin/gamescope || true -NEEDED=$(readelf -d out/usr/local/bin/gamescope | sed -n 's/.*NEEDED.*\[\(.*\)\]/\1/p') +# The WSI layer carries patches too (0117); the runtime's stock copy is replaced. +mkdir -p out/usr/lib +tar --use-compress-program=unzstd -xf "$PKG" -C out usr/lib/libVkLayer_FROG_gamescope_wsi_aarch64.so +strip --strip-unneeded out/usr/lib/libVkLayer_FROG_gamescope_wsi_aarch64.so || true +NEEDED=$(for f in out/usr/local/bin/gamescope out/usr/lib/libVkLayer_FROG_gamescope_wsi_aarch64.so; do readelf -d "$f" | sed -n 's/.*NEEDED.*\[\(.*\)\]/\1/p'; done | sort -u) echo "NEEDED: $NEEDED" MISSING="" for lib in $NEEDED; do grep -qx "$lib" tools/gamescope/runtime-sonames.txt || MISSING="$MISSING $lib"; done diff --git a/tools/gamescope/patches/0117-wsi-cache-present-bypass-check.patch b/tools/gamescope/patches/0117-wsi-cache-present-bypass-check.patch new file mode 100644 index 0000000000..7ce0ec48d1 --- /dev/null +++ b/tools/gamescope/patches/0117-wsi-cache-present-bypass-check.patch @@ -0,0 +1,55 @@ +--- a/layer/VkLayer_FROG_gamescope_wsi.cpp 2026-10-25 07:56:48.179978889 +0000 ++++ b/layer/VkLayer_FROG_gamescope_wsi.cpp 2026-10-25 07:56:48.207978889 +0000 +@@ -23,6 +23,8 @@ + #include + + #include ++#include ++#include + #include + // For limiter file. + #include +@@ -476,6 +478,34 @@ + // Cached for comparison. + std::optional cachedWindowRect; + ++ // canBypassXWayland costs several X round trips; at present time it is refreshed at most ++ // every DROIDDECK_WSI_BYPASS_CHECK_MS (default 0 = every present; DroidDeck's Performance mode sets 100). ++ std::optional presentBypass; ++ bool presentBypassHdr = false; ++ uint64_t presentBypassNs = 0; ++ ++ static uint64_t presentBypassIntervalNs() { ++ static const uint64_t interval = [] { ++ const char *v = getenv("DROIDDECK_WSI_BYPASS_CHECK_MS"); ++ return uint64_t(v && *v ? strtoull(v, nullptr, 10) : 0) * 1000000ull; ++ }(); ++ return interval; ++ } ++ ++ bool canBypassXWaylandAtPresent(bool hdrColorspace) { ++ if (isWayland()) ++ return true; ++ timespec ts; ++ clock_gettime(CLOCK_MONOTONIC, &ts); ++ const uint64_t now = uint64_t(ts.tv_sec) * 1000000000ull + uint64_t(ts.tv_nsec); ++ if (!presentBypass || presentBypassHdr != hdrColorspace || now - presentBypassNs >= presentBypassIntervalNs()) { ++ presentBypass = canBypassXWayland(hdrColorspace); ++ presentBypassHdr = hdrColorspace; ++ presentBypassNs = now; ++ } ++ return *presentBypass; ++ } ++ + bool isWayland() const { + // Is native Wayland? + return connection == nullptr; +@@ -1597,7 +1627,7 @@ + continue; + } + +- const bool canBypass = gamescopeSurface->canBypassXWayland(gamescopeSwapchain->isHdrColorspace); ++ const bool canBypass = gamescopeSurface->canBypassXWaylandAtPresent(gamescopeSwapchain->isHdrColorspace); + if (canBypass != gamescopeSwapchain->isBypassingXWayland) { + if (canBypass) { + if (!(gamescopeSurface->flags & GamescopeLayerClient::Flag::NoSuboptimal)) diff --git a/tools/gamescope/release.env b/tools/gamescope/release.env index 1e741f4aa0..a505f40a87 100644 --- a/tools/gamescope/release.env +++ b/tools/gamescope/release.env @@ -1,3 +1,3 @@ GAMESCOPE_REPO=Droid-Deck/DroidDeck-Components -GAMESCOPE_TAG=gamescope-3.16.29-p12 -GAMESCOPE_SHA256=07b69944a1ebf2741d4a867afa6327dcc63ec458f432a8f7483089dce2197010 +GAMESCOPE_TAG=gamescope-3.16.29-p13 +GAMESCOPE_SHA256=93c789dc9e08828496f1caa2849d56acdf205838de723a24b296547a29c0b6af