Skip to content

Commit

Permalink
Update to wgpu 0.15 (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab authored Jan 31, 2023
1 parent 872fc5c commit f84e244
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 19 deletions.
15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<!-- [![Crates.io](https://img.shields.io/crates/v/vello.svg)](https://crates.io/crates/vello) -->
<!-- [![Docs](https://docs.rs/vello/badge.svg)](https://docs.rs/vello) -->
<!-- [![Build status](https://github.com/linebender/vello/workflows/CI/badge.svg)](https://github.com/linebender/vello/actions) -->
Expand Down
2 changes: 1 addition & 1 deletion examples/usvg_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion examples/with_bevy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "../../" }
9 changes: 7 additions & 2 deletions examples/with_bevy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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()))
}
}

Expand Down Expand Up @@ -124,6 +128,7 @@ fn setup(
usage: TextureUsages::TEXTURE_BINDING
| TextureUsages::COPY_DST
| TextureUsages::STORAGE_BINDING,
view_formats: &[],
},
..default()
};
Expand Down
2 changes: 1 addition & 1 deletion examples/with_winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 6 additions & 2 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/shaders/preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ pub fn preprocess(input: &str, defines: &HashSet<String>, 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 {
Expand Down
8 changes: 6 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ pub struct DeviceHandle {

impl RenderContext {
pub fn new() -> Result<Self> {
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(),
Expand All @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit f84e244

Please sign in to comment.