Async Flips and non-fullscreen windows

Using Ubuntu 20.10 with two X-screens, we are drawing into our main stimulus display (X-screen 1) using synchronous flips without issue. I also wanted to open a small non-fullscreen window on the operator screen (X-screen 0 showing the MATLAB interface), where I can lazily draw the subject eye position (i.e. timing or fidelity is totally not an issue). I use PsychImaging to open both windows. As I don’t want to cause any timing delays for my stimulus, I exerpimented with ASync flips. The first async flip is fine, but if I draw before it completes, then I get an error:

Error in function gluDisk: 	Usage error
Tried to draw into onscreen window with async flip pending and imaging pipeline off. Forbidden!

However, I did use the imaging pipeline to open both windows. My workaround is to use AsyncFlipCheck as a conditional for drawing, but just wondered if this was strictly necessary as the docs for asyncflip suggest we can draw during the async state when the imaging pipeline is used?

That’s because the pipeline didn’t really enable if you didn’t specify some ‘AddTask’ that actually requires it. PsychImaging('OpenWindow') on itself just turns into Screen('OpenWindow') in such scenarios, as the pipeline does come with a small amount of overhead if actually enabled, so one wants to avoid redundant enables. PsychImaging('AddTask', 'General', 'UserVirtualFramebuffer') will enable a minimal pipeline and then it likely would work.

But a better way for your case is just to call Screen('Flip', win, [], [], 2) to run that windowed window without vsync or blocking waits for flip completion. Much simpler, less overhead, given that you won’t mind some potential minimal tearing.


Indeed, I just reread the documentation for PsychImaging('AddTask', 'General', 'UseFastOffscreenWindows') and see it doesn’t enable the pipeline if used alone (this is my basic setup if I don’t enable a 32bit buffer etc.), thats why it gave me that error.

And yes, the asynchronous Screen('Flip',win,[],[],2) works just as well (or better) for my purpose. I remember testing a few years ago and came away with the impression the AsyncFlip was faster, but I just did some profiling and both AsyncFlip and Flip[dontsync=2] take about 1.1ms to return, so there is not any advantage as far as I can see.

The resultant performance is great (at least on Linux). Our main stimulus is procedurally animated in real-time and no frames are lost on the stimulus display when also drawing the eye position and some other stuff to the non-fullscreen window. I initially put in a frame-throttle (draw the eye position every N frames of the stimulus to reduce overhead), but can see no difference with that throttle engaged in terms of performance and dropped frames.