From 89163917e1976db4ae4863ad5337fa14bf348081 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Fri, 17 Mar 2023 12:31:44 +0000 Subject: [PATCH] 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 Reviewed-by: Emma Anholt Acked-by: Olivier Fourdan BlockHandler = glamor_priv->saved_procs.block_handler; screen->BlockHandler(screen, timeout); diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h index da20bc5aa..1032b880b 100644 --- a/glamor/glamor_priv.h +++ b/glamor/glamor_priv.h @@ -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; diff --git a/glamor/glamor_sync.c b/glamor/glamor_sync.c index 907e0c613..3f98be400 100644 --- a/glamor/glamor_sync.c +++ b/glamor/glamor_sync.c @@ -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); diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h index 93a933eed..bee48d989 100644 --- a/glamor/glamor_utils.h +++ b/glamor/glamor_utils.h @@ -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