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 5 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
209 changes: 105 additions & 104 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ puffin = "0.18"
raw-window-handle = "0.5.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 = { git = "https://github.com/gfx-rs/wgpu", commit = "7774f31", features = [
"fragile-send-sync-non-atomic-wasm",
] } # Make the renderer `Sync` even on wasm32, because it makes the code simpler:# TODO: Use a stable version of wgpu.
emilk marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 5 additions & 5 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,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 @@ -373,7 +373,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 @@ -952,7 +952,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 +1031,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 Down Expand Up @@ -1120,7 +1120,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
22 changes: 14 additions & 8 deletions crates/eframe/src/native/wgpu_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub struct Viewport {

/// Window surface state that's initialized when the app starts running via a Resumed event
/// and on Android will also be destroyed if the application is paused.
window: Option<Rc<Window>>,
window: Option<Arc<Window>>,

/// `window` and `egui_winit` are initialized together.
egui_winit: Option<egui_winit::State>,
Expand Down Expand Up @@ -170,9 +170,11 @@ impl WgpuWinitApp {
self.native_options.viewport.transparent.unwrap_or(false),
);

let window = Arc::new(window);

{
crate::profile_scope!("set_window");
pollster::block_on(painter.set_window(ViewportId::ROOT, Some(&window)))?;
pollster::block_on(painter.set_window(ViewportId::ROOT, Some(window.clone())))?;
}

let wgpu_render_state = painter.render_state();
Expand Down Expand Up @@ -260,7 +262,7 @@ impl WgpuWinitApp {
},
screenshot_requested: false,
viewport_ui_cb: None,
window: Some(Rc::new(window)),
window: Some(window),
egui_winit: Some(egui_winit),
},
);
Expand Down Expand Up @@ -323,7 +325,7 @@ impl WinitApp for WgpuWinitApp {
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>> {
self.running
.as_ref()
.and_then(|r| {
Expand Down Expand Up @@ -544,7 +546,8 @@ impl WgpuWinitRunning {

{
crate::profile_scope!("set_window");
if let Err(err) = pollster::block_on(painter.set_window(viewport_id, Some(window)))
if let Err(err) =
pollster::block_on(painter.set_window(viewport_id, Some(window.clone())))
{
log::warn!("Failed to set window: {err}");
}
Expand Down Expand Up @@ -797,7 +800,10 @@ impl Viewport {
Ok(window) => {
windows_id.insert(window.id(), viewport_id);

if let Err(err) = pollster::block_on(painter.set_window(viewport_id, Some(&window)))
let window = Arc::new(window);

if let Err(err) =
pollster::block_on(painter.set_window(viewport_id, Some(window.clone())))
{
log::error!("on set_window: viewport_id {viewport_id:?} {err}");
}
Expand All @@ -813,7 +819,7 @@ impl Viewport {
self.info.minimized = window.is_minimized();
self.info.maximized = Some(window.is_maximized());

self.window = Some(Rc::new(window));
self.window = Some(window);
}
Err(err) => {
log::error!("Failed to create window: {err}");
Expand Down Expand Up @@ -930,7 +936,7 @@ fn render_immediate_viewport(

{
crate::profile_scope!("set_window");
if let Err(err) = pollster::block_on(painter.set_window(ids.this, Some(window))) {
if let Err(err) = pollster::block_on(painter.set_window(ids.this, Some(window.clone()))) {
log::error!(
"when rendering viewport_id={:?}, set_window Error {err}",
ids.this
Expand Down
4 changes: 2 additions & 2 deletions crates/eframe/src/native/winit_integration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{rc::Rc, time::Instant};
use std::{sync::Arc, time::Instant};

use winit::{
event_loop::EventLoopWindowTarget,
Expand Down Expand Up @@ -68,7 +68,7 @@ pub trait WinitApp {

fn integration(&self) -> Option<&EpiIntegration>;

fn window(&self, window_id: WindowId) -> Option<Rc<Window>>;
fn window(&self, window_id: WindowId) -> Option<Arc<Window>>;

fn window_id_from_viewport_id(&self, id: ViewportId) -> Option<WindowId>;

Expand Down
19 changes: 4 additions & 15 deletions crates/eframe/src/web/web_painter_wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ unsafe impl raw_window_handle::HasRawDisplayHandle for EguiWebWindow {
pub(crate) struct WebPainterWgpu {
canvas: HtmlCanvasElement,
canvas_id: String,
surface: wgpu::Surface,
surface: wgpu::Surface<'static>,
surface_configuration: wgpu::SurfaceConfiguration,
render_state: Option<RenderState>,
on_surface_error: Arc<dyn Fn(wgpu::SurfaceError) -> SurfaceErrorAction>,
Expand Down Expand Up @@ -82,20 +82,9 @@ impl WebPainterWgpu {

let canvas = super::canvas_element_or_die(canvas_id);

let surface = if false {
instance.create_surface_from_canvas(canvas.clone())
} else {
// Workaround for https://github.com/gfx-rs/wgpu/issues/3710:
// Don't use `create_surface_from_canvas`, but `create_surface` instead!
let raw_window = EguiWebWindow(egui::util::hash(("egui on wgpu", canvas_id)) as u32);
canvas.set_attribute("data-raw-handle", &raw_window.0.to_string());

#[allow(unsafe_code)]
unsafe {
instance.create_surface(&raw_window)
}
}
.map_err(|err| format!("failed to create wgpu surface: {err}"))?;
let surface = instance
.create_surface(wgpu::SurfaceTarget::Canvas(canvas.clone()))
.map_err(|err| format!("failed to create wgpu surface: {err}"))?;

let depth_format = egui_wgpu::depth_format_from_bits(options.depth_buffer, 0);
let render_state =
Expand Down
4 changes: 1 addition & 3 deletions crates/egui-wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ wgpu.workspace = true
## Enable this when generating docs.
document-features = { version = "0.2", optional = true }

winit = { version = "0.29.4", default-features = false, optional = true, features = [
"rwh_05",
] }
winit = { version = "0.29.4", default-features = false, optional = true }

# Native:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
12 changes: 8 additions & 4 deletions crates/egui-wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ pub enum WgpuError {

#[error(transparent)]
CreateSurfaceError(#[from] wgpu::CreateSurfaceError),

#[cfg(feature = "winit")]
#[error(transparent)]
HandleError(#[from] ::winit::raw_window_handle::HandleError),
}

/// Access to the render state for egui.
Expand Down Expand Up @@ -63,14 +67,14 @@ impl RenderState {
pub async fn create(
config: &WgpuConfiguration,
instance: &wgpu::Instance,
surface: &wgpu::Surface,
surface: &wgpu::Surface<'static>,
depth_format: Option<wgpu::TextureFormat>,
msaa_samples: u32,
) -> Result<Self, WgpuError> {
crate::profile_scope!("RenderState::create"); // async yield give bad names using `profile_function`

#[cfg(not(target_arch = "wasm32"))]
let adapters: Vec<_> = instance.enumerate_adapters(wgpu::Backends::all()).collect();
let adapters: Vec<_> = instance.enumerate_adapters(wgpu::Backends::all());

let adapter = {
crate::profile_scope!("request_adapter");
Expand Down Expand Up @@ -228,8 +232,8 @@ impl Default for WgpuConfiguration {

wgpu::DeviceDescriptor {
label: Some("egui wgpu device"),
features: wgpu::Features::default(),
limits: wgpu::Limits {
required_features: wgpu::Features::default(),
required_limits: wgpu::Limits {
// When using a depth buffer, we have to be able to create a texture
// large enough for the entire surface, and we want to support 4k+ displays.
max_texture_dimension_2d: 8192,
Expand Down
Loading
Loading