-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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: Memory usage skyrockets when window is occluded #5856
Comments
As part of filling information on the related issue on sotrh/learn-wgpu#207 (comment) (which contains sample code on both approaches on a smaller-scale I have updated the main issue body as a result of this. |
…s not visible (#7611) Fixes #5856. Fixes #8080. Fixes #9040. # Objective We need to limit the update rate of games whose windows are not visible (minimized or completely occluded). Compositors typically ignore the VSync settings of windows that aren't visible. That, combined with the lack of rendering work, results in a scenario where an app becomes completely CPU-bound and starts updating without limit. There are currently three update modes. - `Continuous` updates an app as often as possible. - `Reactive` updates when new window or device events have appeared, a timer expires, or a redraw is requested. - `ReactiveLowPower` is the same as `Reactive` except it ignores device events (e.g. general mouse movement). The problem is that the default "game" settings are set to `Contiuous` even when no windows are visible. ### More Context - libsdl-org/SDL#1871 - glfw/glfw#680 - godotengine/godot#19741 - godotengine/godot#64708 ## Solution Change the default "unfocused" `UpdateMode` for games to `ReactiveLowPower` just like desktop apps. This way, even when the window is occluded, the app still updates at a sensible rate or if something about the window changes. I chose 20Hz arbitrarily.
Bevy version
0.8.1
[Optional] Relevant system information
MacBook Pro (16-inch, 2021)
What you did
v0.8.1
tag.shader-instancing
example locally on release mode:cargo run --release --example shader_instancing
.What went wrong
When occluding or minimizing the Bevy window, memory usages skyrockets at gigabytes per second until the window is shown again.
Additional information
The memory usage is caused by gfx-rs/wgpu#1783. The following information stems from a long and somewhat redundant investigation on this issue, plus a bunch of other macOS-related issues (discord thread).
It was concluded that this is impractical to solve entirely at the
wgpu
level, and that there are two primary workarounds for this issue:Detecting window occlusion using
winit
'sWindowEvent::Occluded
and avoiding any rendering at all when the window is occluded.Driving rendering through
CVDisplayLink
(macOS) /CADisplayLink
(iOS) frame callbacks (both essentially do kind of the same).Preliminary tests using the
display-link 0.2
crate on rawwgpu
examples were successful, but more interesting stuff is exposed on the raw APIs themselves (documentation). Apple itself explains how it works in this WWDC 2021 talk.It is noted exploring such integration for Bevy is already being studied as part of macOS and iOS CPU ussage fix #5713.
The text was updated successfully, but these errors were encountered: