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

Update wgpu to 0.19 #3824

Merged
merged 37 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f8c3154
update to wgpu bleeding edge
Wumpf Jan 11, 2024
ba99680
add wgpu-with-webgl-fallback feature
Wumpf Jan 11, 2024
828ddec
web fixup
Wumpf Jan 11, 2024
5297bc2
Use wgpu from main and make setting the window safe (and provide an u…
Wumpf Jan 14, 2024
1871ffe
Remove `wgpu-with-webgl-fallback` again
Wumpf Jan 14, 2024
5a5022f
Remove exe
emilk Jan 15, 2024
5d754c8
Clean up Cargo.toml
emilk Jan 15, 2024
404a95a
In eframe, document the need to turn on webgl/webgpu features of wgpu
emilk Jan 16, 2024
9e6b6ae
Improve docs of egui-wgpu
emilk Jan 16, 2024
84f351d
Fix doc-tests
emilk Jan 16, 2024
ce84ec1
update wgpu and wasm-bindgen
emilk Jan 18, 2024
cd2f6e0
Update to raw-window-handle 0.6 (except for glow, stuck at 0.5)
emilk Jan 18, 2024
4c7540f
Make winit a workspace dependency
emilk Jan 18, 2024
ebba9f5
Don't use deprecated methods of new raw-window-handle
emilk Jan 18, 2024
9c212c3
Fix web build
emilk Jan 18, 2024
ccb9dc8
rwh fixes
emilk Jan 18, 2024
8e16563
Nicer output from check.sh
emilk Jan 18, 2024
b18d4b2
linux build fix
emilk Jan 18, 2024
3840a84
cleanup
emilk Jan 18, 2024
c8c839f
build_demo_web.sh: quiet building
emilk Jan 18, 2024
d6bdadb
remove ehco in build_demo_web.sh
emilk Jan 18, 2024
6b0c20b
Web logger: Mute debug log-spam from wgpu crates
emilk Jan 18, 2024
90d7524
List selected and available adapters in the egui_demo_app backend panel
emilk Jan 18, 2024
08fcca4
Remove "drag-to-move-window" demo from egui_demo_app
emilk Jan 18, 2024
e996df6
fix typo
emilk Jan 18, 2024
7e66aa5
We cannot list available adapters on web
emilk Jan 18, 2024
9b21cde
Warn about the 0.0.0.0 footgun
emilk Jan 18, 2024
5ae0072
typo
emilk Jan 18, 2024
70bec10
check `window.isSecureContext` and print info when not secure
emilk Jan 19, 2024
676cbb9
Explain how to opt-out of WebGPU
emilk Jan 19, 2024
2421a62
Use `get_default_config` on web
emilk Jan 19, 2024
1b110e9
typo
emilk Jan 19, 2024
5fa9794
Use `get_default_config` on native
emilk Jan 19, 2024
5ce6c66
Better docs on how to pick WebGL and/or WebGPU
emilk Jan 19, 2024
a329f83
fix web build
emilk Jan 19, 2024
f71ba2b
Add 'WebGPU' to list of known words in clippy.toml
emilk Jan 19, 2024
d97c8df
Clippy fix
emilk Jan 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 110 additions & 112 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ opt-level = 2
criterion = { version = "0.5.1", default-features = false }
glow = "0.13"
puffin = "0.18"
raw-window-handle = "0.5.0"
raw-window-handle = "0.6.0"
thiserror = "1.0.37"

# Make the renderer `Sync` even on wasm32, because it makes the code simpler:
wgpu = { version = "0.18.0", features = ["fragile-send-sync-non-atomic-wasm"] }

# Use this to build wgpu with WebGL support on the Web *instead* of using WebGPU.
#wgpu = { version = "0.18.0", features = ["webgl"] }
wgpu = { version = "0.19", features = [
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this has already landed, but this really should be no-default-features at least for egui-wgpu

Copy link
Owner Author

Choose a reason for hiding this comment

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

Will fix!

Copy link
Owner Author

Choose a reason for hiding this comment

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

Here we go: #3875

# Make the renderer `Sync` even on wasm32, because it makes the code simpler:
"fragile-send-sync-non-atomic-wasm",
] }
winit = { version = "0.29.4", default-features = false }
29 changes: 24 additions & 5 deletions crates/eframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ android-native-activity = ["egui-winit/android-native-activity"]
default_fonts = ["egui/default_fonts"]

## Use [`glow`](https://github.com/grovesNL/glow) for painting, via [`egui_glow`](https://github.com/emilk/egui/tree/master/crates/egui_glow).
glow = ["dep:glow", "dep:egui_glow", "dep:glutin", "dep:glutin-winit"]
glow = [
"dep:egui_glow",
"dep:glow",
"dep:glutin-winit",
"dep:glutin",
"dep:rwh_05",
"winit/rwh_05",
]

## Enable saving app state to disk.
persistence = [
Expand Down Expand Up @@ -92,8 +99,17 @@ web_screen_reader = [
]

## Use [`wgpu`](https://docs.rs/wgpu) for painting (via [`egui-wgpu`](https://github.com/emilk/egui/tree/master/crates/egui-wgpu)).
##
## This overrides the `glow` feature.
wgpu = ["dep:wgpu", "dep:egui-wgpu", "dep:pollster", "dep:raw-window-handle"]
##
## If you're targeting the web, you also need to turn on the
## `webgl` and/or `webgpu` features of the `wgpu` crate.
emilk marked this conversation as resolved.
Show resolved Hide resolved
## If you turn on both, eframe will prefer WebGPU and fall back on WebGL:
##
## ```ignore
## wgpu = { version = "*", features = ["webgpu", "webgl"] }
## ```
wgpu = ["dep:wgpu", "dep:egui-wgpu", "dep:pollster"]

## Enables compiling for x11.
x11 = ["egui-winit/x11"]
Expand All @@ -109,6 +125,7 @@ egui = { version = "0.25.0", path = "../egui", default-features = false, feature
] }
log = { version = "0.4", features = ["std"] }
parking_lot = "0.12"
raw-window-handle.workspace = true
static_assertions = "1.1.0"
thiserror.workspace = true

Expand All @@ -118,6 +135,10 @@ document-features = { version = "0.2", optional = true }

egui_glow = { version = "0.25.0", path = "../egui_glow", optional = true, default-features = false }
glow = { workspace = true, optional = true }
# glutin stuck on old version of raw-window-handle:
rwh_05 = { package = "raw-window-handle", version = "0.5.2", optional = true, features = [
"std",
] }
ron = { version = "0.8", optional = true, features = ["integer128"] }
serde = { version = "1", optional = true, features = ["derive"] }

Expand All @@ -131,8 +152,7 @@ egui-winit = { version = "0.25.0", path = "../egui-winit", default-features = fa
image = { version = "0.24", default-features = false, features = [
"png",
] } # Needed for app icon
raw-window-handle.workspace = true
winit = { version = "0.29.4", default-features = false, features = ["rwh_05"] }
winit = { workspace = true, default-features = false, features = ["rwh_06"] }

# optional native:
directories-next = { version = "2", optional = true }
Expand Down Expand Up @@ -211,5 +231,4 @@ web-sys = { version = "0.3.58", features = [

# optional web:
egui-wgpu = { version = "0.25.0", path = "../egui-wgpu", optional = true } # if wgpu is used, use it without (!) winit
raw-window-handle = { workspace = true, optional = true }
wgpu = { workspace = true, optional = true }
45 changes: 23 additions & 22 deletions crates/eframe/src/epi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ pub use crate::native::winit_integration::UserEvent;

#[cfg(not(target_arch = "wasm32"))]
use raw_window_handle::{
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, RawDisplayHandle,
RawWindowHandle, WindowHandle,
};
#[cfg(not(target_arch = "wasm32"))]
use static_assertions::assert_not_impl_any;
Expand Down Expand Up @@ -76,30 +77,28 @@ pub struct CreationContext<'s> {

/// Raw platform window handle
#[cfg(not(target_arch = "wasm32"))]
pub(crate) raw_window_handle: RawWindowHandle,
pub(crate) raw_window_handle: Result<RawWindowHandle, HandleError>,

/// Raw platform display handle for window
#[cfg(not(target_arch = "wasm32"))]
pub(crate) raw_display_handle: RawDisplayHandle,
pub(crate) raw_display_handle: Result<RawDisplayHandle, HandleError>,
}

// Implementing `Clone` would violate the guarantees of `HasRawWindowHandle` and `HasRawDisplayHandle`.
#[cfg(not(target_arch = "wasm32"))]
assert_not_impl_any!(CreationContext<'_>: Clone);

#[allow(unsafe_code)]
#[cfg(not(target_arch = "wasm32"))]
unsafe impl HasRawWindowHandle for CreationContext<'_> {
fn raw_window_handle(&self) -> RawWindowHandle {
self.raw_window_handle
impl HasWindowHandle for CreationContext<'_> {
fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError> {
// Safety: the lifetime is correct.
unsafe { Ok(WindowHandle::borrow_raw(self.raw_window_handle.clone()?)) }
}
}

#[allow(unsafe_code)]
#[cfg(not(target_arch = "wasm32"))]
unsafe impl HasRawDisplayHandle for CreationContext<'_> {
fn raw_display_handle(&self) -> RawDisplayHandle {
self.raw_display_handle
impl HasDisplayHandle for CreationContext<'_> {
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
// Safety: the lifetime is correct.
unsafe { Ok(DisplayHandle::borrow_raw(self.raw_display_handle.clone()?)) }
}
}

Expand Down Expand Up @@ -599,30 +598,32 @@ pub struct Frame {

/// Raw platform window handle
#[cfg(not(target_arch = "wasm32"))]
pub(crate) raw_window_handle: RawWindowHandle,
pub(crate) raw_window_handle: Result<RawWindowHandle, HandleError>,

/// Raw platform display handle for window
#[cfg(not(target_arch = "wasm32"))]
pub(crate) raw_display_handle: RawDisplayHandle,
pub(crate) raw_display_handle: Result<RawDisplayHandle, HandleError>,
}

// Implementing `Clone` would violate the guarantees of `HasRawWindowHandle` and `HasRawDisplayHandle`.
// Implementing `Clone` would violate the guarantees of `HasWindowHandle` and `HasDisplayHandle`.
#[cfg(not(target_arch = "wasm32"))]
assert_not_impl_any!(Frame: Clone);

#[allow(unsafe_code)]
#[cfg(not(target_arch = "wasm32"))]
unsafe impl HasRawWindowHandle for Frame {
fn raw_window_handle(&self) -> RawWindowHandle {
self.raw_window_handle
impl HasWindowHandle for Frame {
fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError> {
// Safety: the lifetime is correct.
unsafe { Ok(WindowHandle::borrow_raw(self.raw_window_handle.clone()?)) }
}
}

#[allow(unsafe_code)]
#[cfg(not(target_arch = "wasm32"))]
unsafe impl HasRawDisplayHandle for Frame {
fn raw_display_handle(&self) -> RawDisplayHandle {
self.raw_display_handle
impl HasDisplayHandle for Frame {
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
// Safety: the lifetime is correct.
unsafe { Ok(DisplayHandle::borrow_raw(self.raw_display_handle.clone()?)) }
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::time::Instant;

use winit::event_loop::EventLoopWindowTarget;

use raw_window_handle::{HasRawDisplayHandle as _, HasRawWindowHandle as _};
use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _};

use egui::{DeferredViewportUiCallback, NumExt as _, ViewportBuilder, ViewportId};
use egui_winit::{EventResponse, WindowSettings};
Expand Down Expand Up @@ -165,8 +165,8 @@ impl EpiIntegration {
gl,
#[cfg(feature = "wgpu")]
wgpu_render_state,
raw_display_handle: window.raw_display_handle(),
raw_window_handle: window.raw_window_handle(),
raw_display_handle: window.display_handle().map(|h| h.as_raw()),
raw_window_handle: window.window_handle().map(|h| h.as_raw()),
};

let icon = native_options
Expand Down
35 changes: 21 additions & 14 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use glutin::{
prelude::{GlDisplay, PossiblyCurrentGlContext},
surface::GlSurface,
};
use raw_window_handle::{HasRawDisplayHandle as _, HasRawWindowHandle as _};
use winit::{
event_loop::{EventLoop, EventLoopProxy, EventLoopWindowTarget},
window::{Window, WindowId},
Expand Down Expand Up @@ -126,7 +125,7 @@ struct Viewport {
// These three live and die together.
// TODO(emilk): clump them together into one struct!
gl_surface: Option<glutin::surface::Surface<glutin::surface::WindowSurface>>,
window: Option<Rc<Window>>,
window: Option<Arc<Window>>,
egui_winit: Option<egui_winit::State>,
}

Expand Down Expand Up @@ -294,6 +293,9 @@ impl GlowWinitApp {
.expect("Single-use AppCreator has unexpectedly already been taken");

let app = {
// Use latest raw_window_handle for eframe compatibility
use raw_window_handle::{HasDisplayHandle as _, HasWindowHandle as _};

let window = glutin.window(ViewportId::ROOT);
let cc = CreationContext {
egui_ctx: integration.egui_ctx.clone(),
Expand All @@ -302,8 +304,8 @@ impl GlowWinitApp {
gl: Some(gl),
#[cfg(feature = "wgpu")]
wgpu_render_state: None,
raw_display_handle: window.raw_display_handle(),
raw_window_handle: window.raw_window_handle(),
raw_display_handle: window.display_handle().map(|h| h.as_raw()),
raw_window_handle: window.window_handle().map(|h| h.as_raw()),
};
crate::profile_scope!("app_creator");
app_creator(&cc)
Expand Down Expand Up @@ -373,7 +375,7 @@ impl WinitApp for GlowWinitApp {
self.running.as_ref().map(|r| &r.integration)
}

fn window(&self, window_id: WindowId) -> Option<Rc<Window>> {
fn window(&self, window_id: WindowId) -> Option<Arc<Window>> {
let running = self.running.as_ref()?;
let glutin = running.glutin.borrow();
let viewport_id = *glutin.viewport_from_window.get(&window_id)?;
Expand Down Expand Up @@ -898,15 +900,18 @@ impl GlutinWindowContext {
gl_display.version_string(),
gl_display.supported_features()
);
let raw_window_handle = window.as_ref().map(|w| w.raw_window_handle());
log::debug!("creating gl context using raw window handle: {raw_window_handle:?}");
let glutin_raw_window_handle = window.as_ref().map(|w| {
use rwh_05::HasRawWindowHandle as _; // glutin stuck on old version of raw-window-handle
w.raw_window_handle()
});
log::debug!("creating gl context using raw window handle: {glutin_raw_window_handle:?}");

// create gl context. if core context cannot be created, try gl es context as fallback.
let context_attributes =
glutin::context::ContextAttributesBuilder::new().build(raw_window_handle);
glutin::context::ContextAttributesBuilder::new().build(glutin_raw_window_handle);
let fallback_context_attributes = glutin::context::ContextAttributesBuilder::new()
.with_context_api(glutin::context::ContextApi::Gles(None))
.build(raw_window_handle);
.build(glutin_raw_window_handle);

let gl_context_result = unsafe {
crate::profile_scope!("create_context");
Expand Down Expand Up @@ -952,7 +957,7 @@ impl GlutinWindowContext {
screenshot_requested: false,
viewport_ui_cb: None,
gl_surface: None,
window: window.map(Rc::new),
window: window.map(Arc::new),
egui_winit: None,
},
);
Expand Down Expand Up @@ -1031,7 +1036,7 @@ impl GlutinWindowContext {
);
viewport.info.minimized = window.is_minimized();
viewport.info.maximized = Some(window.is_maximized());
viewport.window.insert(Rc::new(window))
viewport.window.insert(Arc::new(window))
};

viewport.egui_winit.get_or_insert_with(|| {
Expand All @@ -1052,9 +1057,11 @@ impl GlutinWindowContext {
let (width_px, height_px): (u32, u32) = window.inner_size().into();
let width_px = std::num::NonZeroU32::new(width_px.at_least(1)).unwrap();
let height_px = std::num::NonZeroU32::new(height_px.at_least(1)).unwrap();
let surface_attributes =
let surface_attributes = {
use rwh_05::HasRawWindowHandle as _; // glutin stuck on old version of raw-window-handle
glutin::surface::SurfaceAttributesBuilder::<glutin::surface::WindowSurface>::new()
.build(window.raw_window_handle(), width_px, height_px);
.build(window.raw_window_handle(), width_px, height_px)
};

log::trace!("creating surface with attributes: {surface_attributes:?}");
let gl_surface = unsafe {
Expand Down Expand Up @@ -1120,7 +1127,7 @@ impl GlutinWindowContext {
.expect("viewport doesn't exist")
}

fn window(&self, viewport_id: ViewportId) -> Rc<Window> {
fn window(&self, viewport_id: ViewportId) -> Arc<Window> {
self.viewport(viewport_id)
.window
.clone()
Expand Down
Loading
Loading