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 BufferBindings 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.).

Example

// create a GPU buffer binding
const bufferBinding = new BufferBinding({
name: 'params', // name of the WGSL object
bindingType: 'uniform', // should be 'storage' for large arrays
struct: {
opacity: {
type: 'f32',
value: 1,
},
mousePosition: {
type: 'vec2f',
value: new Vec2(),
},
},
})

Hierarchy (view full)

Constructors

Properties

label: string

The label of the Binding

name: string

The name/key of the Binding

visibility: number

The visibility of the Binding in the shaders

shouldResetBindGroup: boolean

Flag indicating whether we should recreate the parentMesh bind group, usually when a resource has changed

shouldResetBindGroupLayout: boolean

Flag indicating whether we should recreate the parentMesh GPU bind group layout, usually when a resource layout has changed

cacheKey: string

A cache key allowing to get / set bindings from the device manager map cache. Used for BufferBinding only at the moment.

bindingType: BufferBindingType

The binding type of the BufferBinding

useStruct: boolean

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.

inputs: Record<string, BufferBindingInput>

All the BufferBinding data inputs

shouldUpdate: boolean

Flag to indicate whether one of the inputs value has changed and we need to update the GPUBuffer linked to the arrayBuffer array

bufferElements: AllowedBufferElement[]

An array describing how each corresponding inputs should be inserted into our arrayView array

arrayBufferSize: number

Total size of our arrayBuffer array in bytes

arrayBuffer: ArrayBuffer

Array buffer that will be sent to the GPUBuffer

arrayView: DataView

Data view of our array buffer

buffer: Buffer

The Buffer holding the GPUBuffer

wgslStructFragment: string

A string to append to our shaders code describing the WGSL structure representing this BufferBinding

wgslGroupFragment: string[]

An array of strings to append to our shaders code declaring all the WGSL variables representing this BufferBinding

Options used to create this BufferBinding

Accessors

  • get resourceLayout(): {
        buffer: GPUBufferBindingLayout;
    }
  • Get GPUBindGroupLayoutEntry#buffer | bind group layout entry resource

    Returns {
        buffer: GPUBufferBindingLayout;
    }

    • buffer: GPUBufferBindingLayout

      GPUBindGroupLayout | bind group layout resource

  • get resource(): {
        buffer: GPUBuffer;
    }
  • Get GPUBindGroupEntry#resource | bind group resource

    Returns {
        buffer: GPUBuffer;
    }

    • buffer: GPUBuffer

      GPUBindGroup | bind group resource

Methods

  • Set the WGSL code snippet to append to the shaders code. It consists of variable (and Struct structures if needed) declarations.

    Returns void

  • Extract the data corresponding to a specific BufferElement from a Float32Array holding the GPU buffer data of this BufferBinding

    Parameters

    • parameters: {
          result: Float32Array;
          bufferElementName: string;
      }

      parameters used to extract the data

      • result: Float32Array

        Float32Array holding GPUBuffer data

      • bufferElementName: string

        name of the BufferElement to use to extract the data

    Returns Float32Array

    • extracted data from the Float32Array