GPUBuffer


public final class GPUBuffer implements AutoCloseable


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

Summary

Public methods

external void
final external void

Immediately destroys the buffer resource.

boolean
equals(Object other)
final external @NonNull ByteBuffer
@FastNative
getConstMappedRange(long offset, long size)

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

final long
final external int

Gets the current mapping state of the buffer.

final external @NonNull ByteBuffer
@FastNative
getMappedRange(long offset, long size)

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

final external long

Gets the size of the buffer in bytes.

final external int

Gets the usage flags the buffer was created with.

int
final void
mapAndAwait(int mode, long offset, long size)

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

final external void
@FastNative
mapAsync(
    int mode,
    long offset,
    long size,
    @NonNull Executor callbackExecutor,
    @NonNull BufferMapCallback callback
)

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

final int
final external void

Reads data from a mapped buffer into CPU memory.

final external void

Sets a debug label for the buffer.

final long
final external void

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

final int
final external void

Writes data from CPU memory into a mapped buffer.

Public methods

close

Added in 1.0.0-alpha01
public external void close()

destroy

Added in 1.0.0-alpha01
@FastNative
public final external void destroy()

Immediately destroys the buffer resource.

equals

public boolean equals(Object other)

getConstMappedRange

Added in 1.0.0-alpha01
@FastNative
public final external @NonNull ByteBuffer getConstMappedRange(long offset, long size)

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

Parameters
long offset

The offset in bytes of the mapped range to retrieve.

long size

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

Returns
@NonNull ByteBuffer

An immutable pointer to the mapped buffer memory.

getHandle

Added in 1.0.0-alpha01
public final long getHandle()

getMapState

Added in 1.0.0-alpha01
@FastNative
public final external int getMapState()

Gets the current mapping state of the buffer.

Returns
int

The buffer's map state.

getMappedRange

Added in 1.0.0-alpha01
@FastNative
public final external @NonNull ByteBuffer getMappedRange(long offset, long size)

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

Parameters
long offset

The offset in bytes of the mapped range to retrieve.

long size

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

Returns
@NonNull ByteBuffer

A mutable pointer to the mapped buffer memory.

getSize

Added in 1.0.0-alpha01
@FastNative
public final external long getSize()

Gets the size of the buffer in bytes.

Returns
long

The size of the buffer.

getUsage

Added in 1.0.0-alpha01
@FastNative
public final external int getUsage()

Gets the usage flags the buffer was created with.

Returns
int

The buffer's usage flags.

hashCode

public int hashCode()

mapAndAwait

Added in 1.0.0-alpha01
public final void mapAndAwait(int mode, long offset, long size)

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

Parameters
int mode

The desired access mode for the mapping.

long offset

The offset in bytes where the mapping should start.

long size

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

mapAsync

Added in 1.0.0-alpha01
@FastNative
public final external void mapAsync(
    int mode,
    long offset,
    long size,
    @NonNull Executor callbackExecutor,
    @NonNull BufferMapCallback callback
)

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

mapState

Added in 1.0.0-alpha01
public final int mapState()

readMappedRange

Added in 1.0.0-alpha01
@FastNative
public final external void readMappedRange(long offset, @NonNull ByteBuffer data)

Reads data from a mapped buffer into CPU memory.

Parameters
long offset

The offset in the mapped buffer to read from.

@NonNull ByteBuffer data

A pointer to the destination CPU memory.

Returns
void

Status code of the operation.

setLabel

Added in 1.0.0-alpha01
@FastNative
public final external void setLabel(@NonNull String label)

Sets a debug label for the buffer.

Parameters
@NonNull String label

The label to assign to the buffer.

size

Added in 1.0.0-alpha01
public final long size()

unmap

Added in 1.0.0-alpha01
@FastNative
public final external void unmap()

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

usage

Added in 1.0.0-alpha01
public final int usage()

writeMappedRange

Added in 1.0.0-alpha01
@FastNative
public final external void writeMappedRange(long offset, @NonNull ByteBuffer data)

Writes data from CPU memory into a mapped buffer.

Parameters
long offset

The offset in the mapped buffer to write to.

@NonNull ByteBuffer data

A pointer to the source CPU memory.

Returns
void

Status code of the operation.