2024-04-02 18:36:04 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2021-09-03 17:23:35 +00:00
|
|
|
|
|
|
|
use deno_core::error::AnyError;
|
2023-10-04 04:25:56 +00:00
|
|
|
use deno_core::op2;
|
2022-03-19 05:31:10 +00:00
|
|
|
use deno_core::OpState;
|
|
|
|
use deno_core::Resource;
|
2021-09-03 17:23:35 +00:00
|
|
|
use deno_core::ResourceId;
|
|
|
|
use std::borrow::Cow;
|
2023-03-03 17:18:01 +00:00
|
|
|
use std::rc::Rc;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
|
|
|
use super::error::WebGpuResult;
|
|
|
|
|
2023-03-03 17:18:01 +00:00
|
|
|
pub(crate) struct WebGpuShaderModule(
|
|
|
|
pub(crate) super::Instance,
|
|
|
|
pub(crate) wgpu_core::id::ShaderModuleId,
|
|
|
|
);
|
2021-09-03 17:23:35 +00:00
|
|
|
impl Resource for WebGpuShaderModule {
|
|
|
|
fn name(&self) -> Cow<str> {
|
|
|
|
"webGPUShaderModule".into()
|
|
|
|
}
|
2023-03-03 17:18:01 +00:00
|
|
|
|
|
|
|
fn close(self: Rc<Self>) {
|
2024-08-06 21:17:47 +00:00
|
|
|
self.0.shader_module_drop(self.1);
|
2023-03-03 17:18:01 +00:00
|
|
|
}
|
2021-09-03 17:23:35 +00:00
|
|
|
}
|
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2022-03-24 17:20:10 +00:00
|
|
|
pub fn op_webgpu_create_shader_module(
|
|
|
|
state: &mut OpState,
|
2023-10-04 04:25:56 +00:00
|
|
|
#[smi] device_rid: ResourceId,
|
|
|
|
#[string] label: Cow<str>,
|
|
|
|
#[string] code: Cow<str>,
|
2021-09-03 17:23:35 +00:00
|
|
|
) -> Result<WebGpuResult, AnyError> {
|
|
|
|
let instance = state.borrow::<super::Instance>();
|
|
|
|
let device_resource = state
|
|
|
|
.resource_table
|
2022-03-24 17:20:10 +00:00
|
|
|
.get::<super::WebGpuDevice>(device_rid)?;
|
2023-03-03 17:18:01 +00:00
|
|
|
let device = device_resource.1;
|
2021-09-03 17:23:35 +00:00
|
|
|
|
2023-10-04 04:25:56 +00:00
|
|
|
let source = wgpu_core::pipeline::ShaderModuleSource::Wgsl(code);
|
2021-09-03 17:23:35 +00:00
|
|
|
|
|
|
|
let descriptor = wgpu_core::pipeline::ShaderModuleDescriptor {
|
2023-10-04 04:25:56 +00:00
|
|
|
label: Some(label),
|
2021-09-28 15:25:33 +00:00
|
|
|
shader_bound_checks: wgpu_types::ShaderBoundChecks::default(),
|
2021-09-03 17:23:35 +00:00
|
|
|
};
|
|
|
|
|
2024-08-06 21:17:47 +00:00
|
|
|
gfx_put!(instance.device_create_shader_module(
|
2021-09-03 17:23:35 +00:00
|
|
|
device,
|
|
|
|
&descriptor,
|
|
|
|
source,
|
2024-01-29 14:37:57 +00:00
|
|
|
None
|
2021-09-03 17:23:35 +00:00
|
|
|
) => state, WebGpuShaderModule)
|
|
|
|
}
|