Skip to content

[Impeller] Recycle HostBuffer arena entries only after GPU completion#188965

Merged
auto-submit[bot] merged 7 commits into
flutter:masterfrom
bdero:bdero/impeller-hostbuffer-completion
Jul 10, 2026
Merged

[Impeller] Recycle HostBuffer arena entries only after GPU completion#188965
auto-submit[bot] merged 7 commits into
flutter:masterfrom
bdero:bdero/impeller-hostbuffer-completion

Conversation

@bdero

@bdero bdero commented Jul 4, 2026

Copy link
Copy Markdown
Member

Fixes #184091.

HostBuffer reuses each arena entry kHostBufferArenaSize (4) resets after it was written, assuming no more than 4 frames are ever in flight. Nothing enforces that assumption. On macOS the embedder applies no frame backpressure, so GPU-heavy workloads run the pipeline deeper than the arena and per-frame uniform and vertex data is overwritten while the GPU is still reading it, corrupting rendering.

This makes reuse completion-aware. Each backend context records command buffer submissions and completions in a monotonic watermark, and HostBuffer::Reset retires entries whose GPU work has not yet completed (keeping their buffers alive until it has) and starts them over with fresh allocations. Deep pipelines now cost transient memory instead of correctness, and the memory drains back once the GPU catches up.

Metal tracks completion via command buffer completed handlers and Vulkan via the fence waiter. GLES tracks at reactor consumption granularity, since GL synchronizes buffer reuse implicitly and provides no equivalent completion signal there.

Before fix (repro: #184091 (comment)):

Screen.Recording.2026-07-04.at.2.12.26.AM.mov

After fix:

Screen.Recording.2026-07-04.at.4.38.56.AM.mov

Pre-launch Checklist

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Jul 4, 2026
@bdero
bdero marked this pull request as ready for review July 4, 2026 13:47

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a GpuSubmissionTracker to track the completion of submitted command buffers, allowing HostBuffer to safely reuse arena entries without racing active GPU reads. This tracking is integrated across the GLES, Metal, and Vulkan backends, and accompanied by comprehensive unit tests. The review feedback suggests optimizing the GpuSubmissionTracker by replacing std::set with std::vector for tracking pending submissions. Since submission IDs are strictly monotonic, utilizing a sorted vector with std::lower_bound avoids per-frame heap allocations and improves performance.

Comment thread engine/src/flutter/impeller/core/gpu_submission_tracker.h Outdated
Comment thread engine/src/flutter/impeller/core/gpu_submission_tracker.h Outdated
Comment thread engine/src/flutter/impeller/core/gpu_submission_tracker.cc
Comment thread engine/src/flutter/impeller/core/gpu_submission_tracker.cc
Comment thread engine/src/flutter/impeller/core/gpu_submission_tracker.cc
Comment thread engine/src/flutter/impeller/core/gpu_submission_tracker.cc
@bdero bdero added the CICD Run CI/CD label Jul 4, 2026
@bdero
bdero requested review from jason-simmons and walley892 July 6, 2026 18:16
@walley892

Copy link
Copy Markdown
Contributor

The logic here looks good to me, but Jason is probably a better reviewer here. He is OOO until Wednesday - good to wait?

jason-simmons
jason-simmons previously approved these changes Jul 8, 2026

@jason-simmons jason-simmons left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

// Sorted, since ids are recorded in increasing order. The pending count
// tracks GPU queue depth and stays small, so erasure is cheap and steady
// state performs no heap allocation.
std::vector<uint64_t> pending_;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an IPLR_GUARDED_BY(mutex_) annotation here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also requires using the impeller::Mutex wrapper class in order to support these annotations on Windows.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a394999 and 6a970b5.

@bdero
bdero requested a review from jason-simmons July 9, 2026 18:49
@bdero bdero added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 10, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Jul 10, 2026
Merged via the queue into flutter:master with commit 1db664b Jul 10, 2026
202 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 10, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jul 10, 2026
flutter/flutter@dc2a870...f7b66f3

2026-07-10 [email protected] [iOS][test] Fix VSyncClient display link deallocation test on iOS 27 (flutter/flutter#188627)
2026-07-10 [email protected] Fix broken listener code in WindowScope (flutter/flutter#189208)
2026-07-10 [email protected] [web] Preserve text field focus across tab switches (flutter/flutter#188738)
2026-07-10 [email protected] [Impeller] Recycle HostBuffer arena entries only after GPU completion (flutter/flutter#188965)
2026-07-10 [email protected] Assert TextStyle height is not NaN (flutter/flutter#186617)
2026-07-10 [email protected] Roll Fuchsia Test Scripts from dFkTCiDxEtPxYK5Nn... to wLST_A-xfOeGT_5mj... (flutter/flutter#189259)
2026-07-10 [email protected] Roll Dart SDK from a11fb7ed40a5 to 0fc1668c4af4 (5 revisions) (flutter/flutter#189257)
2026-07-10 [email protected] Adds a missing `await` to a `FutureOr` (flutter/flutter#189198)
2026-07-10 [email protected] [web] Repair RenderCanvas CSS size drift (flutter/flutter#188797)
2026-07-10 [email protected] Roll Fuchsia Test Scripts from s5_gZFJ8De9AJalTw... to dFkTCiDxEtPxYK5Nn... (flutter/flutter#189215)
2026-07-10 [email protected] Roll Fuchsia Linux SDK from QcRFUtvCw2EobfJ8s... to czpzDg9ABY2oKLAOY... (flutter/flutter#189222)
2026-07-10 [email protected] Update Depdencies Used By `flutter_engine_group_performance` (flutter/flutter#189229)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Impeller] Drawing a lot of large circles corrupts further rendering

3 participants