GPUBuffer


class GPUBuffer : AutoCloseable


A chunk of memory allocated on the GPU, used for vertex data, uniforms, storage, etc.

Summary

Public functions

open external Unit
external Unit

Immediately destroys the buffer resource.

open operator Boolean
equals(other: Any?)
external ByteBuffer

Returns an immutable pointer to the mapped memory range for reading.

external Int

Gets the current mapping state of the buffer.

external ByteBuffer
@FastNative
getMappedRange(offset: Long, size: Long)

Returns a mutable pointer to the mapped memory range for writing.

external Long

Gets the size of the buffer in bytes.

external Int

Gets the usage flags the buffer was created with.

open Int
suspend Unit
mapAndAwait(mode: Int, offset: Long, size: Long)

Requests to map a range of the buffer into CPU-accessible memory asynchronously.

external Unit
@FastNative
mapAsync(
    mode: Int,
    offset: Long,
    size: Long,
    callbackExecutor: Executor,
    callback: BufferMapCallback
)

Requests to map a range of the buffer into CPU-accessible memory asynchronously.

external Unit

Reads data from a mapped buffer into CPU memory.

external Unit

Sets a debug label for the buffer.

external Unit

Unmaps the buffer, making it inaccessible by the CPU and potentially usable by the GPU again.

external Unit

Writes data from CPU memory into a mapped buffer.

Public properties

Long
Int
Long
Int

Public functions

close

Added in 1.0.0-alpha01
open external fun close(): Unit

destroy

Added in 1.0.0-alpha01
@FastNative
external fun destroy(): Unit

Immediately destroys the buffer resource.

equals

open operator fun equals(other: Any?): Boolean

getConstMappedRange

Added in 1.0.0-alpha01
@FastNative
external fun getConstMappedRange(offset: Long = 0, size: Long = Constants.WHOLE_MAP_SIZE): ByteBuffer

Returns an immutable pointer to the mapped memory range for reading.

Parameters
offset: Long = 0

The offset in bytes of the mapped range to retrieve.

size: Long = Constants.WHOLE_MAP_SIZE

The size in bytes of the mapped range to retrieve. Can be whole_map_size.

Returns
ByteBuffer

An immutable pointer to the mapped buffer memory.

getMapState

Added in 1.0.0-alpha01
@FastNative
external fun getMapState(): Int

Gets the current mapping state of the buffer.

Returns
Int

The buffer's map state.

getMappedRange

Added in 1.0.0-alpha01
@FastNative
external fun getMappedRange(offset: Long = 0, size: Long = Constants.WHOLE_MAP_SIZE): ByteBuffer

Returns a mutable pointer to the mapped memory range for writing.

Parameters
offset: Long = 0

The offset in bytes of the mapped range to retrieve.

size: Long = Constants.WHOLE_MAP_SIZE

The size in bytes of the mapped range to retrieve. Can be whole_map_size.

Returns
ByteBuffer

A mutable pointer to the mapped buffer memory.

getSize

Added in 1.0.0-alpha01
@FastNative
external fun getSize(): Long

Gets the size of the buffer in bytes.

Returns
Long

The size of the buffer.

getUsage

Added in 1.0.0-alpha01
@FastNative
external fun getUsage(): Int

Gets the usage flags the buffer was created with.

Returns
Int

The buffer's usage flags.

hashCode

open fun hashCode(): Int

mapAndAwait

Added in 1.0.0-alpha01
suspend fun mapAndAwait(mode: Int, offset: Long, size: Long): Unit

Requests to map a range of the buffer into CPU-accessible memory asynchronously.

Parameters
mode: Int

The desired access mode for the mapping.

offset: Long

The offset in bytes where the mapping should start.

size: Long

The size in bytes of the range to map. Can be whole_map_size.

mapAsync

Added in 1.0.0-alpha01
@FastNative
external fun mapAsync(
    mode: Int,
    offset: Long,
    size: Long,
    callbackExecutor: Executor,
    callback: BufferMapCallback
): Unit

Requests to map a range of the buffer into CPU-accessible memory asynchronously.

readMappedRange

Added in 1.0.0-alpha01
@FastNative
external fun readMappedRange(offset: Long, data: ByteBuffer): Unit

Reads data from a mapped buffer into CPU memory.

Parameters
offset: Long

The offset in the mapped buffer to read from.

data: ByteBuffer

A pointer to the destination CPU memory.

Returns
Unit

Status code of the operation.

setLabel

Added in 1.0.0-alpha01
@FastNative
external fun setLabel(label: String): Unit

Sets a debug label for the buffer.

Parameters
label: String

The label to assign to the buffer.

unmap

Added in 1.0.0-alpha01
@FastNative
external fun unmap(): Unit

Unmaps the buffer, making it inaccessible by the CPU and potentially usable by the GPU again.

writeMappedRange

Added in 1.0.0-alpha01
@FastNative
external fun writeMappedRange(offset: Long, data: ByteBuffer): Unit

Writes data from CPU memory into a mapped buffer.

Parameters
offset: Long

The offset in the mapped buffer to write to.

data: ByteBuffer

A pointer to the source CPU memory.

Returns
Unit

Status code of the operation.

Public properties

handle

Added in 1.0.0-alpha01
val handleLong

mapState

Added in 1.0.0-alpha01
val mapStateInt

size

Added in 1.0.0-alpha01
val sizeLong

usage

Added in 1.0.0-alpha01
val usageInt