-
Notifications
You must be signed in to change notification settings - Fork 79
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
WASM compatibility #41
Comments
No, |
The docs says:
|
I'm going to close this issue. I fully appreciate the value of wasm, and I'm kind of sad that this crate doesn't work with it, but it would be such a large amount of work not only to create a separate backend dedicated to wasm that doesn't use compute shaders, but also to maintain two backends in parallel, that I realistically don't have the time to do this. I hear some Bevy users are working on a CPU particle solution, which would work with wasm (see bevyengine/rfcs#28) so I encourage anyone who needs a particle system that works in wasm to contribute to that RFC and workstream. If you're familiar with Unity, and to hazard an over-flattering comparison that is probably not realistic (yet?), 🎆 Bevy Hanabi is to Unity's VFX Graph what that CPU solution and RFC for Bevy is to Unity's built-in particle system, with the same advantages and drawbacks. CPU solutions are more versatile, easier to support on all platforms, but limited in terms of performance; on the other hand GPU solutions are vastly more performant but require modern API and hardware features (compute shaders) which are not available everywhere. |
too, bad, but I totally undestand your decision. I guess we can only hope that webgpu will solve this in the future... maybe add a small note in the readme that wasm is not supported? |
I thought I already had but apparently not. Fixed now, it's in the README. |
AFAIK compute shaders are now supported by WebGPU. @djeedai would you consider reopening this issue? |
@janhohenheim I would be more than happy to add wasm support to 🎆 Hanabi provided Bevy itself supports compute shaders on wasm. I don't believe this is the case yet though? And I can really spearhead that myself. |
@djeedai hmm, I tried running the .set(RenderPlugin {
wgpu_settings: WgpuSettings {
backends: Some(Backends::BROWSER_WEBGPU),
..default()
},
}) However, I cannot test this further, since I fail to activate WebGPU on my browsers; I cannot render any WebGPU examples on the internet right now. Maybe someone else has better luck? The steps needed to enable WebGPU are described here. I double checked, and yes, WebGPU does indeed support compute shaders. |
I couldn't get webgpu to work at all in firefox, but on chrome, this example worked: https://cx20.github.io/webgpu-test/examples/rust/triangle/index.html However, when I tried patching wgpu panicked at 'Unable to find a GPU! Make sure you have installed required drivers!', crates\bevy_render\src\renderer\mod.rs:125:10 This was on windows 11 with nvidia gtx 970. May give it another try on linux. |
@johanhelsing ah heck! I checked Discord and found this: |
So yes, that's my understanding, and happy to reopen this once Bevy supports it but until then no luck in afraid. |
Seems like there is official support for WebGPU in bevy's main branch, should this issue be reopened? |
I ported bevy_hanabi to main, and with a few fixes for WebGPU it works in the browser firework.mp4 |
@mockersf great, do you have a branch to try? :) |
just pushed it here: https://github.com/mockersf/bevy_hanabi/tree/with-webgpu, started from #179 for some of the Bevy update needed Building for WebGPU: |
Reopening the issue now that Bevy has official support. |
Refresh some of the example animated screenshots, and add a few missing ones. Also update the mention about `wasm` target support to link to #41 and mention the upcoming suport in Bevy 0.11 (next stable).
Refresh some of the example animated screenshots, and add a few missing ones. Also update the mention about `wasm` target support to link to #41 and mention the upcoming suport in Bevy 0.11 (next stable).
I did some initial work and I can build and run all examples. However there's a major bug where only the first effect is visible, and I'm having difficulties debugging on Web (notably, at the minute logs don't show up in console like they should, and I don't know of any way to make GPU captures). So this likely won't make it for the next release unfortunately (next few days, waiting on |
@djeedai could you create a draft PR with that you have? So me and others can maybe help with debugging |
@adamtomecek See the |
Unfortunately no luck running it. It panicks on me with Current version,
|
Looks like a bug on Hanabi side though, unless that |
Are you building for WebGL2 or WebGPU? |
Good question. Not sure. I'm pretty new to Rust/Bevy but I think it's safe to say I'm using default values?
|
I take it back. I finally figured out how to build Bevy with WebGPU and it works spot on with your |
Can you run all examples? At the time I made the branch I could only run examples with a single effect. As soon as there were more, only the first rendered. |
...works spot on with my game, but I use multiple effects. I create all effects while loading the game, save I'll give examples here a try and let you know |
I see all three effects. I couldn't compile examples from your I'll make a working example and send you a link. |
Yes I had to remove the inspector too, but I still don't see the other effects beyond the first one. I'm using the latest Chrome 116 to run the examples on Windows. That looks more and more like a platform bug in Bevy or Wgpu. |
@djeedai code that's working for me. Sadly can't see any major changes compared to your version. Running it like this |
@adamtomecek Indeed the code looks the same. The build command too, mine is: cargo b --release --example spawn --target wasm32-unknown-unknown --no-default-features --features="bevy/bevy_winit bevy/bevy_pbr 3d"
wasm-bindgen --out-name wasm_spawn --out-dir examples/wasm/target --target web target/wasm32-unknown-unknown/release/examples/spawn.wasm From there I run I noted you build in Debug, while I build in Release. However I tried in Debug and it doesn't change anything. I've also upgraded my NVidia drivers to latest just in case, but that had no effect. |
My config. I think the result should be identical. Release and Debug makes no difference for me. Both work.
I have a Macbook Air M2 with latest MacOS |
@djeedai do you see effects in this "game" I made? https://tds.tmck.cz/ There should be firework like effect when you hit an enemy. |
Only on the first killed enemy. Well that's kind of a partial relief, I'm not getting insane, this really looks like a platform bug. FYI @superdump see the above website, on Windows PC with Chrome 116 I don't see the effects after the first one, whereas @adamtomecek can see them all on a Macbook Air M2. This looks like a Chrome bug maybe? |
Had a friend running W10 and latest Chrome test it and he also sees only first one. |
on macOS with an m1 and chromium 117, I see them all... so yeah looks like a chrome bug |
Windows + chrome 117 I also only get the first effect (per enemy type). On firefox nightly (119.01a 2023-09-23) with webgpu enabled it works! It's laggy, but particles spawn every time I kill an enemy. I had to set |
Thanks for the data point, much appreciated. Do you recall what kind of error if any you had with dx12? I'll dig into that indirect dispatch flag too, try to understand why it's not active by default. |
Add support for the WebAssembly target (`wasm`). This requires disabling the `serde` feature, as the `typetag` used to serialize trait objects is not available for that target. Add a web page with all the examples, and move all the GIFs there. Remove the list of examples from the README; instead point users to the web demo at `examples/wasm/index.html`. This should be eventually published live for even easier reference. Temporarily copy `assets/` to `examples/wasm/` so that web examples can directly access them when serving locally. This avoids complicated multi-folder setups. Fixes #41
Add support for the WebAssembly target (`wasm`). This requires disabling the `serde` feature, as the `typetag` used to serialize trait objects is not available for that target. Add a web page with all the examples, and move all the GIFs there. Remove the list of examples from the README; instead point users to the web demo at `examples/wasm/index.html`. This should be eventually published live for even easier reference. Temporarily copy `assets/` to `examples/wasm/` so that web examples can directly access them when serving locally. This avoids complicated multi-folder setups. Fixes #41
Using
bevy_hanabi
fails in WASM becauseVERTEX_WRITABLE_STORAGE
is not supported (even if WGPU doc says it is supported by all platforms).Is it planned to make this crate WASM-compatible?
The text was updated successfully, but these errors were encountered: