Skip to content
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

wgpu and winit update tracker #503

Open
ifsheldon opened this issue Oct 26, 2023 · 13 comments
Open

wgpu and winit update tracker #503

ifsheldon opened this issue Oct 26, 2023 · 13 comments

Comments

@ifsheldon
Copy link

Hey! Here is just a heads-up that wgpu 0.18 and winit 0.29.2 came up recently with a lot breaking changes.

For the breaking changes from wgpu, please see https://github.com/gfx-rs/wgpu/releases/tag/v0.18.0. I think these are easy to be fixed when upgrading from 0.17.

However, for the newer winit, it brings a LOT API changes. See https://github.com/rust-windowing/winit/releases/tag/v0.29.2

I think virtually a rewrite on sections about windowing is needed.

If it helps, I just did the upgrade to winit 0.29.2 for my wgpu DVR renderer in this commit. In short, we need to:

  • enable a feature rwh_05 of winit for raw-window-handle traits
  • checkout (a lot) breaking changes about window events and key events
  • handle subtle changes to redrawing behavior

But wait, why do we need to upgrade winit?

I don't know honestly, because when I upgraded wgpu from 0.17 to 0.18 while keeping winit as 0.27, my code weirdly breaks because an abnormal resize event which gives a new window size to (u32::max, u32::max). I thought that should be a bug from winit so I upgraded winit as well. Probably winit 0.27 does not work with macOS Sonoma, I don't know, but now the problem is gone, so I don't want to dig deeper.

@sotrh
Copy link
Owner

sotrh commented Dec 16, 2023

I've already upgraded to 0.18, but an upgrade to winit 0.29 might take a little longer. I created different demo using winit 0.29 so hopefully it shouldn't be too painful.

@vfx1b
Copy link

vfx1b commented Jan 13, 2024

Hi, I've been working through the learn-wpgu book, but with updated winit and wgpu. Id be happy the help out with rewriting stuff!

@ifsheldon
Copy link
Author

wgpu 0.19 is just released. We just need a few minor changes to remove the last bit of unsafe code in the tutorial when creating a Surface. It works perfectly in my webgpu DVR renderer. But I'm using the latest winit so I don't know how it works with older winit. The breaking changes of wgpu 0.19 are not fully documented but it's easy to fix the breaking pieces. Just for your information, my changes in my renderer due to the wgpu update are here.

@tgross35
Copy link

Winit 0.30 was released just yesterday, which seems to prefer the ApplicationHandler trait rather than an event loop. This was very tricky to get working but I think I have something, which I posted to rust-windowing/winit#3626 (comment).

@ifsheldon ifsheldon changed the title wgpu 0.18 and winit 0.29.2 updates wgpu and winit update tracker Apr 29, 2024
@ifsheldon
Copy link
Author

@tgross35 Thanks for the heads-up. How about async methods?

I have the following code in my GfxStates::new()

let instance = wgpu::Instance::default();
        let surface = instance.create_surface(window).expect("Failed to create surface");
        // need adapter to create the device and queue
        let adapter = instance
            .request_adapter(&wgpu::RequestAdapterOptions {
                power_preference: wgpu::PowerPreference::default(),
                force_fallback_adapter: false,
                compatible_surface: Some(&surface),
            })
            .await
            .unwrap();
        let (device, queue) = adapter
            .request_device(
                &wgpu::DeviceDescriptor {
                    label: None,
                    required_features: wgpu::Features::empty(), //The device you have limits the features you can use
                    required_limits: wgpu::Limits::default(), //The limits field describes the limit of certain types of resource we can create
                },
                None,
            )
            .await
            .unwrap();

but the trait method is synchronous, so do we have to introduce a blockon() to get the result?

@ifsheldon
Copy link
Author

Just FYI, I updated my code to wgpu 0.20, which was released 5 hrs ago and is very easy to migrate to. Just follow rustc's error messages.

@tgross35
Copy link

I have just been using block_on for those two functions, but that is a good point. I wish I better understood why these were async at all, I guess maybe this comes from webgpu? Seems like an unlikely point to have performance wins from a nonblocking API.

(reposting here since I accidentally posted this comment on the winit tracker)

@sotrh
Copy link
Owner

sotrh commented May 6, 2024

Yeah the async bit is from the webgpu spec.

@ifsheldon
Copy link
Author

Using wgpu::Surface with Window of winit>0.30.0 is a bit tricky, which may cause self-reference. You can refer to gfx-rs/wgpu#6005 (comment) and my commit that updates my renderer to get an idea on how to avoid self-referential types and adapt to newer winit APIs.

@Bentebent
Copy link

Bentebent commented Aug 15, 2024

What is the current thoughts on upgrading to winit 0.30? It feels like a significant effort to move all beginner tutorials to 0.30 but could it be interesting to have an intermediate tutorial that shows how to port to 0.30?

@ifsheldon
Copy link
Author

I think as of now, both wgpu and winit have reached a sort of stable stage, as wgpu release a major version 22.x and winit has stayed in 0.30.x for several months and on track of its roadmap. So, I guess now is a good point to revisit the tutorial?

@sotrh
Copy link
Owner

sotrh commented Aug 26, 2024

I created a branch to experiment with 0.30. While I got the code to run on WASM, the canvas was being sized to 1x1 for some reason. That killed the momentum I had to work on it, and I haven't had time to come back to it.

@sotrh sotrh closed this as completed Aug 26, 2024
@sotrh sotrh reopened this Aug 26, 2024
@sotrh
Copy link
Owner

sotrh commented Aug 26, 2024

Accidentally closed the issue while trying to make a comment

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

5 participants