From 3ab68bd0a2aff6df12388f2c3b5ed7ae3333a6ca Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Thu, 20 Jan 2022 15:23:53 +0100 Subject: revert(#13402): experiment: wgpu sync (#13439) --- ext/webgpu/shader.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 ext/webgpu/shader.rs (limited to 'ext/webgpu/shader.rs') diff --git a/ext/webgpu/shader.rs b/ext/webgpu/shader.rs new file mode 100644 index 000000000..2477beceb --- /dev/null +++ b/ext/webgpu/shader.rs @@ -0,0 +1,51 @@ +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. + +use deno_core::error::AnyError; +use deno_core::ResourceId; +use deno_core::{OpState, Resource}; +use serde::Deserialize; +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 { + "webGPUShaderModule".into() + } +} + +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct CreateShaderModuleArgs { + device_rid: ResourceId, + label: Option, + code: String, + _source_map: Option<()>, // not yet implemented +} + +pub fn op_webgpu_create_shader_module( + state: &mut OpState, + args: CreateShaderModuleArgs, + _: (), +) -> Result { + let instance = state.borrow::(); + let device_resource = state + .resource_table + .get::(args.device_rid)?; + let device = device_resource.0; + + let source = + wgpu_core::pipeline::ShaderModuleSource::Wgsl(Cow::from(args.code)); + + let descriptor = wgpu_core::pipeline::ShaderModuleDescriptor { + label: args.label.map(Cow::from), + }; + + gfx_put!(device => instance.device_create_shader_module( + device, + &descriptor, + source, + std::marker::PhantomData + ) => state, WebGpuShaderModule) +} -- cgit v1.2.3