Replies: 2 comments 4 replies
-
If we absolutely need "async all the way up" to target WebGPU, then I think this approach is probably the way to go. My main reservation is that I like having "one way" to do things. Something as central as App setup should be standardized. Having So it sort of feels like we either need to:
In the immediate short term (4) has my preference by a landslide. But that may be impossible, so we should have a contingency plan. I'm biased toward (1) if we can make it suitably ergonomic. |
Beta Was this translation helpful? Give feedback.
-
Is initializing wgpu something we have to do during plugin initialization? If we had async systems could we do it in a startup system? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Why we need it
Wgpu initialization is async, and currently bevy calls it using
futures_lite::future::block_on
. Unfortunately this approach doesn't work well in the browser on wasm32 target. Duringwebgpu
initialization it panics withcondvar wait not supported
- it seems future returned byAdapter::request_device
needs to be await'ed on 'JS executor'. We already do this inbevy_assets
- async function needs to be spawned by TaskPool::spawn_local (which callswasm_bindgen_futures::spawn_local
under the hood)Proposal
Let's introduce additional
App
methods:and corresponding method in
Plugin
traitThe similar thing may be done for
App::add_plugins_async
andPluginGroup
Default
Plugin::build_async
implementation makes it optional, this way we only need to implement it when necessary (currently only forbevy_render2::RenderPlugin
)Additionally we can add support for async main functions to
#[bevy_main]
macro and allow for following:or
Of course standard, non-async main will still work for native (non-web) targets (async version will work for both native and web)
PoC code including async plugin initialization and
#[bevy_main]
proc macro changes is here: https://github.com/mrk-its/bevy/commits/webgpuBeta Was this translation helpful? Give feedback.
All reactions