BufferBinding constructor
parameters used to create our BufferBindings
The label of the Binding
The name/key of the Binding
The visibility of the Binding in the shaders
Flag indicating whether we should recreate the parentMesh bind group, usually when a resource has changed
Flag indicating whether we should recreate the parentMesh GPU bind group layout, usually when a resource layout has changed
A cache key allowing to get / set bindings from the device manager map cache. Used for BufferBinding only at the moment.
The binding type of the BufferBinding
Flag to indicate whether this BufferBinding buffer elements should be packed in a single structured object or if each one of them should be a separate binding.
All the BufferBinding data inputs
Array of children BufferBinding used as struct children.
Flag to indicate whether one of the inputs value has changed and we need to update the GPUBuffer linked to the arrayBuffer array
Total size of our arrayBuffer array in bytes
Array buffer that will be sent to the GPUBuffer
Data view of our array buffer
DataView inside the parent arrayBuffer if set.
Array of bufferElements and according view set functions to use if the parent is set.
Corresponding bufferElement.
Corresponding view set function.
The Buffer holding the GPUBuffer
A string to append to our shaders code describing the WGSL structure representing this BufferBinding
An array of strings to append to our shaders code declaring all the WGSL variables representing this BufferBinding
Options used to create this BufferBinding
Get the BufferBinding parent if any.
Get this BufferBinding offset in bytes inside the parent arrayBuffer.
Get GPUBindGroupLayoutEntry#buffer | bind group layout entry resource.
Get the resource cache key
Get GPUBindGroupEntry#resource | bind group resource.
Static
cloneClone a struct object width new default values.
New cloned struct object.
Clone this BufferBinding into a new one. Allows to skip buffer layout alignment computations.
params to use for cloning
Set this BufferBinding optional childrenBindings.
Array of BufferBindingChildrenBinding to use as childrenBindings.
Set the buffer alignments from inputs.
Set our buffer attributes: Takes all the inputs and adds them to the bufferElements array with the correct start and end offsets (padded), then fill our arrayBuffer typed array accordingly.
Set a binding shouldUpdate flag to true
to update our arrayBuffer array during next render.
the binding name/key to update
Executed at the beginning of a Material render call.
If any of the inputs has changed, run its onBeforeUpdate
callback then updates our arrayBuffer array.
Also sets the shouldUpdate property to true so the BindGroup knows it will need to update the GPUBuffer.
Extract the data corresponding to a specific BufferElement from a Float32Array holding the GPU buffer data of this BufferBinding
parameters used to extract the data
Float32Array holding GPUBuffer data
name of the BufferElement to use to extract the data
Used to format uniforms or storages struct inputs and create a single typed array that will hold all those inputs values. The array needs to be correctly padded depending on every value type, so it can be safely used as a GPUBuffer input.
It will also create WGSL Structs and variables according to the BufferBinding inputs parameters.
The WGSL structs and variables declaration may vary based on the input types, especially if there's one or more arrays involved (i.e.
array<f32>
,array<vec3f>
etc.).It is possible to create complex WGSL structs with children structs by using the childrenBindings parameter.
A BufferBinding can also have a parent BufferBinding, in which case it won't create a GPUBuffer but use its parent GPUBuffer at the right offset. Useful to create a unique BufferBinding with a single GPUBuffer to handle multiple BufferBinding and update them with a single
writeBuffer
call.Example