Repository navigation
[Impeller] Deduplicate GLES render pass state - #193427
Conversation
…ameters Track orthogonal GL state variables (blend enable/factors/ops, color write mask, stencil enable/front/back state, depth enable/compare/mask, scissor rect, and bound program/y-flip uniform) across commands in RenderPassGLES::EncodeCommandsInReactor, and cache the configured SamplerDescriptor key on non-wrapped TextureGLES instances so SamplerGLES::ConfigureBoundTexture skips redundant glTexParameteri calls. Fixes flutter#192147
…edupe tests
- Track the bound program in `RenderPassGLES::EncodeCommandsInReactor` via `std::optional<HandleGLES>` (`HandleGLES::Equal{}`) instead of `const PipelineGLES*` so pipeline variants sharing a compiled `UniqueHandleGLES` skip redundant `glUseProgram` and `_impeller_y_flip` uniform updates.
- Add `RenderPassGLESCommandTest.DeduplicatesEnabledBlendStencilDepthAndSharedProgramAcrossVariants` to verify enabled blend, depth, and stencil deduplication (including `stencil_reference` changes) and shared program handle deduplication across `PipelineGLES` instances.
- Extend `BufferBindingsGLESTest.SkipsRedundantSamplerConfigurationOnSameTexture` to verify that `TextureGLES::WrapTexture(...)` bypasses the sampler parameter cache and re-emits `glTexParameteri` on every bind.
There was a problem hiding this comment.
Code Review
This pull request introduces state caching in the Impeller GLES backend to deduplicate redundant OpenGL state changes, including sampler parameters, blending, stencil, depth, scissor, and program bindings. Feedback on these changes highlights two critical issues: first, the cached sampler key on TextureGLES is not invalidated when texture storage or mip levels are mutated, which can lead to incorrect sampler configurations; second, GL_SCISSOR_TEST is enabled for clipped draws but is never disabled for subsequent unclipped draws within the same render pass, potentially causing incorrect clipping.
gaaclarke
left a comment
There was a problem hiding this comment.
Nice, this is good practice when working with opengl and something we should do.
gaaclarke
left a comment
There was a problem hiding this comment.
Have you done some local testing to see the performance delta? It would be nice to know what we are getting in return of maintaining caches which can be bug vectors.
|
Thanks for the review @gaaclarke! In a4bf0ec I refactored all the per-pass state caches into structs with methods inside an anonymous namespace ( On local Web Impeller (WIMP / WebGL 2.0) benchmarks,
Updated the PR description table with these numbers as well. PTAL! |
Addressed all 10 review comments in a4bf0ec (refactored state caches into structs with methods in anonymous namespace, split out SamplerGLES caching, and added local performance benchmarks); re-requesting review from @gaaclarke.
RenderPass::SetScissor only populates pending_.scissor for the next Draw() call (which moves pending_ into commands_ and resets pending_). Subsequent Draw() calls within the same clip scope have command.scissor == std::nullopt, meaning the active scissor rect remains unchanged (matching Metal and Vulkan; see flutter-team-archive/engine#56494). Do not disable GL_SCISSOR_TEST or clear the cached scissor when command_scissor is std::nullopt in RenderPassStateCache::ConfigureScissor.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces state caching mechanisms, including BlendStateCache, StencilStateCache, DepthStateCache, and RenderPassStateCache, to deduplicate OpenGL state changes across commands in the GLES backend. Unit tests are added to verify this deduplication behavior. Feedback points out a potential null pointer dereference in BlendStateCache::Configure when handling depth-only or stencil-only passes where the color attachment descriptor is null.
flutter/flutter@e89fd0a...d03768e 2026-10-02 [email protected] Roll Skia from 7b7326917e77 to 9e88bf828078 (8 revisions) (flutter/flutter#193694) 2026-10-02 [email protected] [Widget Preview] Provide descriptive error when widget preview is unconstrained (flutter/flutter#193005) 2026-10-02 [email protected] Roll Dart SDK from 0e7642b85457 to ac1a97aae47d (26 revisions) (flutter/flutter#193692) 2026-10-02 [email protected] Remove unused Fuchsia sysmem header files (flutter/flutter#193244) 2026-10-02 [email protected] [Windows] Preserve composing extent in setEditingState (flutter/flutter#189968) 2026-10-02 [email protected] [docs] Make Border.symmetric docs more explicit about their arguments (flutter/flutter#193222) 2026-10-02 [email protected] [Embedder] Support render texture for vulkan (flutter/flutter#188855) 2026-10-02 [email protected] Updated Remaining Engine Defaults to SDK 37 (flutter/flutter#190429) 2026-10-02 [email protected] Document that enableSuggestions: false can disable keyboard languages on Android (flutter/flutter#192714) 2026-10-02 [email protected] [flutter_tools] Explicitly track host CPU architecture in command result analytics (flutter/flutter#191836) 2026-10-02 [email protected] [web] Preserve DOM focus on role update and honor isAccessibilityFocusBlocked (flutter/flutter#192963) 2026-10-02 [email protected] [flutter_tools] Include base href in web hot reload script paths (flutter/flutter#193678) 2026-10-02 [email protected] [Impeller] Deduplicate GLES render pass state (flutter/flutter#193427) 2026-10-02 [email protected] Roll Skia from f2d68e0b8863 to 7b7326917e77 (16 revisions) (flutter/flutter#193676) 2026-10-01 [email protected] Fix analysis failures due to missing `const` (flutter/flutter#193685) 2026-10-01 [email protected] Removes a11y_assessment app (flutter/flutter#193671) 2026-10-01 [email protected] test: configure Xvfb and openbox for windowing_test (flutter/flutter#193529) 2026-10-01 [email protected] Sync CHANGELOG.md from stable (flutter/flutter#193666) 2026-10-01 [email protected] Avoid using relative path in Process.start (flutter/flutter#193664) 2026-10-01 [email protected] [AGP 9.1.0 Migration #6] Deliver Flutter assets as a generated assets source directory on the app path (flutter/flutter#192488) 2026-10-01 [email protected] ci(bringup): android_java17_build_android_host_app_with_module_aar is green (flutter/flutter#193580) 2026-10-01 [email protected] [flutter_tools] Fix Use dependency graph to determine plugin initialization order (flutter/flutter#191591) 2026-10-01 [email protected] [flutter_tools] Migrate DaemonCommand and Daemon domains to constructor DI (flutter/flutter#193542) If this roll has caused a breakage, revert this CL and set the roller to dry run mode 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
…StateCache - Store `VertexAttribStateCache` and `configured_program_y_flip` inside `RenderPassStateCache` in `render_pass_gles.cc` (matching `flutter#193427`), eliminating mutable `configured_y_flip_` from `PipelineGLES`. - Track `bound_sampler_keys` (`std::optional<uint64_t>`) and `bound_textures` (`std::optional<GLuint>`) per texture unit in `VertexAttribStateCache` so the branch is self-contained off `master` (`86798946adc`). - Add `BufferBindingsGLESTest` unit tests for vertex attribute deduplication, active texture/sampler binding deduplication, and dirty-tracked UBO uploads.
Deduplicates redundant OpenGL ES state transitions across draw commands within
RenderPassGLES(EncodeCommandsInReactor):RenderPassStateCache):RenderPassStateCache(BlendStateCache,StencilFaceStateCache,StencilStateCache, andDepthStateCachein an anonymous namespace inrender_pass_gles.cc), tracking enabled/disabled state (GL_BLEND,GL_STENCIL_TEST,GL_DEPTH_TEST,GL_SCISSOR_TEST), active program handle (std::optional<HandleGLES>viaHandleGLES::Equal{}so pipeline variants sharing a compiledUniqueHandleGLESskip redundant program binds and_impeller_y_flipuniform updates), color mask, blend equations/factors, depth compare function and write mask, front/back stencil functions/operations/write masks, viewport, scissor rect, cull mode, and winding order across draw calls withinEncodeCommandsInReactor.ResetGLStateinitializes the tracked state once at pass entry beforeglClear, eliminating the redundant pass-exitResetGLStatecall while ensuring no state leaks across passes,ReactorGLEShandle operations, orBlitPassGLEScommands.WebGL 2.0 Call Count & CPU Command-Encoding Reduction (Web Impeller / WIMP)
1280x720,wimp_st)bouncy(128nodes,441draws)13,2347,983-39.7%(-5,251calls)glBlendEquationSeparate+glBlendFuncSeparate/ frame8024-99.5%glStencilFuncSeparate+Op+Mask/ frame1,3279-99.3%glColorMask/ frame4433-99.3%glEnable+glDisable/ frame1,506225-85.1%glDepthFunc+glDepthMask/ frame884161-81.8%glUseProgram/ frame441105-76.2%glUniform1fv(_impeller_y_flip) / frame441105-76.2%glScissor/ frame175117-33.1%--disable-gl-drawing-for-tests)13.41 ms12.47 ms-7.0%(-0.94 ms,1.08xfaster)grid(1000nodes,5,908draws)154,52194,517-38.8%(-60,004calls)glBlendEquationSeparate+glBlendFuncSeparate/ frame9,474338-96.4%glStencilFuncSeparate+Op+Mask/ frame17,726844-95.2%glColorMask/ frame5,909337-94.3%glEnable+glDisable/ frame18,0712,691-85.1%glUseProgram/ frame5,9082,197-62.8%glUniform1fv(_impeller_y_flip) / frame5,9082,197-62.8%glDepthFunc+glDepthMask/ frame11,8176,051-48.8%--disable-gl-drawing-for-tests)60.86 ms56.13 ms-7.8%(-4.73 ms,1.08xfaster)Fixes #192147
Pre-launch Checklist
///).