Skip to main content

bind_group

Macro bind_group 

Source
macro_rules! bind_group {
    { $struct:ident [
        $( $num:tt $name:ident @ $( $shaderstage:ident )|+ => $buffer:ty /* $( as $bufferinner:ty )? */ ),* $(,)?
    ] } => { ... };
}
Expand description

Define a bind group, with internal buffer types (and their field names), and their shader visibility (see wgpu::ShaderStages). All members are taken ownership of in the struct - good to note that they are reference-counted (Arc’d) by wgpu internally.

You need to number each field, tuples are used and counting is hard in macros.

bind_group! { StuffBindGroup [
    0 matrix_buffer @ VERTEX | COMPUTE => MatrixBuffer,
    1 something_else_buffer @ FRAGMENT => SomethingElseBuffer,
    2 another_matrix_buffer @ VERTEX_FRAGMENT => MatrixBuffer,
] }

// TODO: Create buffers (see buffer docs)
let bind_group: StuffBindGroup = render_context.new_bind_group((matrix_buffer, ..));

queue.write_buffer(&bind_group.something_else_buffer, 0, &[1, 2, 3, ..]);