Repository navigation
[Flutter GPU] Raise Dart errors for invalid render pipelines and memoize per-draw pipeline state - #189899
Conversation
… state Invalid pipelines previously crashed at first draw with no Dart-visible error: a swapped or non-matching shader stage sailed through pipeline creation, a failed shader-function lookup was dereferenced unconditionally, and a failed backend pipeline build flowed into the draw as a null pipeline. Pipeline creation now rejects wrong-stage shaders with a Dart error, and draw failures validation-log the offending shader and fail the draw (which already surfaces as a Dart exception) instead of crashing. Since draw rates reach tens of thousands per frame, the draw path also memoizes the built pipeline: the pipeline-affecting state accessors mark a dirty flag, and consecutive draws with unchanged state skip the descriptor rebuild, hash, and pipeline-library lookup entirely, so the validated path does less per-draw work than before, not more.
There was a problem hiding this comment.
Code Review
This pull request implements pipeline state memoization in RenderPass to optimize consecutive draw calls by avoiding redundant descriptor rebuilding and pipeline lookups. It also adds validation for shader stages during pipeline creation to catch mismatched vertex and fragment shaders early. Feedback on the changes highlights a potential performance issue and log spam if a pipeline fails to build, as the dirty flag is not cleared on failure, causing repeated rebuild attempts on subsequent draws.
A failed build left the dirty flag set, so every subsequent draw retried the build and repeated the validation log. The memo now stores the failure (null) for the unchanged state, and the rebuild path uses a non-dirtying color descriptor accessor so it cannot re-dirty itself.
|
autosubmit label was removed for flutter/flutter/189899, because - The status or check suite Tree_analyze has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
autosubmit label was removed for flutter/flutter/189899, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
PipelineRef is a raw_ptr taking its argument by const reference, so the move never happened and clang-tidy's performance-move-const-arg failed the engine lint.
…#190379) Related to flutter#189899. `RenderPass` memoizes its built pipeline behind a dirty flag, but the fixed-function setters all assign through `GetPipelineDescriptor`, which dirties unconditionally. Callers re-send the same cull mode, winding order, primitive type, and polygon mode ahead of most draws, and rebind the same pipeline, so the memo was being invalidated on nearly every draw. These setters now compare before assigning and leave the state clean when nothing changed.
…12406) Manual roll Flutter from e52f01c920ad to b766512c65d8 (42 revisions) Manual roll requested by [email protected] flutter/flutter@e52f01c...b766512 2026-08-04 [email protected] Roll Dart SDK from 2a799a2404e9 to 9859c0a39adb (4 revisions) (flutter/flutter#190521) 2026-08-04 [email protected] Revert: iOS: Eliminate use of IOSContextNoop in platform view tests (flutter/flutter#190501) 2026-08-04 [email protected] [Impeller] Enable ETC2/ASTC LDR/BC texture compression features at Vulkan device creation (flutter/flutter#189303) 2026-08-03 [email protected] Remove openglessdf from impeller_unittests. (flutter/flutter#190469) 2026-08-03 [email protected] [web] Unify image decoding and codecs on CanvasKit and Skwasm (flutter/flutter#188573) 2026-08-03 [email protected] iOS: Eliminate use of IOSContextNoop in platform view tests (flutter/flutter#190419) 2026-08-03 [email protected] Add path rendering benchmarks (flutter/flutter#188654) 2026-08-03 [email protected] Add windows platform support for primitive_shape_test integration test (flutter/flutter#190464) 2026-08-03 [email protected] Roll Skia from 958c1c1921a1 to a08d918ebd6a (3 revisions) (flutter/flutter#190467) 2026-08-03 [email protected] tests: add --ios-runtime param (flutter/flutter#190414) 2026-08-03 [email protected] iOS: Remove the synchronous first-frame wait (flutter/flutter#190432) 2026-08-03 [email protected] iOS: Eliminate the Impeller/Skia backend selection params (flutter/flutter#190416) 2026-08-03 [email protected] iOS,macOS: Use @autoclosure in Logger (flutter/flutter#190417) 2026-08-03 [email protected] tools: Support FLUTTER_HOST_ARCH in update_dart_sdk scripts (flutter/flutter#190421) 2026-08-03 [email protected] iOS: Hardcode rendering API to Metal in tests (no-op) (flutter/flutter#190422) 2026-08-03 [email protected] a11y: Map disabled/read-only semantics to AX node restriction (flutter/flutter#190353) 2026-08-03 [email protected] [Infra] Replace defunct umbrella template with Wasm issue form (flutter/flutter#190471) 2026-08-03 [email protected] Roll Skia from abecb0dc02c1 to 958c1c1921a1 (4 revisions) (flutter/flutter#190459) 2026-08-03 [email protected] Roll Dart SDK from 65b163be2485 to 2a799a2404e9 (3 revisions) (flutter/flutter#190454) 2026-08-03 [email protected] Roll Skia from 68efb3f2ad16 to abecb0dc02c1 (1 revision) (flutter/flutter#190443) 2026-08-03 [email protected] Roll Packages from 5351d8c to ac87e65 (4 revisions) (flutter/flutter#190441) 2026-08-03 [email protected] Roll Skia from 5a761eb826c1 to 68efb3f2ad16 (1 revision) (flutter/flutter#190440) 2026-08-03 [email protected] Roll Skia from 4c9f8b4805e2 to 5a761eb826c1 (1 revision) (flutter/flutter#190437) 2026-08-03 [email protected] [macOS] Resume app lifecycle on becomeActive to avoid frozen UI after occlusion (flutter/flutter#188772) 2026-08-03 [email protected] Roll Skia from 39cda9d6d7d2 to 4c9f8b4805e2 (6 revisions) (flutter/flutter#190426) 2026-08-03 [email protected] Roll Skia from df13bfb5a54e to 39cda9d6d7d2 (2 revisions) (flutter/flutter#190425) 2026-08-02 [email protected] iOS: Serialise CADisplayLink access in VSyncClient tests (flutter/flutter#190335) 2026-08-02 [email protected] Roll Skia from 32329e5643b5 to df13bfb5a54e (1 revision) (flutter/flutter#190394) 2026-08-02 [email protected] [Impeller] Skip binding dead-code-eliminated resources on Metal (flutter/flutter#190040) 2026-08-01 [email protected] [Flutter GPU] Raise Dart errors for invalid render pipelines and memoize per-draw pipeline state (flutter/flutter#189899) 2026-08-01 [email protected] Revert "Improve non rect platform view rendering (#182662)" (flutter/flutter#190003) 2026-08-01 [email protected] Roll Skia from ebf50520d720 to 32329e5643b5 (1 revision) (flutter/flutter#190389) 2026-08-01 [email protected] Roll Skia from f73c4510d12d to ebf50520d720 (6 revisions) (flutter/flutter#190376) 2026-07-31 [email protected] Primitive shape integration test (flutter/flutter#190368) 2026-07-31 [email protected] Eliminate some early returns in uber_sdf.frag to fix broken UberSDF AA on Windows (flutter/flutter#190260) 2026-07-31 [email protected] chore: swiftshader mirrored + llvm16 (flutter/flutter#181225) 2026-07-31 [email protected] [web] Remove in-repo agent documentation (flutter/flutter#190326) 2026-07-31 [email protected] [windows]: Uses offscreen MSAA when implicit msaa isn't available. (flutter/flutter#190256) 2026-07-31 [email protected] flutter_tools: Use new FileSystemExtension from devtools (flutter/flutter#190360) 2026-07-31 [email protected] Roll Dart SDK from c3acfc2479f6 to 65b163be2485 (1 revision) (flutter/flutter#190358) 2026-07-31 [email protected] Use devicectl for screenshots on Xcode 27, remove idevicescreenshot artifact (flutter/flutter#189091) 2026-07-31 [email protected] Roll Skia from 7ef86a5b0eb9 to f73c4510d12d (1 revision) (flutter/flutter#190352) If this roll has caused a breakage, revert this CL and stop the roller ...
…r#193722) `PipelineLibraryMTL` reads and writes its pipeline maps without a lock, but Flutter GPU calls `GetPipeline` on the UI thread while Impeller calls it on the raster thread. A lookup can hit a concurrent insert and crash in `unordered_map::find`. `PipelineLibraryVK` already guards its maps with a mutex. This PR adds a mutex to `PipelineLibraryMTL`. In `GetPipeline` it covers only the map lookup and the insert, and is released before the Metal pipeline is created, so draws never wait on pipeline creation. The new test, `RendererTest.PipelineLibraryAllowsConcurrentGetPipeline`, looks up a pipeline on one thread while two threads add new ones. It skips GLES. Verified locally on master (macOS, M4 Max): | | Without the lock | With the lock | | --- | --- | --- | | New test, 40 runs | 20 pass, 15 fail, 4 hang, 1 crash | 40/40 pass | | New test under TSan | data races in `PipelineLibraryMTL`, then crash | no race on the maps | | Repro app from the issue under TSan | race reported | no race on the maps | The macOS `impeller_unittests` (CI filter, 2426 passed, 0 failed) and `metal_unittests` pass, and the format and clang-tidy checks are clean. flutter#189899 (on master) makes these lookups rarer but does not remove them. `SamplerLibraryMTL` and `PipelineLibraryGLES` look similar and will be reported separately. Fixes flutter#193721 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/website]: https://github.com/flutter/website [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Invalid
gpu.RenderPipelines currently crash the process at first draw with no Dart-visible error (observed on macOS/Metal withimpeller::PipelineDescriptor::GetHash()on top of the stack). This change surfaces those failures as Dart exceptions instead:createRenderPipelinerejects wrong-stage shaders up front, and a failed stage-function lookup or backend pipeline build logs the offending shader and fails the draw rather than dereferencing null.Since draw rates reach tens of thousands per frame, the draw path also gets cheaper rather than more expensive:
RenderPassnow memoizes the built pipeline behind a dirty flag, so consecutive draws with unchanged state skip the per-draw descriptor copy, hash, and pipeline-library lookup entirely. Includes unit tests for the dirty tracking and the stage validation.Pre-launch Checklist
///).