flutter3d_webgpu_web library

The half of this backend that needs a browser: the device, the pass encoder and the bindings under both.

Separate from flutter3d_webgpu.dart because dart:js_interop is not a library the Dart VM has, and a barrel that re-exports one importing it cannot be imported on the VM at all. The translation tables and the pipeline signature are worth asserting whether or not there is a GPU in the room — they are what catch a typo in "less-equal" in a second — so they stay in the barrel that loads everywhere, and this one carries what only a browser can run.

An application opens a device through openWebGpu and never touches anything else here. The rest is exported because a backend is a package somebody may have to debug from outside: the encoder's signature, the frame arenas' counts and WebGpuDevice.debugDrainErrors are how a wrong picture is turned into a sentence.

Classes

GpuBufferUsage
What a buffer may be used for, declared when it is made and never after.
GpuColorWrite
The channels a colour target writes, for GPUColorTargetState.writeMask.
GpuErrorFilter
The three kinds of error a scope can be pushed for.
GpuFeature
The optional features worth asking an adapter about.
GpuMapMode
Which way a mapped buffer may be read, for GPUBuffer.mapAsync.
GpuShaderStage
Which stages a binding is visible to, for GPUBindGroupLayoutEntry.
GpuTextureUsage
What a texture may be used for.
WebGpuBindingLayouts
The bind group layouts one stage pair needs, and the pipeline layout over them.
WebGpuDevice
WebGPU as a GraphicsDevice, and as the compiler its shader libraries reach a browser through.
WebGpuEncoder
One pass, recorded and submitted.
WebGpuFrameArena
A bump allocator over one GPUBuffer, reset every frame. See the library comment, which is where the argument for this shape is.
WebGpuGeometry
A buffer this device owns.
WebGpuTexture
A texture this device owns, and the views it has been asked for.

Properties

gpuNavigator GpuNavigator
navigator, for the one property that says whether this browser has WebGPU at all.
no setter

Functions

gpuChecked<T>(GPUDevice device, String what, T body()) Future<T>
Runs body with a validation scope open, and throws where the browser complained.
gpuRequiredLimits(Map<String, int> limits) JSObject
limits as GPUDeviceDescriptor.requiredLimits takes them.
gpuShaderStageOf(WebGpuVisibility visibility) int
Which stages a binding is visible to, as this API's flag word.
gpuStrings(Iterable<String> names) JSArray<JSString>
names as this API takes a list of strings.
openWebGpu({required int width, required int height}) Future<GraphicsDevice>
Opens this backend with the engine's own shaders, or throws with something worth putting on screen.
webgpuCreateCubeRenderTarget(GPUDevice gpu, List<WebGpuTexture> tracked, {required int size, required TextureFormat format, int mipLevels = 1}) → TextureHandle?
An empty cube a pass may draw into, one face and one level at a time. See GraphicsDevice.createCubeRenderTarget.
webgpuCreateCubeTextureFromPixels(GPUDevice gpu, List<WebGpuTexture> tracked, {required int size, required TextureFormat format, required List<ByteData> faces, List<List<ByteData>>? mipLevels}) → TextureHandle?
faces in +X, −X, +Y, −Y, +Z, −Z order as one cube texture. See GraphicsDevice.createCubeTextureFromPixels.
webgpuCreateTexture(GPUDevice gpu, List<WebGpuTexture> tracked, RenderTargetSpec spec, {int levels = 1}) → TextureHandle
A texture matching spec, with a chain levels deep. See GraphicsDevice.createTexture.
webgpuCreateTextureFromPixels(GPUDevice gpu, List<WebGpuTexture> tracked, {required int width, required int height, required TextureFormat format, required ByteData pixels, List<ByteData>? mipLevels}) → TextureHandle?
A texture already holding pixels, and mipLevels below it. See GraphicsDevice.createTextureFromPixels.
webgpuDisposePersistentResources(List<WebGpuTexture> textures, List<GPUBuffer> buffers) → void
Destroys every tracked texture and buffer and empties both lists. See GraphicsDevice.dispose.
webgpuIsDepthStencil(TextureFormat format) bool
Whether format is a depth or stencil layout, which decides what a texture in it may be used for.
webgpuReleaseGeometry(Object buffer, List<GPUBuffer> tracked) bool
Destroys one geometry buffer and stops tracking it. See webgpuReleaseTexture.
webgpuReleaseTexture(WebGpuTexture backend, List<WebGpuTexture> tracked) bool
Destroys one texture and stops tracking it, or answers false for a handle this device does not hold — a double release, or one from another device.
webgpuTexelBytes(TextureFormat format) int?
How many bytes one texel of format takes, for the uploads that state a row stride.
webgpuUploadGeometry(GPUDevice gpu, List<GPUBuffer> tracked, ByteData bytes, GeometryUsage usage) → GeometryBuffer
Geometry uploaded once and bound many times, until the device that made it is disposed. See GraphicsDevice.uploadGeometry.

Typedefs

WebGpuSlice = ({GPUBuffer buffer, int length, int offset})
Where an arena put some bytes: the buffer they landed in, and how far into it.

Exceptions / Errors

GpuDeviceError
A WebGPU error that reached Dart, which without gpuChecked none of them do.