# WebGpu

Artifact: [androidx.webgpu:webgpu](https://developer.android.com/jetpack/androidx/releases/webgpu) [View Source](https://cs.android.com/search?q=file:androidx/webgpu/helper/WebGpu.kt+class:androidx.webgpu.helper.WebGpu) Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

*** ** * ** ***


```
abstract class WebGpu : AutoCloseable
```

<br />

*** ** * ** ***

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 |
|---|
| `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu#WebGpu()()` |

| ### Public functions |
|---|---|
| `suspend T` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu#execute(kotlin.coroutines.SuspendFunction0)(block: suspend () -> T)` Executes the given suspending `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu#execute(kotlin.coroutines.SuspendFunction0)` on the dedicated WebGPU dispatcher. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu#processEventsLoop()()` Runs a continuous loop on the WebGPU dispatcher to poll for and process WebGPU events. |

| ### Public properties |
|---|---|
| `abstract https://developer.android.com/reference/kotlin/androidx/webgpu/GPUAdapter` | `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu#adapter()` |
| `abstract https://developer.android.com/reference/kotlin/androidx/webgpu/GPUDevice` | `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu#device()` |
| `abstract https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html` | `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu#dispatcher()` |
| `abstract https://developer.android.com/reference/kotlin/androidx/webgpu/GPUInstance` | `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu#instance()` |
| `abstract https://developer.android.com/reference/kotlin/androidx/webgpu/GPUSurface` | `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu#webgpuSurface()` |

| ### Protected properties |
|---|---|
| `https://developer.android.com/reference/java/util/concurrent/atomic/AtomicBoolean.html` | `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu#isClosed()` |

### Inherited functions

From [java.lang.AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable.html) `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/lang/AutoCloseable.html#close()()`

## Public constructors

### WebGpu

Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
WebGpu()
```

## Public functions

### execute

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

Executes the given suspending `https://developer.android.com/reference/kotlin/androidx/webgpu/helper/WebGpu#execute(kotlin.coroutines.SuspendFunction0)` 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](https://developer.android.com/jetpack/androidx/releases/webgpu#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](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
abstract val adapter: GPUAdapter
```

### device

Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
abstract val device: GPUDevice
```

### dispatcher

Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
abstract val dispatcher: CoroutineDispatcher
```

### instance

Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
abstract val instance: GPUInstance
```

### webgpuSurface

Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
abstract val webgpuSurface: GPUSurface
```

## Protected properties

### isClosed

Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
protected val isClosed: AtomicBoolean
```