summaryrefslogtreecommitdiff
path: root/op_crates/webgpu/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'op_crates/webgpu/lib.rs')
-rw-r--r--op_crates/webgpu/lib.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/op_crates/webgpu/lib.rs b/op_crates/webgpu/lib.rs
index 3249b2818..046472905 100644
--- a/op_crates/webgpu/lib.rs
+++ b/op_crates/webgpu/lib.rs
@@ -198,7 +198,16 @@ pub async fn op_webgpu_request_adapter(
) -> Result<Value, AnyError> {
let mut state = state.borrow_mut();
check_unstable(&state, "navigator.gpu.requestAdapter");
- let instance = state.borrow::<Instance>();
+ let instance = if let Some(instance) = state.try_borrow::<Instance>() {
+ instance
+ } else {
+ state.put(wgpu_core::hub::Global::new(
+ "webgpu",
+ wgpu_core::hub::IdentityManagerFactory,
+ wgpu_types::BackendBit::PRIMARY,
+ ));
+ state.borrow::<Instance>()
+ };
let descriptor = wgpu_core::instance::RequestAdapterOptions {
power_preference: match args.power_preference {