From a80aff283bcbdc3f426e96c90e956bef6caf59f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= Date: Fri, 21 Feb 2025 21:08:07 +0200 Subject: [PATCH] present: Don't ping-pong between sync and async flips MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Many Intel GPUs can't switch between sync and async flips willy nilly. Sometimes that change itself will take one extra frame. This means that constant ping-pong between sync and async flips is only going to cause problems. Stay in async flip mode as long as the client is requesting it. The present protocol spec does say: "If 'options' contains PresentOptionAsync, and the 'target-msc' is less than or equal to the current msc for 'window', then the operation will be performed as soon as possible, not necessarily waiting for the next vertical blank interval." So there is an expectation that a future target-msc will still be respected even when PresentOptionAsync is specified. Staying in async flip mode won't actually change that given that present_scmd_pixmap() takes the flip mode into account when calculating exec_msc. So visually the flip should still happen on the correct target_msc regardles of whether we executed it as sync or async. Signed-off-by: Ville Syrjälä --- present/present_vblank.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/present/present_vblank.c b/present/present_vblank.c index 1c0461e84..d87f28abf 100644 --- a/present/present_vblank.c +++ b/present/present_vblank.c @@ -39,6 +39,20 @@ present_vblank_notify(present_vblank_ptr vblank, CARD8 kind, CARD8 mode, uint64_ } } +static Bool +present_want_async_flip(uint32_t options, uint32_t capabilities) +{ + if (options & PresentOptionAsync && + capabilities & PresentCapabilityAsync) + return TRUE; + + if (options & PresentOptionAsyncMayTear && + capabilities & PresentCapabilityAsyncMayTear) + return TRUE; + + return FALSE; +} + /* The memory vblank points to must be 0-initialized before calling this function. * * If this function returns FALSE, present_vblank_destroy must be called to clean @@ -117,15 +131,13 @@ present_vblank_init(present_vblank_ptr vblank, if (pixmap != NULL && !(options & PresentOptionCopy) && screen_priv->check_flip) { - if (msc_is_after(target_msc, crtc_msc) && - screen_priv->check_flip (target_crtc, window, pixmap, TRUE, valid, x_off, y_off, &reason)) - { - vblank->flip = TRUE; - vblank->sync_flip = TRUE; - } else if ((capabilities & PresentAllAsyncCapabilities) && - screen_priv->check_flip (target_crtc, window, pixmap, FALSE, valid, x_off, y_off, &reason)) + Bool sync_flip = !present_want_async_flip(options, capabilities); + + if (screen_priv->check_flip (target_crtc, window, pixmap, + sync_flip, valid, x_off, y_off, &reason)) { vblank->flip = TRUE; + vblank->sync_flip = sync_flip; } } vblank->reason = reason;