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 Summary)

Constructors

Properties

name: string

The name of the BufferElement

type: string

The WGSL variable type of the BufferElement (stripped of array).

baseType: string

The WGSL base variable type of the BufferElement (stripped of array and atomic).

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: InputValue) => void

Function assigned to set the view values

Accessors

Methods