Used to handle all inputs data sent to the GPU.
In WebGPU, data (buffers, textures or samplers, called bindings) are organised by bind groups, containing those bindings.

Bindings

A BindGroup is responsible for creating each BufferBinding GPUBuffer and then the GPUBindGroup and GPUBindGroupLayout that are used to create GPUComputePipeline or GPURenderPipeline.
Those are generally automatically created by the Material using this BindGroup. If you need to manually create them, you will have to call its createBindGroup() method

Samplers and textures

A BindGroup is best suited to handle GPUBuffer only bindings. If you need to handle GPUSampler, a GPUTexture or a GPUExternalTexture, you should use a TextureBindGroup instead.

Updating a GPUBindGroup or GPUBindGroupLayout

Each time one of the binding resource changes, its bindGroup will be recreated (usually, when a GPUTexture is uploaded).
Each time one of the binding resource layout changes, its bindGroupLayout and bindGroup will be recreated, and the GPUComputePipeline or GPURenderPipeline will be recreated as well.

Example

// set our main GPUCurtains instance
const gpuCurtains = new GPUCurtains({
container: '#canvas' // selector of our WebGPU canvas container
})

// set the GPU device
// note this is asynchronous
await gpuCurtains.setDevice()

const bindGroup = new BindGroup(gpuCurtains, {
label: 'My bind group',
uniforms: {
params: {
visibility: ['fragment'],
struct: {
opacity: {
value: 'f32',
value: 1,
},
mousePosition: {
value: 'vec2f',
value: new Vec2(),
},
},
},
},
})

// create the GPU buffer, bindGroupLayout and bindGroup
bindGroup.createBindGroup()

Hierarchy (view full)

Constructors

Properties

type: string

The type of the BindGroup

uuid: string

The universal unique id of the BindGroup

renderer: Renderer

The Renderer used

Options used to create this BindGroup

index: number

Index of this BindGroup, used to link struct in the shaders

List of bindings (buffers, texture, etc.) handled by this BindGroup

Our BindGroup entries objects

bindGroupLayout: GPUBindGroupLayout

Our BindGroupGPUBindGroupLayout

bindGroup: GPUBindGroup

Our BindGroup GPUBindGroup

layoutCacheKey: string

A cache key allowing to get / set GPUBindGroupLayout from the device manager map cache.

pipelineCacheKey: string

A cache key allowing the PipelineManager to compare RenderPipelineEntry bind groups content.

needsPipelineFlush: boolean

Flag indicating whether we need to flush and recreate the pipeline using this BindGroup s

consumers: Set<string>

A Set to store this BindGroup consumers (Material uuid)

Accessors

Methods

  • Fill in our entries bindGroupLayout and bindGroup arrays with the correct binding resources. For buffer struct, create a GPUBuffer first if needed

    Returns void