Skip to content

M3b spike: Metal zero-copy feasibility (wgpu-hal interop + rive external-record) #5

Description

@Bantarus

Context

Metal is planned but NEVER spiked — strictly less advanced than D3D12, which got a full source-read feasibility report. rive ships a Metal backend (RenderContextMetalImpl::MakeContext(id<MTLDevice>, ContextOptions), render_context_metal_impl.h:111-116, .mm). Metal's submission model is a third variant: rive's FlushResources.externalCommandBuffer is id<MTLCommandBuffer>, which self-submits via commit. The C-ABI siblings are already declared+stubbed. This issue is the spike that must precede any Metal implementation, mirroring the D3D12 feasibility spike (summarized in ROADMAP.md).

Open questions to resolve (source-read, no Apple HW needed for the spike)

  • Does rive's Metal flush() record into a caller-provided id<MTLCommandBuffer> without committing (the make-or-break, analogous to D3D12 :1041-1056)?
  • wgpu-hal metal interop: this session found Texture::raw_handle() -> &metal::Texture (metal/mod.rs:544) and Queue::as_raw() (:373) ARE public, BUT CommandEncoder.raw_cmd_buf is PRIVATE with only a Debug impl (:990) — the Metal analog of the dx12 open-list ADAPT — and the MTLDevice is behind a private AdapterShared.device Mutex (:328, no Device accessor). Can we (a) extract the MTLDevice/MTLCommandQueue to feed MakeContext, and (b) hand rive wgpu's open command buffer, or use rive's own + ordering on the shared MTLCommandQueue?
  • Watermark: use MTLSharedEvent / completion handlers (wgpu-hal exposes raw_shared_event() at metal/mod.rs:929)?
  • Native Metal (preferred, bring-your-own-device: rive into a wgpu-allocated MTLTexture) vs Vulkan-via-MoltenVK (nonconformant, reuses shipping code)?

Scope

  • Produce docs/M3b_METAL_SPIKE.md with per-primitive GO/ADAPT/BLOCKED verdicts citing exact sources, mirroring the D3D12 spike format. No bridge code.

Acceptance criteria

  • Every Metal primitive has a verdict traced to a cited source location; the open-command-buffer and device-extraction questions are answered; native-vs-MoltenVK recommended; build/CI prerequisites enumerated.

Refs

  • vendor/rive-runtime/renderer/include/rive/renderer/metal/render_context_metal_impl.h:111-116
  • vendor/rive-runtime/renderer/src/metal/render_context_metal_impl.mm
  • crates/rive-renderer-sys/shim/rive_shim.h:452-459, src/lib.rs:549-565
  • wgpu-hal-27.0.4/src/metal/mod.rs:328,373,544,929,988-990

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions