flutter3d_webgpu library

WebGPU as an implementation of flutter3d_hardware.

The fourth backend, and the first one whose API disagrees with the contract about when a pipeline exists. Impeller, WebGL2 and the software rasteriser all take cull mode, winding, depth compare and the blend equation as pass state a draw can change; WebGPU takes every one of them as a field of the pipeline object, alongside the attachment formats a pass only settles when it is opened. So a backend here cannot build anything where the contract says createPipeline — it records the stage pair, accumulates the setters, and looks a real pipeline up at the draw. WebGpuPipelineSignature is that lookup key, and it is why this barrel begins with a table rather than a device.

The device is in flutter3d_webgpu_web.dart, and the split is about the VM. Everything here is pure Dart, so a harness on the VM can hold the translation and the signature to their answers without a browser; the device, the encoder and the bindings import dart:js_interop, which the VM does not have, and a barrel re-exporting one of those cannot be imported at all off the web. An application imports the other file and calls openWebGpu.

No status line here, deliberately. flutter3d_webgl's barrel carries a paragraph saying what that backend can and cannot draw yet, and warns in its own last sentence that the paragraph said the opposite for as long as the shaders took to write. It is the first thing a reader meets on pub.flutter-io.cn and nothing fails when it goes stale. What this package can draw is recorded where it can be wrong out loud — in CHANGELOG.md, and in the tests.

Classes

WebGpuAttribute
One vertex input, by the name the engine binds it under.
WebGpuBlock
One uniform block, by the type name the engine binds it under.
WebGpuBlockMember
Where one member of a uniform block begins, and how many bytes it spans.
WebGpuBoundBlock
One uniform block of a group, and which stages see it.
WebGpuBoundSampler
One texture-and-sampler pair of a group, and which stages see it.
WebGpuGroupShape
What one @group of a pipeline holds, each list in binding order.
WebGpuPipeline
What a PipelineHandle carries here: two modules, the vertex layout they will be built with, and the reflection a bind group needs.
WebGpuPipelineCache<T extends Object>
The pipelines this device has built, by the signature that produced each.
WebGpuPipelineKey
What WebGPU bakes into a render pipeline that PassEncoder sets per draw.
WebGpuPipelineSignature
Everything WebGPU bakes into a GPURenderPipeline that this contract sets somewhere else.
WebGpuSampler
One texture-and-sampler pair, by the name the engine binds it under.
WebGpuShader
What a ShaderHandle carries here: one compiled stage, and which kind.
WebGpuShaderLibrary
A ShaderLibrary over a sidecar's stages, compiled on first use.
WebGpuStage
One shader stage: the WGSL, and what a pipeline needs to know about it.
WebGpuVertexAttribute
One vertex input, resolved: where its bytes are and which location wants them.
WebGpuVertexBuffer
One vertex buffer a pipeline reads, in the slot its position gives it.
WgslModuleCompiler
Turns WGSL text into whatever the backend's module object is.

Enums

WebGpuTextureDimension
Which shape of texture a sampler reads.

Constants

webgpuEntryPoint → const String
The entry point inside every module this backend compiles.

Functions

compileWebGpuStage(WgslModuleCompiler compiler, String name, WebGpuStage stage, {required bool isVertex}) → ShaderHandle
Compiles one stage into a handle, or throws naming it.
createWebGpuPipeline(ShaderHandle vertex, ShaderHandle fragment, {VertexLayoutSpec? layout}) → PipelineHandle
Pairs two stages into a pipeline, resolving the vertex layout against the vertex stage's own attribute table.
decodeWebGpuSection(ByteData bytes) WebGpuSectionStages
The stages in bytes.
encodeWebGpuSection({required Map<String, WebGpuStage> vertex, required Map<String, WebGpuStage> fragment}) ByteData
The section bytes for vertex and fragment stages.
gpuAddressMode(SamplerAddressMode mode) String
gpuBlendFactor(BlendFactor factor) String?
The blend factor WebGPU calls factor, or null where it has none.
gpuBlendOperation(BlendOperation operation) String
gpuBlockLayoutOf(TextureFormat format, int width, int height) → ({int byteLength, int bytesPerRow, int rowsPerImage})
The row stride and the number of rows writeTexture wants for a width by height level of a block-compressed format.
gpuCompareFunction(CompareFunction compare) String
gpuCullMode(CullMode mode) String
gpuFilterMode(MinMagFilter filter) String
gpuFrontFace(WindingOrder order) String
Straight through — and it was written crossed first, on an argument that turned out to be wrong.
gpuIndexFormat(IndexType type) String
gpuLoadOp(LoadAction action) String
LoadAction.dontCare becomes "clear", which is a choice rather than a translation: WebGPU has "load" and "clear" and no third option meaning "the contents are undefined". Clearing is the one of the two that cannot leak the previous frame into a target whose contents the caller said it did not care about, and a caller that did not care cannot be harmed by it.
gpuMipmapFilterMode(MipFilter filter) String
gpuPrimitiveTopology(PrimitiveType type) String
gpuResolves(StoreAction action) bool
Whether action asks for a resolve, which WebGPU takes as an attachment field rather than as part of the store operation.
gpuStencilOperation(StencilOperation operation) String
StencilOperation.setToReferenceValue is WebGPU's "replace", which is the one name in this table that is not the engine's word for the same thing.
gpuStoreOp(StoreAction action) String
The store operation, which in WebGPU says nothing about resolving: a resolve is resolveTarget on the attachment, and the store op then says whether the multisampled texture is kept as well.
gpuTextureFormat(TextureFormat format) String?
The texture format WebGPU calls format, or null where it has none.
gpuTextureFormatFeature(TextureFormat format) String?
The adapter feature format rides on, or null for one every WebGPU device has.
gpuVertexFormat(VertexFormat format) String
gpuVertexStepMode(VertexStepMode mode) String
gpuWritableBytes(ByteData bytes) Uint8List
bytes as queue.writeBuffer will take them: a length that is a multiple of four, padded with zeros where it is not.
paddedBytesPerRow(int width) int
The row stride copyTextureToBuffer demands for a width-pixel region of four-byte texels: a multiple of 256, whatever the region is.
webgpuStencilFingerprint(StencilState? front, StencilState? back) String?
front and back as a string, or null where the test is off on both faces.
webgpuVertexLayoutFingerprint(VertexLayoutSpec layout) String
layout as a string two layouts can be compared by.

Typedefs

WebGpuCode = ({Object module, WebGpuStage stage})
The WGSL of one stage, the reflection that goes with it, and the module the two produced.
WebGpuSectionStages = ({Map<String, WebGpuStage> fragment, Map<String, WebGpuStage> vertex})
What the section decodes to.
WebGpuVisibility = ({bool fragment, bool vertex})
Which stages one binding is visible to.