macOS: Fix one-second delay when switching a wgpu app to the foreground#9141
macOS: Fix one-second delay when switching a wgpu app to the foreground#9141Wumpf merged 9 commits intogfx-rs:trunkfrom
Conversation
|
I hear from @Wumpf (on other channels) that we should return a new error code instead of returning My plan is to change |
Wumpf
left a comment
There was a problem hiding this comment.
looks good to me, except for the wrong comment I found. Much cleaner than before!
Wumpf
left a comment
There was a problem hiding this comment.
nice. Going to land that and further investigate correct reaction to inclusion events as part of #9089
Which I want to review soonish; I'll then put some effort into learning about how to correctly process occluded events on winit and will transfer those learnings to eframe as well if it can be mitigated there
|
It actually looks like I accidentally counteracted the same problem in this PR: On egui main now (without the fix in this wgpu PR), I get zero delay when moving the window to the front EXCEPT if I do so very quickly (switch back and forth within a single second). |
Connections
get_current_texturelocks for exactly one second #8309Description
get_current_texturecan now returnSurfaceError::Occluded(only on Mac currently)fn acquire_textureto return timeouts as an error variantOn macOS, when a window is occluded (minimized, behind other windows, or on another virtual desktop),
CAMetalLayer.nextDrawable()can block for up to 1 second. This happens because presented drawables get stuck waiting for vsync that isn't happening while the window is hidden.When switching back to a wgpu application that was in the background, users experience a noticeable 1-second delay before the application becomes responsive.
This PR adds a fix: in the top of
aquire_texturewe first check if the window is occluded. If it is, we return a newSurfaceError::Occludederror right away, avoiding the 1 second delay.This then requires users to actually handle this new error by attempting again later.
Thanks to Claude and @Wumpf for helping me with this PR!
Testing
I ran
cargo r -p wgpu-example-02-hello-window, switching the app to be behind and then in front of another opaque window.cargo run --bin wgpu-examples cubecargo run --bin wgpu-examples hello_trianglecargo run --bin wgpu-examples uniform_valuescargo r -p wgpu-example-02-hello-windowSquash or Rebase?
Squash
Checklist
cargo fmt.taplo format.cargo clippy --tests. If applicable, add:--target wasm32-unknown-unknowncargo xtask testto run tests.CHANGELOG.mdentry.