Expand description
Bind groups bind buffers, textures, and samplers into a shader-visible layout.
§Overview
- Create a
BindGroupLayoutthat matches your WGSL@group/@bindingdeclarations. - Populate GPU resources and build the concrete [
wgpu::BindGroup]. - Set the bind group inside a render or compute pass.
§Example: PBR material
use wde_wgpu::{
bind_group::*,
buffer::{Buffer, BufferUsage},
instance::RenderInstanceData,
render_pipeline::ShaderStages,
texture::{Texture, TextureFormat, TextureUsages},
};
let uniform_buffer = Buffer::new(instance, "material-uniform", 64, BufferUsage::UNIFORM, None);
let albedo = Texture::new(instance, "albedo", (512, 512), TextureFormat::Rgba8Unorm, TextureUsages::TEXTURE_BINDING, 1, 1);
let normal = Texture::new(instance, "normal", (512, 512), TextureFormat::Rgba8Unorm, TextureUsages::TEXTURE_BINDING, 1, 1);
let layout = BindGroupLayout::new("material-layout", |builder| {
builder.add_buffer(0, ShaderStages::FRAGMENT, BufferBindingType::Uniform);
builder.add_texture_view(1, ShaderStages::FRAGMENT);
builder.add_texture_sampler(2, ShaderStages::FRAGMENT);
builder.add_texture_view(3, ShaderStages::FRAGMENT);
builder.add_texture_sampler(4, ShaderStages::FRAGMENT);
});
let wgpu_layout = layout.build(instance);
let bind_group = BindGroup::build(
"material-bind-group",
instance,
&wgpu_layout,
&vec![
BindGroup::buffer(0, &uniform_buffer),
BindGroup::texture_view(1, &albedo),
BindGroup::texture_sampler(2, &albedo),
BindGroup::texture_view(3, &normal),
BindGroup::texture_sampler(4, &normal),
],
);
(wgpu_layout, bind_group)Depth-only layouts follow the same pattern using add_depth_texture_view and
add_depth_texture_sampler.
§Tips
- Keep per-frame data in group 0, per-material in group 1, and per-object in group 2 to minimize rebinding during draws.
- The order of
set_bind_groupson pipelines must match the order of layouts you provide here.
Structs§
- Bind
Group - Bind
Group Builder - Structure for a bind group.
- Bind
Group Layout - Structure for a bind group layout. Stores the layout description and builder data.
- Bind
Group Layout Builder - Builder for a bind group layout.
Type Aliases§
- Bind
Group Entry - The wgpu bind group entry type.
- Buffer
Binding Type - The buffer binding type.
- Wgpu
Bind Group Layout - The wgpu bind group layout type.