abstract class WebGpu : 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 functions

suspend T
<T : Any?> execute(block: suspend () -> T)

Executes the given suspending block on the dedicated WebGPU dispatcher.

suspend Unit

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

Public properties

abstract GPUAdapter
abstract GPUDevice
abstract CoroutineDispatcher
abstract GPUInstance
abstract GPUSurface

Protected properties

AtomicBoolean

Inherited functions

From java.lang.AutoCloseable
abstract Unit

Public constructors

WebGpu

Added in 1.0.0-alpha06
WebGpu()

Public functions

execute

suspend fun <T : Any?> execute(block: suspend () -> T): T

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
block: suspend () -> T

The block of code to execute.

Returns
T

The result of executing the block.

processEventsLoop

Added in 1.0.0-alpha06
suspend fun processEventsLoop(): Unit

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.

Public properties

adapter

Added in 1.0.0-alpha06
abstract val adapter: GPUAdapter

device

Added in 1.0.0-alpha06
abstract val device: GPUDevice

dispatcher

Added in 1.0.0-alpha06
abstract val dispatcher: CoroutineDispatcher

instance

Added in 1.0.0-alpha06
abstract val instance: GPUInstance

webgpuSurface

Added in 1.0.0-alpha06
abstract val webgpuSurface: GPUSurface

Protected properties

isClosed

Added in 1.0.0-alpha06
protected val isClosed: AtomicBoolean