WebGPU & WebGL2 Dual-Backend Runtime
All runtime logic lives in plain ES modules (runtime/) with zero third-party packages or WebAssembly binaries.
Backend Selection & Parity Mechanics
probeCapabilities()/createFrameFlow()tries WebGPU Compute first (automatically requestingshader-f16when supported, otherwise aliasingF = f32), then falls back to WebGL2 Fragment Shaders requiring float/half-float renderable FBO support.- When neither is supported, session creation fails explicitly instead of falling back to CPU/WASM compute that would starve host emulators.
parseModel()&compilePlan()(runtime/loader.js) validate even binary byte length,format_version === 1, tensor offsets, graph references, decode little-endian IEEE-754f16weights viaf16ToF32, pad working sizes withalign32(), and unrollrepeatloops into staticpairSteps+midSteps.FrameFlowPacer(runtime/pacer.js) maintains an EMA frame-interval estimate (clamped over 4–200 ms source deltas), queues2×/3×intermediate slots without calling GPU readback in the hot loop, and drops stale items when queue depth exceedsfactor + 2.
| Dimension | WebGPU Backend | WebGL2 Backend |
|---|---|---|
| Tensor layout | 1D storage buffers (array<f16> / array<f32>) | RGBA16F TEXTURE_2D_ARRAY (4 channels/layer) |
| Conv dispatch | 3D compute workgroups (@workgroup_size) | 4-target MRT drawBuffers (16 output ch/draw) |
| External zero-copy | { device: GPUDevice } + setExternalInputTexture() | { gl: WebGL2RenderingContext, flipSrcY } |