From 0bc3a2493d4ca8ac63b974fcbee1f28db10aa1d1 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Fri, 28 Jan 2022 23:44:21 +0000 Subject: [PATCH] steamcompmgr: Add tuneables for vblank red zone + decay rate --- src/steamcompmgr.cpp | 12 ++++++++++++ src/vblankmanager.cpp | 7 ++++--- src/vblankmanager.hpp | 6 ++++++ src/xwayland_ctx.hpp | 3 +++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index dd7efa3..06263cb 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -3477,6 +3477,14 @@ handle_property_notify(xwayland_ctx_t *ctx, XPropertyEvent *ev) } } } + if ( ev->atom == ctx->atoms.gamescopeTuneableVBlankRedZone ) + { + g_uVblankDrawBufferRedZoneNS = (uint64_t)get_prop( ctx, ctx->root, ctx->atoms.gamescopeTuneableVBlankRedZone, g_uDefaultVBlankRedZone ); + } + if ( ev->atom == ctx->atoms.gamescopeTuneableRateOfDecay ) + { + g_uVBlankRateOfDecayPercentage = (uint64_t)get_prop( ctx, ctx->root, ctx->atoms.gamescopeTuneableRateOfDecay, g_uDefaultVBlankRateOfDecayPercentage ); + } } static int @@ -4316,6 +4324,10 @@ void init_xwayland_ctx(gamescope_xwayland_server_t *xwayland_server) ctx->atoms.gamescopeMouseFocusDisplay = XInternAtom(ctx->dpy, "GAMESCOPE_MOUSE_FOCUS_DISPLAY", false); ctx->atoms.gamescopeKeyboardFocusDisplay = XInternAtom( ctx->dpy, "GAMESCOPE_KEYBOARD_FOCUS_DISPLAY", false ); + // In nanoseconds... + ctx->atoms.gamescopeTuneableVBlankRedZone = XInternAtom( ctx->dpy, "GAMESCOPE_TUNEABLE_VBLANK_REDZONE", false ); + ctx->atoms.gamescopeTuneableRateOfDecay = XInternAtom( ctx->dpy, "GAMESCOPE_TUNEABLE_VBLANK_RATE_OF_DECAY_PERCENTAGE", false ); + ctx->root_width = DisplayWidth(ctx->dpy, ctx->scr); ctx->root_height = DisplayHeight(ctx->dpy, ctx->scr); diff --git a/src/vblankmanager.cpp b/src/vblankmanager.cpp index 4449489..e3b58e6 100644 --- a/src/vblankmanager.cpp +++ b/src/vblankmanager.cpp @@ -27,17 +27,18 @@ const uint64_t g_uStartingDrawTime = 3'000'000; std::atomic g_uVblankDrawTimeNS = { g_uStartingDrawTime }; // Tuneable -// 2.0ms +// 2.0ms by default. (g_DefaultVBlankRedZone) // This is the leeway we always apply to our buffer. // This also accounts for some time we cannot account for (which (I think) is the drm_commit -> triggering the pageflip) // It would be nice to make this lower if we can find a way to track that effectively // Perhaps the missing time is spent elsewhere, but given we track from the pipe write // to after the return from `drm_commit` -- I am very doubtful. -uint64_t g_uVblankDrawBufferRedZoneNS = 2'000'000; +uint64_t g_uVblankDrawBufferRedZoneNS = g_uDefaultVBlankRedZone; // Tuneable +// 93% by default. (g_uVBlankRateOfDecayPercentage) // The rate of decay (as a percentage) of the rolling average -> current draw time -uint64_t g_uVBlankRateOfDecayPercentage = 93; +uint64_t g_uVBlankRateOfDecayPercentage = g_uDefaultVBlankRateOfDecayPercentage; const uint64_t g_uVBlankRateOfDecayMax = 100; diff --git a/src/vblankmanager.hpp b/src/vblankmanager.hpp index 94cb0cf..84cbdc2 100644 --- a/src/vblankmanager.hpp +++ b/src/vblankmanager.hpp @@ -5,3 +5,9 @@ int vblank_init( void ); void vblank_mark_possible_vblank( uint64_t nanos ); extern std::atomic g_uVblankDrawTimeNS; + +const unsigned int g_uDefaultVBlankRedZone = 2'000'000; +const unsigned int g_uDefaultVBlankRateOfDecayPercentage = 93; + +extern uint64_t g_uVblankDrawBufferRedZoneNS; +extern uint64_t g_uVBlankRateOfDecayPercentage; diff --git a/src/xwayland_ctx.hpp b/src/xwayland_ctx.hpp index 4ba2087..eee937b 100644 --- a/src/xwayland_ctx.hpp +++ b/src/xwayland_ctx.hpp @@ -109,5 +109,8 @@ struct xwayland_ctx_t Atom gamescopeFocusDisplay; Atom gamescopeMouseFocusDisplay; Atom gamescopeKeyboardFocusDisplay; + + Atom gamescopeTuneableVBlankRedZone; + Atom gamescopeTuneableRateOfDecay; } atoms; };