-
Notifications
You must be signed in to change notification settings - Fork 105
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
Turn off vsync throttling when macOS hardware sleeps #927
Conversation
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.
Thanks!
I left important comments need to be discussed.
[self onVSync]; | ||
} | ||
|
||
- (void)systemDidWake:(NSNotification *)notification { |
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.
When the system wakes up, we need to notify the window to redraw the content. If system calls the AWT function paint()
, it will redraw it. But can we guarantee that? If not, we should send a signal to AWT here.
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.
It seems the fix isn't about disabling redrawing, but about disabling vsync. In this case, no need to notify. But will we have unlimited FPS, and should stop drawing in case of sleeping?
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.
The issue is about deadlock on the conditional variable encpsulating vsync state. I can't reproduce that so my speculation is to destroy this mechanism temporarily while the device is sleeping.
I have an idea that have some really funny race-condition, where the logical screen for the window changes mid-flight due to some OS-level reconfigurations (flickering when connecting a display/waking up), so we wait on vsync from the screen which no longer exists/and AppKit didn't gracefully changed the screen to the existing one, but I have no idea currently how to fix that so I'd better try this solution and see if it fixes the issue.
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.
Potentially, it can indeed cause discarded drawables (because of redundant redraws, the initial issue that vsync mechanism fixed) if multiple were presented during a single hardware vsync after the the sleep notification, but that's an edge case that I bet will not affect the users
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.
macOS has less strict policy about drawables management and metal commands issuing from what I've observed, so stopping drawing altogether doesn't seem to be needed for correctness. Plus the AWT logic will also suspend at some point, hopefully.
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.
vsync also prevents unlimited FPS, which can load GPU/CPU. Do this code run for some time after sleeping?
I've noticed one more strange thing, not sure that it's related with this changes, but anyway. Usually we call |
Speculative fix for a freeze issue.