From f84e244fd78234117a28978059d59ec8588730c7 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Tue, 31 Jan 2023 16:07:03 +0000 Subject: [PATCH] Update to wgpu 0.15 (#263) --- Cargo.toml | 15 +++++++++------ README.md | 2 +- examples/usvg_viewer/Cargo.toml | 2 +- examples/with_bevy/Cargo.toml | 2 +- examples/with_bevy/src/main.rs | 9 +++++++-- examples/with_winit/Cargo.toml | 2 +- src/engine.rs | 8 ++++++-- src/lib.rs | 1 + src/shaders/preprocess.rs | 6 +++--- src/util.rs | 8 ++++++-- 10 files changed, 36 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b8ba15b..0529880 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,16 +1,19 @@ [workspace] resolver = "2" -members = ["examples/with_winit", "examples/with_bevy", "examples/run_wasm", "examples/usvg_viewer"] +members = [ + "examples/with_winit", + "examples/with_bevy", + "examples/run_wasm", + "examples/usvg_viewer", +] [workspace.package] edition = "2021" version = "0.1.0" -[patch.crates-io] -# Required for metal support to work on wgpu -# TODO: remove when wgpu is upgraded to 0.15 -naga = { git = "https://github.com/gfx-rs/naga", rev = "ddcd5d3121150b2b1beee6e54e9125ff31aaa9a2" } +[workspace.dependencies] +wgpu = "0.15" [package] name = "vello" @@ -19,7 +22,7 @@ license = "MIT/Apache-2.0" edition = "2021" [dependencies] -wgpu = "0.14" +wgpu = { workspace = true } raw-window-handle = "0.5" futures-intrusive = "0.5.0" parking_lot = "0.12" diff --git a/README.md b/README.md index ed9f658..26de51c 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Xi Zulip](https://img.shields.io/badge/Xi%20Zulip-%23gpu-blue?logo=Zulip)](https://xi.zulipchat.com/#narrow/stream/197075-gpu) [![dependency status](https://deps.rs/repo/github/linebender/vello/status.svg)](https://deps.rs/repo/github/linebender/vello) [![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)](#license) -[![wgpu version](https://img.shields.io/badge/wgpu-v0.14-orange.svg)](https://crates.io/crates/wgpu) +[![wgpu version](https://img.shields.io/badge/wgpu-v0.15-orange.svg)](https://crates.io/crates/wgpu) diff --git a/examples/usvg_viewer/Cargo.toml b/examples/usvg_viewer/Cargo.toml index 768857c..a5cd575 100644 --- a/examples/usvg_viewer/Cargo.toml +++ b/examples/usvg_viewer/Cargo.toml @@ -18,5 +18,5 @@ sha2 = "0.10" ureq = "2.6" usvg = "0.28" vello = { path = "../../" } -wgpu = "0.14" +wgpu = { workspace = true } winit = "0.27.5" diff --git a/examples/with_bevy/Cargo.toml b/examples/with_bevy/Cargo.toml index 9c5600a..8b95069 100644 --- a/examples/with_bevy/Cargo.toml +++ b/examples/with_bevy/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy = "0.9" +bevy = { git = "https://github.com/bevyengine/bevy", rev = "5d514fb24f2459700f68d8e57d4791bdf5b1b595" } vello = { path = "../../" } diff --git a/examples/with_bevy/src/main.rs b/examples/with_bevy/src/main.rs index 540bbe5..0f2c3a4 100644 --- a/examples/with_bevy/src/main.rs +++ b/examples/with_bevy/src/main.rs @@ -91,12 +91,16 @@ impl ExtractComponent for VelloScene { type Filter = (); - fn extract_component((fragment, target): bevy::ecs::query::QueryItem<'_, Self::Query>) -> Self { + type Out = Self; + + fn extract_component( + (fragment, target): bevy::ecs::query::QueryItem<'_, Self::Query>, + ) -> Option { let mut scene = Scene::default(); let mut builder = SceneBuilder::for_scene(&mut scene); builder.append(&fragment.0, None); builder.finish(); - Self(scene, target.0.clone()) + Some(Self(scene, target.0.clone())) } } @@ -124,6 +128,7 @@ fn setup( usage: TextureUsages::TEXTURE_BINDING | TextureUsages::COPY_DST | TextureUsages::STORAGE_BINDING, + view_formats: &[], }, ..default() }; diff --git a/examples/with_winit/Cargo.toml b/examples/with_winit/Cargo.toml index e807914..a8930be 100644 --- a/examples/with_winit/Cargo.toml +++ b/examples/with_winit/Cargo.toml @@ -8,7 +8,7 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -wgpu = "0.14" +wgpu = { workspace = true } vello = { path = "../../", features = ["buffer_labels"] } winit = "0.27.5" pollster = "0.2.5" diff --git a/src/engine.rs b/src/engine.rs index d3f152e..9250265 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -280,6 +280,7 @@ impl Engine { contents: bytes, usage: wgpu::BufferUsages::COPY_SRC, }); + let format = image_proxy.format.to_wgpu(); let texture = device.create_texture(&wgpu::TextureDescriptor { label: None, size: wgpu::Extent3d { @@ -291,7 +292,8 @@ impl Engine { sample_count: 1, dimension: wgpu::TextureDimension::D2, usage: TextureUsages::TEXTURE_BINDING | TextureUsages::COPY_DST, - format: image_proxy.format.to_wgpu(), + format, + view_formats: &[], }); let texture_view = texture.create_view(&wgpu::TextureViewDescriptor { label: None, @@ -632,6 +634,7 @@ impl BindMap { continue; } if let Entry::Vacant(v) = self.image_map.entry(proxy.id) { + let format = proxy.format.to_wgpu(); let texture = device.create_texture(&wgpu::TextureDescriptor { label: None, size: wgpu::Extent3d { @@ -643,7 +646,8 @@ impl BindMap { sample_count: 1, dimension: wgpu::TextureDimension::D2, usage: TextureUsages::TEXTURE_BINDING | TextureUsages::COPY_DST, - format: proxy.format.to_wgpu(), + format, + view_formats: &[], }); let texture_view = texture.create_view(&wgpu::TextureViewDescriptor { label: None, diff --git a/src/lib.rs b/src/lib.rs index 7217311..30f3bc8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -286,6 +286,7 @@ impl TargetTexture { dimension: wgpu::TextureDimension::D2, usage: wgpu::TextureUsages::STORAGE_BINDING | wgpu::TextureUsages::TEXTURE_BINDING, format: wgpu::TextureFormat::Rgba8Unorm, + view_formats: &[], }); let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); Self { diff --git a/src/shaders/preprocess.rs b/src/shaders/preprocess.rs index 2981622..bb9ed68 100644 --- a/src/shaders/preprocess.rs +++ b/src/shaders/preprocess.rs @@ -139,10 +139,10 @@ pub fn preprocess(input: &str, defines: &HashSet, imports: &HashMap<&str } } if stack.iter().all(|item| item.active) { - // Naga does not yet recognize `const` but web does not allow global `let`. We + // wgsl-analyzer does not yet recognize `const` but naga does not allow global `let`. We // use `let` in our canonical sources to satisfy wgsl-analyzer but replace with - // `const` when targeting web. - if cfg!(target_arch = "wasm32") && line.starts_with("let ") { + // `const` when using + if line.starts_with("let ") { output.push_str("const"); output.push_str(&line[3..]); } else { diff --git a/src/util.rs b/src/util.rs index a75f804..4d5b09c 100644 --- a/src/util.rs +++ b/src/util.rs @@ -39,7 +39,10 @@ pub struct DeviceHandle { impl RenderContext { pub fn new() -> Result { - let instance = Instance::new(wgpu::Backends::PRIMARY); + let instance = Instance::new(wgpu::InstanceDescriptor { + backends: wgpu::Backends::PRIMARY, + dx12_shader_compiler: wgpu::Dx12Compiler::Fxc, + }); Ok(Self { instance, devices: Vec::new(), @@ -51,7 +54,7 @@ impl RenderContext { where W: HasRawWindowHandle + HasRawDisplayHandle, { - let surface = unsafe { self.instance.create_surface(window) }; + let surface = unsafe { self.instance.create_surface(window) }.unwrap(); let format = wgpu::TextureFormat::Bgra8Unorm; let config = wgpu::SurfaceConfiguration { usage: wgpu::TextureUsages::RENDER_ATTACHMENT, @@ -60,6 +63,7 @@ impl RenderContext { height, present_mode: wgpu::PresentMode::Fifo, alpha_mode: wgpu::CompositeAlphaMode::Auto, + view_formats: vec![], }; let dev_id = self.device(Some(&surface)).await.unwrap(); surface.configure(&self.devices[dev_id].device, &config);