mirror of
https://github.com/italicsjenga/vello.git
synced 2025-01-07 19:31:31 +11:00
Some WASM changes - including a run_wasm alias (#251)
This commit is contained in:
parent
f84e244fd7
commit
9721d4a6ac
5
.cargo/config.toml
Normal file
5
.cargo/config.toml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
[alias]
|
||||||
|
run_wasm = "run --release --package run_wasm --"
|
||||||
|
# Other crates use the alias run-wasm, even though crate names should use `_`s not `-`s
|
||||||
|
# Allow this to be used
|
||||||
|
run-wasm = "run_wasm"
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
||||||
target/
|
/target
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
|
|
@ -51,13 +51,16 @@ cargo run -p with_bevy
|
||||||
Because Vello relies heavily on compute shaders, we rely on the emerging WebGPU standard to run on the web.
|
Because Vello relies heavily on compute shaders, we rely on the emerging WebGPU standard to run on the web.
|
||||||
Until browser support becomes widespread, it will probably be necessary to use development browser versions (e.g. Chrome Canary) and explicitly enable WebGPU.
|
Until browser support becomes widespread, it will probably be necessary to use development browser versions (e.g. Chrome Canary) and explicitly enable WebGPU.
|
||||||
|
|
||||||
The following command builds and runs a web version of the [winit demo](#winit).
|
Note: Other examples use the `-p` shorthand, but `cargo-run-wasm` requires the full `--package` to be specified
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
cargo run --release -p run-wasm -- --package with_winit
|
cargo run_wasm --package with_winit
|
||||||
```
|
```
|
||||||
|
|
||||||
Additionally, the web is not currently a primary target, so other issues are likely to arise.
|
The web is not currently a primary target for vello, and WebGPU implementations are incomplete, so you might run into issues running this example.
|
||||||
|
|
||||||
## Community
|
## Community
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "run-wasm"
|
name = "run_wasm"
|
||||||
version.workspace = true
|
version.workspace = true
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
publish = false
|
publish = false
|
||||||
|
@ -7,4 +7,5 @@ publish = false
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cargo-run-wasm = "0.2.0"
|
# We use cargo-run-wasm main because of our workspace layout
|
||||||
|
cargo-run-wasm = { git = "https://github.com/rukai/cargo-run-wasm", rev = "d14f73de77eaae44714b4817d660026a31f5f5a9" }
|
||||||
|
|
|
@ -1,3 +1,21 @@
|
||||||
|
/// Use [cargo-run-wasm](https://github.com/rukai/cargo-run-wasm) to build an example for web
|
||||||
|
///
|
||||||
|
/// Usage:
|
||||||
|
/// ```
|
||||||
|
/// cargo run_wasm --package [example_name]
|
||||||
|
/// ```
|
||||||
|
/// Generally:
|
||||||
|
/// ```
|
||||||
|
/// cargo run_wasm --package with_winit
|
||||||
|
/// ```
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
// HACK: We rely heavily on compute shaders; which means we need WebGPU to be supported
|
||||||
|
// However, that requires unstable APIs to be enabled, which are not exposed through a feature
|
||||||
|
let current_value = std::env::var("RUSTFLAGS").unwrap_or("".to_owned());
|
||||||
|
std::env::set_var(
|
||||||
|
"RUSTFLAGS",
|
||||||
|
format!("{current_value} --cfg=web_sys_unstable_apis",),
|
||||||
|
);
|
||||||
cargo_run_wasm::run_wasm_with_css("body { margin: 0px; }");
|
cargo_run_wasm::run_wasm_with_css("body { margin: 0px; }");
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ mod pico_svg;
|
||||||
mod simple_text;
|
mod simple_text;
|
||||||
mod test_scene;
|
mod test_scene;
|
||||||
|
|
||||||
use std::{borrow::Cow, path::PathBuf, time::Instant};
|
use std::{borrow::Cow, time::Instant};
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use vello::{
|
use vello::{
|
||||||
|
@ -41,7 +41,7 @@ struct Args {
|
||||||
/// Path to the svg file to render. If not set, the GhostScript Tiger will be rendered
|
/// Path to the svg file to render. If not set, the GhostScript Tiger will be rendered
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
svg: Option<PathBuf>,
|
svg: Option<std::path::PathBuf>,
|
||||||
/// When rendering an svg, what scale to use
|
/// When rendering an svg, what scale to use
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
scale: Option<f64>,
|
scale: Option<f64>,
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::time::Instant;
|
|
||||||
|
|
||||||
use crate::pico_svg::PicoSvg;
|
use crate::pico_svg::PicoSvg;
|
||||||
use crate::simple_text::SimpleText;
|
use crate::simple_text::SimpleText;
|
||||||
use vello::kurbo::{Affine, BezPath, Ellipse, PathEl, Point, Rect};
|
use vello::kurbo::{Affine, BezPath, Ellipse, PathEl, Point, Rect};
|
||||||
|
@ -83,7 +81,7 @@ pub fn render_svg_scene(
|
||||||
let scene_frag = scene.get_or_insert_with(|| {
|
let scene_frag = scene.get_or_insert_with(|| {
|
||||||
use super::pico_svg::*;
|
use super::pico_svg::*;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
let start = Instant::now();
|
let start = std::time::Instant::now();
|
||||||
eprintln!("Starting to parse svg");
|
eprintln!("Starting to parse svg");
|
||||||
let svg = PicoSvg::load(svg, scale).unwrap();
|
let svg = PicoSvg::load(svg, scale).unwrap();
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
|
Loading…
Reference in a new issue