Merge pull request #220 from linebender/raph-browser

Full pipeline running in browser
This commit is contained in:
Raph Levien 2022-12-08 10:27:37 -08:00 committed by GitHub
commit a7dbeb3b9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 454 additions and 57 deletions

376
Cargo.lock generated
View file

@ -28,6 +28,12 @@ dependencies = [
"libc",
]
[[package]]
name = "anyhow"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
[[package]]
name = "arrayref"
version = "0.3.6"
@ -61,6 +67,16 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "base64"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643"
dependencies = [
"byteorder",
"safemem",
]
[[package]]
name = "bit-set"
version = "0.5.3"
@ -133,6 +149,17 @@ dependencies = [
"vec_map",
]
[[package]]
name = "cargo-run-wasm"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "611b811fad83eebfcdcf47ae1e425c82d1249608bc571d537448d706be08cf27"
dependencies = [
"devserver_lib",
"pico-args",
"wasm-bindgen-cli-support",
]
[[package]]
name = "cc"
version = "1.0.73"
@ -201,6 +228,26 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "console_error_panic_hook"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"
dependencies = [
"cfg-if",
"wasm-bindgen",
]
[[package]]
name = "console_log"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "501a375961cef1a0d44767200e66e4a559283097e91d0730b1d75dfb2f8a1494"
dependencies = [
"log",
"web-sys",
]
[[package]]
name = "core-foundation"
version = "0.9.3"
@ -338,6 +385,12 @@ dependencies = [
"syn",
]
[[package]]
name = "devserver_lib"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fb4b71acc1405be2431a93892a79a0d82ed5ba6885649ddbdfc62caa4d67b1c"
[[package]]
name = "dispatch"
version = "0.2.0"
@ -383,6 +436,15 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "fastrand"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499"
dependencies = [
"instant",
]
[[package]]
name = "flate2"
version = "1.0.24"
@ -560,12 +622,27 @@ dependencies = [
"ahash",
]
[[package]]
name = "heck"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "hexf-parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
[[package]]
name = "id-arena"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005"
[[package]]
name = "ident_case"
version = "1.0.1"
@ -594,6 +671,12 @@ dependencies = [
"web-sys",
]
[[package]]
name = "itoa"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
[[package]]
name = "jni-sys"
version = "0.3.0"
@ -635,6 +718,12 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "leb128"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "libc"
version = "0.2.135"
@ -944,6 +1033,12 @@ version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
[[package]]
name = "pico-args"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315"
[[package]]
name = "piet-scene"
version = "0.1.0"
@ -1064,6 +1159,15 @@ dependencies = [
"bitflags",
]
[[package]]
name = "remove_dir_all"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [
"winapi",
]
[[package]]
name = "renderdoc-sys"
version = "0.7.1"
@ -1079,12 +1183,31 @@ dependencies = [
"xmlparser",
]
[[package]]
name = "run-wasm"
version = "0.1.0"
dependencies = [
"cargo-run-wasm",
]
[[package]]
name = "rustc-demangle"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "ryu"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
[[package]]
name = "safe_arch"
version = "0.5.2"
@ -1094,6 +1217,12 @@ dependencies = [
"bytemuck",
]
[[package]]
name = "safemem"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072"
[[package]]
name = "scoped-tls"
version = "1.0.0"
@ -1135,6 +1264,17 @@ dependencies = [
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "servo-fontconfig"
version = "0.5.1"
@ -1223,6 +1363,20 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "tempfile"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
dependencies = [
"cfg-if",
"fastrand",
"libc",
"redox_syscall",
"remove_dir_all",
"winapi",
]
[[package]]
name = "termcolor"
version = "1.1.3"
@ -1292,6 +1446,12 @@ version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
[[package]]
name = "unicode-segmentation"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a"
[[package]]
name = "unicode-width"
version = "0.1.10"
@ -1316,6 +1476,32 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "walrus"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eb08e48cde54c05f363d984bb54ce374f49e242def9468d2e1b6c2372d291f8"
dependencies = [
"anyhow",
"id-arena",
"leb128",
"log",
"walrus-macro",
"wasmparser 0.77.0",
]
[[package]]
name = "walrus-macro"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a6e5bd22c71e77d60140b0bd5be56155a37e5bd14e24f5f87298040d0cc40d7"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
@ -1347,6 +1533,40 @@ dependencies = [
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-cli-support"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03f35e0387a2c787ca5ee299bfb4259352b2a2184b406f8ee9f978c3c4671645"
dependencies = [
"anyhow",
"base64",
"log",
"rustc-demangle",
"serde_json",
"tempfile",
"walrus",
"wasm-bindgen-externref-xform",
"wasm-bindgen-multi-value-xform",
"wasm-bindgen-shared",
"wasm-bindgen-threads-xform",
"wasm-bindgen-wasm-conventions",
"wasm-bindgen-wasm-interpreter",
"wit-text",
"wit-validator",
"wit-walrus",
]
[[package]]
name = "wasm-bindgen-externref-xform"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d010a32a516a793adbea5835eab6f736d11c0cdd10ebe0c762c420f67510244"
dependencies = [
"anyhow",
"walrus",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.33"
@ -1382,12 +1602,76 @@ dependencies = [
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-multi-value-xform"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78b8c8d5dcc451b7e6a9c98d8fd966ff768a1e8f8afb270a829780086f2885ac"
dependencies = [
"anyhow",
"walrus",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f"
[[package]]
name = "wasm-bindgen-threads-xform"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d10f9246c4daa911283a7096fc3be9f1fab9e3e36400478a4ab8d7056701420"
dependencies = [
"anyhow",
"walrus",
"wasm-bindgen-wasm-conventions",
]
[[package]]
name = "wasm-bindgen-wasm-conventions"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4a5ab217f12f73b7c3ff23cbbbb5d36f7ee97dd65bb0be44beebda887df9002"
dependencies = [
"anyhow",
"walrus",
]
[[package]]
name = "wasm-bindgen-wasm-interpreter"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8fbb6c773b486889b7c1211d27a7a08eebaf54ec4269380266cadf69e269cd91"
dependencies = [
"anyhow",
"log",
"walrus",
"wasm-bindgen-wasm-conventions",
]
[[package]]
name = "wasmparser"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a950e6a618f62147fd514ff445b2a0b53120d382751960797f85f058c7eda9b9"
[[package]]
name = "wasmparser"
version = "0.77.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b35c86d22e720a07d954ebbed772d01180501afe7d03d464f413bb5f8914a8d6"
[[package]]
name = "wast"
version = "21.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b1844f66a2bc8526d71690104c0e78a8e59ffa1597b7245769d174ebb91deb5"
dependencies = [
"leb128",
]
[[package]]
name = "wayland-client"
version = "0.29.5"
@ -1696,18 +1980,6 @@ version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
[[package]]
name = "winit"
version = "0.1.0"
dependencies = [
"piet-scene",
"piet-wgsl",
"pollster",
"roxmltree",
"wgpu",
"winit 0.27.5",
]
[[package]]
name = "winit"
version = "0.27.5"
@ -1741,6 +2013,22 @@ dependencies = [
"x11-dl",
]
[[package]]
name = "winit-demo"
version = "0.1.0"
dependencies = [
"console_error_panic_hook",
"console_log",
"piet-scene",
"piet-wgsl",
"pollster",
"roxmltree",
"wasm-bindgen-futures",
"web-sys",
"wgpu",
"winit",
]
[[package]]
name = "wio"
version = "0.2.2"
@ -1750,6 +2038,70 @@ dependencies = [
"winapi",
]
[[package]]
name = "wit-parser"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f5fd97866f4b9c8e1ed57bcf9446f3d0d8ba37e2dd01c3c612c046c053b06f7"
dependencies = [
"anyhow",
"leb128",
"wit-schema-version",
]
[[package]]
name = "wit-schema-version"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfee4a6a4716eefa0682e7a3b836152e894a3e4f34a9d6c2c3e1c94429bfe36a"
[[package]]
name = "wit-text"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33358e95c77d660f1c7c07f4a93c2bd89768965e844e3c50730bb4b42658df5f"
dependencies = [
"anyhow",
"wast",
"wit-writer",
]
[[package]]
name = "wit-validator"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c11d93d925420e7872b226c4161849c32be38385ccab026b88df99d8ddc6ba6"
dependencies = [
"anyhow",
"wasmparser 0.59.0",
"wit-parser",
"wit-schema-version",
]
[[package]]
name = "wit-walrus"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad559e3e4c6404b2a6a675d44129d62a3836e3b951b90112fa1c5feb852757cd"
dependencies = [
"anyhow",
"id-arena",
"walrus",
"wit-parser",
"wit-schema-version",
"wit-writer",
]
[[package]]
name = "wit-writer"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2ad01ba5e9cbcff799a0689e56a153776ea694cec777f605938cb9880d41a09"
dependencies = [
"leb128",
"wit-schema-version",
]
[[package]]
name = "x11-dl"
version = "2.20.0"

View file

@ -1,7 +1,12 @@
[workspace]
resolver = "2"
members = ["piet-scene", "piet-wgsl", "piet-wgsl/examples/winit"]
members = ["piet-scene", "piet-wgsl", "piet-wgsl/examples/winit", "run-wasm"]
[workspace.package]
edition = "2021"
version = "0.1.0"
authors = ["piet-gpu developers"]
[patch.crates-io]
# Required for metal support to work on wgpu

View file

@ -1,7 +1,8 @@
[package]
name = "winit"
version = "0.1.0"
edition = "2021"
name = "winit-demo"
version.workspace = true
authors.workspace = true
edition.workspace = true
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -14,3 +15,9 @@ winit = "0.27.5"
pollster = "0.2.5"
# for picosvg
roxmltree = "0.13"
[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.7"
console_log = "0.2"
wasm-bindgen-futures = "0.4.33"
web-sys = "0.3.60"

View file

@ -19,25 +19,15 @@ mod simple_text;
mod test_scene;
use piet_scene::{Scene, SceneBuilder};
use piet_wgsl::{util::RenderContext, Renderer, Result};
use piet_wgsl::{util::RenderContext, Renderer};
use winit::{event_loop::EventLoop, window::Window};
async fn run() -> Result<()> {
use winit::{
dpi::LogicalSize,
event::*,
event_loop::{ControlFlow, EventLoop},
window::WindowBuilder,
};
let event_loop = EventLoop::new();
let window = WindowBuilder::new()
.with_inner_size(LogicalSize::new(1044, 800))
.with_resizable(true)
.build(&event_loop)
.unwrap();
let render_cx = RenderContext::new().await?;
async fn run(event_loop: EventLoop<()>, window: Window) {
use winit::{event::*, event_loop::ControlFlow};
let render_cx = RenderContext::new().await.unwrap();
let size = window.inner_size();
let mut surface = render_cx.create_surface(&window, size.width, size.height);
let mut renderer = Renderer::new(&render_cx.device)?;
let mut renderer = Renderer::new(&render_cx.device).unwrap();
let mut simple_text = simple_text::SimpleText::new();
let mut current_frame = 0usize;
let mut scene_ix = 0usize;
@ -75,7 +65,7 @@ async fn run() -> Result<()> {
match scene_ix % N_SCENES {
0 => test_scene::render_anim_frame(&mut builder, &mut simple_text, current_frame),
1 => test_scene::render_blend_grid(&mut builder),
2 => test_scene::render_tiger(&mut builder, false),
2 => test_scene::render_tiger(&mut builder),
3 => test_scene::render_brush_transform(&mut builder, current_frame),
4 => test_scene::render_funky_paths(&mut builder),
_ => test_scene::render_scene(&mut builder),
@ -103,5 +93,35 @@ async fn run() -> Result<()> {
}
fn main() {
pollster::block_on(run()).unwrap();
#[cfg(not(target_arch = "wasm32"))]
{
use winit::{dpi::LogicalSize, window::WindowBuilder};
let event_loop = EventLoop::new();
let window = WindowBuilder::new()
.with_inner_size(LogicalSize::new(1044, 800))
.with_resizable(true)
.build(&event_loop)
.unwrap();
pollster::block_on(run(event_loop, window));
}
#[cfg(target_arch = "wasm32")]
{
let event_loop = EventLoop::new();
let window = winit::window::Window::new(&event_loop).unwrap();
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
console_log::init().expect("could not initialize logger");
use winit::platform::web::WindowExtWebSys;
// On wasm, append the canvas to the document body
let canvas = window.canvas();
canvas.set_width(1044);
canvas.set_height(800);
web_sys::window()
.and_then(|win| win.document())
.and_then(|doc| doc.body())
.and_then(|body| body.append_child(&web_sys::Element::from(canvas)).ok())
.expect("couldn't append canvas to document body");
wasm_bindgen_futures::spawn_local(run(event_loop, window));
}
}

View file

@ -48,9 +48,8 @@ pub fn render_funky_paths(sb: &mut SceneBuilder) {
const N_CIRCLES: usize = 0;
#[allow(unused)]
pub fn render_svg(sb: &mut SceneBuilder, svg: &PicoSvg, print_stats: bool) {
pub fn render_svg(sb: &mut SceneBuilder, svg: &PicoSvg) {
use crate::pico_svg::*;
let start = std::time::Instant::now();
for item in &svg.items {
match item {
Item::Fill(fill) => {
@ -73,22 +72,15 @@ pub fn render_svg(sb: &mut SceneBuilder, svg: &PicoSvg, print_stats: bool) {
}
}
}
if print_stats {
println!("flattening and encoding time: {:?}", start.elapsed());
}
}
#[allow(unused)]
pub fn render_tiger(sb: &mut SceneBuilder, print_stats: bool) {
pub fn render_tiger(sb: &mut SceneBuilder) {
use super::pico_svg::*;
let xml_str =
std::str::from_utf8(include_bytes!("../../assets/Ghostscript_Tiger.svg")).unwrap();
let start = std::time::Instant::now();
let svg = PicoSvg::load(xml_str, 6.0).unwrap();
if print_stats {
println!("parsing time: {:?}", start.elapsed());
}
render_svg(sb, &svg, print_stats);
render_svg(sb, &svg);
}
pub fn render_scene(sb: &mut SceneBuilder) {

View file

@ -33,8 +33,8 @@ var<workgroup> sh_stack_bbox: array<vec4<f32>, WG_SIZE>;
var<workgroup> sh_bbox: array<vec4<f32>, WG_SIZE>;
var<workgroup> sh_link: array<i32, WG_SIZE>;
fn search_link(bic: ptr<function, Bic>, ix: u32) -> i32 {
var ix = ix;
fn search_link(bic: ptr<function, Bic>, ix_in: u32) -> i32 {
var ix = ix_in;
var j = 0u;
while j < firstTrailingBit(WG_SIZE) {
let base = 2u * WG_SIZE - (2u << (firstTrailingBit(WG_SIZE) - j));
@ -130,7 +130,7 @@ fn main(
// Read input and compute Bic binary tree
let inp = load_clip_path(global_id.x);
let is_push = inp >= 0;
var bic = Bic(1u - u32(is_push), u32(is_push));
bic = Bic(1u - u32(is_push), u32(is_push));
sh_bic[local_id.x] = bic;
if is_push {
let path_bbox = path_bboxes[inp];

View file

@ -55,8 +55,7 @@ var<workgroup> sh_part_offsets: array<u32, WG_SIZE>;
var<workgroup> sh_drawobj_ix: array<u32, WG_SIZE>;
var<workgroup> sh_tile_stride: array<u32, WG_SIZE>;
var<workgroup> sh_tile_width: array<u32, WG_SIZE>;
var<workgroup> sh_tile_x0: array<u32, WG_SIZE>;
var<workgroup> sh_tile_y0: array<u32, WG_SIZE>;
var<workgroup> sh_tile_x0y0: array<u32, WG_SIZE>;
var<workgroup> sh_tile_count: array<u32, WG_SIZE>;
var<workgroup> sh_tile_base: array<u32, WG_SIZE>;
@ -235,8 +234,7 @@ fn main(
let x1 = clamp(i32(path.bbox.z) - i32(bin_tile_x), 0, i32(N_TILE_X));
let y1 = clamp(i32(path.bbox.w) - i32(bin_tile_y), 0, i32(N_TILE_Y));
sh_tile_width[local_id.x] = u32(x1 - x0);
sh_tile_x0[local_id.x] = u32(x0);
sh_tile_y0[local_id.x] = u32(y0);
sh_tile_x0y0[local_id.x] = u32(x0) | u32(y0 << 16u);
tile_count = u32(x1 - x0) * u32(y1 - y0);
// base relative to bin
let base = path.tiles - u32(dy * i32(stride) + dx);
@ -270,8 +268,9 @@ fn main(
tag = scene[config.drawtag_base + drawobj_ix];
let seq_ix = ix - select(0u, sh_tile_count[el_ix - 1u], el_ix > 0u);
let width = sh_tile_width[el_ix];
let x = sh_tile_x0[el_ix] + seq_ix % width;
let y = sh_tile_y0[el_ix] + seq_ix / width;
let x0y0 = sh_tile_x0y0[el_ix];
let x = (x0y0 & 0xffffu) + seq_ix % width;
let y = (x0y0 >> 16u) + seq_ix / width;
let tile_ix = sh_tile_base[el_ix] + sh_tile_stride[el_ix] * y + x;
let tile = tiles[tile_ix];
let is_clip = (tag & 1u) != 0u;

View file

@ -74,8 +74,8 @@ fn lum(c: vec3<f32>) -> f32 {
return dot(c, f);
}
fn clip_color(c: vec3<f32>) -> vec3<f32> {
var c = c;
fn clip_color(c_in: vec3<f32>) -> vec3<f32> {
var c = c_in;
let l = lum(c);
let n = min(c.x, min(c.y, c.z));
let x = max(c.x, max(c.y, c.z));

View file

@ -140,7 +140,15 @@ pub fn preprocess(input: &str, defines: &HashSet<String>, imports: &HashMap<&str
}
}
if stack.iter().all(|item| item.active) {
output.push_str(line);
// Naga does not yet recognize `const` but web 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 ") {
output.push_str("const");
output.push_str(&line[3..]);
} else {
output.push_str(line);
}
output.push('\n');
}
}

11
run-wasm/Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "run-wasm"
version.workspace = true
authors.workspace = true
edition.workspace = true
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cargo-run-wasm = "0.2.0"

3
run-wasm/src/main.rs Normal file
View file

@ -0,0 +1,3 @@
fn main() {
cargo_run_wasm::run_wasm_with_css("body { margin: 0px; }");
}