GPUBuffer
class GPUBuffer : AutoCloseable
A block of memory accessible by the GPU.
Summary
Public functions |
|
|---|---|
open external Unit |
close()Decrements the reference count of the object and frees resources when the count reaches zero. |
external Unit |
Destroys the buffer and releases its resources. |
open operator Boolean |
|
external ByteBuffer |
@FastNativeGets a read-only pointer to the mapped range of the buffer. |
external Int |
Gets the current mapping state of the buffer. |
external ByteBuffer |
@FastNativeGets a pointer to the mapped range of the buffer. |
external Long |
Gets the size of the buffer in bytes. |
external Int |
Gets the allowed usages of the buffer. |
open Int |
hashCode() |
suspend Unit |
mapAndAwait(mode: Int, offset: Long, size: Long)Asynchronously maps a range of the buffer for CPU access. |
external Unit |
@FastNativeAsynchronously maps a range of the buffer for CPU access. |
external Unit |
@FastNativeCopies data from a mapped range into a destination pointer. |
external Unit |
@FastNativeSets a human-readable label for debugging. |
external Unit |
Unmaps the buffer, making it accessible to the GPU again. |
external Unit |
@FastNativeCopies data from a source pointer into a mapped range. |
Public functions
close
open external fun close(): Unit
Decrements the reference count of the object and frees resources when the count reaches zero.
This is the standard way to manage object lifetimes and should be used in use blocks. After calling this, the object is no longer usable.
destroy
@FastNative
external fun destroy(): Unit
Destroys the buffer and releases its resources.
getConstMappedRange
@FastNative
external fun getConstMappedRange(offset: Long = 0, size: Long = Constants.WHOLE_MAP_SIZE): ByteBuffer
Gets a read-only pointer to the mapped range of the buffer.
| Parameters | |
|---|---|
offset: Long = 0 |
The offset in bytes from the beginning of the buffer. |
size: Long = Constants.WHOLE_MAP_SIZE |
The size in bytes of the range to get. |
| Returns | |
|---|---|
ByteBuffer |
A read-only pointer to the mapped memory. |
getMapState
@FastNative
external fun getMapState(): Int
Gets the current mapping state of the buffer.
| Returns | |
|---|---|
Int |
The buffer map state. |
getMappedRange
@FastNative
external fun getMappedRange(offset: Long = 0, size: Long = Constants.WHOLE_MAP_SIZE): ByteBuffer
Gets a pointer to the mapped range of the buffer.
| Parameters | |
|---|---|
offset: Long = 0 |
The offset in bytes from the beginning of the buffer. |
size: Long = Constants.WHOLE_MAP_SIZE |
The size in bytes of the range to get. |
| Returns | |
|---|---|
ByteBuffer |
A pointer to the mapped memory. |
getSize
@FastNative
external fun getSize(): Long
Gets the size of the buffer in bytes.
| Returns | |
|---|---|
Long |
The buffer size. |
getUsage
@FastNative
external fun getUsage(): Int
Gets the allowed usages of the buffer.
| Returns | |
|---|---|
Int |
The buffer usage flags. |
mapAndAwait
suspend fun mapAndAwait(mode: Int, offset: Long, size: Long): Unit
Asynchronously maps a range of the buffer for CPU access.
mapAsync
@FastNative
external fun mapAsync(
mode: Int,
offset: Long,
size: Long,
callbackExecutor: Executor,
callback: GPURequestCallback<Unit>
): Unit
Asynchronously maps a range of the buffer for CPU access.
readMappedRange
@FastNative
external fun readMappedRange(offset: Long, data: ByteBuffer): Unit
Copies data from a mapped range into a destination pointer.
| Parameters | |
|---|---|
offset: Long |
The offset in bytes from the beginning of the buffer. |
data: ByteBuffer |
The destination pointer. |
| Returns | |
|---|---|
Unit |
The status of the operation. |
setLabel
@FastNative
external fun setLabel(label: String): Unit
Sets a human-readable label for debugging.
| Parameters | |
|---|---|
label: String |
The label string. |
unmap
@FastNative
external fun unmap(): Unit
Unmaps the buffer, making it accessible to the GPU again.
writeMappedRange
@FastNative
external fun writeMappedRange(offset: Long, data: ByteBuffer): Unit
Copies data from a source pointer into a mapped range.
| Parameters | |
|---|---|
offset: Long |
The offset in bytes from the beginning of the buffer. |
data: ByteBuffer |
The source pointer. |
| Returns | |
|---|---|
Unit |
The status of the operation. |