Skip to content

WGPU renderer

The WGPU backend in vestra-render-wgpu implements the common RenderBackend contract and keeps GPU state inside one prepared render.

Preparation

The backend obtains a shared root WGPU instance, selects an adapter under the requested graphics API, requests the device and queue, then builds pipelines, textures, buffers, source resources and readback state. AdapterInfo records the actual graphics backend and device classification so the SDK can distinguish a hardware adapter from software WGPU.

Preparation uploads static image/font/source data and creates reusable GPU resources.

Frame execution

Frame evaluation still happens outside the backend. For each evaluated frame, the backend uploads changed video data, builds source/effect/composite passes from the evaluated layer tree, renders nested groups recursively, submits commands and schedules a readback of the completed RGBA frame. The readback path accounts for row alignment and repacks rows into the public tightly packed frame format.

Canvas extents and mask precision

The two root canvases and readback use output dimensions. Shared layer/effect scratch and group targets use the componentwise maximum of output and local canvas extents. Each operation carries its logical extent for dispatch, source sizing, clipping and sampling. Resource estimates and adapter limits account for those actual allocations. Orthogonal aspect ratios can amplify shared scratch memory because the pool uses fixed preparation-time targets. Group resource budgets constrain logical canvases, not total device memory.

Owned group-mask recursion preserves both the consumer pixels and accumulated coverage in the existing reserved composition slots. In local canvas contexts, mask coverage is presented before feathering in parent pixels, and track mattes remain in parent coordinates. The legacy unsized WGPU path retains its existing transform/feather ordering. Feather scratch preserves R/G coverage state and uses the unused B channel for alpha rounding residuals between box passes, avoiding accumulated byte-rounding error without allocating another target.

Accumulated coverage between masks remains byte-valued. Repeated faint masks at 12 or 64 stages can differ from CPU float coverage by three channel levels; ordinary mask parity checks retain their two-level tolerance. This is a precision limit of the retained coverage state.

Resource ownership and reuse

Root instances are process-owned and shared by backend selection to preserve WSL/Mesa GL's EGL lifetime. Each prepared renderer owns its device, queue and resources. Keep device, queue and submission identities distinct when managing completion; see the upstream identity correction and lifecycle verification.

The backend has bounded in-flight work. Resource reuse follows completion:

  1. Retain texture pools, source caches, staging buffers, pending static layers and readback slots across the prepared operation.
  2. Associate submitted work with its GPU completion token.
  3. Release or reuse those resources only when completion makes it safe.

VESTRA_WGPU_IN_FLIGHT controls implementation pipeline depth only when valid; it is not a semantic setting. A PreparedProject owns one backend instance and is not freely concurrent because these resources and submissions share state.

Frame planning and module ownership

The internal frame path has these owners, all inside crates/vestra-render-wgpu/src/wgpu/:

Module Owns
video_pool.rs Decoder factories/sessions, independent placement cursors, per-asset cache budgets, immutable request sharing, retirement and cumulative decoder metrics
backend.rs Prepared resources and per-submission slots, video uploads, cache reservations, polling, cancellation and lifecycle coordination
frame_plan/mod.rs, frame_plan/operations.rs Frame-plan interface, authoritative operation and texture-role definitions, canvas alternation
frame_plan/builder.rs Ordered frame construction, recursive layers/groups, static-cache operations and compositing
frame_plan/masks.rs Mask coverage, feathering, isolated sources and matte planning
frame_plan/effects.rs Core effect-pass expansion, logical-resource liveness and physical texture-slot binding
frame_plan/validation.rs Texture initialization and logical values, aliasing, operation sequencing and diagnostics
parameters/ Typed WGSL-compatible records, packing and the aligned uniform arena; parameters/frame.rs encodes records in operation order and prepares particle ranges/uploads
registry.rs One kernel/support/record/label/ordered-shader declaration, projected into shaders, parameter variants, identity, upload and ABI-test coverage
bind_groups.rs Prepared bind-group creation, reuse and lookup, plus binding construction for cached layer textures
executor.rs Parameter upload, command encoding, pipeline dispatch, texture copies and submission metrics

The private FramePlanBuilder owns the operation/layer vectors and shared parameter/value counters. Recursive calls retain explicit canvas and logical value transitions. Effect expansion and validation consume the same operation and texture definitions in a fixed-slot planner.

Caching and capability policy

support.rs owns WGPU kernel/blend capability policy and plan validation. Common supplies kernel identifiers and operation/requirement mapping; the facade uses backend validation for selection and fallback. Shader source/labels and pipelines stay in WGPU, alongside private planning/resource tests. Cross-backend parity tests live in the facade and use public submission/completion contracts.

Bind groups remain owned by the backend's frame slots. Most are prepared once; bindings for static cached textures are created on demand during command encoding and counted in that scope. Topology, requirements, pipelines, texture pools and readback have separate resource responsibilities.

Shader labels and ordered static WGSL fragments derive from registry.rs; pipeline.rs prepares supported kernels in common inventory order. Unsupported kernels need an explicit backend decision. Registered code, backend support, device capabilities and prepared-resource requirements remain separate facts. The effect_parameters! record macro and registry-driven tests check every registered record's size/alignment, named field offsets and scalar types against validated WGSL, plus typed upload. Numerical packing and algorithms still need their own specimens and rendered-pixel tests. The runtime kernel-mismatch guard remains in parameter/frame planning.

Metrics and current limits

The current pipeline/shader counter omits one of nine base entries: with 19 effect kernels it reports 27 for 28 actual creations. Interpret that metric with this limitation; registration order and pipeline reuse do not depend on it.

Kernel identifiers and operation requirements stay backend-neutral. Shared shape rasterization prepares immutable pixels consumed by both backends. WGPU resource tests run with the WGPU feature alone. Tests comparing CPU and WGPU output additionally require CPU.

Metrics distinguish initialization, command encoding/submission, uploads, readback waits and row repacking. A request for WGPU can still fail at adapter, device, pipeline, upload or runtime-pass boundaries. Automatic renderer selection may report VESTRA-WGPU-FALLBACK and use CPU; an explicit request follows preflight policy. Do not hide either case behind a generic "GPU" label.

This page describes implementation ownership. For adapter commands and hardware classification, use GPU validation. For user recovery steps, use WGPU troubleshooting. The public selection contract is in Backends.