-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
macOS and iOS CPU ussage fix #5713
Comments
You can enable vsync for this, right? |
No it seems like the runloop used in all scenarios is the NSApp runloop which shouldn’t be used like this. |
We need NSApp for input events, right? |
Well, no actually. Fetching mouse position and getting current keyboard state doesn’t require the NSApp runloop |
And what about window events and game controllers? Also if you use a CoreVideo based event loop can you still use NSView/UIView? Wgpu requires one to show the rendered framebuffer in. |
I don’t know why you would want to recieve window events but you can still use apple's Game controller api and you can update the NSView/UIView although on mac when updating the NSView you have to do a |
Wgpu doesn't support running on a thread that can't access the NSView AFAIK. |
Maybe it would be possible to add a new optional runloop mode and window manager for macOS that is optimised for games? |
Maybe? I think it makes sense to prototype it first as external plugin though. Using vsync would solve the cpu usage issue AFAIK and the only benefit to using CoreVideo is improving latency, so maybe it could be combined with https://github.com/aevyrie/bevy_framepace? cc @superdump @aevyrie |
Oké, I'm currently writting a proof of concept Plugin to demonstrate what I mean |
It would be interesting your results to |
I'm almost done (going from 100%-150% cpu to 20%-30%) but, I can’t seem to find where bevy actually draws the renderer texture. Do you know where @bjorn3 ? |
bevy/crates/bevy_render/src/view/window.rs Lines 182 to 191 in 992681b
|
|
I've looked into it and created https://github.com/Kees-van-Beilen/CocoaBird, which whilst in debug mode grants a cpu benefit of ~50% to ~ 10% comming to an avarage of 60% cpu usage (with winit this is about 90%). In release mode these two are virtually the same. |
What problem does this solve or what need does it fill?
increasing iOS and macOS game performance whilst saving battery live is a hard task but can be done quite easily, since macOS and iOS usually fix application framerate (with the exclusion to scrollviews or when programmatically demmanded). Currently a basic bevy app uses ~100% cpu on mac, which is a shame because it can be lower
What solution would you like?
Since application framerate is capped, using CADisplayLink on iOS and CVDisplayLink on macOS will give you a non-blocking 60 tick per second callback
What alternative(s) have you considered?
There's no other way on macOS , because the most common run loop [NSApp getevent.....] is really slow and CoreVideo bypasses all of the objc event system
Additional context
As someone who has implemented both CADisplayLink and CVDisplayLink once in the past. I can assure you it saves alot on cpu usage going from ~>100% to <20% which in turn saves on a lot of battery life. Also because apple ctr-alt-deleted there good old CoreVideo documention here’s a quick overview in obj-c (even though corevideo is mostly a c-api):
The text was updated successfully, but these errors were encountered: