macro_rules! buffer {
{ @buffertype STORAGE } => { ... };
{ @buffertype UNIFORM } => { ... };
{ $struct:ident as $( $usage:ident )|+ } => { ... };
{ $struct:ident < $inner:ty > as $storageuniform:ident $( | $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.
If omitted, the internal type will default to u8, so you can initialize
the buffer using a number of bytes manually.
You also need to specify the
wgpu::BufferUsages,
but note that it requires either STORAGE or UNIFORM as the first usage.
buffer! { MatrixBuffer <SomeMatrixStructYouDefinedBefore> as UNIFORM | COPY_DST }
let buffer: MatrixBuffer = render_context.new_buffer(1);
queue.write_buffer(&buffer, 0, &[1, 2, 3, ..]);