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
- 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 -
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 - supportsCubeTextures → bool
-
True: a cube is a six-layer texture with a
"cube"view over it, and the sky pass needs one.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
-
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 -
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. -
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. -
present(
TextureHandle frame, {BoxFit fit = BoxFit.fill, FilterQuality quality = FilterQuality.none}) → Widget -
The canvas, in the widget tree, with
framecopied into it. -
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. -
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.
-
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.