summaryrefslogtreecommitdiff
path: root/runtime/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 /runtime/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 'runtime/js')
-rw-r--r--runtime/js/98_global_scope.js40
1 files changed, 7 insertions, 33 deletions
diff --git a/runtime/js/98_global_scope.js b/runtime/js/98_global_scope.js
index 14b11cbde..de8319528 100644
--- a/runtime/js/98_global_scope.js
+++ b/runtime/js/98_global_scope.js
@@ -42,6 +42,12 @@ import * as globalInterfaces from "ext:deno_web/04_global_interfaces.js";
import * as webStorage from "ext:deno_webstorage/01_webstorage.js";
import * as prompt from "ext:runtime/41_prompt.js";
import * as imageData from "ext:deno_web/16_image_data.js";
+import {
+ loadWebGPU,
+ webgpu,
+ webGPUNonEnumerable,
+} from "ext:deno_webgpu/00_init.js";
+import * as webgpuSurface from "ext:deno_webgpu/02_surface.js";
import { unstableIds } from "ext:runtime/90_deno_ns.js";
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope
@@ -189,6 +195,7 @@ unstableForWindowOrWorkerGlobalScope[unstableIds.webgpu] = {
GPUError: webGPUNonEnumerable(() => webgpu.GPUError),
GPUValidationError: webGPUNonEnumerable(() => webgpu.GPUValidationError),
GPUOutOfMemoryError: webGPUNonEnumerable(() => webgpu.GPUOutOfMemoryError),
+ GPUCanvasContext: webGPUNonEnumerable(() => webgpuSurface.GPUCanvasContext),
};
class Navigator {
@@ -229,39 +236,6 @@ const numCpus = memoizeLazy(() => ops.op_bootstrap_numcpus());
const userAgent = memoizeLazy(() => ops.op_bootstrap_user_agent());
const language = memoizeLazy(() => ops.op_bootstrap_language());
-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");
- }
-}
-
ObjectDefineProperties(Navigator.prototype, {
gpu: {
configurable: true,