Skip to content

[GPU 03/20] Add versioned GPU canvas resources and scene lease ABI #25

Open

Description

@danwalmsley

Parent epic: #22
Implementation order: 03 of 20.
Depends on: #24.

Outcome

Represent GPU canvases as retained references to existing GPU allocations, not serialized pixel snapshots, while preserving scene ordering and lifetime.

Implementation

  • Introduce a common canvas backing identity for 2D, WebGL and WebGPU. Track exclusive context mode, bitmap size, allocation generation and content/frame serial.
  • Add a separately versioned scene view/acquisition API and explicit GPU-resource lease operations. Preserve the old ABI for old consumers; reject unsupported GPU scenes at capability negotiation.
  • Carry opaque image identity, dimensions, format, alpha mode, color space, orientation, generation/frame serial and producer readiness. Keep native texture/Skia pointers outside JS and portable scene tables.
  • Define acquire/retain/release and consumer-completion semantics. Scene acknowledgement must not free or recycle pixels still used by the GPU, a retained frame or a snapshot.
  • Use a bounded presentation pool, initially at most three reusable color images per active canvas. Define allocation backpressure and memory accounting; do not overwrite busy slots or grow the ring indefinitely.
  • Preserve actual bounded ordered publication behavior and stale-base/checkpoint recovery. Coalescing presentation must not discard native queue side effects.
  • Refine retained paint operations to interleave GPU images with DOM/Canvas/SVG content where required, including transforms, clipping, opacity, isolation and damage.
  • On bitmap resize, issue a new allocation generation while retaining old leases until consumers complete. CSS size changes alone do not always require new pixel storage.

Tests

  • ABI layout/size/version/symbol checks and old-consumer/new-producer negotiation.
  • Delayed consumer completion, skipped scenes, retained redraw, stale generations and checkpoint recovery.
  • Resize while old frames are in flight; remove/reparent/reinsert a canvas; detach/dispose engines.
  • Three-slot saturation; ensure backpressure and plateaued allocations.
  • Paint-order/clip/damage fixtures with interleaved transparent canvases and DOM.

Verification evidence

Document the lease state machine and producer→scene→presenter→release timeline. Include tests demonstrating that changing a scene/frame serial does not allocate/copy pixel storage by itself.

Acceptance

  • GPU resources are represented by versioned metadata and leases.
  • Resource lifetime is independent of scene acknowledgement.
  • Old ABI consumers continue functioning for supported non-GPU scenes.
  • Resize, dropped presentation and delayed GPU completion cannot cause stale sampling/use-after-free.
  • Paint order and bounded pool behavior are covered by executable tests.

Completion requirements

Link the implementation PR, exact test commands, native/runtime/framework revisions and verification artifacts before closing. Follow the epic's architecture and copy/lifetime invariants. Any unavailable mandatory hardware or missing required functionality remains incomplete, not a pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions