Repository navigation
Conversation
78176a0 to
35fb63a
Compare
Profile and debug builds counted each draw's pipeline by hashing its descriptor under a library-wide writer lock, which cost about a fifth of Flutter GPU's per-draw encode time on Metal and serialized threads encoding at the same time. Passes now count uses by pointer and report each distinct pipeline once when encoded.
Metal's binding cache walked nested std::maps for every bind and allocated nodes in each pass, so it now uses flat arrays. Binding no longer touches reference counts, and an unchanged pipeline isn't reapplied to the encoder. Vulkan binds a pipeline only when it changes, and doesn't track textures the caller keeps alive, which matches BufferView's raw pointer mode. Tracking only deduplicates against the last entry, so it grew by one entry per bind. OpenGL ES can presize its command storage, and reuses one buffer when unpadding uniform arrays instead of allocating one per draw.
A steady frame now makes no heap allocations per draw on either thread. Ops go into pooled 64 KiB chunks, a pass retains each object it uses once through a stamp, and pipeline state is plain data resolved through a per-pipeline cache, so a state change costs one hash. Replay binds through non-owning references, caches samplers, and presizes backend command storage. Tests hold recording and replay to zero allocations with a counting operator new.
Encoding happens on the raster thread, so a thread submitting command buffers in a loop could queue recordings without limit. Submitting now waits, for at most a second, while 32 MiB of recordings are in flight.
…lure Some backends report kError for a failed submission before returning the failure, so the callback ran twice, and the second run used a consumed Dart handle.
Texture.fromImage built an AiksContext on the calling thread to read an image's texture, which created the content context and its pipelines there. It now reads the texture the image already holds.
The target was built in CI but never run.
35fb63a to
539e941
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces performance optimizations and resource tracking improvements in Impeller and Flutter GPU, such as batching pipeline usage logging via PipelineUseCounter, optimizing PassBindingsCacheMTL with fixed-size arrays and __unsafe_unretained pointers, and refactoring RenderPass to use a lightweight PipelineState struct. Feedback suggests checking for null textures in RenderPass::CaptureRenderTargetState to prevent null pointer dereferences, zero-initializing the PipelineState key in RenderPipeline::Core::Resolve to avoid copying uninitialized stack memory, and overriding aligned memory allocation operators in AllocationCounter to track aligned allocations.
Over-aligned types allocate through the aligned operator new, which the counter did not replace, so a path that used one would have read as allocation-free.
…n counter" This reverts commit 2535668. Replacing all four overridable forms of operator new leaves nothing referencing the __lcxx_override section of libc++ on ELF, so the linker drops it and the nothrow forms can no longer find its bounds. Nothing on the recorded paths is over-aligned.
gaaclarke
left a comment
There was a problem hiding this comment.
I asked Gemini to split up the PR, it proposed 17 different PRs lol. Here is a counter proposal. I like this because it makes reviewing impeller changes easier by splitting it up. The agent is really concerned about PR E so it wants a separate PR for that. I think alternatively [A1, A2, B+C+D, E] may be fine too?
I haven't dove into it. I'm trying to be careful, this one touches impeller proper a lot more. What do you think?
| PR | Scope | ~Lines | Depends on |
|---|---|---|---|
| A1 | Impeller, Metal: flat-array binding cache (with tests), inline GetMTLBuffer, cached resolved MTLTexture |
340 | — |
| A2 | Impeller, all backends: PipelineUseCounter (usage reported once per pass), Metal and Vulkan skip already-bound pipelines, GLES uniform scratch buffer |
230 | — |
| B | Flutter GPU fixes and behavior changes: run gpu_unittests in CI, completion runs once, Texture.fromImage without building a renderer, tracing |
100 | — |
| C | Flutter GPU: plain-data PipelineState, per-pipeline pipeline cache, leaf FFI calls (isLeaf: true), allocation-counting test harness with budgets |
750 | — |
| D | Flutter GPU (plus Impeller APIs): RetainStamp, RecordingPool (the arena part), non-owning buffer/texture references and ReserveCommands, non-owning replay, zero-allocation tests |
720 | C |
| E | In-flight memory limit (blocks the UI thread for up to 1 s) | 100 | D (optional) |
A1, A2, B, and C can all be reviewed at the same time.
Related to #193745. Follows #194882.
The big juice.
This is basically the grabbag of perf improvements to make #194882 well worth the squeeze. Haven't tested for display list canvas ops yet, but on my high draw count tests for flutter_gpu, this PR increases throughput by ~40%!
Gets us to the point where a steady frame makes no heap allocations per draw on either thread:
operator new.In Impeller, Metal's binding cache now uses flat arrays and skips reapplying an unchanged pipeline, Vulkan binds a pipeline only when it changes and skips tracking non-owning references, OpenGL ES presizes its command storage and reuses a scratch buffer for padded uniform arrays, and render passes report pipeline use counts once per pipeline instead of once per draw.
Smaller changes:
Texture.fromImageno longer builds a renderer on the calling threadgpu_unittestsnow runs with the host engine tests.Pre-launch Checklist
///).