diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2024-02-06 22:28:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-06 22:28:32 +0100 |
commit | c8b2af8ed1b27822b0e6193b7a82903f54e56d95 (patch) | |
tree | 0ea57f0d038552971914d08b95e0dec5d93ef102 /ext/webgpu | |
parent | c6def993e052626be3933de4299bf4b2eb76e48a (diff) |
refactor: use web utils and lazy load utils from core (#22289)
Diffstat (limited to 'ext/webgpu')
-rw-r--r-- | ext/webgpu/00_init.js | 37 | ||||
-rw-r--r-- | ext/webgpu/02_surface.js | 12 |
2 files changed, 8 insertions, 41 deletions
diff --git a/ext/webgpu/00_init.js b/ext/webgpu/00_init.js index b7014bd45..0f10847ce 100644 --- a/ext/webgpu/00_init.js +++ b/ext/webgpu/00_init.js @@ -1,38 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { op_lazy_load_esm } from "ext:core/ops"; +import { core } from "ext:core/mod.js"; -let webgpu; +const loadWebGPU = core.createLazyLoader("ext:deno_webgpu/01_webgpu.js"); -function webGPUNonEnumerable(getter) { - let valueIsSet = false; - let value; - - return { - get() { - loadWebGPU(); - - if (valueIsSet) { - return value; - } else { - return getter(); - } - }, - set(v) { - loadWebGPU(); - - valueIsSet = true; - value = v; - }, - enumerable: false, - configurable: true, - }; -} - -function loadWebGPU() { - if (!webgpu) { - webgpu = op_lazy_load_esm("ext:deno_webgpu/01_webgpu.js"); - } -} - -export { loadWebGPU, webgpu, webGPUNonEnumerable }; +export { loadWebGPU }; diff --git a/ext/webgpu/02_surface.js b/ext/webgpu/02_surface.js index 94b0a5d54..f35f745af 100644 --- a/ext/webgpu/02_surface.js +++ b/ext/webgpu/02_surface.js @@ -22,7 +22,7 @@ const { import * as webidl from "ext:deno_webidl/00_webidl.js"; import { createFilteredInspectProxy } from "ext:deno_console/01_console.js"; -import { loadWebGPU, webgpu } from "ext:deno_webgpu/00_init.js"; +import { loadWebGPU } from "ext:deno_webgpu/00_init.js"; const _surfaceRid = Symbol("[[surfaceRid]]"); const _configuration = Symbol("[[configuration]]"); @@ -55,7 +55,7 @@ class GPUCanvasContext { context: "Argument 1", }); - const { _device, assertDevice } = webgpu; + const { _device, assertDevice } = loadWebGPU(); this[_device] = configuration.device[_device]; this[_configuration] = configuration; const device = assertDevice(this, { @@ -78,7 +78,7 @@ class GPUCanvasContext { } unconfigure() { - const { _device } = webgpu; + const { _device } = loadWebGPU(); webidl.assertBranded(this, GPUCanvasContextPrototype); @@ -94,7 +94,7 @@ class GPUCanvasContext { if (this[_configuration] === null) { throw new DOMException("context is not configured.", "InvalidStateError"); } - const { createGPUTexture, assertDevice } = webgpu; + const { createGPUTexture, assertDevice } = loadWebGPU(); const device = assertDevice(this, { prefix, context: "this" }); @@ -130,7 +130,7 @@ class GPUCanvasContext { // Required to present the texture; browser don't need this. [_present]() { - const { assertDevice } = webgpu; + const { assertDevice } = loadWebGPU(); webidl.assertBranded(this, GPUCanvasContextPrototype); const prefix = "Failed to execute 'present' on 'GPUCanvasContext'"; @@ -160,8 +160,6 @@ const GPUCanvasContextPrototype = GPUCanvasContext.prototype; function createCanvasContext(options) { // lazy load webgpu if needed - loadWebGPU(); - const canvasContext = webidl.createBranded(GPUCanvasContext); canvasContext[_surfaceRid] = options.surfaceRid; canvasContext[_canvas] = options.canvas; |