diff --git a/op_crates/webgpu/01_webgpu.js b/op_crates/webgpu/01_webgpu.js index 743f875e98..1b790914e7 100644 --- a/op_crates/webgpu/01_webgpu.js +++ b/op_crates/webgpu/01_webgpu.js @@ -14,8 +14,8 @@ const eventTarget = window.__bootstrap.eventTarget; /** - * @param {any} self - * @param {{prefix: string, context: string}} opts + * @param {any} self + * @param {{prefix: string, context: string}} opts * @returns {InnerGPUDevice & {rid: number}} */ function assertDevice(self, { prefix, context }) { @@ -31,9 +31,9 @@ } /** - * @param {InnerGPUDevice} self - * @param {any} resource - * @param {{prefix: string, resourceContext: string, selfContext: string}} opts + * @param {InnerGPUDevice} self + * @param {any} resource + * @param {{prefix: string, resourceContext: string, selfContext: string}} opts * @returns {InnerGPUDevice & {rid: number}} */ function assertDeviceMatch( @@ -55,8 +55,8 @@ } /** - * @param {any} self - * @param {{prefix: string, context: string}} opts + * @param {any} self + * @param {{prefix: string, context: string}} opts * @returns {number} */ function assertResource(self, { prefix, context }) { @@ -452,7 +452,7 @@ const _message = Symbol("[[message]]"); /** - * + * * @param {string | undefined} reason * @param {string} message * @returns {GPUDeviceLostInfo} @@ -524,10 +524,10 @@ const _device = Symbol("[[device]]"); const _queue = Symbol("[[queue]]"); - /** + /** * @typedef ErrorScope * @property {string} filter - * @property {GPUError | undefined} error + * @property {GPUError | undefined} error */ /** diff --git a/op_crates/webgpu/lib.rs b/op_crates/webgpu/lib.rs index 3249b2818b..046472905d 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 { let mut state = state.borrow_mut(); check_unstable(&state, "navigator.gpu.requestAdapter"); - let instance = state.borrow::(); + let instance = if let Some(instance) = state.try_borrow::() { + instance + } else { + state.put(wgpu_core::hub::Global::new( + "webgpu", + wgpu_core::hub::IdentityManagerFactory, + wgpu_types::BackendBit::PRIMARY, + )); + state.borrow::() + }; let descriptor = wgpu_core::instance::RequestAdapterOptions { power_preference: match args.power_preference { diff --git a/runtime/ops/webgpu.rs b/runtime/ops/webgpu.rs index d3b9cfa19c..bee08b9f64 100644 --- a/runtime/ops/webgpu.rs +++ b/runtime/ops/webgpu.rs @@ -4,11 +4,6 @@ pub fn init(rt: &mut deno_core::JsRuntime) { { let op_state = rt.op_state(); let mut state = op_state.borrow_mut(); - state.put(wgpu_core::hub::Global::new( - "webgpu", - wgpu_core::hub::IdentityManagerFactory, - wgpu_types::BackendBit::PRIMARY, - )); let unstable_checker = state.borrow::(); let unstable = unstable_checker.unstable; state.put(Unstable(unstable));