docs.rodeo

MDN Web Docs mirror

GPUDevice: createBindGroup() method

{{APIRef("WebGPU API")}} {{SeeCompatTable}} {{SecureContext_Header}} {{AvailableInWorkers}} 

The createBindGroup() method of the {{domxref("GPUDevice")}}  interface creates a {{domxref("GPUBindGroup")}}  based on a {{domxref("GPUBindGroupLayout")}}  that defines a set of resources to be bound together in a group and how those resources are used in shader stages.

Syntax

createBindGroup(descriptor)

Parameters

GPUBufferBinding objects

A GPUBufferBinding object can contain the following properties:

Return value

A {{domxref("GPUBindGroup")}}  object instance.

Validation

The following criteria must be met when calling createBindGroup(), otherwise a {{domxref("GPUValidationError")}}  is generated and an invalid {{domxref("GPUBindGroup")}}  object is returned:

Examples

[!NOTE] The WebGPU samples feature many more examples.

Basic example

Our basic compute demo shows an example of creating a bind group layout and then using that as a template when creating a bind group.

// ...

const bindGroupLayout = device.createBindGroupLayout({
  entries: [
    {
      binding: 0,
      visibility: GPUShaderStage.COMPUTE,
      buffer: {
        type: "storage",
      },
    },
  ],
});

const bindGroup = device.createBindGroup({
  layout: bindGroupLayout,
  entries: [
    {
      binding: 0,
      resource: {
        buffer: output,
      },
    },
  ],
});

// ...

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN