Advertisement
Advertisement
β‘ Community Insights
Discussion Sentiment
100% Positive
Analyzed from 337 words in the discussion.
Trending Topics
#frame#duration#window#timing#jitter#average#frames#fps#games#divides
Discussion Sentiment
Analyzed from 337 words in the discussion.
Trending Topics
Discussion (3 Comments)Read Original on HackerNews
But that's just the nerd in me talking. The article is great!
The measured frame duration will have jitter up to 1 or even 2 milliseconds for various 'external reasons', and what you are measuring is actually the duration of the last frame, but you'll use that duration for timing-dependent computation of the current frame. E.g. if the last frame was a 'long' frame, but the current frame will be 'short', you'll overshoot and introduce visible micro-stuttering.
The measurement jitter may be caused by different reasons, e.g. most of it is probably caused by the operating system process/thread scheduler which doesn't care about a thread being scheduled a millisecond early or late. On web browsers all time sources have reduced precision since Sprectre/Meltdown, but thankfully the 'precision jitter' goes both ways and averaging over enough frames gives you back the exact frame duration (e.g. 8.333 or 16.667 milliseconds).
On some 3D APIs you can also query the 'presentation timestamp', but so far I only found the timestamp provided by CAMetalLayer on macOS and iOS to be completely jitter-free.
For this smoothing/filtering purpose, I found an EMA (Exponential Moving Average) more useful than a simple sliding window average (which I used before in sokol_app.h). An properly tuned EMA filter reacts quicker and 'less harshly' to frame duration changes (like moving the render window to a display with different refresh rate), it's also easier to implement since it doesn't require a ring buffer of previous frame durations.
TL;DR: frame timing for games is a surprisingly complex topic.
Also see the most influental blog post about the topic (IIRC the post is quite a bit older than 2018 but had been re-hosted):
https://medium.com/@alen.ladavac/the-elusive-frame-timing-16...