Sensory Latency and glFinish

This article discusses the factors that contribute to overall sensor latency and the importance of turning on glFinish in the Vizard script to reduce render latency.

Total end-to-end latency is defined as the time delay between a physical motion and the corresponding change in display (light) output the user can see. Specifically, it is T = A + C + R + D, where:

T          Total end-to-end sensor to display latency
A          Acquisition latency (sensor device dependent)
C          Communication latency (e.g., serial, Ethernet dependent)
R          Render latency (graphics content, vsync state, CPU, and GPU dependent)
D          Display latency (display device dependent) and always equals 1/(refresh rate in Hz)

Most of these factors are dependent on the hardware being used. Render latency, however, can be influenced by the content that's being displayed and Vizard's glFinish setting.

When glFinish is set, Vizard blocks at the end of every frame (versus rendering ahead one) until the frame is displayed. Blocking ensures that Vizard has the freshest possible sensor data before drawing the next frame. For example, take a standard setup with a 60 Hz display and vsync enabled. If the scene renders well within 1/60 of a second, setting glFinish will reduce sensor lag by nearly 17 ms (the better part of one frame period) and the framerate will remain unaffected. If, on the other hand, the scene is more complex and takes longer to render, setting glFinish may cause the framerate to drop because the CPU and GPU workloads are forced into serial order. While enabling glFinish may result in a lower frame rate, it will still not increase latency.

The following chart shows various scenarious that can occur with glFinish enabled/disabled. Some typical values for latency are used to illustrate the differences:

Scenario End-to-End Latency Framerate
glFinish off
scene complexity low
50 ms 60 fps
glFinish on
scene complexity low
33 ms 60 fps
glFinish off
scene complexity high
50 ms 60 fps
glFinish on
scene complexity high
50 ms 30 fps

Usage: By default, Vizard attemps to maximize framerate. If minimizing latency is most important for your usage, try setting glFinish in your script. Simply add the following line of code:

viz.setOption('viz.glFinish',1)

If you don't see a framerate drop (press F4 with the script running) , glFinish is reducing the overall sensor latency.