-
Hello, I'm making an wasm application where user can specify WebGPU or WebGL as backend using a parameter from js. static new(canvas: HTMLCanvasElement, backend: Backend): Promise<any>; #[wasm_bindgen]
pub fn new(canvas: &web_sys::HtmlCanvasElement, backend: Backend) -> js_sys::Promise {
......
let backends = match backend {
Backend::All => wgpu::util::backend_bits_from_env().unwrap_or(wgpu::Backends::all()),
Backend::WebGPU => wgpu::Backends::BROWSER_WEBGPU,
Backend::WebGL => wgpu::Backends::GL,
};
let instance = wgpu::Instance::new(backends);
let size = CanvasSize::new(canvas.width(), canvas.height());
let surface = instance.create_surface_from_canvas(&canvas);
wasm_bindgen_futures::future_to_promise(async move {
let adapter = wgpu::util::initialize_adapter_from_env_or_default(
&instance,
backends,
Some(&surface),
)
.await
.expect("No suitable GPU adapters found on the system!");
......
} I have managed to run my application in Chrome Canary with WebGPU without feature Does this case work as expected? What should I do if I want to get a WebGPU Backend with feature |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi! 👋 The choice between WebGL vs. WebGPU is currently decided at compile-time, although we plan to allow picking an adapter at run-time later. For now you could use two separate JavaScript+wasm bundles and either redirect to another page or conditionally load one bundle. |
Beta Was this translation helpful? Give feedback.
Hi! 👋 The choice between WebGL vs. WebGPU is currently decided at compile-time, although we plan to allow picking an adapter at run-time later.
For now you could use two separate JavaScript+wasm bundles and either redirect to another page or conditionally load one bundle.