mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
a16c11c5d1
Required for #17826
45 lines
1.2 KiB
Rust
45 lines
1.2 KiB
Rust
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
|
|
use deno_core::error::AnyError;
|
|
use deno_core::op;
|
|
use deno_core::OpState;
|
|
use deno_core::Resource;
|
|
use deno_core::ResourceId;
|
|
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<str> {
|
|
"webGPUShaderModule".into()
|
|
}
|
|
}
|
|
|
|
#[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
|
|
.get::<super::WebGpuDevice>(device_rid)?;
|
|
let device = device_resource.0;
|
|
|
|
let source = wgpu_core::pipeline::ShaderModuleSource::Wgsl(Cow::from(code));
|
|
|
|
let descriptor = wgpu_core::pipeline::ShaderModuleDescriptor {
|
|
label: label.map(Cow::from),
|
|
shader_bound_checks: wgpu_types::ShaderBoundChecks::default(),
|
|
};
|
|
|
|
gfx_put!(device => instance.device_create_shader_module(
|
|
device,
|
|
&descriptor,
|
|
source,
|
|
()
|
|
) => state, WebGpuShaderModule)
|
|
}
|