2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2021-03-01 11:31:13 +01:00
|
|
|
|
|
|
|
use deno_core::error::AnyError;
|
2022-03-14 23:14:15 +05:30
|
|
|
use deno_core::op;
|
2022-07-20 01:22:26 +01:00
|
|
|
use deno_core::OpState;
|
|
|
|
use deno_core::Resource;
|
2021-03-19 22:55:37 +05:30
|
|
|
use deno_core::ResourceId;
|
2021-03-01 11:31:13 +01:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
2021-04-05 18:40:24 +02:00
|
|
|
use super::error::WebGpuResult;
|
2021-03-01 11:31:13 +01:00
|
|
|
|
2021-03-26 03:17:37 +09:00
|
|
|
pub(crate) struct WebGpuShaderModule(pub(crate) wgpu_core::id::ShaderModuleId);
|
|
|
|
impl Resource for WebGpuShaderModule {
|
2021-03-01 11:31:13 +01:00
|
|
|
fn name(&self) -> Cow<str> {
|
|
|
|
"webGPUShaderModule".into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-20 01:22:26 +01:00
|
|
|
#[op]
|
|
|
|
pub fn op_webgpu_create_shader_module(
|
|
|
|
state: &mut OpState,
|
2021-03-19 22:55:37 +05:30
|
|
|
device_rid: ResourceId,
|
2021-03-01 11:31:13 +01:00
|
|
|
label: Option<String>,
|
2021-08-24 13:29:42 +02:00
|
|
|
code: String,
|
2021-04-05 18:40:24 +02:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
2021-03-01 11:31:13 +01:00
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
let device_resource = state
|
|
|
|
.resource_table
|
2022-07-20 01:22:26 +01:00
|
|
|
.get::<super::WebGpuDevice>(device_rid)?;
|
2021-03-01 11:31:13 +01:00
|
|
|
let device = device_resource.0;
|
|
|
|
|
2022-07-20 01:22:26 +01:00
|
|
|
let source = wgpu_core::pipeline::ShaderModuleSource::Wgsl(Cow::from(code));
|
2021-03-01 11:31:13 +01:00
|
|
|
|
|
|
|
let descriptor = wgpu_core::pipeline::ShaderModuleDescriptor {
|
2022-07-20 01:22:26 +01:00
|
|
|
label: label.map(Cow::from),
|
2022-01-24 23:47:05 +01:00
|
|
|
shader_bound_checks: wgpu_types::ShaderBoundChecks::default(),
|
2021-03-01 11:31:13 +01:00
|
|
|
};
|
|
|
|
|
2021-05-03 16:42:59 +02:00
|
|
|
gfx_put!(device => instance.device_create_shader_module(
|
2021-03-01 11:31:13 +01:00
|
|
|
device,
|
|
|
|
&descriptor,
|
|
|
|
source,
|
2023-01-30 15:14:16 +01:00
|
|
|
()
|
2021-05-03 16:42:59 +02:00
|
|
|
) => state, WebGpuShaderModule)
|
2021-03-01 11:31:13 +01:00
|
|
|
}
|