diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2023-12-09 01:19:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-09 01:19:16 +0100 |
commit | 393abed3873d83019feb5bcebb10a6929133862a (patch) | |
tree | c346e6d628e6b037fb8f881a70ca2ae6f70692b6 /runtime | |
parent | 123d9ea047a2e10803e260ebf00f31fcc98463ee (diff) |
feat: bring back WebGPU (#20812)
Signed-off-by: Leo Kettmeir <crowlkats@toaxl.com>
Co-authored-by: Kenta Moriuchi <moriken@kimamass.com>
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/Cargo.toml | 2 | ||||
-rw-r--r-- | runtime/build.rs | 1 | ||||
-rw-r--r-- | runtime/errors.rs | 1 | ||||
-rw-r--r-- | runtime/js/90_deno_ns.js | 5 | ||||
-rw-r--r-- | runtime/js/98_global_scope.js | 90 | ||||
-rw-r--r-- | runtime/lib.rs | 1 | ||||
-rw-r--r-- | runtime/snapshot.rs | 1 | ||||
-rw-r--r-- | runtime/web_worker.rs | 1 | ||||
-rw-r--r-- | runtime/worker.rs | 1 |
9 files changed, 102 insertions, 1 deletions
diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index b8c012f63..39d907a61 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -57,6 +57,7 @@ deno_kv.workspace = true deno_tls.workspace = true deno_url.workspace = true deno_web.workspace = true +deno_webgpu.workspace = true deno_webidl.workspace = true deno_websocket.workspace = true deno_webstorage.workspace = true @@ -88,6 +89,7 @@ deno_node.workspace = true deno_tls.workspace = true deno_url.workspace = true deno_web.workspace = true +deno_webgpu.workspace = true deno_webidl.workspace = true deno_websocket.workspace = true deno_webstorage.workspace = true diff --git a/runtime/build.rs b/runtime/build.rs index e0881836b..9975aecee 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -224,6 +224,7 @@ mod startup_snapshot { Default::default(), Default::default(), ), + deno_webgpu::deno_webgpu::init_ops_and_esm(), deno_fetch::deno_fetch::init_ops_and_esm::<Permissions>( Default::default(), ), diff --git a/runtime/errors.rs b/runtime/errors.rs index 2061a5e0b..c05e5bd62 100644 --- a/runtime/errors.rs +++ b/runtime/errors.rs @@ -167,6 +167,7 @@ pub fn get_nix_error_class(error: &nix::Error) -> &'static str { pub fn get_error_class_name(e: &AnyError) -> Option<&'static str> { deno_core::error::get_custom_error_class(e) + .or_else(|| deno_webgpu::error::get_error_class_name(e)) .or_else(|| deno_web::get_error_class_name(e)) .or_else(|| deno_webstorage::get_not_supported_error_class_name(e)) .or_else(|| deno_websocket::get_network_error_class_name(e)) 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, diff --git a/runtime/lib.rs b/runtime/lib.rs index 6a0a6569c..1a97a3376 100644 --- a/runtime/lib.rs +++ b/runtime/lib.rs @@ -18,6 +18,7 @@ pub use deno_node; pub use deno_tls; pub use deno_url; pub use deno_web; +pub use deno_webgpu; pub use deno_webidl; pub use deno_websocket; pub use deno_webstorage; diff --git a/runtime/snapshot.rs b/runtime/snapshot.rs index a0f0665b4..c2e8b0df2 100644 --- a/runtime/snapshot.rs +++ b/runtime/snapshot.rs @@ -203,6 +203,7 @@ pub fn create_runtime_snapshot( Default::default(), Default::default(), ), + deno_webgpu::deno_webgpu::init_ops_and_esm(), deno_fetch::deno_fetch::init_ops_and_esm::<Permissions>(Default::default()), deno_cache::deno_cache::init_ops_and_esm::<SqliteBackedCache>(None), deno_websocket::deno_websocket::init_ops_and_esm::<Permissions>( diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index 4244f1045..b669b5c2a 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -408,6 +408,7 @@ impl WebWorker { options.blob_store.clone(), Some(main_module.clone()), ), + deno_webgpu::deno_webgpu::init_ops_and_esm(), deno_fetch::deno_fetch::init_ops_and_esm::<PermissionsContainer>( deno_fetch::Options { user_agent: options.bootstrap.user_agent.clone(), diff --git a/runtime/worker.rs b/runtime/worker.rs index 2a7e82c54..0bfb9305c 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -307,6 +307,7 @@ impl MainWorker { options.blob_store.clone(), options.bootstrap.location.clone(), ), + deno_webgpu::deno_webgpu::init_ops_and_esm(), deno_fetch::deno_fetch::init_ops_and_esm::<PermissionsContainer>( deno_fetch::Options { user_agent: options.bootstrap.user_agent.clone(), |