My experiment involves realtime monitoring/processing of camera images coming in at 80fps, and the moment a certain feature is detected in an image (say image_frame1) some very basic shapes are printed to a display monitor (240 hz refresh rate).
Using these same cameras, I can measure the latency between when I send the screen(‘Flip’) command and when it actually appears on the display monitor.
Strangely, on a freshly opened onscreen window, the latency between finished execution of the Screen(‘Flip’) command and when things appear on the display monitor is ~4-5 milliseconds. However, on subsequent trials this latency jumps to ~18 milliseconds UNLESS I close and reopen a fresh onscreen window between each trial. Note that it does not continue to incrementally increase throughout the trials - it remains steady at an average of 18 milliseconds for the remaining trials.
This is important for my experiment as I need to have a total latency of 50 milliseconds or less, which would include:
- first detecting the onset of the phenomenon in the camera (4.8 milliseconds after onset)
- Grabbing two more images (at 80fps) to gather needed data (additional 25 milliseconds)
- doing computations on the image, drawing textures, and Screen(‘Flip’) (additional 10ms)
- stimulus appearing on the screen (5 milliseconds for first screen flip, 18ms for all subsequent screen flips)
Altogether, if the display monitor latency is 5ms, everything works (~45ms total latency). However, a display monitor latency of 18-20 milliseconds is ~20% increase in total latency (~60ms total latency).
Does anyone know why something like this might happen? To be clear, why is the first screen(‘flip’) on a fresh window faster than subsequent flips? I have included some important details about my setup and experiment below.
OS: windows 10 enterprise (64 bit)
processor: Intel Core i7-8700K @3.70 GHz
ram: 16 GB
GPU: NVIDIA GeForce GTX 1070
Matlab version: 2020a
PTB version: 3.0.16
display monitor: AW2518Hf (240Hz, display with on-screen window for stimulus presentation)
side monitor: P2719h (60 Hz, no on-screen window)
- because I have two monitors attached and I’m only opening the onscreen window on the 240Hz monitor, I use Screen(‘Preference’, ‘SkipSyncTests’, 1);
Screen(‘OpenWindow’, 2, [0 0 0]);
to open the new window
- ALL textures are pre-drawn after first opening the window
- the textures are simple circles or rings, premade using Screen(‘MakeTexture’,…) - they are MxNx4 matrices to define color and transparency
- Screen(‘BlendFunction’,params.win,GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - this is the function call I use to turn on the transparency features for my textures
- after grabbing the last image from the cameras (image_frame1) and performing some computations on the image data (whose computation I am measuring) I only use Screen(‘DrawTexture’) commands to put the pre-made textures on the off-screen buffer
- To flip to the screen, I am using: Screen(‘Flip’,params.win,0,0,2);
specifically with the [dontsync] option set to 2, which displays the stimulus immediately without syncing to the screen refresh rate
- between each trial there are 3 textures containing text that are made and drawn to the screen (I doubt that these piling up is causing the slow down, as the display monitor latency is ~18 milliseconds even on the second screen(‘flip’), and doesn’t increase even with 40-50 subsequent trials)