justingardner / mgl

A suite of mex/m files for displaying psychophysics stimuli
http://justingardner.net/mgl
Other
18 stars 22 forks source link

Grab frame timestamps "closer to the metal" #70

Closed benjamin-heasly closed 1 year ago

benjamin-heasly commented 2 years ago

Currently our Metal app is making a best effort to return frame completion timestamps, near the top of the "draw" callback from the system -- here.

It seems likely this timestamp includes significant jitter. We expect each next draw call to happen some time after the previous frame completed, but there's no guarantee about when these things will be scheduled by the OS relative to each other. The system may have other priorities, besides making our MGL timestamps as accurate as possible.

We haven't dug too deep yet. It may be that the Metal API can provide us an explicit timestamp for each frame, which we could use in place of our best effort timestamps.

Or, it may be that we can do better by moving our best effort timestamps "closer to the metal". For example, there' a concept of a Metal command queue completion handler. I'm not sure if "command queue completion" has the same meaning as "frame onset" or "frame completion", but we could look into this or look for a similar callback mechanism that means what we want.

justingardner commented 1 year ago

Seems like a good thing for the future, but I'm going to close and we can open again if this is functionality that is important to someone.