Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PID controller for sleep error #36

Open
UkoeHB opened this issue Apr 18, 2023 · 1 comment
Open

PID controller for sleep error #36

UkoeHB opened this issue Apr 18, 2023 · 1 comment

Comments

@UkoeHB
Copy link

UkoeHB commented Apr 18, 2023

Attached is a patch that adds a PID controller. I found that the derivative factor adds stutter, but using proportional and integral factors improves the 'sleep error' (difference between target sleep time and actual sleep time) dramatically. The PID design is fundamentally different from the current controller, which is setting the sleep time equal to the previous error, whereas the PID controller tries to reduce that error to zero (which makes more sense to me).

  • The PID controller fixes the 3-5 FPS frame loss that the current design suffers from.
  • The PID controller does NOT appear compatible with vsync when 'delay waiting for a frame to present' is not incorporated. I noticed worse latency when vsync is enabled. It seems to be random luck that the current design works well with vsync.

I hacked the bevy render function to record frame presentation delays and incorporated those into the framepace app. Doing so resulted in extremely low latencies with vsync enabled (even better than the current code, afaict). It would require a pretty critical PR to update the core bevy render function in order to get timing info on the frame presentation step.

add_PID_controller.patch

@aevyrie
Copy link
Owner

aevyrie commented Apr 18, 2023

Link to full thread on the Bevy discord server: https://discord.com/channels/691052431525675048/1088685202752155719/1095468054747561985

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants