diff options
Diffstat (limited to 'runtime/js')
-rw-r--r-- | runtime/js/90_deno_ns.js | 5 | ||||
-rw-r--r-- | runtime/js/98_global_scope.js | 90 |
2 files changed, 94 insertions, 1 deletions
diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index 83c4a4d03..0c771ba83 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -164,7 +164,8 @@ const unstableIds = { kv: 6, net: 7, unsafeProto: 8, - workerOptions: 9, + webgpu: 9, + workerOptions: 10, }; const denoNsUnstableById = {}; @@ -216,6 +217,8 @@ denoNsUnstableById[unstableIds.net] = { // denoNsUnstableById[unstableIds.unsafeProto] = {} +// denoNsUnstableById[unstableIds.webgpu] = {} + // denoNsUnstableById[unstableIds.workerOptions] = {} // when editing this list, also update unstableDenoProps in cli/tsc/99_main_compiler.js diff --git a/runtime/js/98_global_scope.js b/runtime/js/98_global_scope.js index 65a9c6933..d5ec700db 100644 --- a/runtime/js/98_global_scope.js +++ b/runtime/js/98_global_scope.js @@ -151,6 +151,45 @@ unstableForWindowOrWorkerGlobalScope[unstableIds.broadcastChannel] = { unstableForWindowOrWorkerGlobalScope[unstableIds.net] = { WebSocketStream: util.nonEnumerable(webSocketStream.WebSocketStream), }; +unstableForWindowOrWorkerGlobalScope[unstableIds.webgpu] = { + GPU: webGPUNonEnumerable(() => webgpu.GPU), + GPUAdapter: webGPUNonEnumerable(() => webgpu.GPUAdapter), + GPUAdapterInfo: webGPUNonEnumerable(() => webgpu.GPUAdapterInfo), + GPUSupportedLimits: webGPUNonEnumerable(() => webgpu.GPUSupportedLimits), + GPUSupportedFeatures: webGPUNonEnumerable(() => webgpu.GPUSupportedFeatures), + GPUDeviceLostInfo: webGPUNonEnumerable(() => webgpu.GPUDeviceLostInfo), + GPUDevice: webGPUNonEnumerable(() => webgpu.GPUDevice), + GPUQueue: webGPUNonEnumerable(() => webgpu.GPUQueue), + GPUBuffer: webGPUNonEnumerable(() => webgpu.GPUBuffer), + GPUBufferUsage: webGPUNonEnumerable(() => webgpu.GPUBufferUsage), + GPUMapMode: webGPUNonEnumerable(() => webgpu.GPUMapMode), + GPUTextureUsage: webGPUNonEnumerable(() => webgpu.GPUTextureUsage), + GPUTexture: webGPUNonEnumerable(() => webgpu.GPUTexture), + GPUTextureView: webGPUNonEnumerable(() => webgpu.GPUTextureView), + GPUSampler: webGPUNonEnumerable(() => webgpu.GPUSampler), + GPUBindGroupLayout: webGPUNonEnumerable(() => webgpu.GPUBindGroupLayout), + GPUPipelineLayout: webGPUNonEnumerable(() => webgpu.GPUPipelineLayout), + GPUBindGroup: webGPUNonEnumerable(() => webgpu.GPUBindGroup), + GPUShaderModule: webGPUNonEnumerable(() => webgpu.GPUShaderModule), + GPUShaderStage: webGPUNonEnumerable(() => webgpu.GPUShaderStage), + GPUComputePipeline: webGPUNonEnumerable(() => webgpu.GPUComputePipeline), + GPURenderPipeline: webGPUNonEnumerable(() => webgpu.GPURenderPipeline), + GPUColorWrite: webGPUNonEnumerable(() => webgpu.GPUColorWrite), + GPUCommandEncoder: webGPUNonEnumerable(() => webgpu.GPUCommandEncoder), + GPURenderPassEncoder: webGPUNonEnumerable(() => webgpu.GPURenderPassEncoder), + GPUComputePassEncoder: webGPUNonEnumerable(() => + webgpu.GPUComputePassEncoder + ), + GPUCommandBuffer: webGPUNonEnumerable(() => webgpu.GPUCommandBuffer), + GPURenderBundleEncoder: webGPUNonEnumerable(() => + webgpu.GPURenderBundleEncoder + ), + GPURenderBundle: webGPUNonEnumerable(() => webgpu.GPURenderBundle), + GPUQuerySet: webGPUNonEnumerable(() => webgpu.GPUQuerySet), + GPUError: webGPUNonEnumerable(() => webgpu.GPUError), + GPUValidationError: webGPUNonEnumerable(() => webgpu.GPUValidationError), + GPUOutOfMemoryError: webGPUNonEnumerable(() => webgpu.GPUOutOfMemoryError), +}; class Navigator { constructor() { @@ -190,7 +229,49 @@ 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, + enumerable: true, + get() { + webidl.assertBranded(this, NavigatorPrototype); + loadWebGPU(); + return webgpu.gpu; + }, + }, hardwareConcurrency: { configurable: true, enumerable: true, @@ -251,6 +332,15 @@ class WorkerNavigator { const workerNavigator = webidl.createBranded(WorkerNavigator); ObjectDefineProperties(WorkerNavigator.prototype, { + gpu: { + configurable: true, + enumerable: true, + get() { + webidl.assertBranded(this, WorkerNavigatorPrototype); + loadWebGPU(); + return webgpu.gpu; + }, + }, hardwareConcurrency: { configurable: true, enumerable: true, |