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 /ext/webgpu/shader.rs | |
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 'ext/webgpu/shader.rs')
-rw-r--r-- | ext/webgpu/shader.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/ext/webgpu/shader.rs b/ext/webgpu/shader.rs new file mode 100644 index 000000000..a6850d55a --- /dev/null +++ b/ext/webgpu/shader.rs @@ -0,0 +1,55 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. + +use deno_core::error::AnyError; +use deno_core::op2; +use deno_core::OpState; +use deno_core::Resource; +use deno_core::ResourceId; +use std::borrow::Cow; +use std::rc::Rc; + +use super::error::WebGpuResult; + +pub(crate) struct WebGpuShaderModule( + pub(crate) super::Instance, + pub(crate) wgpu_core::id::ShaderModuleId, +); +impl Resource for WebGpuShaderModule { + fn name(&self) -> Cow<str> { + "webGPUShaderModule".into() + } + + fn close(self: Rc<Self>) { + let instance = &self.0; + gfx_select!(self.1 => instance.shader_module_drop(self.1)); + } +} + +#[op2] +#[serde] +pub fn op_webgpu_create_shader_module( + state: &mut OpState, + #[smi] device_rid: ResourceId, + #[string] label: Cow<str>, + #[string] code: Cow<str>, +) -> Result<WebGpuResult, AnyError> { + let instance = state.borrow::<super::Instance>(); + let device_resource = state + .resource_table + .get::<super::WebGpuDevice>(device_rid)?; + let device = device_resource.1; + + let source = wgpu_core::pipeline::ShaderModuleSource::Wgsl(code); + + let descriptor = wgpu_core::pipeline::ShaderModuleDescriptor { + label: Some(label), + shader_bound_checks: wgpu_types::ShaderBoundChecks::default(), + }; + + gfx_put!(device => instance.device_create_shader_module( + device, + &descriptor, + source, + () + ) => state, WebGpuShaderModule) +} |