Repository navigation
[stable] [Flutter GPU] Add a project-level Flutter GPU setting to the Linux and Windows embedders - #190872
Conversation
…d Windows embedders (flutter#190684) Adds `fl_dart_project_set_enable_flutter_gpu` (Linux) and `DartProject::set_enable_flutter_gpu` (Windows), forwarding `--enable-flutter-gpu` to the engine the same way the existing project-level Impeller settings do. Release desktop builds ignore engine switches from the environment, so this is the only way a released app on these platforms can enable Flutter GPU, matching the permanent opt-ins the other platforms already have (`FLTEnableFlutterGPU` in Info.plist on iOS and macOS, the `EnableFlutterGPU` manifest flag on Android). ## 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]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [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. - [ ] 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/ [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 [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md (cherry picked from commit 4ff86d4)
|
This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter. Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed. |
There was a problem hiding this comment.
Code Review
This pull request adds programmatic support for enabling the Flutter GPU API on both Linux and Windows platforms by introducing configuration fields, getters, setters, and command-line argument forwarding, along with corresponding unit tests. Feedback points out that adding the enable_flutter_gpu field to the public FlutterDesktopEngineProperties struct on Windows is an ABI-breaking change because the struct is client-allocated and lacks a size or version field, which could lead to out-of-bounds reads or crashes.
loic-sharma
left a comment
There was a problem hiding this comment.
Windows / Linux changes LGTM from technical standpoint
mattkae
left a comment
There was a problem hiding this comment.
One sanity check that I punted to Loic, but looks good overall
|
Alrighty, thanks for the reviews. Is there any other action I should take here in order to help shepherd this into 3.47.1? It's been quite a while since I've last participated in the stable cherry-pick process. :P |
|
@bdero It's in the cherrypick queue, so the release engineer should pick this up when they start the 3.47.1 release :) |
0c94720
into
flutter:flutter-3.47-candidate.0
Cherry-pick of #190684 (
4ff86d444fb94c39c38111f4b9be649bb716dff7) ontoflutter-3.47-candidate.0. It applies cleanly with no conflicts.The 3.47.0 cherry-pick window is already closed, so this is a request to reopen the conversation rather than a routine cherry-pick. The reasoning is under "Why this is requested after the window closed" below, and I am happy to take a no.
Issue Link:
#190871
Why this is requested after the window closed:
This is an API addition rather than a regression fix, so it does not meet the usual bar. Three things make it worth asking about anyway.
Flutter GPU already has a permanent, project-level opt-in on every other platform (
FLTEnableFlutterGPUinInfo.pliston iOS and macOS, theEnableFlutterGPUmanifest key on Android). Linux and Windows are the only platforms with no equivalent, so this closes a parity gap rather than adding new capability.Release-mode desktop builds compile out
GetSwitchesFromEnvironment(engine_switches.ccguards it with#ifndef FLUTTER_RELEASE), so--enable-flutter-gpureaches the engine only underflutter run. Without a project-level setter there is no way at all to ship a released Linux or Windows app that usespackage:flutter_gpu.It landed on master on August 7, two days after
flutter-3.48-candidate.0branched on August 5, so it missed both this branch and the next beta branch. If it is not picked up here, the first beta carrying it is 3.49 and the first stable is roughly a quarter out.Impacted Users:
Developers shipping Flutter desktop apps on Linux and Windows that use
package:flutter_gpu, either directly or through a package built on top of it. Issue #167734 has been open since April 2025 with users repeatedly asking how to enable Flutter GPU on Windows, and the most recent comment describes exactly this case, that the command line flag works underflutter runbut a packaged executable has no way to set it.Impact Description:
Production apps on Linux and Windows cannot ship Flutter GPU at all. A release build throws on the first Flutter GPU call with "Flutter GPU must be enabled via the Flutter GPU manifest setting", and that message names only the iOS and Android opt-ins because the desktop ones did not exist. This does not affect development, since
flutter run --enable-flutter-gpuworks, which is what makes it easy to discover the problem only at packaging time.Changelog Description:
[flutter/190871] Flutter GPU could not be enabled in release builds on Linux and Windows, since those embedders had no project-level opt-in and release builds ignore engine switches from the environment.
Workaround:
No practical one. Shipping the app in debug or profile mode is the only way to get the environment switches honored, and neither is shippable. The alternative is patching the embedder and building a custom engine.
Risk:
What is the risk level of this cherry-pick?
The change is additive and defaults to off. Both embedders append
--enable-flutter-gpuonly when the project setting is true, and skip it when an environment switch already carries it, so an app that does not opt in produces a byte-identical switch list. Nothing in the engine, Impeller, or the rendering path changes. The Linux side also hoists a repeatedGetSwitchesFromEnvironment()call into a local, which is behavior neutral.One caveat worth naming. A
bool enable_flutter_gpufield is appended toFlutterDesktopEnginePropertiesin the publicflutter_windows.h, which changes that struct's layout. The header andflutter_windows.dllship together in the SDK artifact cache so they stay consistent, but it is a public C struct change, and once it ships in a stable the shape of the API is locked in.Test Coverage:
Are you confident that your fix is well-tested by automated tests?
Unit tests cover both embedders. On Linux,
fl_dart_project_test.cccovers the getter, setter, and default, andfl_engine_test.cccovers switch forwarding and the environment switch deduplication. On Windows,dart_project_unittests.cc,flutter_project_bundle_unittests.cc, andflutter_windows_engine_unittests.cccover the client wrapper, the project bundle, and the engine switch assembly.Validation Steps:
package:flutter_gpuand run it in release mode on Linux or Windows without the new setting. Confirm it throws "Flutter GPU must be enabled via the Flutter GPU manifest setting".fl_dart_project_set_enable_flutter_gpu(project, TRUE);inlinux/runner/my_application.cc. On Windows, addproject.set_enable_flutter_gpu(true);inwindows/runner/main.cpp.flutter run. Confirm Flutter GPU initializes and renders.Pre-launch Checklist
///).