macro_rules! buffer {
{ @searchbinding $struct:ident ; } => { ... };
{ @searchbinding $struct:ident ; $first:ident $( $rest:ident )* } => { ... };
{ @trybinding $struct:ident ; STORAGE } => { ... };
{ @trybinding $struct:ident ; UNIFORM } => { ... };
{ @trybinding $struct:ident ; $other:ident } => { ... };
{ $struct:ident as $( $usage:ident )|+ } => { ... };
{ $struct:ident < $inner:ty > as $( $usage:ident )|+ } => { ... };
}Expand description
Define a storage buffer, with an optional internal type/struct to align its length with.
For example, if the buffer stores an array of f32 matrices, you could set
the internal type to [f32; 16], and the buffer descriptor will initialize
a multiple of the internal type’s size. This doesn’t validate the data
written in any way.
If omitted, the internal type will default to u8, so you can initialize
the buffer using a number of bytes manually.
Not all buffers need to be used in bind groups, for example vertex/index
buffers. If you don’t specify either STORAGE or UNIFORM as one of the
wgpu::BufferUsages,
you won’t be able to put it in a bind group. Also note only one of those is
allowed at a time, can’t have a uniform that’s also a storage.
buffer! { MatrixBuffer <SomeMatrixStructYouDefinedBefore> as VERTEX | COPY_DST }
let buffer: MatrixBuffer = render_context.new_buffer(16);
queue.write_buffer(&buffer, 0, &[1, 2, 3, ..]);