Module bind_group

Module bind_group 

Source
Expand description

Bind groups bind buffers, textures, and samplers into a shader-visible layout.

§Overview

  1. Create a BindGroupLayout that matches your WGSL @group / @binding declarations.
  2. Populate GPU resources and build the concrete [wgpu::BindGroup].
  3. 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_groups on pipelines must match the order of layouts you provide here.

Structs§

BindGroup
BindGroupBuilder
Structure for a bind group.
BindGroupLayout
Structure for a bind group layout. Stores the layout description and builder data.
BindGroupLayoutBuilder
Builder for a bind group layout.

Type Aliases§

BindGroupEntry
The wgpu bind group entry type.
BufferBindingType
The buffer binding type.
WgpuBindGroupLayout
The wgpu bind group layout type.