files/en-us/web/api/gpudevice/createbindgroup/index.md
{{APIRef("WebGPU API")}}{{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.
createBindGroup(descriptor)
descriptor
entries
layout. Each entry object has the following properties:
binding
binding value of a corresponding {{domxref("GPUBindGroupLayout")}} entry. In addition, it matches the n index value of the corresponding @binding(n) attribute in the shader ({{domxref("GPUShaderModule")}}) used in the related pipeline.resource
GPUBufferBinding: Wraps a {{domxref("GPUBuffer")}}; see GPUBufferBinding objects for a definition.GPUBufferBinding, provided the default offset and size values are being used.GPUExternalTexture provided it is compatible (a 2D format with a single subresource, that is, dimension: "2d").GPUTextureView, provided a default view is desired. When used in this context, GPUTexture is equivalent to a GPUTextureView object created using a {{domxref("GPUTexture.createView()")}} call with no argument specified.label {{optional_inline}}
layout
entries of this bind group will conform to.A GPUBufferBinding object can contain the following properties:
buffer
offset {{optional_inline}}
buffer to the beginning of the range exposed to the shader by the buffer binding. If omitted, offset defaults to 0.size {{optional_inline}}
size will be the range starting at offset and ending at the end of the buffer. If both offset and size are omitted, the entire buffer is exposed to the shader.A {{domxref("GPUBindGroup")}} object instance.
The following criteria must be met when calling createBindGroup(), otherwise a {{domxref("GPUValidationError")}} is generated and an invalid {{domxref("GPUBindGroup")}} object is returned:
layout {{domxref("GPUBindGroupLayout")}} equals the number of entry objects in entries.layout {{domxref("GPUBindGroupLayout")}}, the corresponding entry object in entries binds the correct resource type. For example, a buffer resource layout object has a GPUBufferBinding object specified in the corresponding binding.buffer:
offset and size) contained inside it completely, with a non-zero size.buffer resource layout's minBindingSize.type is "uniform":
usage that includes GPUBufferUsage.UNIFORM.maxUniformBufferBindingSize {{domxref("GPUSupportedLimits", "limit", "", "nocode")}}.GPUBufferBinding offset is a multiple of the {{domxref("GPUDevice")}}'s minUniformBufferOffsetAlignment {{domxref("GPUSupportedLimits", "limit", "", "nocode")}}.type is "storage" or "read-only-storage":
usage that includes GPUBufferUsage.STORAGE.maxStorageBufferBindingSize {{domxref("GPUSupportedLimits", "limit", "", "nocode")}}.GPUBufferBinding offset is a multiple of the {{domxref("GPUDevice")}}'s minStorageBufferOffsetAlignment {{domxref("GPUSupportedLimits", "limit", "", "nocode")}}.storageTexture, the corresponding bound {{domxref("GPUTextureView")}}:
dimension equal to the resource layout object's viewDimension (see {{domxref("GPUTexture.createView()")}} for more details of a texture view's settings).format equal to the resource layout object's sampleType.mipLevelCount equal to 1.usage that includes GPUTextureUsage.STORAGE_BINDING.texture, the corresponding bound {{domxref("GPUTextureView")}}:
dimension equal to the resource layout object's viewDimension (see {{domxref("GPUTexture.createView()")}} for more details of a texture view's settings).format compatible with the resource layout object's sampleType.usage that includes GPUTextureUsage.TEXTURE_BINDING.sampleCount greater than 1 if the resource layout object's multisampled property is true, or equal to 1 if it is false.[!NOTE] The WebGPU samples feature many more examples.
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}}
{{Compat}}