WebGpuDevice class final
WebGPU as a GraphicsDevice, and as the compiler its shader libraries reach
a browser through.
- Implemented types
Properties
- debugBindGroupCount → int
-
How many distinct bind groups this device has assembled. Diagnostic, for
the reason debugSamplerCount is: the dynamic offset on a uniform block
exists to keep this number small, and nothing else would notice if it
stopped working.
no setter
- debugSamplerCount → int
-
Every GPU object this device owns and would have to release: the textures
and geometry it handed out, the frame arenas and fallbacks it made for
itself, and the modules, layouts, samplers, bind groups and pipelines it
cached.
no setter
- debugTrackedResourceCount → int
-
no setter
- defaultColorFormat → TextureFormat
-
The colour format this device prefers.
no setter
- defaultDepthStencilFormat → TextureFormat
-
The depth/stencil format this device prefers. Legitimately
TextureFormat.unknownon a context that has none.no setter - depthRange → DepthRange
-
Near at zero, far at one. The engine builds its projections for this and
corrects at the boundary for a backend that says otherwise, so this is the
case that needs no correction.
no setter
- framebufferOrigin → FramebufferOrigin
-
Top left, like Metal and Impeller and unlike OpenGL. WebGPU's framebuffer
coordinates start at the top left corner and its attachments are written
from there, so nothing has to be turned over anywhere: an uploaded image
and a rendered one are the same way up, which is the pair the WebGL2
backend has to keep apart with a flag on every texture.
no setter
- gpuDevice → GPUDevice
-
The browser's device. Public because the encoder beside this one records
into it.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- hdrColorFormat → TextureFormat
-
The format to render high dynamic range colour into.
no setter
-
hdrOutputFormats
→ List<
TextureFormat> -
rgba16floaton a display the browser says has a high dynamic range —R9— asked once, when the device is made. A frame in it is presented through a canvas configured for extended tone mapping; see copyToCanvas.no setter - indexArena → WebGpuFrameArena
-
Where
PassEncoder.bindIndexData's bytes land.final - maxAnisotropy → int
-
Sixteen, which is what this API's
maxAnisotropytops out at. A sampler asking for more is clamped by samplerFor rather than refused.no setter - maxColorAttachments → int
-
Four —
gfx-50n.no setter -
pipelines
→ WebGpuPipelineCache<
GPURenderPipeline> -
Real pipelines, by the signature that produced each. Shared across passes:
the signature already carries the attachment formats and the sample count.
final
- preferredSampleCount → int
-
Four, which is the only multisample count above one WebGPU guarantees.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- shaders → ShaderLibrary
-
The compiled bundle this device was built with.
no setter
- supportsBlendColor → bool
-
False, and the false is a finding rather than a limitation. See
WebGpuEncoder.setBlendColor, which is the refusal this promises.no setter - supportsCompute → bool
-
Whether compute pipelines can be created and dispatched —
H6. The members below it throw an UnsupportedError where this is false.no setter - supportsCubeTextures → bool
-
True: a cube is a six-layer texture with a
"cube"view over it, and the sky pass needs one.no setter - supportsFloat32Filtering → bool
-
True where the adapter granted
float32-filterable, which create asks for whenever it is offered.no setter - supportsGpuTimestamps → bool
-
Whether this device measures how long the GPU spends in each labelled
pass —
H2. When true, onGpuTimings is called with them.no setter - supportsIndependentBlend → bool
-
Every colour target in a WebGPU pipeline carries its own equation, and
the pipeline signature keys on the list of them, so the index has always
been honoured here —
R8only asked.no setter - supportsMipmaps → bool
-
Whether a texture built with a hand-supplied mip chain samples correctly.
no setter
- supportsOffscreenMsaa → bool
-
Whether a multisampled offscreen target is available at all.
no setter
- supportsRenderToMip → bool
-
True, and what it turns on is reflection probes.
no setter
- supportsStencil → bool
-
Whether the depth attachment this device hands out carries a stencil
that
PassEncoder.setStencilcan test against.no setter - supportsWireframe → bool
-
False: WebGPU has no polygon fill mode at all. A wireframe here is line
primitives and an index buffer built for them, which is the renderer's
decision — the same answer WebGL2 gives for the same reason.
no setter
- uniformArena → WebGpuFrameArena
-
Where a uniform block written this frame lands. See
webgpu_resources.dartfor why one arena reset per frame is safe.final - vertexArena → WebGpuFrameArena
-
Where
PassEncoder.bindVertexData's bytes land.final - viewType → String
-
The platform view type this device's canvas is registered under.
latefinal
Methods
-
applyCanvasStyle(
{BoxFit fit = BoxFit.fill, FilterQuality quality = FilterQuality.none}) → void -
Styles the canvas through CSS, honouring
fitandqualitythe way Flutter would if it composited these pixels itself. -
beginComputePass(
{String? label}) → ComputeEncoder -
Opens a compute pass;
labelnames it to a debugger and to onGpuTimings. -
beginFrame(
) → void - Rewinds the three frame arenas.
-
beginRenderPass(
RenderPassDescriptor descriptor) → CommandEncoder - Opens a pass and returns the encoder that records into it.
-
bindGroupFor(
WebGpuBindingLayouts layouts, int group, Map< int, WebGpuSlice> ? blocks, Map<int, GPUTextureView> ? views, Map<int, GPUSampler> ? samplers) → GPUBindGroup -
The bind group for one
@groupoflayouts, assembled from what the pass has bound and cached by what went into it. -
bindingsFor(
WebGpuPipeline pipeline) → WebGpuBindingLayouts -
The bind group layouts
pipeline's stage pair needs, made once. -
compileModule(
String name, String wgsl) → Object -
Turns
wgslinto aGPUShaderModule, and asks the browser what it thought of it.override -
copyToCanvas(
TextureHandle frame) → void -
Copies
frameinto the canvas the browser composites. -
createComputePipeline(
ShaderHandle shader) → ComputePipelineHandle - A pipeline from a compute stage of this device's shader library.
-
createCubeRenderTarget(
{required int size, required TextureFormat format, int mipLevels = 1}) → TextureHandle? - A cube a pass may aim at one face and one level of.
-
createCubeTextureFromPixels(
{required int size, required TextureFormat format, required List< ByteData> faces, List<List< ? mipLevels}) → TextureHandle?ByteData> > - Uploads six square images as one cube texture.
-
createPipeline(
ShaderHandle vertex, ShaderHandle fragment, {VertexLayoutSpec? layout}) → PipelineHandle -
Records the stage pair, its layout and the reflection a bind group will
need. Nothing is built: see WebGpuPipeline, and
webgpu_encoder.dartfor what a draw does with it. -
createStorageBuffer(
ByteData bytes, {bool hostReadable = false}) → StorageBuffer -
A storage buffer holding
bytes.hostReadableallows readBuffer. -
createTexture(
RenderTargetSpec spec, {int levels = 1}) → TextureHandle -
A brand-new texture matching
spec, with the singleTextureHandlethat will ever stand for it. -
createTextureFromPixels(
{required int width, required int height, required TextureFormat format, required ByteData pixels, List< ByteData> ? mipLevels}) → TextureHandle? -
Creates a texture already holding
pixels. -
debugDrainErrors(
[String where = '']) → Future< String?> - Everything the browser complained about since the last drain, or null when it complained about nothing.
-
dispose(
) → void - Releases everything: the textures and buffers handed out, the arenas, the caches, the canvas's configuration and the device itself.
-
guard<
T> (String what, T body()) → T -
Runs
bodywith a validation scope open, recording whatever the browser says into debugDrainErrors. -
loadShaders(
ByteData bytes) → Future< LoadedShaderLibrary> - The bundle's own WGSL, compiled by this device, as a library that can be reloaded.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onFrameComplete(
void whenDone()) → void -
Runs
whenDoneonce the GPU has finished with the frame being encoded now. -
onGpuTimings(
void listener(GpuFrameTimings timings)?) → void - Sets where each frame's GPU timings go, a frame or two after it was encoded; null stops them. Never called on a device whose supportsGpuTimestamps is false.
-
overwriteGeometry(
GeometryBuffer target, int offsetInBytes, ByteData bytes) → void -
Writes
bytesintotargetstartingoffsetInBytesinto it, in place. -
overwriteTexture(
TextureHandle target, ByteData rgba, {ScreenRect? region, int mipLevel = 0}) → Future< void> -
Overwrites
region(the whole texture by default) oftarget's base level withrgba— raw RGBA8 bytes,region.width * region.height * 4of them, row-major from the top the same way readback answers them. -
readback(
TextureHandle texture, {ScreenRect? region}) → Future< ByteData> -
The pixels of
region— the whole texture by default — as they stand at this point in the queue, without waiting for the GPU to get there. -
readBuffer(
StorageBuffer buffer) → Future< ByteData> -
The contents of
buffer, once every pass submitted before this call has finished writing it.buffermust behostReadable. -
readPixels(
TextureHandle texture) → Future< ByteData?> - The texture's pixels, premultiplied RGBA8, rows from the top.
-
releaseGeometry(
GeometryBuffer geometry) → void - Releases one geometry buffer, rather than waiting for the whole device to go.
-
releaseStorageBuffer(
StorageBuffer buffer) → void - Releases one storage buffer, as releaseGeometry releases geometry.
-
releaseTexture(
TextureHandle texture) → void - Gives one back, rather than waiting for the whole device to go.
-
samplerFor(
SamplerOptions options) → GPUSampler -
The sampler object for
options, made once per distinct description. -
supportsTextureFormat(
TextureFormat format) → bool -
Whether WebGPU has a name for
formatand this device was granted the feature it needs. -
toString(
) → String -
A string representation of this object.
inherited
-
uploadGeometry(
ByteData bytes, GeometryUsage usage) → GeometryBuffer - Uploads geometry that will outlive the frame.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
create(
{required int width, required int height, required WebGpuSectionStages stages}) → Future< WebGpuDevice?> -
Opens a device over a canvas of
widthbyheight, or answers null where this browser has no WebGPU.