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 render pass on paint callback has now static lifetime #5149

Merged
merged 2 commits into from
Sep 23, 2024

Conversation

Wumpf
Copy link
Collaborator

@Wumpf Wumpf commented Sep 23, 2024

A very common usability issue on egui-wgpu callbacks is that paint can't access any data that doesn't strictly outlive the callback resources' data. E.g. if the callback resources have an Arc to some resource manager, you can't easily pull out resources since you statically needed to ensure that those resource references outlived the renderpass, whose lifetime was only constrained to the callback resources themselves.

Wgpu 22 no longer has this restriction! Its (render/compute-)passes take care of the lifetime of any passed resource internally. The lifetime constraint is still opt-out since it protects from a common runtime error of adding commands/passes on the parent encoder while a previously created pass wasn't closed yet.
This is not a concern in egui-wgpu since the paint method where we have to access the render pass doesn't even have access to the encoder!

@Wumpf Wumpf changed the title Render pass on paint callback has now static lifetime Wgpu render pass on paint callback has now static lifetime Sep 23, 2024
Copy link

Preview available at https://egui-pr-preview.github.io/pr/5149-static-renderpass
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

nice

crates/egui-wgpu/src/renderer.rs Outdated Show resolved Hide resolved
@Wumpf Wumpf merged commit 1603f05 into master Sep 23, 2024
40 checks passed
@Wumpf Wumpf deleted the static-renderpass branch September 23, 2024 09:48
@torokati44
Copy link
Contributor

May I request some assistance for making ruffle-rs/ruffle#18082 work, after this change?

@Wumpf
Copy link
Collaborator Author

Wumpf commented Sep 27, 2024

@torokati44 should be fairly straight forward: Just remove the lifetimes on paint. Since all changes are strictly lessenings of previous lifetime constraints it should be working out of the box once you adjusted the callback method's signature. Let me know if you have any concrete issues and I can have a look!

@Wumpf
Copy link
Collaborator Author

Wumpf commented Sep 27, 2024

ah I see you're using the renderer directly. In that case the other thing you're missing is something similar to this https://github.com/emilk/egui/pull/5149/files#diff-1173066e54f2d90c3a1f1e737b92a1800a8aa9be5e99e8103e9aeae4832834b7R339

@torokati44
Copy link
Contributor

Okay, I think I got it, thank you! My issue was that I tried to call .forget_lifetime() multiple times, at the places of usage, instead of right after creation.

hacknus pushed a commit to hacknus/egui that referenced this pull request Oct 30, 2024
A very common usability issue on egui-wgpu callbacks is that `paint`
can't access any data that doesn't strictly outlive the callback
resources' data. E.g. if the callback resources have an `Arc` to some
resource manager, you can't easily pull out resources since you
statically needed to ensure that those resource references outlived the
renderpass, whose lifetime was only constrained to the callback
resources themselves.

Wgpu 22 no longer has this restriction! Its (render/compute-)passes take
care of the lifetime of any passed resource internally. The lifetime
constraint is _still_ opt-out since it protects from a common runtime
error of adding commands/passes on the parent encoder while a previously
created pass wasn't closed yet.
This is not a concern in egui-wgpu since the paint method where we have
to access the render pass doesn't even have access to the encoder!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants