Limited availability
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
The createBindGroup()
method of the GPUDevice
interface creates a GPUBindGroup
based on a 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)
Parameters
descriptor
An object containing the following properties:
entries
An array of entry objects describing the resources to expose to the shader. There will be one for each corresponding entry described by the GPUBindGroupLayout
referenced in layout
. Each entry object has the following properties:
binding
A number representing a unique identifier for this resource binding, which matches the binding
value of a corresponding GPUBindGroupLayout
entry. In addition, it matches the n
index value of the corresponding @binding(n)
attribute in the shader (GPUShaderModule
) used in the related pipeline.
resource
The resource to bind. This can be one of the following:
GPUBufferBinding
(which wraps a GPUBuffer
; see GPUBufferBinding objects for a definition)GPUExternalTexture
GPUSampler
GPUTextureView
; can be used in place of a GPUExternalTexture
provided it is compatible (a 2D format with a single subresource, that is, dimension: "2d"
).label
Optional
A string providing a label that can be used to identify the object, for example in GPUError
messages or console warnings.
layout
The GPUBindGroupLayout
that the entries
of this bind group will conform to.
A GPUBufferBinding
object can contain the following properties:
buffer
The GPUBuffer
object you want to bind.
offset
Optional
The offset, in bytes, from the beginning of the buffer
to the beginning of the range exposed to the shader by the buffer binding. If omitted, offset
defaults to 0.
size
Optional
The size, in bytes, of the buffer binding. If omitted, 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 GPUBindGroup
object instance.
The following criteria must be met when calling createBindGroup()
, otherwise a GPUValidationError
is generated and an invalid GPUBindGroup
object is returned:
layout
GPUBindGroupLayout
equals the number of entry objects in entries
.layout
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
:
GPUBuffer
:
offset
and size
) contained inside it completely, with a non-zero size.buffer
resource layout's minBindingSize
.type
is "uniform"
:
GPUBuffer
has a usage
that includes GPUBufferUsage.UNIFORM
.GPUDevice
's maxUniformBufferBindingSize
limit.GPUBufferBinding
offset
is a multiple of the GPUDevice
's minUniformBufferOffsetAlignment
limit.type
is "storage"
or "read-only-storage"
:
GPUBuffer
has a usage
that includes GPUBufferUsage.STORAGE
.GPUDevice
's maxStorageBufferBindingSize
limit.GPUBufferBinding
offset
is a multiple of the GPUDevice
's minStorageBufferOffsetAlignment
limit.storageTexture
, the corresponding bound GPUTextureView
:
dimension
equal to the resource layout object's viewDimension
(see GPUTexture.createView()
for more details of a texture view's settings).format
equal to the resource layout object's sampleType
.mipLevelCount
equal to 1.GPUTexture
with a usage
that includes GPUTextureUsage.STORAGE_BINDING
.texture
, the corresponding bound GPUTextureView
:
dimension
equal to the resource layout object's viewDimension
(see GPUTexture.createView()
for more details of a texture view's settings).format
compatible with the resource layout object's sampleType
.GPUTexture
with a usage
that includes GPUTextureUsage.TEXTURE_BINDING
.GPUTexture
with a 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.
Basic exampleOur 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 Browser compatibility See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4