Skip to main content

Buffer

Holds a block of GPU memory. The length of a buffer cannot be changed after creation.

Types

BufferProps

PropertyTypeDescription
usage?numberBit mask of Usage flags
byteLength?numberLength of buffer (cannot be changed after creation).
data?ArrayBuffer | ArrayBufferViewData to be copied into buffer. byteLength will be deduced if not supplied.
byteOffset?numberOffset for data
indexType?'uint16' | 'uint32'If props.usage & Buffer.INDEX

Usage

Usage expresses two things: The type of buffer and what operations can be performed on it.

Note that the allowed combinations are very limited, especially in WebGPU.

Usage FlagValueDescription
Buffer.INDEX0x0010An index buffer (array of 16 or 32 bit unsigned integers
Buffer.VERTEX0x0020A vertex buffer (a binary column)
Buffer.UNIFORM0x0040A uniform buffer
Buffer.STORAGE0x0080A storage buffer
Buffer.INDIRECT0x0100
Buffer.QUERY_RESOLVE0x0200
Buffer.MAP_READ0x01Whether the buffer can be mapped for read
Buffer.MAP_WRITE0x02Whether the buffer can be mapped for write
Buffer.COPY_SRC0x0004Supports commandEncoder.copyBufferTo...
Buffer.COPY_DST0x0008Supports commandEncoder.copy...ToBuffer

Members

  • device: Device - holds a reference to the Device that created this Buffer.
  • handle: unknown - holds the underlying WebGL or WebGPU shader object
  • props: BufferProps - holds a copy of the BufferProps used to create this Buffer.

Methods

constructor(props: BufferProps)

Buffer is an abstract class and cannot be instantiated directly. Create with device.createBuffer(...).

destroy(): void

Free up any GPU resources associated with this buffer immediately (instead of waiting for garbage collection).