[Impeller] Recycle HostBuffer arena entries only after GPU completion#188965
Conversation
There was a problem hiding this comment.
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.
|
The logic here looks good to me, but Jason is probably a better reviewer here. He is OOO until Wednesday - good to wait? |
| // 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_; |
There was a problem hiding this comment.
Add an IPLR_GUARDED_BY(mutex_) annotation here
There was a problem hiding this comment.
This also requires using the impeller::Mutex wrapper class in order to support these annotations on Windows.
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
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
///).