home/ atoms/ webgpu-bind-group

A bind group links GPU resources to shader binding points and must be created from a layout and set before each draw or dispatch call

A bind group is a collection of GPU resources (uniform buffers, storage buffers, textures, samplers) bundled together and made accessible to shaders via @group(n) @binding(m) declarations in WGSL. Created with device.createBindGroup({ layout, entries }) where each entry maps a binding index to a resource. The layout can be inferred from the pipeline with getBindGroupLayout(0) or declared explicitly. Bind groups are immutable after creation — you cannot swap a resource in, but you can change the buffer’s contents. During rendering or compute, pass.setBindGroup(index, group) activates the group.

Examples

const bindGroup = device.createBindGroup({
  layout: cellPipeline.getBindGroupLayout(0),
  entries: [{ binding: 0, resource: { buffer: uniformBuffer } }],
});
pass.setBindGroup(0, bindGroup);

Assessment

If you update a uniform buffer’s contents via writeBuffer after creating a bind group that references it, does the bind group need to be recreated? Explain why or why not.

“immutable handle. You can't change the resources that a bind group points to aft”
corpus · your-first-webgpu-app-google-codelab · chunk 10