GPUBuffer

The GPUBuffer interface of the WebGPU API represents a block of memory that can be used to store raw data to use in GPU operations. Available only in secure contexts.

MDN Reference

Properties

Link copied to clipboard
Link copied to clipboard

The mapState read-only property of the GPUBuffer interface represents the mapped state of the GPUBuffer.

Link copied to clipboard

The size read-only property of the GPUBuffer interface represents the length of the GPUBuffer's memory allocation, in bytes.

Link copied to clipboard

The usage read-only property of the GPUBuffer interface contains the bitwise flags representing the allowed usages of the GPUBuffer.

Functions

Link copied to clipboard
fun destroy()

The destroy() method of the GPUBuffer interface destroys the GPUBuffer.

Link copied to clipboard
fun getMappedRange(offset: GPUSize64 = definedExternally, size: GPUSize64 = definedExternally): ArrayBuffer

The getMappedRange() method of the GPUBuffer interface returns an ArrayBuffer containing the mapped contents of the GPUBuffer in the specified range.

Link copied to clipboard
inline suspend fun GPUBuffer.map(mode: GPUMapModeFlags)
inline suspend fun GPUBuffer.map(mode: GPUMapModeFlags, offset: GPUSize64)
inline suspend fun GPUBuffer.map(mode: GPUMapModeFlags, offset: GPUSize64, size: GPUSize64)

The mapAsync() method of the GPUBuffer interface maps the specified range of the GPUBuffer. It returns a Promise that resolves when the GPUBuffer's content is ready to be accessed. While the GPUBuffer is mapped it cannot be used in any GPU commands.

Link copied to clipboard
fun mapAsync(mode: GPUMapModeFlags, offset: GPUSize64 = definedExternally, size: GPUSize64 = definedExternally): Promise<Void?>

The mapAsync() method of the GPUBuffer interface maps the specified range of the GPUBuffer. It returns a Promise that resolves when the GPUBuffer's content is ready to be accessed. While the GPUBuffer is mapped it cannot be used in any GPU commands.

Link copied to clipboard
fun unmap()

The unmap() method of the GPUBuffer interface unmaps the mapped range of the GPUBuffer, making its contents available for use by the GPU again after it has previously been mapped with GPUBuffer.mapAsync() (the GPU cannot access a mapped GPUBuffer).