-
Notifications
You must be signed in to change notification settings - Fork 143
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
Fix WASM build #312
Conversation
crates.io/crates/instant provides a std::time::Instant implementation that works on both WASM and non-wasm builds.
This prevents the scaling caused by the hardcoded canvas dimensions on high dpi platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code seems reasonable to me, although I can't test it without a WebGPU compatible browser.
examples/scenes/Cargo.toml
Outdated
@@ -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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
src/engine.rs
Outdated
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(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
The potential division by zero in this line led to visible visual artifacts when running against WebGPU in Chrome.
Unfortunately this PR breaks the bevy example since bevy_render currently depends on wgpu 0.15. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the changes here are good, there are just a few additions I think should be included in this PR.
I think this can probably incorporate the changes from #301. In particular, that's an update of cargo-run-wasm
, including the new support for the -p
shorthand; adding the WASM target to the instructions is optional but would be nice.
Also, I'd like us to add a Warning to the Bevy section of the README that the example temporarily doesn't compile. (For context, we decided on Zulip that the Bevy example shouldn't block needed changes, so long as there's a reasonable expectation it won't be broken for long)
Warning
This example currently does not compile. We expect to resolve this as soon as bevy's has updated to wgpu 0.16
Additionally, we specify the wgpu version in a badge in README.md. This also needs to be updated. There should probably also be a comment to this effect in the root Cargo.toml.
Done. I cherry-picked your change from #301 into the PR and updated the WASM build instructions to say |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So long as the most recent changes have been tested (i.e. in a browser), this seems all good
Co-authored-by: Daniel McNab <[email protected]>
std::time::Instant
which works on WASM and native builds.This resolves #276