Skip to content

How to handle window resizing on macOS #249

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

Closed
DagAgren opened this issue Jul 17, 2019 · 12 comments
Closed

How to handle window resizing on macOS #249

DagAgren opened this issue Jul 17, 2019 · 12 comments

Comments

@DagAgren
Copy link

I am playing around with using wgpu in a macOS project (and eventually iOS, but haven't tried it yet).

Right now I am struggling with how to handle window resizing. I'm currently rendering using CVDisplayLink, and for each frame checking if the size of the window has changed since last frame, and if so, I create a new swap chain.

This is causing double buffer flickering when resizing the window - every other frame is a frozen frame from the double buffer, and ever other is live updating and correct.

If I do not recreate the swap chain at all, it actually looks slightly better: Rendering seems to block completely for short times while resizing, and the contents of the previous frame is just resized instead.

Any clues what is going on? Am I doing something wrong, or is wgpu?

(Also, if I fullscreen, my framerate drops through the floor, and I get occasional squares of corruption on individual frames, but is that the same issue as #78 ?)

@kvark
Copy link
Member

kvark commented Jul 17, 2019

Did you try running https://github.com/gfx-rs/wgpu-rs examples and see how they resize in your environment?

@DagAgren
Copy link
Author

No, I will try that.

@DagAgren
Copy link
Author

Sorry, I am not very familiar with rust, so, how do I actually build the examples? "cargo build" does not seem to do it?

@kvark
Copy link
Member

kvark commented Jul 18, 2019

@DagAgren no worries, we'd be happy to walk you through. Sorry about inconvenience!
Basically, if you install Rust+Cargo (e.g. via https://rustup.rs/), you can do:

git clone https://github.com/gfx-rs/wgpu-rs
cd wgpu-rs
cargo run --example cube --features metal

@DagAgren
Copy link
Author

Thanks!

Resizing is very broken in a different way in the examples: The animation freezes, and the last frame is stretched to the window size.

@DagAgren
Copy link
Author

The examples also have the same problem where going to fullscreen will kill the framerate. The animation to fullscreen is of course also frozen the same way.

@kvark
Copy link
Member

kvark commented Jul 18, 2019

Thank you for verifying! One of the things we are currently doing is stalling the CPU to wait for GPU on resizing:

device.raw.wait_idle().unwrap();

There is also a number of issues with have with swapchain in gfx-rs Metal backend, including that fullscreen bug. We are looking for ways to resolve them, e.g. gfx-rs/gfx#2882

@DagAgren
Copy link
Author

All right! I guess in conclusion I should not try too hard to resolve this on my side, but rather wait a while for a few more issues to be addressed and then try again?

@kvark
Copy link
Member

kvark commented Jul 19, 2019 via email

@mtak-
Copy link

mtak- commented Jul 24, 2019

@DagAgren I would also caution that displaylink runs on a background thread. This could be the cause of the corrupted frames. If you are using objc/swift for CVDisplayLink, I would suggest switching to the display-link crate. It adds a send requirement on the callback which should make any threading issues more obvious.

Also, IIRC winit doesn't support live resize on macos super well until winit 0.20 comes out.

@seivan
Copy link
Contributor

seivan commented Aug 20, 2019

@mtak- It happens without using DisplayLink on macOS as well. Then again Metal might use one internally.

@kvark
Copy link
Member

kvark commented Sep 10, 2019

I consider this fixed by #330. Please re-open otherwise!

@kvark kvark closed this as completed Sep 10, 2019
kvark pushed a commit to kvark/wgpu that referenced this issue Jun 3, 2021
249: Derive `Default` for `CommandEncoderDescriptor` r=kvark a=grovesNL

Fixes gfx-rs#243

Co-authored-by: Joshua Groves <[email protected]>
Patryk27 pushed a commit to Patryk27/wgpu that referenced this issue Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants