Skip to content

[GPU 02/20] Implement native graphics ownership, execution and completion services #24

Open

Description

@danwalmsley

Parent epic: #22
Implementation order: 02 of 20.
Depends on: #23.

Outcome

Provide a native lifetime and execution foundation for Dawn, ANGLE and presenter resources without introducing per-draw managed calls or V8 thread-affinity violations.

Implementation

  • Add a native graphics service with explicit instance/adapter/device/context ownership. Define engine-thread binding access, ANGLE context-thread execution, presenter-thread resources and callback delivery.
  • Use typed generation-bearing handles; reject stale/wrong-device/wrong-context handles before dereferencing. Independent JavaScript devices must retain independent destroy/loss behavior.
  • Integrate Dawn event processing and native completion delivery with the engine task queue. Mapping/pipeline/error/loss completions must progress without RAF, even while hidden/headless.
  • Establish bounded native work/completion queues and reusable arenas. Copy or retain upload data at the API-required point before JavaScript can mutate/detach it. Never defer reads from unowned V8 memory.
  • Preserve FIFO queue side effects. Backpressure may delay work; only presentation opportunities may later be coalesced, not submitted compute/draw/upload commands.
  • Implement cancellation/navigation/shutdown sequencing, late-callback rejection, pending-promise termination and destruction after in-flight GPU work. GC finalizers enqueue safe release rather than calling arbitrary GPU APIs on the wrong thread.
  • Keep framework-owned Skia objects confined to presenter scopes. Document the distinction between native graphics API resources and borrowed framework GPU state.
  • Add service metrics for live resources, queue depth/high-water, upload/copy/readback bytes, deferred destruction and completion latency. Enable expensive timing only through diagnostics.

Tests

  • Destroy a device with pending mapping/submission; navigate/dispose before callbacks complete.
  • Multiple engines, adapters/devices and ANGLE contexts; stale generation and cross-owner resource use.
  • Mutate/detach typed-array data after enqueue; verify uploaded content matches call-time semantics.
  • Pause RAF/hide the window; verify completion progress.
  • Saturate queues, inject delayed completions, force device/context loss and exercise teardown repeatedly.

Verification evidence

Provide an ownership/thread diagram, queue invariants, sanitizer/native stress results and resource-counter before/after snapshots. Demonstrate absence of UI-thread dependency for native completion/query progress.

Acceptance

  • No V8 callback executes off its owning engine thread.
  • Native commands remain ordered with bounded storage.
  • In-flight resources survive until safe release; stale handles fail deterministically.
  • Device/context isolation and late-callback cancellation work.
  • Idle/non-GPU overhead remains within the epic baseline gate.

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