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

Make egui work on WebGPU out of the box. #2945

Merged
merged 8 commits into from
Apr 24, 2023
Merged

Make egui work on WebGPU out of the box. #2945

merged 8 commits into from
Apr 24, 2023

Conversation

Wumpf
Copy link
Collaborator

@Wumpf Wumpf commented Apr 21, 2023

BREAKING: Makes WebGL for wgpu opt-in. By default wasm builds for egui will now use WebGPU. To use WebGL, you need to add wgpu = { version = "0.16.0", features = ["webgl"] } now to your Cargo.toml.

Works around a surface creation issue which made any subsequent call to any method on the surface fail (in a rather arcane manner) - see gfx-rs/wgpu#3710

Regarding the breaking change: Wgpu doesn't allow both WebGPU and a "direct" backend, like WebGL, to live side by side (i.e. wgpu is either in a "wrap WebGPU" or "implement WebGPU" mode). Therefore, egui now inherits the webgl-opt-in behavior. Since Web is memory constraint and availability of WebGPU can be queried easily, two separate builds for WebGPU and WebGL seem to be desirable regardless, so I don't think this is a big issue.

Fixes #2137

@Wumpf
Copy link
Collaborator Author

Wumpf commented Apr 21, 2023

./scripts/build_demo_web.sh --release with feature glow changed to wgpu

egui_demo_app_bg.wasm filesize:

before: 6.62mb
after: 4.96mb

not too bad (:

@Wumpf Wumpf added eframe Relates to epi and eframe and removed egui-wgpu labels Apr 21, 2023
@emilk
Copy link
Owner

emilk commented Apr 21, 2023

So WebGPU must be configured at compile-time to user either WebGL or WebGPU, but you cannot ever configure it so that you pick at runtime?

So in effect we'll need to have a app_gl.wasm and app_wgpu.wasm and pick the correct one using JavaScript?

@Wumpf
Copy link
Collaborator Author

Wumpf commented Apr 21, 2023

yes, that's my understanding of the state of things!

@Wumpf
Copy link
Collaborator Author

Wumpf commented Apr 21, 2023

confirmed that now: gfx-rs/wgpu#3119 (comment)
Concluded that more from the code I debugged, but didn't go into the details. Personally I only ever looked at the backends that go through direct.rs (all backends except WebGPU, including webgl) and never looked at the mechanism that dispatches to web.rs instead.

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.

Very cool!

It would be nice with a --webgpu flag to scripts/build_demo_web.sh so this can be easily tested

crates/eframe/CHANGELOG.md Outdated Show resolved Hide resolved
crates/eframe/src/web/web_painter_wgpu.rs Outdated Show resolved Hide resolved
crates/eframe/CHANGELOG.md Outdated Show resolved Hide resolved
@emilk emilk added egui-winit porblems related to winit and removed egui-winit porblems related to winit labels Apr 24, 2023
@Wumpf
Copy link
Collaborator Author

Wumpf commented Apr 24, 2023

confirmed non-workaround path working with pending fix on wgpu

@Wumpf Wumpf merged commit 0e6d69d into master Apr 24, 2023
@Wumpf Wumpf deleted the egui-on-webgpu branch April 24, 2023 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eframe Relates to epi and eframe
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Eframe : Support for experimental webGPU backend
2 participants