use burn::prelude::Backend;
#[cfg(target_arch = "wasm32")]
use std::cell::Cell;
pub type BackendImpl = burn::backend::Wgpu<f32, i32>;
pub type BackendDevice = <BackendImpl as Backend>::Device;
pub fn default_device() -> BackendDevice {
BackendDevice::default()
}
#[cfg(target_arch = "wasm32")]
thread_local! {
static WASM_WGPU_RUNTIME_READY: Cell<bool> = const { Cell::new(false) };
}
#[cfg(target_arch = "wasm32")]
pub async fn ensure_wasm_wgpu_runtime(device: &BackendDevice) {
if WASM_WGPU_RUNTIME_READY.with(Cell::get) {
return;
}
burn::backend::wgpu::init_setup_async::<burn::backend::wgpu::graphics::WebGpu>(
device,
burn::backend::wgpu::RuntimeOptions::default(),
)
.await;
WASM_WGPU_RUNTIME_READY.with(|flag| flag.set(true));
}