From 9c0b9cf21d6a392a5a07b444a8a1a30a7c40c55e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= Date: Tue, 24 Jun 2025 22:38:41 +0200 Subject: [PATCH] present: Don't ping-pong between sync and async flips 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: notbabaisyou --- present/present_vblank.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/present/present_vblank.c b/present/present_vblank.c index 72a8b2e3e..7b83bc630 100644 --- a/present/present_vblank.c +++ b/present/present_vblank.c @@ -40,6 +40,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 @@ -118,15 +132,14 @@ 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;