public abstract class WebGpu implements AutoCloseable


A helper class representing a WebGPU environment, encapsulating the instance, adapter, device, and surface. All operations on these components should be executed on the dedicated dispatcher.

Summary

Public constructors

Public methods

final @NonNull T
<T extends Object> execute(@NonNull SuspendFunction0<@NonNull T> block)

Executes the given suspending block on the dedicated WebGPU dispatcher.

abstract @NonNull GPUAdapter
abstract @NonNull GPUDevice
abstract @NonNull CoroutineDispatcher
abstract @NonNull GPUInstance
abstract @NonNull GPUSurface
final void

Runs a continuous loop on the WebGPU dispatcher to poll for and process WebGPU events.

Protected methods

final @NonNull AtomicBoolean

Inherited methods

From java.lang.AutoCloseable
abstract void

Public constructors

WebGpu

Added in 1.0.0-alpha06
public WebGpu()

Public methods

execute

public final @NonNull T <T extends Object> execute(@NonNull SuspendFunction0<@NonNull T> block)

Executes the given suspending block on the dedicated WebGPU dispatcher.

Use this method to wrap all operations on native WebGPU objects (like creating buffers, pipeline creation, or issuing draw/compute calls) to ensure thread-safety.

Parameters
@NonNull SuspendFunction0<@NonNull T> block

The block of code to execute.

Returns
@NonNull T

The result of executing the block.

getAdapter

Added in 1.0.0-alpha06
public abstract @NonNull GPUAdapter getAdapter()

getDevice

Added in 1.0.0-alpha06
public abstract @NonNull GPUDevice getDevice()

getDispatcher

Added in 1.0.0-alpha06
public abstract @NonNull CoroutineDispatcher getDispatcher()

getInstance

Added in 1.0.0-alpha06
public abstract @NonNull GPUInstance getInstance()

getWebgpuSurface

Added in 1.0.0-alpha06
public abstract @NonNull GPUSurface getWebgpuSurface()

processEventsLoop

Added in 1.0.0-alpha06
public final void processEventsLoop()

Runs a continuous loop on the WebGPU dispatcher to poll for and process WebGPU events. This is required for asynchronous operations (e.g., buffer mapping callbacks) to trigger.

Protected methods

isClosed

Added in 1.0.0-alpha06
protected final @NonNull AtomicBoolean isClosed()