1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/// Internal namespace.
mod private
{
use crate::*;
/// Describes the configuration for creating a WebGPU compute pipeline.
#[ derive( Clone ) ]
pub struct ComputePipelineDescriptor< 'a >
{
/// A `GpuProgrammableStage` that defines the compute shader and its entry point.
/// This is the core part of the compute pipeline descriptor.
compute : web_sys::GpuProgrammableStage,
/// An optional label for the compute pipeline, which can be helpful for debugging and
/// performance tracing.
///
/// Defaults to `None`.
label : Option< &'a str >,
/// The `GpuPipelineLayout` for the compute pipeline. This layout specifies the
/// bind groups that the pipeline will use. If this is `None`, a default, automatically
/// generated layout is used.
///
/// Defaults to 'auto'.
layout : Option< &'a web_sys::GpuPipelineLayout >,
}
impl< 'a > ComputePipelineDescriptor< 'a >
{
/// Creates a new `ComputePipelineDescriptor` with a given compute stage.
pub fn new< T : Into< web_sys::GpuProgrammableStage > >( compute : T ) -> Self
{
let label = None;
let layout = None;
let compute = compute.into();
ComputePipelineDescriptor
{
compute,
label,
layout
}
}
/// Sets an optional label for the compute pipeline.
pub fn label( mut self, label : &'a str ) -> Self
{
self.label = Some( label );
self
}
/// Sets the `GpuPipelineLayout` for the compute pipeline.
pub fn layout( mut self, layout : &'a web_sys::GpuPipelineLayout ) -> Self
{
self.layout = Some( layout );
self
}
/// Creates a `web_sys::GpuComputePipeline` synchronously.
pub fn create( self, device : &web_sys::GpuDevice ) -> web_sys::GpuComputePipeline
{
compute_pipeline::create( device, &self.into() )
}
/// Creates a `web_sys::GpuComputePipeline` asynchronously.
pub async fn create_async( self, device : &web_sys::GpuDevice ) -> Result< web_sys::GpuComputePipeline, WebGPUError >
{
compute_pipeline::create_async( device, &self.into() ).await
}
}
impl From< ComputePipelineDescriptor< '_ > > for web_sys::GpuComputePipelineDescriptor
{
fn from( value: ComputePipelineDescriptor< '_ > ) -> Self
{
let layout =
if let Some( l ) = value.layout
{
l.into()
}
else
{
"auto".into()
};
let desc = web_sys::GpuComputePipelineDescriptor::new( &layout, &value.compute );
if let Some( v ) = value.label { desc.set_label( v ); }
desc
}
}
}
crate::mod_interface!
{
exposed use
{
ComputePipelineDescriptor
};
}