2021-03-01 05:31:13 -05:00
|
|
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
use deno_core::error::AnyError;
|
2021-03-19 13:25:37 -04:00
|
|
|
use deno_core::ResourceId;
|
2021-03-01 05:31:13 -05:00
|
|
|
use deno_core::{OpState, Resource};
|
|
|
|
use serde::Deserialize;
|
|
|
|
use std::borrow::Cow;
|
|
|
|
|
2021-04-05 12:40:24 -04:00
|
|
|
use super::error::WebGpuResult;
|
2021-03-01 05:31:13 -05:00
|
|
|
|
2021-03-25 14:17:37 -04:00
|
|
|
pub(crate) struct WebGpuShaderModule(pub(crate) wgpu_core::id::ShaderModuleId);
|
|
|
|
impl Resource for WebGpuShaderModule {
|
2021-03-01 05:31:13 -05:00
|
|
|
fn name(&self) -> Cow<str> {
|
|
|
|
"webGPUShaderModule".into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CreateShaderModuleArgs {
|
2021-03-19 13:25:37 -04:00
|
|
|
device_rid: ResourceId,
|
2021-03-01 05:31:13 -05:00
|
|
|
label: Option<String>,
|
2021-08-24 07:29:42 -04:00
|
|
|
code: String,
|
2021-03-01 05:31:13 -05:00
|
|
|
_source_map: Option<()>, // not yet implemented
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn op_webgpu_create_shader_module(
|
|
|
|
state: &mut OpState,
|
|
|
|
args: CreateShaderModuleArgs,
|
2021-08-24 07:29:42 -04:00
|
|
|
_: (),
|
2021-04-05 12:40:24 -04:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 05:31:13 -05:00
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
let device_resource = state
|
|
|
|
.resource_table
|
2021-08-15 07:29:19 -04:00
|
|
|
.get::<super::WebGpuDevice>(args.device_rid)?;
|
2021-03-01 05:31:13 -05:00
|
|
|
let device = device_resource.0;
|
|
|
|
|
2021-08-24 07:29:42 -04:00
|
|
|
let source =
|
|
|
|
wgpu_core::pipeline::ShaderModuleSource::Wgsl(Cow::from(args.code));
|
2021-03-01 05:31:13 -05:00
|
|
|
|
|
|
|
let descriptor = wgpu_core::pipeline::ShaderModuleDescriptor {
|
|
|
|
label: args.label.map(Cow::from),
|
|
|
|
};
|
|
|
|
|
2021-05-03 10:42:59 -04:00
|
|
|
gfx_put!(device => instance.device_create_shader_module(
|
2021-03-01 05:31:13 -05:00
|
|
|
device,
|
|
|
|
&descriptor,
|
|
|
|
source,
|
|
|
|
std::marker::PhantomData
|
2021-05-03 10:42:59 -04:00
|
|
|
) => state, WebGpuShaderModule)
|
2021-03-01 05:31:13 -05:00
|
|
|
}
|