Repository navigation
Conversation
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 reapplied a pipeline's whole state to the encoder on every draw, and Vulkan rebound it on every draw, even when it had not changed. Both now remember what is bound for the pass. OpenGL ES reuses one buffer when unpadding uniform arrays instead of allocating one per draw.
There was a problem hiding this comment.
Code Review
This pull request introduces a PipelineUseCounter to batch and defer pipeline usage logging in Impeller, moving the overhead of hashing descriptors out of individual draw calls. It updates RenderPass and its backend implementations (GLES, Metal, Vulkan) to count pipeline uses and flush them to the PipelineLibrary when encoding commands. Additionally, it optimizes GLES uniform buffer binding by reusing a scratch vector. The review feedback suggests adding a defensive null check for pipeline in RenderPassMTL::SetPipeline to prevent potential null pointer dereferences, and marking unused parameters with [[maybe_unused]] in PipelineUseCounter::Count, PipelineLibrary::LogPipelineUsage, and PipelineUseCounter::Flush to avoid compiler warnings in release builds.
A null pipeline on a pass with nothing bound matched the remembered pipeline and left the pass marked as having a valid one.
gaaclarke
left a comment
There was a problem hiding this comment.
This is looking good, there's just a few places i'd like cleaned up with conditional compilations. Here's roughly my goals with the pipeline usage counter code:
- minimize the amount of conditional compilation
- put conditional compilation in .cc files outside of standard impeller classes
- minimize code in standard impeller classes for it (prefer to put logic in the counter compilation units)
| bool has_valid_pipeline_ = false; | ||
| // The pipeline whose state is set on the encoder, which persists across | ||
| // draws. | ||
| const Pipeline<PipelineDescriptor>* bound_pipeline_ = nullptr; |
There was a problem hiding this comment.
Raw pointers are verboten. Bare minimum we should be documenting the lifetime. Maybe use a weak_ptr on debug builds?
There was a problem hiding this comment.
Done in 36c8215. It is a PipelineRef now, and the comment covers the lifetime.
| #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG || \ | ||
| FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_PROFILE | ||
| if (auto library = context_->GetPipelineLibrary()) { | ||
| pipeline_uses_.Flush(*library); | ||
| } | ||
| #endif |
There was a problem hiding this comment.
The preprocessor macro is superfluous here.
| /// | ||
| class PipelineUseCounter { | ||
| public: | ||
| void Count(const Pipeline<PipelineDescriptor>* pipeline) { |
There was a problem hiding this comment.
can we put this in the .cc file please?
| #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG || \ | ||
| FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_PROFILE |
There was a problem hiding this comment.
let's not optimize this away to keep the code simpler, its basically nothing if it's never used anyways.
|
|
||
| // |RenderPass| | ||
| void RenderPassMTL::SetPipeline(PipelineRef pipeline) { | ||
| CountPipelineUse(pipeline); |
There was a problem hiding this comment.
Do we want this after the !pipeline check?
Counting moves out of the header, the counter's members exist in every build mode, and a pass no longer guards the flush. Metal remembers the bound pipeline as a PipelineRef and counts a use only after rejecting a null one.
Related to #193745. Split out of #196621.
Profile and debug builds counted each draw's pipeline by hashing its descriptor under a library-wide writer lock, which was 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 and Vulkan also skip a pipeline that is already bound for the pass, and OpenGL ES reuses one scratch buffer when unpadding uniform arrays.
Pre-launch Checklist
///).