Skip to content

[Epic] Native WebGPU and WebGL 1/2 with GPU-resident canvas composition and Kestrel compatibility #22

Open
0 of 20 issues completed

Description

@danwalmsley

Current delivery priority: macOS first

The epic author has authorized prioritizing a working macOS implementation and
qualifying Windows and Linux afterward. This overrides the earlier strict
cross-platform implementation-order gate; the complete desktop scope and
acceptance criteria remain unchanged.

The same native Dawn/Tint, ANGLE and GPU-resident Skia architecture applies.
The Graphite host experiment remains diagnostic evidence; it does not by itself
authorize declaring a renderer migration complete or bypass rendering parity.

Outcome

WebScene must run browser-authored WebGPU and WebGL content through its native V8 engine, integrate GPU canvases into normal DOM/Canvas/SVG composition, and present efficiently without CPU pixel copies during ordinary rendering.

Implement WebGPU through Dawn/Tint, WebGL 1 and 2 through ANGLE, and GPU image composition through the existing Skia rendering stack. Preserve native execution and retained scenes; avoid per-draw managed interop. This epic includes the full implementation and qualification roadmap, not only a Kestrel-specific API subset.

Agreed scope

  • Initial desktop matrix: Windows, macOS and Linux; both Avalonia and Uno presenters.
  • Initial packaged RIDs: win-x64, osx-arm64, linux-x64. Other architectures need equivalent qualification before support claims.
  • Full WebGPU and WebGL 1/2 APIs, delivered through staged gates. Kestrel is the early acceptance application, not a substitute for standards coverage.
  • Run Kestrel unchanged: rendering, CAD editing, navigation, KCAD/DXF import/export, PNG export, themes, high DPI and resize.
  • Target smooth 60 Hz interaction; measure 10,000- and 100,000-line workloads against hardware-accelerated Chrome on identical hardware.
  • Native presenter/framework changes are allowed where required. Preserve existing Skia composition initially; a wholesale Graphite migration is not a prerequisite.
  • Flutter/mobile, optional DWG conversion-service integration, and printing are outside the first desktop release.
  • Remain in-process, consistent with the existing native engine. This is not a claim of browser-style process sandboxing.

Existing implementation and concrete gaps

Source inspection found:

  1. The native V8 engine owns DOM/CSS/layout and publishes immutable scene data to framework render threads.
  2. Native HTMLCanvasElement.getContext() accepts only "2d"; other modes return null.
  3. Canvas toBlob()/toDataURL() use host snapshot handoffs rather than complete browser-compatible encoded pixel results.
  4. The retained presenter uses Skia pictures without a shared GPU-image resource/lifetime contract.
  5. Avalonia is pinned to 11.3.4 with SkiaSharp 2.88.9; Uno uses SkiaSharp 3.119.2. Do not exchange native Skia object pointers between incompatible builds.
  6. The current WebIDL generator installs an exposure catalog; it does not implement browser semantics.
  7. The existing OpenGl capability is not proof of WebGL conformance.
  8. Current publication code supports bounded ordered consumption as well as legacy latest-only behavior. Preserve actual code-level ordering and acknowledgement contracts when extending it.

Repository starting points:

Kestrel evidence and requirements

The supplied Kestrel-CAD.zip is MIT licensed, copyright 2026 Kestrel CAD contributors.
Archive SHA-256: 1e9a272449923ea1d2a24b4ce7f1a1f424d0a6c9a979ef155e2a67c1424d9f7d.

The fixture is a user-supplied archive, not an existing public source URL. The baseline sub-issue must make a checksum-pinned fixture available to developers/CI with its license preserved. Do not depend on an author's Downloads directory.

Kestrel uses:

  • WGSL instanced antialiased line quads and depth-tested lit triangles.
  • Retained vertex buffers; a 96-byte camera uniform buffer; queue.writeBuffer().
  • Bind-group layouts, bind groups, pipeline layouts and three rendering pipelines.
  • Four-sample MSAA and depth24plus; resolve into the current canvas texture.
  • Shader compilation information, validation error scopes, uncaptured error events, adapter information and device.lost.
  • A Canvas 2D overlay for annotations and interaction.
  • Cross-canvas drawImage() and toBlob() for PNG export.
  • ResizeObserver, animation frames, storage, Blob/File and download behavior. Its I/O worker has an existing synchronous fallback.

The nine supplied GPU tests also require copyTextureToBuffer(), aligned row strides, mapAsync(), getMappedRange(), unmapping and onSubmittedWorkDone(). They cover actual pixels, buffer retention, shading/MSAA, depth, coordinates near 1e9, styles, themes, resize and presentation.

The archive explicitly records webgpu_hardware_tested: false; its GPU result is UNAVAILABLE, not a pass. Supplied images and browser results do not prove GPU correctness.

Kestrel falls back to Canvas 2D, not WebGL. Keep it unchanged. Prove WebGPU → WebGL 2 → WebGL 1 application fallback with a separate fixture.

Backend research and decision

Option Evaluation Decision
Dawn + Tint C/C++ WebGPU implementation underlying Chromium; explicit shared-memory and fence extensions; matches the native C++ engine. Primary WebGPU implementation.
wgpu / wgpu-native + Naga Credible native alternative; Rust HAL interop exists, but native C exposure and texture-sharing requirements need additional bridging/audit. Reference/comparison candidate; do not ship a second WebGPU implementation initially.
ANGLE Established OpenGL ES translation and WebGL compatibility validation. Does not provide WebScene's JavaScript or all browser semantics. Independent WebGL 1/2 implementation.
Existing Skia/Ganesh Preserves Canvas 2D, text, SVG and presenter behavior; needs external GPU-image imports and synchronization. Initial production compositor.
Skia Graphite on Dawn Accepts a Dawn device/queue; attractive future common native compositor, but moving current renderer behavior is substantial and host interop remains. Separate future migration, requiring rendering-parity and measured performance evidence.
ProGPU Useful native presentation, retained resources, typed GPU operations and explicit shared-texture lifetimes; replacing framework/Skia layers is broader than this API feature. Reference design, not a runtime dependency.
Direct Vulkan/Metal/D3D12, SDL GPU or bgfx Lower-level graphics access leaves WebGPU validation, WGSL and WebGL compatibility work to WebScene. Reject for this feature.
Vello/other replacement 2D renderer Solves vector rendering rather than browser GPU APIs and creates extra parity work. Reject as a prerequisite.
Embedded Chromium/WebView Replaces WebScene execution/rendering architecture. Out of scope.

Dawn is the recommended engineering fit, not a benchmark-proven performance winner. The planning research did not execute comparative GPU benchmarks.

Inspect ProGPU at revision 102e39e5088b462624da6296ff70a43ed2c5d8b4. Adopt ideas for generation-bearing handles, explicit access scopes, bounded command storage, resource lifetime and separately measured presentation costs. Preserve attribution if code is reused. Do not copy its broader framework replacement or SkiaSharp compatibility layer into the hot path.

Rendering architecture

flowchart TD
    JS[Native V8 application]
    JS --> GPU[WebGPU bindings: Dawn / Tint]
    JS --> GL[WebGL bindings: ANGLE]
    JS --> DOM[DOM / CSS / Canvas 2D]
    GPU --> Images[GPU canvas texture leases]
    GL --> Images
    Images --> Scene[Immutable scene and versioned resource references]
    DOM --> Scene
    Scene --> Skia[Retained Skia composition]
    Skia --> Hosts[Avalonia / Uno presentation]
Loading

Native API boundary

  • Bind V8 directly to native graphics implementation. Extend WebIDL exposure/conversions and implement semantics explicitly.
  • Keep descriptor conversion, typed-array handling, command encoding and validation outside the managed boundary.
  • Preserve uploaded data at the API-defined point; deferred execution must not see subsequent JavaScript mutation/detachment.
  • Resolve promises and dispatch compilation/errors/loss on the owning V8 event loop, including when no animation frame or visible window exists.
  • Separate independent JavaScript device/context ownership. Do not combine independent GPUDevice lifetimes into one destroyable device.
  • Keep framework-owned Skia resources on the presenter thread. Native graphics wrappers/services have their own documented lifetime and execution ownership.
  • Dawn's Node bindings are a reference for conversions/CTS integration, not a drop-in embedded-V8 dependency.

What "versioned GPU canvas images" means

These are metadata references to GPU textures, not copied screenshots. Identify a resource, allocation generation, canvas generation and rendered-frame serial. Include dimensions, format, alpha/color/orientation, producer completion and an opaque lease.

Normal path: the application renders into a GPU allocation, the presenter imports/references that allocation, and Skia samples it. Passing a handle does not copy pixel storage.

  • Avoid CPU readback, CPU bitmap upload and repeated full-frame pixel copies during ordinary presentation.
  • MSAA resolve and final composition still perform GPU work. A necessary GPU-local conversion copy is allowed only when measured and reported.
  • Explicit readback/export operations may copy pixels to CPU memory.
  • Reuse a bounded texture pool (initial maximum three presentation images per active canvas). A new scene revision does not imply a new allocation or pixel copy.
  • Do not overwrite or free an image until producer work and all consumer use have completed.
  • Scene acknowledgement/release is distinct from GPU completion. Skipped scenes, retained redraw and snapshots must keep referenced resources alive.

Canvas/scene contract

  • Use a common backing identity for 2D/WebGL/WebGPU canvases with exclusive context mode and allocation/content generations.
  • Repeated same-mode getContext returns the same object; incompatible mode requests return null.
  • Add a separately versioned scene view/acquisition ABI and a typed GPU-resource lease/import boundary. Old presenters retain the old ABI; unsupported GPU scenes fail capability negotiation.
  • Preserve correct paint order, interleaved DOM, transforms, opacity, clipping, isolation and damage. Refine the backdrop/canvas/overlay representation where necessary.
  • drawImage observes the source at the specified snapshot point, not whichever future frame occupies the same allocation.
  • Support real PNG bytes from combined GPU canvas and Canvas 2D overlay exports.

Platform texture sharing

Platform Default producers Interop target
Windows Dawn D3D12; ANGLE D3D11 Compatible DXGI shared allocations with negotiated fences/keyed mutexes.
macOS Dawn Metal; ANGLE Metal IOSurface-backed images with explicit producer/consumer completion.
Linux Dawn Vulkan; ANGLE Vulkan, with GL fallback where appropriate Negotiated external memory, formats/modifiers/layouts and synchronization handles.
  • Select presentation-compatible adapter identity for GPU canvases; negotiate capabilities instead of assuming cross-adapter sharing.
  • Allocate shareable single-sample color images. Keep MSAA/depth private and resolve into the shared color allocation.
  • Honor Dawn BeginAccess/EndAccess and exported/imported fence ownership.
  • Use typed presenter hooks within actual Skia draw scope; narrowly pinned framework patches are allowed.
  • Do not exchange Skia object pointers between incompatible builds.
  • Avalonia's public image import/synchronization is a starting point, not proof that all needed custom-draw hooks exist.
  • Uno's supplied GLCanvasElement performs ReadPixels into a bitmap; that path does not satisfy this epic.
  • If a configuration cannot satisfy the interop gate, report it unsupported; do not silently replace it with CPU presentation.

Scheduling and resource limits

  • Preserve compositor frame timestamps, RAF behavior and bounded scene-publication ordering.
  • Drop obsolete presentation opportunities only. Never drop queue submissions, compute work, uploads or observable side effects.
  • Apply backpressure with bounded queues/resource residency instead of growing allocations indefinitely.
  • Resize attachments only when bitmap requirements change; distinguish CSS layout from backing resolution.
  • Reuse imports, buffers/pipelines and retained pictures for unchanged content.
  • Batch native WebGL work where appropriate; synchronous queries flush only required work and return exact results without UI-thread dependency.
  • Progress callbacks/readback and teardown without global GPU idle waits in ordinary rendering.

Capabilities, fallback and failure behavior

  • Add explicit WebGl1/WebGl2 capabilities; do not reinterpret OpenGl as WebGL conformance.
  • Distinguish implementation support, adapter availability, acceleration and tested conformance status.
  • Support manifests accepting alternative graphics capabilities.
  • Default host policy enables available hardware APIs; provide controls to disable WebGPU or hardware for tests.
  • Preserve secure-context exposure/origin semantics; never globally spoof isSecureContext.
  • WebGPU adapter failure leaves WebGL independently available. WebGL must work on configurations that cannot provide WebGPU.
  • Device loss/context loss follows standard observable behavior. Applications choose recreation/fallback.
  • Never silently convert a webgpu canvas into a webgl canvas or claim arbitrary WGSL/compute can execute as WebGL.

Delivery sequence and gates

  1. Presentation proof: pin dependencies and build native Dawn/ANGLE offscreen probes; prove both presenter integrations on the desktop matrix before relying on them for browser API acceptance.
  2. Kestrel: implement its WebGPU requirements and all nine supplied GPU tests, add actual presented-pixel assertions, and run the unchanged CAD workflow.
  3. WebGL and fallback: complete WebGL 1/2 bindings and an independently validated WebGPU/WebGL fallback fixture; compose all canvas modes together.
  4. Full standards coverage: complete remaining WebGPU features, sources, external textures, dedicated-worker/OffscreenCanvas integration and actual JS-level official conformance.
  5. Release qualification: hardware performance, resilience, clean-package consumers, symbols/licenses and accurate support documentation.

The ordered sub-issues below provide the detailed implementation breakdown and direct dependencies.

Recommended implementation order is the numbered sequence below. Direct prerequisites are also listed; platform bridges can be developed independently after the shared ABI is ready.

Order Sub-issue Direct prerequisites
01 #23 — Pin graphics dependencies and establish hardware/fixture baselines None
02 #24 — Implement native graphics ownership, execution and completion services #23
03 #25 — Add versioned GPU canvas resources and scene lease ABI #24
04 #26 — Implement Windows DXGI texture and synchronization interop #25
05 #27 — Implement macOS IOSurface and Metal synchronization interop #25
06 #28 — Implement Linux external-memory and semaphore interop #25
07 #29 — Integrate GPU canvas images into Avalonia retained composition #26, #27, #28
08 #30 — Integrate GPU canvas images into Uno Skia composition #26, #27, #28
09 #31 — Implement V8 WebGPU objects, discovery, resource bindings and capabilities #29, #30
10 #32 — Implement WebGPU rendering, canvas presentation and Kestrel pipelines #31
11 #33 — Complete WebGPU async errors, mapping, copies and device-loss semantics #32
12 #34 — Implement cross-canvas snapshots and real PNG/Blob pixel export #33
13 #35 — Qualify the unchanged Kestrel CAD workflow in Avalonia and Uno #34
14 #36 — Implement native WebGL 1 bindings and ANGLE browser semantics #35
15 #37 — Implement WebGL 2 and explicit application GPU fallback coverage #36
16 #38 — Complete remaining WebGPU core APIs and feature validation #37
17 #39 — Implement dedicated-worker GPU APIs and OffscreenCanvas ownership #38
18 #40 — Complete external image/video sources and GPU texture interoperability #39
19 #41 — Qualify WebGPU/WebGL conformance, resilience and support claims #40
20 #42 — Enforce performance budgets and ship qualified desktop runtime packages #41

Progress checklist

Test and verification policy

  • Run native/ABI tests, presenter integration/pixel tests and actual V8 JavaScript tests. Testing Dawn or ANGLE alone is insufficient.
  • Run official pinned WebGPU CTS, Khronos WebGL suites and relevant WPT cases through WebScene's own exposed APIs.
  • Report passed/failed/skipped/unavailable/harness-blocked separately with an explicit denominator. Missing hardware or harness support never counts as a pass.
  • Exercise resize/high DPI, CSS clipping/transforms, transparent overlays, multiple devices/documents/canvases, detach/reparent, context loss, cancellation and shutdown.
  • Verify memory lifetime under delayed consumer completion, skipped publication, stale-generation handles, failed imports and out-of-order callbacks.
  • Kestrel: courtyard/fixture examples, wireframe/shaded/edged/x-ray, editing/navigation, dark/light, DPR 1/2, KCAD/DXF exchange and composed PNG. Test its existing Canvas 2D fallback separately.
  • Full-support claims require applicable official coverage. Kestrel success alone may justify only the explicitly bounded preview capability.

Performance gates

Compare identical drawings, viewports and interaction scripts with hardware Chrome on the same machine. Capture OS, GPU/driver, adapter, framework/runtime commits and acceleration evidence.

  • 10,000 lines: sustained 60 Hz at a 1920×1080 logical viewport, DPR 1 and 2.
  • 100,000 lines: 60 Hz where Chrome achieves it; otherwise p95 render/submission time within 20% of Chrome.
  • Zero CPU pixel-readback bytes during ordinary GPU presentation; identify all GPU-local copies and their causes.
  • No full geometry reupload on unchanged frames or camera-only movement.
  • No GPU work for unchanged idle content.
  • Bounded memory after repeated resize, document replacement, loss/recovery and a 30-minute interaction run.
  • Existing non-GPU performance gates within 5% of a pinned baseline under repeatable measurement.

Measure CPU API/encoding/submission, GPU work, presentation, input latency, dropped frames, allocations, GPU residency and copy bytes separately. Do not substitute reported app CPU time for actual frame presentation or GPU timing.

Epic completion checklist

  • Dawn and ANGLE dependencies are reproducible and correctly packaged.
  • Windows/macOS/Linux texture sharing is hardware-proven for Avalonia and Uno.
  • Normal presentation uses no CPU pixel readback/upload loop.
  • Native WebGPU, WebGL 1 and WebGL 2 expose correct browser behavior.
  • Canvas context locking, texture snapshots, export and GPU lifetime are correct.
  • Unmodified Kestrel CAD workflow and all nine GPU tests pass with presented-pixel evidence.
  • Independent WebGPU → WebGL 2 → WebGL 1 fallback works.
  • Remaining APIs, source types, dedicated workers and OffscreenCanvas are covered.
  • Applicable pinned CTS/WebGL/WPT coverage passes for the claimed desktop configurations.
  • Performance, loss/recovery, long-run memory and non-GPU regression gates pass.
  • Clean consumers can install and run the three initial RIDs with symbols/licenses/support matrix.
  • All child issues have completion evidence; no unsupported test is represented as a pass.

Research references

Research establishes the design, not measured implementation success. Interoperability/performance assertions must be demonstrated by the implementation gates.

Platform agent handovers

Both start from pushed revision 038c0678e5b4667f36f68cdee68861460cbd761f (or a verified descendant of PR #43), include the tracked original Kestrel ZIP and checksum, and require the same Chrome-inspired scheduling, retained resize images, GPU waits/retirement and shared text optimizations. They coordinate target-platform work without waiving numbered issue acceptance or unavailable hardware gates.

Sub-issues

Sub-issues

0 of 20 Issues completed
Loading 20 sub-issues

Activity

  1. added
    enhancement
    on Sep 7, 2026
  2. added sub-issues on Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementsize/XXL

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions