Flutter embedder step 3b: Metal zero-copy renderer - #33
Merged
Conversation
Design for switching the out-of-process guest from the software renderer to the Metal renderer, rendering directly into shared IOSurface-backed Metal textures with a GPU completion fence before FrameReady. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces the cross-thread retired-ring mechanism with raster-thread reallocation inside get_next_drawable, where the engine holds no texture. Simpler and equally correct. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The out-of-process guest now renders directly into shared IOSurface-backed Metal textures instead of memcpy'ing software-rendered frames. FrameReady is sent from a GPU completion-handler fence; the surface ring is reallocated inside get_next_drawable on resize. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Step 3b of the experimental Flutter engine embedder: the out-of-process guest
switches from the software renderer to the Metal renderer, rendering
directly into shared
IOSurface-backed Metal textures — a true zero-copy pathwith no per-frame
memcpyand no RGBA→BGRA swap.FlutterRendererConfigbecomeskMetal. Each ringIOSurfacealso backs anid<MTLTexture>the engine renders into viaget_next_drawable/present_drawable.present_drawablecommits an emptycommand buffer on the shared
present_command_queueand sendsFrameReadyfrom its completion handler, so the GUI never reads a half-rendered surface.
surface.c→surface.m(Objective-C, ARC).get_next_drawablewhen the requested size changes; at that point the engineholds no texture, so a resize never races an in-flight texture and no ring
mutex is needed.
--capture-rawsmoke now reads the IOSurfaceback via
IOSurfaceLock;decodeRawFramedecodes BGRA.embedded_engine.dart,protocol.dart,EmbedderTexturePlugin.swift) and the wire protocol are unchanged — theplugin already wraps the IOSurfaces as Metal-compatible
CVPixelBuffers.Design and plan:
docs/superpowers/specs/2026-05-15-flutter-embedder-step3b-design.md,docs/superpowers/plans/2026-05-15-flutter-embedder-step3b.md.Test plan
flutter test test/embedder— protocol + raw-frame unit tests pass (raw-frame fixtures updated to BGRA)dart run app/tool/embedder/run.dart) renders the scene with correct colors/tmpsocket because the worktree path exceeds the macOS AF_UNIX limitflutter analyze— no issuesflutter run -t lib/main_embedder_dev.dart -d macos …) and confirm the live scene renders, resizes, and takes pointer/keyboard input with no Metal/IOSurface console errors or tearing🤖 Generated with Claude Code