summaryrefslogtreecommitdiff
path: root/ext/webgpu/00_init.js
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-01-05 19:55:01 +0530
committerGitHub <noreply@github.com>2024-01-05 19:55:01 +0530
commit9f86705fa64db7c1569f9244673e97376ae75782 (patch)
tree726e0274aefef13792d85cac5198844c43dfc787 /ext/webgpu/00_init.js
parent611993fbe020a0668da103b7c1a9c2f1d9d25d4e (diff)
chore(ext/webgpu): include GPUCanvasContext in snapshot (#21773)
Part 1 of #21713 Changes: - Remove `.present()` and add a `presentGPUCanvasContext` (not exposed yet to users) - Move lazy load logic to `00_init.js`. This can be used to use webgpu on-demand from future code (OffScreenCanvas)
Diffstat (limited to 'ext/webgpu/00_init.js')
-rw-r--r--ext/webgpu/00_init.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/ext/webgpu/00_init.js b/ext/webgpu/00_init.js
new file mode 100644
index 000000000..b559fe3db
--- /dev/null
+++ b/ext/webgpu/00_init.js
@@ -0,0 +1,39 @@
+// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+
+import { core } from "ext:core/mod.js";
+const ops = core.ops;
+
+let webgpu;
+
+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 = ops.op_lazy_load_esm("ext:deno_webgpu/01_webgpu.js");
+ }
+}
+
+export { loadWebGPU, webgpu, webGPUNonEnumerable };