-
-
Notifications
You must be signed in to change notification settings - Fork 205
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
Android: refactor frame loop to use vsync #2142
base: dev
Are you sure you want to change the base?
Conversation
scheduleUpdate(); | ||
} | ||
|
||
void MainLoopTest::update(float dt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I do not clearly understand what about this fix. Does it help to get requested fps for high frequency devices?
Why such implementation of update? As I see:
- Remember now time with some Delta
- Wait while this Delta expiration nothing doing
You can use Node::schedule with selector for this purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should fix the issue of requested animation interval not working on devices with high refresh rate displays. And it also fixes frames not starting on vsync.
The MainLoopTest::update()
thing is the simplest thing to add simulation of slow frame updates.
@smilediver Hi! Nice job on the PR
Edit: I tried to look what the issue was but not found yet; in both P6 or S8 the interval between each call to
|
Strange... it updates and shows frames every other frame, just as it's supposed to do. Maybe try running the game on 120 and 60 Hz devices at the same time and see if there's any visual/feel difference between them? |
It’s what I said earlier, when requesting 60Hz interval on the 120Hz device it’s like it runs at lower frequency than 60Hz, but I can’t explain why. The code seems fine to me that’s quite strange. |
Can you check what values |
I’ll get few rows of values tomorrow but I’m sure mVsyncPeriod is 16666667 |
For 120Hz display |
This value made me tilt; I checked and I got 11111111 which was surprising. The reason is simple, I thought the Pixel 6 was 120Hz but it's 90Hz... My bad on this. But that's why we have this value and why we have an issue on the display with desync and lags sometimes as it's not a modulo of 60Hz. (Just as a note the Pixel 6 PRO is a 120Hz device which it's why it confused me).
|
I think that presentation time might be getting ahead of slow updates on fast displays disabling any buffering, so I'm thinking that more correct way to do it would be this: long frameTime = Math.Max(sAnimationInterval.get(), mVsyncInterval);
long frameTimeWithVsync = frameTime + frameTime % mVsyncInterval;
long framePresentationTime = frameStartTime + frameTimeWithVsync + mVsyncInterval; Basically
In theory this should help with jitters. Can you test this? I'll do some testing tomorrow too. Also, on 90 Hz device you can't run at 60 FPS, as the closest you can get is 45 FPS, and that's why it feels that the game is running slower than 60 FPS. The only FPS' for 90 Hz you can run at are 90 / N, and in this case closest is N = 2. If you requested 40 FPS, your game would be running at 30 FPS, ie N = 3. |
@smilediver I tried and it works as expected so 45Hz on the Pixel 6 for 60Hz asked, works for 90Hz or 30Hz requested too. |
Refactors Android's frame loop to use vsync.
Related other PR: #2125
Issue: #2129
It would be nice if more people tested this on different devices.