1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-12 02:27:46 -05:00
denoland-deno/ext/webgpu/shader.rs

46 lines
1.2 KiB
Rust
Raw Normal View History

// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use deno_core::error::AnyError;
use deno_core::op;
2022-07-19 20:22:26 -04:00
use deno_core::OpState;
use deno_core::Resource;
use deno_core::ResourceId;
use std::borrow::Cow;
use super::error::WebGpuResult;
2021-03-25 14:17:37 -04:00
pub(crate) struct WebGpuShaderModule(pub(crate) wgpu_core::id::ShaderModuleId);
impl Resource for WebGpuShaderModule {
fn name(&self) -> Cow<str> {
"webGPUShaderModule".into()
}
}
2022-07-19 20:22:26 -04:00
#[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
2022-07-19 20:22:26 -04:00
.get::<super::WebGpuDevice>(device_rid)?;
let device = device_resource.0;
2022-07-19 20:22:26 -04:00
let source = wgpu_core::pipeline::ShaderModuleSource::Wgsl(Cow::from(code));
let descriptor = wgpu_core::pipeline::ShaderModuleDescriptor {
2022-07-19 20:22:26 -04:00
label: label.map(Cow::from),
2022-01-24 17:47:05 -05:00
shader_bound_checks: wgpu_types::ShaderBoundChecks::default(),
};
gfx_put!(device => instance.device_create_shader_module(
device,
&descriptor,
source,
2023-01-30 09:14:16 -05:00
()
) => state, WebGpuShaderModule)
}