BufferElement constructor
parameters used to create our BufferElement
The name of the BufferElement
The WGSL variable type of the BufferElement
The key of the BufferElement
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
Optional
viewArray containing the BufferElement values
Function assigned to set the view values
Function assigned to set the view values
Get the total number of rows used by this BufferElement
Get the total number of bytes used by this BufferElement based on alignment start and end offsets
Get the total number of bytes used by this BufferElement, including final padding
Get the offset (i.e. byte index) at which our BufferElement starts
Get the array offset (i.e. array index) at which our BufferElement starts
Get the offset (i.e. byte index) at which our BufferElement ends
Get the array offset (i.e. array index) at which our BufferElement ends
Get the position at given offset (i.e. byte index)
byte index to use
Get the number of bytes at a given position
position from which to count
Check that a byte position does not overflow its max value (16)
Get the number of bytes between two positions
first position
second position
Compute the right alignment (i.e. start and end rows and bytes) given the size and align properties and the next available position
next position at which we should insert this element
position at which to start inserting the values in the buffer binding array
Set the alignment from an offset (byte count)
offset at which to start inserting the values in the buffer binding array
Set the view
Set the view value from a float or an int
float or int to use
Set the view value from an array
array to use
Set the view value from an array with pad applied
array to use
Update the view based on the new value
new value to use
Extract the data corresponding to this specific BufferElement from a Float32Array holding the GPUBuffer data of the parentMesh BufferBinding
Float32Array holding GPUBuffer data
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:
see https://webgpufundamentals.org/webgpu/lessons/resources/wgsl-offset-computer.html