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
/// Internal namespace.
mod private
{
use crate::*;
/// Describes a buffer to be created and initialized with data.
pub struct BufferInitDescriptor< 'a, T : AsBytes >
{
/// A reference to the data that will be copied into the buffer.
pub data : &'a T,
/// A bitmask that specifies how the buffer will be used, such as for vertex data,
/// index data, or uniform data. This is a crucial hint to the GPU driver for
/// optimizing memory layout.
pub usage : u32,
/// An optional label for the buffer. This can be helpful for debugging and
/// performance tracing in tools like the browser's GPU debugger.
/// Defaults to `None`.
pub label : Option< &'a str >
}
impl< 'a, T : AsBytes > BufferInitDescriptor< 'a, T >
{
/// Creates a new `BufferInitDescriptor` with a given data reference and usage.
pub fn new( data : &'a T, usage : u32 ) -> Self
{
let label = None;
BufferInitDescriptor
{
data,
usage,
label
}
}
/// Sets an optional label for the buffer.
pub fn label( mut self, label : &'a str ) -> Self
{
self.label = Some( label );
self
}
/// Creates a `web_sys::GpuBuffer` from this descriptor.
pub fn create( &self, device : &web_sys::GpuDevice ) -> Result< web_sys::GpuBuffer, WebGPUError >
{
buffer::init( device, &self )
}
}
}
crate::mod_interface!
{
exposed use
{
BufferInitDescriptor
};
}