<div dir="ltr">I don't remember the details of how we did the sync in XCB back when: we did something very like what you are doing, but the details are a bit tricky to get right. In particular, XCB will only send an input focus request when no request (not just input focus) has received a reply in the last 64K requests. So...yeah. It's been literally a decade since I looked at this stuff, but I *think* you should be able to dig the last-sync count out of XCB and just work from that: probably can just use the XCB code or at least algorithm to tell you when to sync. We had a correctness proof at one point. We had it again after we found and fixed a bug in the proof. :-)</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Dec 28, 2017 at 11:39 AM Clemens Eisserer <<a href="mailto:linuxhippy@gmail.com">linuxhippy@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Bart,<br>
<br>
> The overhead of doing separate XShmPutImages should be minimal.<br>
<br>
Xcb is performing fine, what is causing performance issues is how the<br>
drivers implement those tiny XPutImage requests (especially when<br>
operating on top of OpenGL like all glamor based setups).<br>
I've found a way to implement the deferred protocol submission using<br>
the socket handoff mechanism and it seems to work really well.<br>
<br>
However, currently the socket owner changes quite frequently, so I am<br>
struggling with the requirement to issue a XGetInputFocus-Request<br>
*every* time I call xcb_take_socket.<br>
For cases where there are only 4 requests to submit, an additional<br>
XGetInputFocus hurts.<br>
<br>
What I tried instead was:<br>
<br>
uint64_t lastManualSyncSeq; //Remember sequence-number, when the last<br>
manual sync was issued<br>
uint64_t socketTakenSeq; //Sequence number when the socket was taken<br>
uint32_t self_generated_count; //Number of self-generated X requests<br>
<br>
while(1) {<br>
xcb_take_socket(xcbCon, &returnSocketCB, &flags, 0, &socketTakenSeq);<br>
<br>
while(1) {<br>
if((socketTakenSeq + self_generated_count) - lastManualSyncSeq > 65000) {<br>
//will cause socket to be revoked, callback will take care of<br>
flushing out generated protocol<br>
lastManualSyncSeq = xcb_get_input_focus(xcbCon).sequence;<br>
xcb_discard_reply(xcbCon, lastManualSyncSeq);<br>
self_generated_count = 0;<br>
break;<br>
}<br>
<br>
self_generated_count++;<br>
GenerateXrenderFillRectanglesRequest(); //appends reply-less<br>
request to request data buffer<br>
}<br>
<br>
<br>
<br>
The idea is I can't be sure when xcb automatically generated the last<br>
XGetInputFocus request, but I know when I last called<br>
xcb_get_input_focus myself.<br>
As long as the last call to xcb_get_input_focus is less than 65k<br>
requests away, everything is fine (regardless of whether xcb issued<br>
some xcb_get_input_focus requests in between).<br>
<br>
However, this doesn't seem to work out as expected - I still get hangs<br>
from time to time.<br>
<br>
Any idea what is wrong with the above snippit?<br>
<br>
Thank you in advance, Clemens<br>
</blockquote></div>