Research if it's possible to use the Present extension to get notified about buffer swap completion
On EGL, there is no any extension that you could use to get notified when the buffer swap completes. From #xorg-devel IRC channel
10:44:52 AM <zzag> MrCooper: is there any way for an application that uses EGL to get notified when a buffer swap completes (similar to the GLX_INTEL_swap_event extension)?
10:45:20 AM <MrCooper> don't know offhand
10:47:06 AM <zzag> MrCooper: I also looked into using the Present extension, but since Mesa has a separate (internal) event queue for present events, I highly doubt that this will work
10:48:28 AM <MrCooper> you can get the same Present events in your own queue, the question is if you'll be able to make sense of them :)
10:50:40 AM <emersion> speaking of which…
10:51:14 AM <emersion> i've been trying to emulate the wayland mailbox frame submission using Present
10:51:28 AM <emersion> to do so i'm setting target-msc to the last received msc + 1
10:51:49 AM <emersion> but this change causes stuttering in video players
10:51:57 AM <emersion> am i doing it wrong?
10:52:47 AM <emersion> basically i want a Present request to wait for the next vblank before being displayed
10:53:05 AM <zzag> MrCooper: hmm, so if I call PresentNotifyMSC() before eglSwapBuffers(), the x server will send a corresponding CompleteNotify event, right?
10:53:28 AM <emersion> zzag: sounds correct
10:53:55 AM <MrCooper> zzag: yes, but you don't know if the swap completed in that same MSC
10:57:45 AM <emersion> (cc romangg)
10:59:27 AM <MrCooper> if there's no EGL functionality for this yet, it would be better to add an EGL extension than to second-guess from Present events
11:00:29 AM <zzag> MrCooper: that would be ideal; in my use case, I only want to know when the buffer swap completes, i.e. UST
11:03:38 AM <MrCooper> emersion: video player + mailbox sounds like an odd combination :) anyway, assuming it's about fullscreen (so the X server can use page flipping), the xserver Present code currently doesn't support mailbox semantics very well in that case, e.g. it'll use the first available pixmap instead of the last one for the next flip
11:04:00 AM <emersion> oh
11:04:10 AM <emersion> hm, it's not about fullscreen though
11:04:39 AM <emersion> i'm writing a compositor and running a video player in it (non-fullscreen)
11:04:48 AM <emersion> but it does seem like some old frames are displayed
11:05:28 AM <emersion> it also happens in xwayland
11:05:48 AM <emersion> (i mean, same behaviour in plain non-fullscreen Xorg and Xwayland)
11:06:10 AM <emersion> is there a way to fix it, e.g. with the COPY flag?
11:06:37 AM <MrCooper> without page flipping, the pixmap contents are just copied to the window, so any old contents would have to be from a client pixmap
11:06:44 AM <emersion> hm
11:06:54 AM <emersion> ok, so it should work then
11:07:17 AM <emersion> is target-msc necessary? is last received + 1 a good value?
11:07:46 AM <emersion> i'm also setting divisor/remainder to 0 (like mesa i think?), is this all right?
11:07:50 AM <MrCooper> yeah, should; bugs are always possible, but it's hard to imagine an xserver bug which would result in old contents showing up
11:08:32 AM <MrCooper> sounds reasonable
11:08:42 AM <emersion> yeah, i wouldn't be surprised to find a bug in my code at all :)
11:08:46 AM <emersion> ok, thanks!
11:09:59 AM <MrCooper> np
11:43:39 AM <zzag> MrCooper: PresentNotifyMSC() before eglSwapBuffers() works, but it seems like I receive both my CompleteNotify events and Mesa's CompleteNotify events
11:44:35 AM <emersion> are you setting eventid ?
11:44:42 AM <zzag> emersion: yes, I do
11:44:54 AM <MrCooper> yes, all Present event contexts receive all events for the window
11:45:08 AM <emersion> you probably need to filter with eventid
11:46:06 AM <zzag> emersion: I filter events using eventid
11:46:28 AM <zzag> MrCooper: sigh, and it seems like there is no any way to differentiate between my events and Mesa's event :(
11:46:35 AM <zzag> events*
11:46:37 AM <emersion> and still receive both events, with eventid set to the one you generated?
11:46:43 AM <emersion> mesa's eventid should be different
11:48:13 AM <MrCooper> each event delivery target receives all events with its eventid
11:48:47 AM <zzag> emersion: that's correct! I receive two events for the same eventid (one that I requested, and the one that Mesa requested)
11:49:03 AM <emersion> that's weird
11:49:20 AM <emersion> when we tried to use present events in wlroots a while ago we ran into the same issue iirc
11:49:30 AM <emersion> we just assumed we used Present wrong
11:49:54 AM <MrCooper> the semantics might be like this accidentally, but there are clients relying on them, so we can't change them (I tried) :(
11:50:30 AM <emersion> iirc this completely breaks mesa, because mesa doesn't receive present events anymore?
11:50:48 AM <MrCooper> only the Gallium nine frontend
11:51:37 AM <MrCooper> which uses multiple display connections, and relies on events from Present requests sent on one of them to be delivered to the other one as well
11:52:23 AM <emersion> wew
As MrCooper (Michel Dänzer) said, Present events are sent to all event contexts. This makes the task of distinguishing present events requested by us from the ones requested by Mesa a challenging task. Ideally, there has to be an EGL extension similar to GLX_INTEL_swap_event, but this still can be useful as a fallback for platforms such as NVIDIA.