From 8a35c51289ef2a4d7a186fca88ad35871d07b0a7 Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Sun, 23 Apr 2023 11:56:57 -0700 Subject: [PATCH 01/13] Roll wgpu to 0.16 --- Cargo.toml | 2 +- src/engine.rs | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3b56fbb..63b835b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,7 @@ vello_encoding = { path = "crates/encoding" } bytemuck = { version = "1.12.1", features = ["derive"] } fello = { git = "https://github.com/dfrg/fount", rev = "58a284eaae67512fb61cf76177c5d33238d79cb1" } peniko = { git = "https://github.com/linebender/peniko", rev = "cafdac9a211a0fb2fec5656bd663d1ac770bcc81" } -wgpu = "0.15" +wgpu = "0.16" # Used for examples clap = "4.1.0" diff --git a/src/engine.rs b/src/engine.rs index 28772cf..cd1404e 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -311,8 +311,8 @@ impl Engine { bytes, wgpu::ImageDataLayout { offset: 0, - bytes_per_row: NonZeroU32::new( - image_proxy.width * format.describe().block_size as u32, + bytes_per_row: Some( + image_proxy.width * format.block_size(None).unwrap(), ), rows_per_image: None, }, @@ -338,9 +338,7 @@ impl Engine { &data[..], wgpu::ImageDataLayout { offset: 0, - bytes_per_row: NonZeroU32::new( - *width * format.describe().block_size as u32, - ), + bytes_per_row: Some(*width * format.block_size(None).unwrap()), rows_per_image: None, }, wgpu::Extent3d { From 5543ad01febdccaa6513a3a27a4ed752e596fe02 Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Sun, 23 Apr 2023 11:57:38 -0700 Subject: [PATCH 02/13] [examples] Use instant crate's time::Instant crates.io/crates/instant provides a std::time::Instant implementation that works on both WASM and non-wasm builds. --- examples/scenes/Cargo.toml | 1 + examples/scenes/src/svg.rs | 2 +- examples/with_winit/Cargo.toml | 1 + examples/with_winit/src/lib.rs | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/scenes/Cargo.toml b/examples/scenes/Cargo.toml index 7037d28..7d2551f 100644 --- a/examples/scenes/Cargo.toml +++ b/examples/scenes/Cargo.toml @@ -16,6 +16,7 @@ vello_svg = { path = "../../integrations/vello_svg" } anyhow = { workspace = true } clap = { workspace = true, features = ["derive"] } image = "0.24.5" +instant = "0.1.12" # Used for the `download` command byte-unit = "4.0" diff --git a/examples/scenes/src/svg.rs b/examples/scenes/src/svg.rs index 2fbbac6..708be50 100644 --- a/examples/scenes/src/svg.rs +++ b/examples/scenes/src/svg.rs @@ -1,10 +1,10 @@ use std::{ fs::read_dir, path::{Path, PathBuf}, - time::Instant, }; use anyhow::{Ok, Result}; +use instant::Instant; use vello::{kurbo::Vec2, SceneBuilder, SceneFragment}; use vello_svg::usvg; diff --git a/examples/with_winit/Cargo.toml b/examples/with_winit/Cargo.toml index f5f3843..446422e 100644 --- a/examples/with_winit/Cargo.toml +++ b/examples/with_winit/Cargo.toml @@ -24,6 +24,7 @@ vello = { path = "../../", features = ["buffer_labels"] } scenes = { path = "../scenes" } anyhow = { workspace = true } clap = { workspace = true, features = ["derive"] } +instant = "0.1.12" pollster = { workspace = true } wgpu = { workspace = true } diff --git a/examples/with_winit/src/lib.rs b/examples/with_winit/src/lib.rs index 2536e4c..dc46b54 100644 --- a/examples/with_winit/src/lib.rs +++ b/examples/with_winit/src/lib.rs @@ -14,8 +14,8 @@ // // Also licensed under MIT license, at your choice. +use instant::Instant; use std::collections::HashSet; -use std::time::Instant; use anyhow::Result; use clap::{CommandFactory, Parser}; From 4642fa024f8ce1e53afc227beb75eef9de3ab946 Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Sun, 23 Apr 2023 12:00:42 -0700 Subject: [PATCH 03/13] [with_winit] Set the canvas size to thw winit Window's inner size This prevents the scaling caused by the hardcoded canvas dimensions on high dpi platforms. --- examples/with_winit/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/with_winit/src/lib.rs b/examples/with_winit/src/lib.rs index dc46b54..e08add2 100644 --- a/examples/with_winit/src/lib.rs +++ b/examples/with_winit/src/lib.rs @@ -483,8 +483,9 @@ pub fn main() -> Result<()> { let window = create_window(&event_loop); // On wasm, append the canvas to the document body let canvas = window.canvas(); - canvas.set_width(1044); - canvas.set_height(800); + let size = window.inner_size(); + canvas.set_width(size.width); + canvas.set_height(size.height); web_sys::window() .and_then(|win| win.document()) .and_then(|doc| doc.body()) From bb117da3520b25ee70b989007d2083ecbc1e9538 Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Sun, 23 Apr 2023 16:00:01 -0700 Subject: [PATCH 04/13] Enable wasm-bindgen feature of instant crate --- Cargo.toml | 1 + examples/scenes/Cargo.toml | 2 +- examples/with_winit/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 63b835b..b51b0cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,4 +60,5 @@ wgpu = "0.16" # Used for examples clap = "4.1.0" anyhow = "1.0" +instant = { version = "0.1.12", features = [ "wasm-bindgen" ] } pollster = "0.3.0" diff --git a/examples/scenes/Cargo.toml b/examples/scenes/Cargo.toml index 7d2551f..c68ffa3 100644 --- a/examples/scenes/Cargo.toml +++ b/examples/scenes/Cargo.toml @@ -16,7 +16,7 @@ vello_svg = { path = "../../integrations/vello_svg" } anyhow = { workspace = true } clap = { workspace = true, features = ["derive"] } image = "0.24.5" -instant = "0.1.12" +instant = { workspace = true } # Used for the `download` command byte-unit = "4.0" diff --git a/examples/with_winit/Cargo.toml b/examples/with_winit/Cargo.toml index 446422e..3303388 100644 --- a/examples/with_winit/Cargo.toml +++ b/examples/with_winit/Cargo.toml @@ -24,7 +24,7 @@ vello = { path = "../../", features = ["buffer_labels"] } scenes = { path = "../scenes" } anyhow = { workspace = true } clap = { workspace = true, features = ["derive"] } -instant = "0.1.12" +instant = { workspace = true } pollster = { workspace = true } wgpu = { workspace = true } From 84915dc28904d0532bf54abb24e00a37dfefa864 Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Sun, 23 Apr 2023 16:00:53 -0700 Subject: [PATCH 05/13] Use expect instead of unwrap on image format block size --- src/engine.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index cd1404e..85a5208 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -17,7 +17,7 @@ use std::{ borrow::Cow, collections::{hash_map::Entry, HashMap, HashSet}, - num::{NonZeroU32, NonZeroU64}, + num::NonZeroU64, sync::atomic::{AtomicU64, Ordering}, }; @@ -277,6 +277,9 @@ impl Engine { } Command::UploadImage(image_proxy, bytes) => { let format = image_proxy.format.to_wgpu(); + let block_size = format + .block_size(None) + .expect("ImageFormat must have a valid block size"); let texture = device.create_texture(&wgpu::TextureDescriptor { label: None, size: wgpu::Extent3d { @@ -311,9 +314,7 @@ impl Engine { bytes, wgpu::ImageDataLayout { offset: 0, - bytes_per_row: Some( - image_proxy.width * format.block_size(None).unwrap(), - ), + bytes_per_row: Some(image_proxy.width * block_size), rows_per_image: None, }, wgpu::Extent3d { @@ -328,6 +329,9 @@ impl Engine { Command::WriteImage(proxy, [x, y, width, height], data) => { if let Ok((texture, _)) = self.bind_map.get_or_create_image(*proxy, device) { let format = proxy.format.to_wgpu(); + let block_size = format + .block_size(None) + .expect("ImageFormat must have a valid block size"); queue.write_texture( wgpu::ImageCopyTexture { texture, @@ -338,7 +342,7 @@ impl Engine { &data[..], wgpu::ImageDataLayout { offset: 0, - bytes_per_row: Some(*width * format.block_size(None).unwrap()), + bytes_per_row: Some(*width * block_size), rows_per_image: None, }, wgpu::Extent3d { From 7526d1ca26a6d72dab400ba827918662428dcdb8 Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Sun, 23 Apr 2023 16:02:15 -0700 Subject: [PATCH 06/13] Update run_wasm instructions --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8b0f680..bcab485 100644 --- a/README.md +++ b/README.md @@ -86,10 +86,10 @@ Until browser support becomes widespread, it will probably be necessary to use d The following command builds and runs a web version of the [winit demo](#winit). This uses [`cargo-run-wasm`](https://github.com/rukai/cargo-run-wasm) to build the example for web, and host a local server for it -Other examples use the `-p` shorthand, but `cargo-run-wasm` requires the full `--package` to be specified +Other examples use the `-p` shorthand, but `cargo-run-wasm` requires the full `--package` and binary name to be specified ```shell -cargo run_wasm --package with_winit +cargo run_wasm --package with_winit --bin with_winit_bin ``` > **Warning** From bc903d1c3b78d41732ecf9037a1cd90e6826dd07 Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Sun, 23 Apr 2023 16:05:08 -0700 Subject: [PATCH 07/13] Add check for division-by-zero in path_coarse_full The potential division by zero in this line led to visible visual artifacts when running against WebGPU in Chrome. --- shader/path_coarse_full.wgsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shader/path_coarse_full.wgsl b/shader/path_coarse_full.wgsl index ef1bed5..58a4364 100644 --- a/shader/path_coarse_full.wgsl +++ b/shader/path_coarse_full.wgsl @@ -60,7 +60,7 @@ fn estimate_subdiv(p0: vec2, p1: vec2, p2: vec2, sqrt_tol: f32) - let d12 = p2 - p1; let dd = d01 - d12; let cross = (p2.x - p0.x) * dd.y - (p2.y - p0.y) * dd.x; - let cross_inv = 1.0 / cross; + let cross_inv = select(1.0 / cross, 1.0e9, abs(cross) < 1.0e-9); let x0 = dot(d01, dd) * cross_inv; let x2 = dot(d12, dd) * cross_inv; let scale = abs(cross / (length(dd) * (x2 - x0))); From 51f00fbd1f62e992080c1d796b6eaae76d66ced8 Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Mon, 24 Apr 2023 10:41:25 -0700 Subject: [PATCH 08/13] Fix the headless example for wgpu 0.16 --- examples/headless/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/headless/src/main.rs b/examples/headless/src/main.rs index 93e3234..0fa9c7e 100644 --- a/examples/headless/src/main.rs +++ b/examples/headless/src/main.rs @@ -1,6 +1,5 @@ use std::{ fs::File, - num::NonZeroU32, path::{Path, PathBuf}, }; @@ -189,7 +188,7 @@ async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> { buffer: &buffer, layout: wgpu::ImageDataLayout { offset: 0, - bytes_per_row: NonZeroU32::new(padded_byte_width), + bytes_per_row: Some(padded_byte_width), rows_per_image: None, }, }, From 1529945a5a6f1335d6ac41f5cf69362e512f1600 Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Wed, 5 Apr 2023 14:40:51 +0100 Subject: [PATCH 09/13] Update cargo-run-wasm --- README.md | 6 +++--- examples/run_wasm/Cargo.toml | 3 +-- examples/run_wasm/src/main.rs | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bcab485..6524e00 100644 --- a/README.md +++ b/README.md @@ -86,10 +86,10 @@ Until browser support becomes widespread, it will probably be necessary to use d The following command builds and runs a web version of the [winit demo](#winit). This uses [`cargo-run-wasm`](https://github.com/rukai/cargo-run-wasm) to build the example for web, and host a local server for it -Other examples use the `-p` shorthand, but `cargo-run-wasm` requires the full `--package` and binary name to be specified - ```shell -cargo run_wasm --package with_winit --bin with_winit_bin +# Make sure the Rust toolchain supports the wasm32 target +rustup target add wasm32-unknown-unknown +cargo run_wasm -p with_winit ``` > **Warning** diff --git a/examples/run_wasm/Cargo.toml b/examples/run_wasm/Cargo.toml index 91801ad..de51958 100644 --- a/examples/run_wasm/Cargo.toml +++ b/examples/run_wasm/Cargo.toml @@ -10,5 +10,4 @@ repository.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -# We use cargo-run-wasm main because of our workspace layout -cargo-run-wasm = { git = "https://github.com/rukai/cargo-run-wasm", rev = "d14f73de77eaae44714b4817d660026a31f5f5a9" } +cargo-run-wasm = "0.3.2" diff --git a/examples/run_wasm/src/main.rs b/examples/run_wasm/src/main.rs index 9666918..84868c6 100644 --- a/examples/run_wasm/src/main.rs +++ b/examples/run_wasm/src/main.rs @@ -6,7 +6,7 @@ /// ``` /// Generally: /// ``` -/// cargo run_wasm --package with_winit +/// cargo run_wasm -p with_winit /// ``` fn main() { From d3c54ed12d11521559ac9a781ae40e8f925a52e9 Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Mon, 24 Apr 2023 15:49:49 -0700 Subject: [PATCH 10/13] Include `--bin with_winit_bin` in run_wasm instructions --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6524e00..dceac80 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,9 @@ This uses [`cargo-run-wasm`](https://github.com/rukai/cargo-run-wasm) to build t ```shell # Make sure the Rust toolchain supports the wasm32 target rustup target add wasm32-unknown-unknown -cargo run_wasm -p with_winit + +# The binary name must also be explicitly provided as it differs from the package name +cargo run_wasm -p with_winit --bin with_winit_bin ``` > **Warning** From b442ba550bdd04591220b4f8b4c9729ff74a6b70 Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Mon, 24 Apr 2023 15:56:38 -0700 Subject: [PATCH 11/13] Update wgpu version badge in README --- Cargo.toml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b51b0cc..f0b6e13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,7 @@ vello_encoding = { path = "crates/encoding" } bytemuck = { version = "1.12.1", features = ["derive"] } fello = { git = "https://github.com/dfrg/fount", rev = "58a284eaae67512fb61cf76177c5d33238d79cb1" } peniko = { git = "https://github.com/linebender/peniko", rev = "cafdac9a211a0fb2fec5656bd663d1ac770bcc81" } -wgpu = "0.16" +wgpu = "0.16" # NOTE: Make sure to keep this in sync with the version badge in README.md # Used for examples clap = "4.1.0" diff --git a/README.md b/README.md index dceac80..661184d 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.15-orange.svg)](https://crates.io/crates/wgpu) +[![wgpu version](https://img.shields.io/badge/wgpu-v0.16-orange.svg)](https://crates.io/crates/wgpu) From b0cc221d7a88c7a475e90076a42999748ccbcf1c Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Mon, 24 Apr 2023 15:57:12 -0700 Subject: [PATCH 12/13] Add warning to README about the Bevy example's compilation status --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 661184d..d4b4d9a 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,9 @@ cargo run -p with_winit -- download ### Bevy +> **Warning** +> This example currently does not compile. We expect to resolve this as soon as Bevy updates to wgpu 0.16 + The [Bevy] example ([examples/with_bevy](examples/with_bevy)) demonstrates using Vello within a [Bevy] application. This currently draws to a [`wgpu`] `Texture` using `vello`, then uses that texture as the faces of a cube. From c9d7a15fadd7fff065f0b52175d7fd4ddeffb427 Mon Sep 17 00:00:00 2001 From: Arman Uguray Date: Tue, 25 Apr 2023 00:37:06 -0700 Subject: [PATCH 13/13] Put the Warning label in its own line Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d4b4d9a..909f1f8 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ cargo run -p with_winit -- download ### Bevy -> **Warning** +> **Warning** > This example currently does not compile. We expect to resolve this as soon as Bevy updates to wgpu 0.16 The [Bevy] example ([examples/with_bevy](examples/with_bevy)) demonstrates using Vello within a [Bevy] application.