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

Fix WASM build #312

Merged
merged 13 commits into from
Apr 25, 2023
Merged
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions examples/scenes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to instant's documentation, one of the stdweb or wasm-bindgen features need to be updated.

I still don't have a working browser with WebGPU, so maybe this works? Perhaps instant's docs need updating

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I went ahead and enabled wasm-bindgen though AFAICT all the animated scenes still worked without it.


# Used for the `download` command
byte-unit = "4.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/scenes/src/svg.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
1 change: 1 addition & 0 deletions examples/with_winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
7 changes: 4 additions & 3 deletions examples/with_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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())
Expand Down
8 changes: 3 additions & 5 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
image_proxy.width * format.block_size(None).unwrap(),
image_proxy.width * format.block_size(None).expect("All supported ImageFormats have a valid block size"),

or words to that effect

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

),
rows_per_image: None,
},
Expand All @@ -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 {
Expand Down