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 <though-went-some-simple@proton.me>
This commit is contained in:
Ville Syrjälä 2025-06-24 22:38:41 +02:00 committed by notbabaisyou
parent dcf8371a81
commit 9c0b9cf21d

View File

@ -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;