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

Bump wgpu to 0.19 and winit to 0.29 #391

Merged
merged 14 commits into from
Sep 22, 2024

Conversation

mkrasnitski
Copy link
Contributor

@mkrasnitski mkrasnitski commented Jan 31, 2024

Also bumps raw-window-handle to 0.6. Blocked on the following:

Right now this PR uses these libraries are used as git dependencies. I point at my own fork of imgui-wgpu-rs for now.

@mkrasnitski
Copy link
Contributor Author

mkrasnitski commented Jan 31, 2024

There is one major bug that manifests in the imgui-winit example and seems to come from imgui-wgpu-rs. Resizing the window crashes with the following error:

[2024-01-31T01:42:15Z ERROR wgpu::backend::wgpu_core] Handling wgpu errors as fatal by default
thread 'main' panicked at /home/michael/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.19.1/src/backend/wgpu_core.rs:3009:5:
wgpu error: Validation Error

Caused by:
    In a RenderPass
      note: encoder = `pixels_command_encoder`
    In a set_scissor_rect command
    Scissor Rect { x: 0, y: 0, w: 641, h: 480 } is not contained in the render target (640, 480, 1)

Making the window smaller doesn't crash - only larger. Removing the gui.handle_event line from the example prevents the bug, so this is likely from imgui-wgpu-rs; also there's a call to set_scissor_rect internally in the lib.

Another annoyance that only happens with my fork is that key events are logged to the terminal like so:

KEY EVENT: KeyEvent { physical_key: Code(AltLeft), logical_key: Named(Alt), text: None, location: Left, state: Pressed, repeat: false, platform_specific: KeyEventExtra { key_without_modifiers: Named(Alt), text_with_all_modifiers: None } }

I don't know why this happens. I'd appreciate help diagnosing the cause of both of these problems, and would consider them a current blocker.

My fork: https://github.com/mkrasnitski/imgui-wgpu-rs. The only changes I made to the lib itself are to Cargo.toml, so I'm extra confused why these bugs arise.

@parasyte
Copy link
Owner

Hi, thanks for starting this! I'll kick off the CI pipeline shortly.

The difference between the scissor rect and surface has been a very common battle. Specifically I believe it's #338 (which still needs more info). The same issue was fixed in the custom-shader example in #286.

@parasyte
Copy link
Owner

Another annoyance that only happens with my fork is that key events are logged to the terminal like so:

KEY EVENT: KeyEvent { physical_key: Code(AltLeft), logical_key: Named(Alt), text: None, location: Left, state: Pressed, repeat: false, platform_specific: KeyEventExtra { key_without_modifiers: Named(Alt), text_with_all_modifiers: None } }

This is printed by the imgui-winit-support crate: https://github.com/imgui-rs/imgui-rs/blob/ca05418cb449dadaabf014487c5c965908dfcbdd/imgui-winit-support/src/lib.rs#L486

Copy link
Owner

@parasyte parasyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some comments. I think the one todo! is worth addressing. But also, now that I review the value for other compressed texture formats, I'm not even sure if those are correct...

examples/minimal-tao/src/main.rs Show resolved Hide resolved
internals/pixels-mocks/src/lib.rs Show resolved Hide resolved
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: self.backend,
..Default::default()
});

// TODO: Use `options.pixel_aspect_ratio` to stretch the scaled texture
let surface = unsafe { instance.create_surface(self.surface_texture.window) }?;
let surface = instance.create_surface(self.surface_texture.window)?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ... incredible! Does that mean #238 is fixed, and we can add #![forbid(unsafe_code)] back to the lib?

Copy link
Contributor Author

@mkrasnitski mkrasnitski Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised my approach worked. Since the handle traits have auto-impls for &W, I was able to switch from &'win W to W bounded on + 'win, which means you can also pass owned objects which satisfy a + 'static bound. This way I was able to overcome the borrow checker for some of the examples by using Arc.

src/builder.rs Outdated Show resolved Hide resolved
@mkrasnitski
Copy link
Contributor Author

mkrasnitski commented Jan 31, 2024

Looks like egui 0.24 bumped MSRV to Rust 1.72. Since we're bounding types using the new versions of the rwh traits, we're not compatible with older versions of egui except the newest one (when it releases). So, maybe that means we should bump MSRV as well. Thoughts?

@mkrasnitski
Copy link
Contributor Author

mkrasnitski commented Jan 31, 2024

This is printed by the imgui-winit-support crate: https://github.com/imgui-rs/imgui-rs/blob/ca05418cb449dadaabf014487c5c965908dfcbdd/imgui-winit-support/src/lib.rs#L486

That definitely seems like it was accidentally left in. Probably worth a PR to imgui.

EDIT: For reference: imgui-rs/imgui-rs#763

@mkrasnitski
Copy link
Contributor Author

Seems like CI is failing because of impl_trait_projections, which were stabilized in Rust 1.74. I could change Pixels::new_async to explicitly name Pixels<'win> instead of Self, or we could bump MSRV again to 1.74.

@parasyte
Copy link
Owner

parasyte commented Feb 1, 2024

or we could bump MSRV again to 1.74

Let's just do that. We'll eventually be increasing the MSRV to 1.74 anyway. Might as well do it early for the next release with breaking changes.

@mkrasnitski mkrasnitski force-pushed the bump-wgpu-winit branch 2 times, most recently from fa2f451 to 7bc8a32 Compare February 1, 2024 18:42
@mkrasnitski
Copy link
Contributor Author

mkrasnitski commented Feb 2, 2024

Oh, didn't see the other "MSRV"-style CI checks. I guess I should bump the 1.70 test version to 1.74, but the Rust-version check seems redundant. Especially because the external crate takes a git dependency on the git head of this project, which means it doesn't even use the current PR for testing.

@parasyte
Copy link
Owner

parasyte commented Feb 3, 2024

That check is there to handle this clause from our MSRV policy:

The MSRV will be chosen as the minimum version of rustc that can successfully pass CI, including documentation, lints, and all examples. For this reason, the minimum version supported may be higher than the minimum version required to compile the pixels crate itself.

Because dependencies in the examples tend to require a newer version of the compiler than the library needs, testing the two versions independently allows the library to require a compiler version that diverges from the examples.

Using the git HEAD is an unfortunate case of laziness where I just never added a way to select the correct branch or PR.

There is more information on this setup here:

So, no. It is definitely not redundant.

@mkrasnitski
Copy link
Contributor Author

Because dependencies in the examples tend to require a newer version of the compiler than the library needs, testing the two versions independently allows the library to require a compiler version that diverges from the examples.

Thanks for the explanation, that makes sense.

Using the git HEAD is an unfortunate case of laziness where I just never added a way to select the correct branch or PR.

This is unfortunate because this PR adds a dependency on the impl_trait_projections feature for constructing Pixels via the new_async method. So, I think the rust-version test will end up failing as soon as this PR gets merged (since the crate points to the git HEAD). It would be great if somehow CI could point at the current branch HEAD instead. Otherwise, PRs that raise the minimum required version would only fail that test after they're merged (even though MSRV is ahead of the new required version).

@parasyte
Copy link
Owner

parasyte commented Feb 4, 2024

It is valid criticism and thank you for the reminder. I am currently OK with doing the maintainer thing and keeping CI happy post-merge with additional PRs. (That responsibility falls on me, not other contributors.)

@lukexor
Copy link

lukexor commented Feb 12, 2024

Excitingly looking forward to this merging as I'm working on a project to add egui to my existing winit project using pixels. However, I'm concerned about the new lifetime requirement on Pixels as that has a very wide ranging impact on any application with a lot of impl blocks for any struct containing the pixels instance.

I specifically switched to winit/pixels to get away from some of the performance issues of rust-sdl2 - which also requires a lifetime bound for textures (unless you use the unsafe_textures feature flag) and the only reasonable way to get around that is to Box::leak it.

None of the examples for either library are complex enough to reveal how painful this can be when you don't want to stuff all of your initialization logic into main.

Edit: Though after further contemplation - it seems this isn't so bad when you wrap the window in an Arc. If only I had understood the magic of heap-allocated lifetimes earlier...Might be good to call that out in the docs/example setup for new Rust devs who might get tripped up since the signature of SurfaceTexture::new doesn't lead one to thing of using an Arc, Rc, or Box

@mkrasnitski
Copy link
Contributor Author

mkrasnitski commented Feb 12, 2024

Yes, I agree that the docs should make it more obvious that to avoid lifetime headaches you should just wrap your window in an Arc and use Pixels<'static>. Suggestions welcome.

@tuzz
Copy link

tuzz commented Feb 15, 2024

Hey @mkrasnitski, game-loop version 1.1.0 is now updated to use version 0.29.x of winit. I hope that helps, thanks.

@JacobMillward
Copy link

This seems to supersede my PR at #386 . I'm not quite sure what we're waiting on for this PR now, can someone explain?

@JacobMillward JacobMillward mentioned this pull request Apr 7, 2024
@mkrasnitski
Copy link
Contributor Author

mkrasnitski commented Apr 7, 2024

This PR is currently blocked on imgui-wgpu-rs supporting wgpu 0.19 and winit 0.29, so that the imgui-winit example compiles. Which should be easy, however it requires that lib changing to take a git dependency on imgui-rs, which got support for the new vesions of wgpu and winit a few months ago but hasn't seen a release since April 2023. I could open a PR to see if they're OK with that.

@parasyte
Copy link
Owner

parasyte commented Apr 7, 2024

I would be in support of any effort to upstream some of the unblocking work. Speaking of, I should be able to make some more progress on imgui-rs/imgui-rs#716 now! (Just looked briefly, and the PR has been obsoleted by others)

@vincenthz
Copy link

vincenthz commented May 2, 2024

Would it make sense to drop imgui example (temporarily) and not block this PR ?

Once imgui catch up, the example can be added back, in the meantime imgui user can use the existing old version

@parasyte
Copy link
Owner

parasyte commented May 2, 2024

I believe that is probably the right compromise. Both wgpu and winit have released new versions while this has been in limbo.

My proposal would be updating the imgui example to use the previous release version, with a comment somewhere about the transitive dependency issue.

@mkrasnitski
Copy link
Contributor Author

mkrasnitski commented May 7, 2024

As if on cue, imgui had its 0.12 release 2 days ago. All that remains now is Yatekii/imgui-wgpu-rs#107. Unfortunately, the imgui example still crashes the same way it did previously when resizing the window. Ideally this should be resolved before the PR is merged, but I have no idea what might be causing it.

@tuzz
Copy link

tuzz commented May 7, 2024

I've updated game-loop again (version 1.2.0) to support the newly released winit 0.30.x.

@mkrasnitski
Copy link
Contributor Author

mkrasnitski commented May 7, 2024

From what I can tell, supporting winit 0.30 in pixels would require similar efforts for adding support to other dependencies. The ecosystem hasn't yet moved over. So, probably this PR should remain at 0.29 rather than entering another waiting period.

@parasyte
Copy link
Owner

parasyte commented May 7, 2024

Yeah, upgrading winit is going to be kind of rough.

They plan to remove the existing event hander callback and replace it with a bucket of callbacks defined in a trait: rust-windowing/winit#3626. Somehow digging deeper into Inversion of Control territory is appealing to the maintainers.

I'm keen to stick with 0.29 for now, but I'll be planning on a general replacement since they insist on making app and game development more difficult than it should be.

@jeapostrophe
Copy link

Is there a way to use this with only winit and game-loop? I don't care about imgui, egui, or fltk. It is frustrating to wait so long to update when the release is held up by features that don't affect me.

@mkrasnitski
Copy link
Contributor Author

Is there a way to use this with only winit and game-loop? I don't care about imgui, egui, or fltk. It is frustrating to wait so long to update when the release is held up by features that don't affect me.

Certainly - just point at my fork. Compatibility with dependencies you aren't using won't matter for you so you'll be able to use the lib fine.

@jeapostrophe
Copy link

@mkrasnitski Thank you!

@JacobMillward
Copy link

JacobMillward commented Jun 8, 2024

Is there a way to use this with only winit and game-loop? I don't care about imgui, egui, or fltk. It is frustrating to wait so long to update when the release is held up by features that don't affect me.

I tend to agree that there is an underlying issue here. The core library can be upgraded, it is merely the surrounding example integrations that consistently keep this project out of date.

@parasyte it might be worth considering moving complex examples to pinned versions of the library, or moving them into a separate repository?

@mkrasnitski
Copy link
Contributor Author

Ok I'm fed up waiting for imgui-wgpu-rs to update support for wgpu, so the solution is to just pin the example to use a specific pixels commit instead of using path, and keep the dependencies on the old versions. This PR has been sitting blocked on transitive dependencies for far too long.

Btw @parasyte it might be worth it to cut release 0.13.1 off the current project HEAD and publish it so that the imgui example can point to 0.13.1 instead of a specific git commit.

@mkrasnitski
Copy link
Contributor Author

Sorry for the ping @parasyte, do you have any additional concerns, or is this PR free to merge?

@parasyte
Copy link
Owner

My apologies for dropping the ball on this! I've had my attention focused elsewhere.

Just about to publish a new version from main. It required some version bumps and will lead to some conflicts.

@parasyte
Copy link
Owner

I recognize how much effort this was, and how important the updates are. All of the checks are green, so I'm comfortable merging without hesitation. Any other needs can be addressed in smaller PRs.

Thank you for everything you did here, @mkrasnitski!

@parasyte parasyte merged commit 07e169d into parasyte:main Sep 22, 2024
9 checks passed
@mkrasnitski mkrasnitski deleted the bump-wgpu-winit branch September 23, 2024 18:32
@parasyte parasyte mentioned this pull request Nov 13, 2024
parasyte added a commit that referenced this pull request Nov 13, 2024
Adds CI steps to check and lint the example. And fixes build failures introduced by updating `winit` and `wgpu` in #391.

`run-wasm` still won't fail out the WASM CI job when there are build errors. That is tracked upstream in rukai/cargo-run-wasm#49

Closes #406
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

Successfully merging this pull request may close these issues.

7 participants