diff options
author | Leo Kettmeir <crowlkats@toaxl.com> | 2023-02-20 17:48:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-20 16:48:02 +0000 |
commit | a16c11c5d10052c688ba4c2eca09fd1a225e395a (patch) | |
tree | 34fb4b4fb028ca2c19a0d7059915f86a5d511540 /ext/webgpu/shader.rs | |
parent | 6915a9b7a701dde0e1078867961c9a91811c1850 (diff) |
refactor: move webgpu files to ext root (#17832)
Required for #17826
Diffstat (limited to 'ext/webgpu/shader.rs')
-rw-r--r-- | ext/webgpu/shader.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/ext/webgpu/shader.rs b/ext/webgpu/shader.rs new file mode 100644 index 000000000..242cb85ba --- /dev/null +++ b/ext/webgpu/shader.rs @@ -0,0 +1,45 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. + +use deno_core::error::AnyError; +use deno_core::op; +use deno_core::OpState; +use deno_core::Resource; +use deno_core::ResourceId; +use std::borrow::Cow; + +use super::error::WebGpuResult; + +pub(crate) struct WebGpuShaderModule(pub(crate) wgpu_core::id::ShaderModuleId); +impl Resource for WebGpuShaderModule { + fn name(&self) -> Cow<str> { + "webGPUShaderModule".into() + } +} + +#[op] +pub fn op_webgpu_create_shader_module( + state: &mut OpState, + device_rid: ResourceId, + label: Option<String>, + code: String, +) -> Result<WebGpuResult, AnyError> { + let instance = state.borrow::<super::Instance>(); + let device_resource = state + .resource_table + .get::<super::WebGpuDevice>(device_rid)?; + let device = device_resource.0; + + let source = wgpu_core::pipeline::ShaderModuleSource::Wgsl(Cow::from(code)); + + let descriptor = wgpu_core::pipeline::ShaderModuleDescriptor { + label: label.map(Cow::from), + shader_bound_checks: wgpu_types::ShaderBoundChecks::default(), + }; + + gfx_put!(device => instance.device_create_shader_module( + device, + &descriptor, + source, + () + ) => state, WebGpuShaderModule) +} |