glamor: Don't glFlush/ctx switch unless any work has been performed

`glamor_make_current` is always called before any calls to GL.

Apply some dirty-tracking to whenever we call `glamor_make_current` so
that we can avoid a decent amount of redundant GL work on each
Dispatch cycle.

Gamescope previously was waking up an empty Xwayland server with an
XQueryPointer and I noticed a significant amount of churn doing
redundant GL work.

This has been addressed on the Gamescope side as well, but avoiding any
useless GL context switches and flushes when glamor is doing nothing
is still beneficial for CPU and power usage on portable devices.

Signed-off-by: Joshua Ashton <joshua@froggi.es>
Reviewed-by: Emma Anholt <emma@anholt.net>
Acked-by: Olivier Fourdan <ofourdan@redhat.com
This commit is contained in:
Joshua Ashton 2023-03-17 12:31:44 +00:00
parent e880e971fc
commit 89163917e1
4 changed files with 15 additions and 7 deletions

View File

@ -271,9 +271,7 @@ void
glamor_block_handler(ScreenPtr screen)
{
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
glamor_make_current(glamor_priv);
glFlush();
glamor_flush(glamor_priv);
}
static void
@ -281,8 +279,7 @@ _glamor_block_handler(ScreenPtr screen, void *timeout)
{
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
glamor_make_current(glamor_priv);
glFlush();
glamor_flush(glamor_priv);
screen->BlockHandler = glamor_priv->saved_procs.block_handler;
screen->BlockHandler(screen, timeout);

View File

@ -314,6 +314,7 @@ typedef struct glamor_screen_private {
Bool suppress_gl_out_of_memory_logging;
Bool logged_any_fbo_allocation_failure;
Bool logged_any_pbo_allocation_failure;
Bool dirty;
/* xv */
glamor_program xv_prog;

View File

@ -52,8 +52,7 @@ glamor_sync_fence_set_triggered (SyncFence *fence)
struct glamor_sync_fence *glamor_fence = glamor_get_sync_fence(fence);
/* Flush pending rendering operations */
glamor_make_current(glamor);
glFlush();
glamor_flush(glamor);
fence->funcs.SetTriggered = glamor_fence->set_triggered;
fence->funcs.SetTriggered(fence);

View File

@ -672,6 +672,17 @@ glamor_make_current(glamor_screen_private *glamor_priv)
lastGLContext = glamor_priv->ctx.ctx;
glamor_priv->ctx.make_current(&glamor_priv->ctx);
}
glamor_priv->dirty = TRUE;
}
static inline void
glamor_flush(glamor_screen_private *glamor_priv)
{
if (glamor_priv->dirty) {
glamor_make_current(glamor_priv);
glFlush();
glamor_priv->dirty = FALSE;
}
}
static inline BoxRec