diff --git a/node-graph/gstd/Cargo.toml b/node-graph/gstd/Cargo.toml index 79d8d8ca..10ea5758 100644 --- a/node-graph/gstd/Cargo.toml +++ b/node-graph/gstd/Cargo.toml @@ -77,6 +77,8 @@ features = [ "CanvasRenderingContext2d", "ImageData", "Document", + "Navigator", + "Gpu", "HtmlCanvasElement", "ImageBitmapRenderingContext", ] diff --git a/node-graph/gstd/src/wasm_application_io.rs b/node-graph/gstd/src/wasm_application_io.rs index 5cadb611..4503855e 100644 --- a/node-graph/gstd/src/wasm_application_io.rs +++ b/node-graph/gstd/src/wasm_application_io.rs @@ -40,11 +40,25 @@ pub struct WasmApplicationIo { impl WasmApplicationIo { pub async fn new() -> Self { + #[cfg(all(feature = "wgpu", target_arch = "wasm32"))] + let executor = if let Some(gpu) = web_sys::window().map(|w| w.navigator().gpu()) { + let request_adapter = js_sys::Reflect::get(&gpu, &wasm_bindgen::JsValue::from_str("requestAdapter")).unwrap(); + let function = js_sys::Function::try_from(&request_adapter).unwrap(); + let result = function.call0(&gpu); + match result { + Err(_) => None, + Ok(_) => WgpuExecutor::new().await, + } + } else { + None + }; + #[cfg(all(feature = "wgpu", not(target_arch = "wasm32")))] + let executor = None; let mut io = Self { #[cfg(target_arch = "wasm32")] ids: RefCell::new(0), #[cfg(feature = "wgpu")] - gpu_executor: WgpuExecutor::new().await, + gpu_executor: executor, #[cfg(not(target_arch = "wasm32"))] windows: RefCell::new(Vec::new()), resources: HashMap::new(),