Repository navigation
dbe: fix frame timing at high frame rates - #69
Merged
Merged
Conversation
In zig 0.17 the dbe example waits for socket data with io.operateTimeout, which rounds the time left down to whole milliseconds when it polls (and is allowed to return early). A 1ms timeout returned immediately, so at the "1000 FPS" setting the example rendered ~56000 frames per second and flooded the X server, which looked like rendering stopping. 0.15's poll(timeout_ms) never woke up early. - after an early timeout, check whether it's time to render instead of rendering unconditionally - round the timeout up so the wait doesn't spin until it's reached - compute the animation progress from nanoseconds instead of truncated milliseconds, which slowed the animation at high frame rates Amp-Thread-ID: https://ampcode.com/threads/T-01a14b88-aff8-717e-bb9f-364137832240 Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since the zig 0.17 upgrade, dbe stops rendering when the rate is turned up to 1000 FPS with double buffering disabled.
Cause: dbe waits for socket data with
io.operateTimeout. std 0.17's posix batch wait converts the time left to milliseconds with@divTruncbefore callingpoll, and returnserror.Timeoutwhenpolltimes out (its comments say spurious timeouts are OK). So a timeout always comes back up to 1ms early: measured, a 1ms timeout returns after 0–11µs, 2ms after ~1ms, 15ms after ~14ms. dbe rendered on every timeout, so at the 1ms frame setting it rendered ~56,000 frames/s and flooded the X server. 0.15'spoll(timeout_ms)never woke early.Fix:
continue) instead of rendering unconditionallypoll(0)until the frame is dueVerification
Instrumented build on Xvfb with double buffering disabled, logging frames per second and animation progress (should advance 0.5/s):
With only the re-check (no rounding up) it was 999 frames/s but used 100% of a core spinning. Animation progress now advances 0.50/s at both settings.
zig build install install-xauth test-non-interactivepasses; x86_64 windows compiles.https://ampcode.com/threads/T-01a14b88-aff8-717e-bb9f-364137832240