Repository navigation
Description
When Android renders platform views using Hybrid Composition or HCPP, the root Flutter surface and any overlay surfaces share a single GPU context and tracer. The Vulkan GPU tracer assumes only one frame can be active at a time, so acquiring and presenting multiple surfaces within a single Flutter frame corrupts the traced frame boundaries.
Under HCPP, the overlay surface starts and finishes its traced frame before the root surface finishes encoding and submitting its work, which triggers a debug assertion on overlapping frame starts and drops the root surface's GPU work from the trace. Under Hybrid Composition, each overlay surface emits its own GPU frame time event that dilutes the reported average, and frames that acquire an overlay surface without submitting it leave the tracer stuck mid-frame and hit the debug assertion on the next frame.
Specifically, AndroidSurfaceVKImpeller shares a single ContextVK and GPUTracerVK across surfaces, and GPUTracerVK gates frame tracking with a single in_frame_ boolean toggled by MarkFrameStart and MarkFrameEnd. In #196822, GPU frame time metrics were disabled for the affected HCPP and Hybrid Composition benchmarks (createAndroidHCPPScrollPerfTest and createAndroidViewScrollPerfTest in dev/devicelab/lib/tasks/perf_tests.dart). Once GPUTracerVK supports multi-surface frames, re-enabling those metrics is in scope for this issue.
Related:
Activity
andywolff commentedon Nov 18, 2026
While planning the fix for this issue, I uncovered two additional problems beyond overlapping frame starts and premature frame ends.
First, frames that acquire a surface without presenting it (such as the first platform-view frame or retried frames) never close the tracer's frame scope, leaving it stuck mid-frame. Specifically,
AcquireNextDrawablecallsGPUTracerVK::MarkFrameStart(), and whenSurfaceFrame::Submit()is skipped (for example onRasterStatus::kSkipAndRetryorprevious_frame_view_count_ == 0),Present()never runs to callMarkFrameEnd(), leavingin_frame_set totrue.Second, overlay swapchains hold onto their last onscreen command buffer in a ring buffer until that slot is reused two presents later on the same swapchain. When an overlay goes idle while the root surface keeps rendering, those retained probes keep pending buffer counts non-zero on the shared trace state, dropping metrics and hitting the pending-buffer assertion once the trace state ring wraps around. Specifically,
AHBSwapchainImplVKandKHRSwapchainImplVKkeepsync->final_cmd_buffer(and itsGPUProbe) alive until the swapchain reuses that frame slot, rather than releasing it on GPU fence completion viaFenceWaiterVK.To keep reviews small, I plan to split this into three focused engine PRs before re-enabling the benchmarks:
final_cmd_bufferprobes viaFenceWaiterVKon GPU completion so idle swapchains do not retainpending_buffers, and updateGPUTracerVK::RecordCmdBufferEndto index*probe.index_instead ofcurrent_state_.bool in_frame_with a reference-countedactive_frames_counter, an RAII frame-scope token owned bySurfaceVK/ the swap callback, and explicitGPUTraceState::frame_endedcoordination, fixing HCPP and unsubmitted/retried frames.frame_boundary = falsethroughGPUSurfaceVulkanImpellerandAndroidExternalViewEmbedder::SubmitFlutterViewfollowed byGPUTracerVK::MarkFrameBoundary(), combining Hybrid Composition root and overlay surfaces into one traced frame.There is also a metrics semantics decision to make for Hybrid Composition: whether the merged GPU frame time should measure the wall-clock span across the whole frame or only the time the GPU is actively busy. Because Hybrid Composition submits the root surface, performs CPU, JNI, and fence-wait work, and then submits overlay surfaces, a single
max - minspan includes that idle gap between submits, while summing per-surface work excludes it. To preserve both views, I propose keepingFrameTimeMSas the wall-clockmax - minspan (consistent withGpuSumarizerand existing single-surface expectations) while also recording per-command-buffer(start_index, end_index)intervals and emitting a supplementalActiveTimeMScounter value on the sameGPUTracerevent.[devicelab] Enable Vulkan GPU tracing by default on Android Impeller …
andywolff commentedon Nov 24, 2026
I was talking to @gaaclarke about this, and we agreed that the complexity required to support everything I mentioned in my previous comment is likely not worth it. For now, we'll add frame time measurement to HCPP test cases only.
To summarize the reasoning:
In a platform-view frame, there are multiple Flutter surfaces sharing one Vulkan context and frame time tracker: the root surface (Flutter UI below the platform view) and one or more overlay surfaces (Flutter UI on top of the platform view; a single shared overlay in HCPP).
What do we actually want to measure? Frame time, which in the case of multiple surfaces is fine to measure as the union of the surfaces (latest end minus earliest start across the frame). That is the closest thing to a whole frame. It loses some detail when there are idle gaps between submits, which is why I previously suggested adding a secondary "active time" metric, though it is not clear we need that extra complexity.
Do we actually need to measure both surfaces independently? Not necessarily, though the answer depends on HCPP versus Hybrid Composition because their lifecycles differ. In HCPP, the overlay surface lifecycle is nested inside the root surface, so we do not need to track the overlay as its own frame: ignoring nested frame start and end markers still captures the overlay's command buffers inside the root frame and gives us the union automatically. In Hybrid Composition, the surfaces run sequentially (root surface, then JNI glue work, then overlay surfaces). Skipping the overlays there would only measure the root surface, missing whatever Flutter UI is drawn on top of the platform view. On the other hand, combining them into a union for Hybrid Composition requires plumbing a frame-boundary signal across multiple layers and still includes that JNI gap unless we also build out active-time interval tracking.
Looking at the options in order of complexity:
Even though HCPP is not the default yet, it is the path forward on modern Android, and the jump in maintenance complexity from option 2 to options 3 and 4 is large. Proceeding with option 2 gives us a clean, maintainable path in three smaller PRs: