Used to handle each buffer binding array view and data layout alignment. Compute the exact alignment offsets needed to fill an ArrayBuffer that will be sent to a GPUBuffer, based on an input type and value. Also update the view array at the correct offset.

So all our struct need to be packed into our arrayBuffer using a precise layout. They will be stored in rows, each row made of 4 slots and each slots made of 4 bytes. Depending on the binding element type, its row and slot may vary and we may have to insert empty padded values. All in all it looks like that:

         slot 0    slot 1    slot 2    slot 3
row 0 | _ _ _ _ | _ _ _ _ | _ _ _ _ | _ _ _ _ |
row 1 | _ _ _ _ | _ _ _ _ | _ _ _ _ | _ _ _ _ |
row 2 | _ _ _ _ | _ _ _ _ | _ _ _ _ | _ _ _ _ |

see https://webgpufundamentals.org/webgpu/lessons/resources/wgsl-offset-computer.html

Hierarchy (view full)

Constructors

Properties

name: string

The name of the BufferElement

type: string

The WGSL variable type of the BufferElement

key: string

The key of the BufferElement

bufferLayout: BufferLayout

BufferLayout used to fill the buffer binding array at the right offsets

Object defining exactly at which place a binding should be inserted into the buffer binding array

view?: TypedArray

Array containing the BufferElement values

setValue: ((value) => void)

Function assigned to set the view values

Type declaration

    • (value): void
    • Function assigned to set the view values

      Parameters

      Returns void

Accessors

Methods

  • Set the view value from an array

    Parameters

    • value: number[] | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array

      array to use

    Returns void

  • Set the view value from an array with pad applied

    Parameters

    • value: number[] | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array

      array to use

    Returns void