# 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)

*** ** * ** ***


```
public abstract class WebGpu implements 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/androidx/webgpu/helper/WebGpu#WebGpu()()` |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull T` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/webgpu/helper/WebGpu#execute(kotlin.coroutines.SuspendFunction0)(@https://developer.android.com/reference/androidx/annotation/NonNull SuspendFunction0<@https://developer.android.com/reference/androidx/annotation/NonNull T> block)` Executes the given suspending `https://developer.android.com/reference/androidx/webgpu/helper/WebGpu#execute(kotlin.coroutines.SuspendFunction0)` on the dedicated WebGPU dispatcher. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/webgpu/GPUAdapter` | `https://developer.android.com/reference/androidx/webgpu/helper/WebGpu#getAdapter()()` |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/webgpu/GPUDevice` | `https://developer.android.com/reference/androidx/webgpu/helper/WebGpu#getDevice()()` |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html` | `https://developer.android.com/reference/androidx/webgpu/helper/WebGpu#getDispatcher()()` |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/webgpu/GPUInstance` | `https://developer.android.com/reference/androidx/webgpu/helper/WebGpu#getInstance()()` |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/webgpu/GPUSurface` | `https://developer.android.com/reference/androidx/webgpu/helper/WebGpu#getWebgpuSurface()()` |
| `final void` | `https://developer.android.com/reference/androidx/webgpu/helper/WebGpu#processEventsLoop()()` Runs a continuous loop on the WebGPU dispatcher to poll for and process WebGPU events. |

| ### Protected methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/atomic/AtomicBoolean.html` | `https://developer.android.com/reference/androidx/webgpu/helper/WebGpu#isClosed()()` |

### Inherited methods

From [java.lang.AutoCloseable](https://developer.android.com/reference/java/lang/AutoCloseable.html) `abstract void` `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)

```
public WebGpu()
```

## Public methods

### execute

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

Executes the given suspending `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull SuspendFunction0<@https://developer.android.com/reference/androidx/annotation/NonNull T> block` | The block of code to execute. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull T` | The result of executing the block. |

### getAdapter

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

```
public abstract @NonNull GPUAdapter getAdapter()
```

### getDevice

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

```
public abstract @NonNull GPUDevice getDevice()
```

### getDispatcher

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

```
public abstract @NonNull CoroutineDispatcher getDispatcher()
```

### getInstance

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

```
public abstract @NonNull GPUInstance getInstance()
```

### getWebgpuSurface

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

```
public abstract @NonNull GPUSurface getWebgpuSurface()
```

### processEventsLoop

Added in [1.0.0-alpha06](https://developer.android.com/jetpack/androidx/releases/webgpu#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](https://developer.android.com/jetpack/androidx/releases/webgpu#1.0.0-alpha06)

```
protected final @NonNull AtomicBoolean isClosed()
```