From d5453c62e9bdbf0cea030b009c41b892b700496d Mon Sep 17 00:00:00 2001 From: Elham Aryanpur Date: Wed, 12 Apr 2023 23:38:21 +0300 Subject: [PATCH 1/4] Update `wgpu` to `0.15` --- examples/integration_wgpu/src/main.rs | 37 +++++++++++++++++---------- wgpu/Cargo.toml | 4 +-- wgpu/src/image/atlas.rs | 2 ++ wgpu/src/triangle/msaa.rs | 2 ++ wgpu/src/window/compositor.rs | 25 +++++++++++++++--- 5 files changed, 50 insertions(+), 20 deletions(-) diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs index 2a56b6fa4f..6e86833227 100644 --- a/examples/integration_wgpu/src/main.rs +++ b/examples/integration_wgpu/src/main.rs @@ -23,18 +23,17 @@ use web_sys::HtmlCanvasElement; #[cfg(target_arch = "wasm32")] use winit::platform::web::WindowBuilderExtWebSys; -pub fn main() { +pub fn main() -> Result<(), Box> { #[cfg(target_arch = "wasm32")] let canvas_element = { - console_log::init_with_level(log::Level::Debug) - .expect("could not initialize logger"); + console_log::init_with_level(log::Level::Debug)?; + std::panic::set_hook(Box::new(console_error_panic_hook::hook)); web_sys::window() .and_then(|win| win.document()) .and_then(|doc| doc.get_element_by_id("iced_canvas")) - .and_then(|element| element.dyn_into::().ok()) - .expect("Canvas with id `iced_canvas` is missing") + .and_then(|element| element.dyn_into::().ok())? }; #[cfg(not(target_arch = "wasm32"))] env_logger::init(); @@ -45,11 +44,10 @@ pub fn main() { #[cfg(target_arch = "wasm32")] let window = winit::window::WindowBuilder::new() .with_canvas(Some(canvas_element)) - .build(&event_loop) - .expect("Failed to build winit window"); + .build(&event_loop)?; #[cfg(not(target_arch = "wasm32"))] - let window = winit::window::Window::new(&event_loop).unwrap(); + let window = winit::window::Window::new(&event_loop)?; let physical_size = window.inner_size(); let mut viewport = Viewport::with_physical_size( @@ -61,7 +59,6 @@ pub fn main() { let mut clipboard = Clipboard::connect(&window); // Initialize wgpu - #[cfg(target_arch = "wasm32")] let default_backend = wgpu::Backends::GL; #[cfg(not(target_arch = "wasm32"))] @@ -70,8 +67,12 @@ pub fn main() { let backend = wgpu::util::backend_bits_from_env().unwrap_or(default_backend); - let instance = wgpu::Instance::new(backend); - let surface = unsafe { instance.create_surface(&window) }; + let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { + backends: backend, + ..Default::default() + }); + + let surface = unsafe { instance.create_surface(&window) }?; let (format, (device, queue)) = futures::executor::block_on(async { let adapter = wgpu::util::initialize_adapter_from_env_or_default( @@ -93,9 +94,15 @@ pub fn main() { ( surface - .get_supported_formats(&adapter) - .first() + .get_capabilities(&adapter) + .formats + .iter() + .filter(|format| format.describe().srgb) .copied() + .next() + .or_else(|| { + surface.get_capabilities(&adapter).formats.first().copied() + }) .expect("Get preferred format"), adapter .request_device( @@ -120,6 +127,7 @@ pub fn main() { height: physical_size.height, present_mode: wgpu::PresentMode::AutoVsync, alpha_mode: wgpu::CompositeAlphaMode::Auto, + view_formats: vec![], }, ); @@ -214,7 +222,8 @@ pub fn main() { width: size.width, height: size.height, present_mode: wgpu::PresentMode::AutoVsync, - alpha_mode: wgpu::CompositeAlphaMode::Auto + alpha_mode: wgpu::CompositeAlphaMode::Auto, + view_formats: vec![] }, ); diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index f1e22cf682..4dcd07f771 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -28,8 +28,8 @@ spirv = ["wgpu/spirv"] webgl = ["wgpu/webgl"] [dependencies] -wgpu = "0.14" -wgpu_glyph = "0.18" +wgpu = "0.15" +wgpu_glyph = "0.19" glyph_brush = "0.7" raw-window-handle = "0.5" log = "0.4" diff --git a/wgpu/src/image/atlas.rs b/wgpu/src/image/atlas.rs index eafe2f9656..82504147e5 100644 --- a/wgpu/src/image/atlas.rs +++ b/wgpu/src/image/atlas.rs @@ -39,6 +39,7 @@ impl Atlas { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, + view_formats: &[], usage: wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::TEXTURE_BINDING, @@ -247,6 +248,7 @@ impl Atlas { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, + view_formats: &[], usage: wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::TEXTURE_BINDING, diff --git a/wgpu/src/triangle/msaa.rs b/wgpu/src/triangle/msaa.rs index e76f7d5eaa..d24f8e1abb 100644 --- a/wgpu/src/triangle/msaa.rs +++ b/wgpu/src/triangle/msaa.rs @@ -222,6 +222,7 @@ impl Targets { sample_count, dimension: wgpu::TextureDimension::D2, format, + view_formats: &[], usage: wgpu::TextureUsages::RENDER_ATTACHMENT, }); @@ -232,6 +233,7 @@ impl Targets { sample_count: 1, dimension: wgpu::TextureDimension::D2, format, + view_formats: &[], usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING, }); diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index 6d0c36f6d3..d66aca71f5 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -31,7 +31,10 @@ impl Compositor { settings: Settings, compatible_window: Option<&W>, ) -> Option { - let instance = wgpu::Instance::new(settings.internal_backend); + let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { + backends: settings.internal_backend, + ..Default::default() + }); log::info!("{:#?}", settings); @@ -46,7 +49,7 @@ impl Compositor { #[allow(unsafe_code)] let compatible_surface = compatible_window - .map(|window| unsafe { instance.create_surface(window) }); + .and_then(|window| unsafe { instance.create_surface(window).ok() }); let adapter = instance .request_adapter(&wgpu::RequestAdapterOptions { @@ -63,7 +66,18 @@ impl Compositor { log::info!("Selected: {:#?}", adapter.get_info()); let format = compatible_surface.as_ref().and_then(|surface| { - surface.get_supported_formats(&adapter).first().copied() + surface + .get_capabilities(&adapter) + .formats + .iter() + .filter(|format| format.describe().srgb) + .copied() + .next() + .or_else(|| { + log::warn!("No sRGB format found!"); + + surface.get_capabilities(&adapter).formats.first().copied() + }) })?; log::info!("Selected format: {:?}", format); @@ -144,7 +158,9 @@ impl iced_graphics::window::Compositor for Compositor { ) -> wgpu::Surface { #[allow(unsafe_code)] unsafe { - self.instance.create_surface(window) + self.instance + .create_surface(window) + .expect("Create surface") } } @@ -163,6 +179,7 @@ impl iced_graphics::window::Compositor for Compositor { width, height, alpha_mode: wgpu::CompositeAlphaMode::Auto, + view_formats: vec![], }, ); } From b677345ac1b1d087bc7f331c9c8c5be06933ba6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 13 Apr 2023 05:42:56 +0200 Subject: [PATCH 2/4] Get surface capabilities only once in `iced_wgpu` --- examples/integration_wgpu/src/main.rs | 9 ++++----- wgpu/src/window/compositor.rs | 7 ++++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs index 6e86833227..8e0056f3b3 100644 --- a/examples/integration_wgpu/src/main.rs +++ b/examples/integration_wgpu/src/main.rs @@ -92,17 +92,16 @@ pub fn main() -> Result<(), Box> { #[cfg(not(target_arch = "wasm32"))] let needed_limits = wgpu::Limits::default(); + let capabilities = surface.get_capabilities(&adapter); + ( - surface - .get_capabilities(&adapter) + capabilities .formats .iter() .filter(|format| format.describe().srgb) .copied() .next() - .or_else(|| { - surface.get_capabilities(&adapter).formats.first().copied() - }) + .or_else(|| capabilities.formats.first().copied()) .expect("Get preferred format"), adapter .request_device( diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index d66aca71f5..d4a5947187 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -66,8 +66,9 @@ impl Compositor { log::info!("Selected: {:#?}", adapter.get_info()); let format = compatible_surface.as_ref().and_then(|surface| { - surface - .get_capabilities(&adapter) + let capabilities = surface.get_capabilities(&adapter); + + capabilities .formats .iter() .filter(|format| format.describe().srgb) @@ -76,7 +77,7 @@ impl Compositor { .or_else(|| { log::warn!("No sRGB format found!"); - surface.get_capabilities(&adapter).formats.first().copied() + capabilities.formats.first().copied() }) })?; From 9410fb98275fb51f67c55b676d8b37a5197222b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 13 Apr 2023 05:46:18 +0200 Subject: [PATCH 3/4] Update `env_logger` in `integration_wgpu` example --- examples/integration_wgpu/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/integration_wgpu/Cargo.toml b/examples/integration_wgpu/Cargo.toml index eaa1df7e17..c0e4fd810c 100644 --- a/examples/integration_wgpu/Cargo.toml +++ b/examples/integration_wgpu/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] iced_winit = { path = "../../winit" } iced_wgpu = { path = "../../wgpu", features = ["webgl"] } -env_logger = "0.8" +env_logger = "0.10" [target.'cfg(target_arch = "wasm32")'.dependencies] console_error_panic_hook = "0.1.7" From db4b899fd215f0607474006a9aef0361e74d481f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 13 Apr 2023 06:03:44 +0200 Subject: [PATCH 4/4] Fix Wasm target for `integration_wgpu` --- examples/integration_wgpu/src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs index 8e0056f3b3..3ac458b3d2 100644 --- a/examples/integration_wgpu/src/main.rs +++ b/examples/integration_wgpu/src/main.rs @@ -33,7 +33,8 @@ pub fn main() -> Result<(), Box> { web_sys::window() .and_then(|win| win.document()) .and_then(|doc| doc.get_element_by_id("iced_canvas")) - .and_then(|element| element.dyn_into::().ok())? + .and_then(|element| element.dyn_into::().ok()) + .expect("Canvas with id `iced_canvas` is missing") }; #[cfg(not(target_arch = "wasm32"))] env_logger::init();