[Flutter GPU] Inject per-backend defines into shader bundle compilation#187081
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces platform-discriminating preprocessor defines (such as IMPELLER_TARGET_METAL) during the compilation of bundled shaders, allowing them to specialize per backend. It adds the helper function ShaderBundleTargetPlatformDefines to map target platforms to their respective defines, integrates these defines into the compilation options, and adds corresponding unit tests. The review feedback suggests optimizing performance by returning std::string_view instead of std::string to avoid heap allocations, and ensuring correctness by explicitly setting the target platform on both the backend and reflector options.
gaaclarke
left a comment
There was a problem hiding this comment.
Mostly looks good. I just have questions about what we want to do about opengles vs opengl.
| case TargetPlatform::kOpenGLDesktop: | ||
| return {"IMPELLER_TARGET_OPENGLES"}; |
There was a problem hiding this comment.
I don't think we want to conflate opengl and opengles.
There was a problem hiding this comment.
Done. Split into separate defines.
| /// that Impeller's own shaders receive from the build templates. | ||
| /// | ||
| /// @note Exposed only for testing purposes. | ||
| std::vector<std::string_view> ShaderBundleTargetPlatformDefines( |
There was a problem hiding this comment.
Can you add a verb to this function name, please?
- kOpenGLDesktop now emits IMPELLER_TARGET_OPENGL instead of sharing IMPELLER_TARGET_OPENGLES with kOpenGLES. - Rename ShaderBundleTargetPlatformDefines to GetShaderBundleTargetPlatformDefines.
gaaclarke
left a comment
There was a problem hiding this comment.
lgtm, this is timely for me, thanks
|
@gaaclarke Using Flutter GPU for something? :) |
Oh no, I was working on text rendering on linux. Because we use coretext on macos and freetype on linux there is some differences in the fragment shader I had to make to correct gamma. I wish I had free time right now to play around with stuff. |
|
autosubmit label was removed for flutter/flutter/187081, because - The status or check suite Mac build_android_host_app_with_module_aar has failed. Please fix the issues identified (or deflake) before re-applying this label. |
flutter/flutter@c8f2f16...e70534d 2026-05-28 [email protected] Linux glyph gamma correction (flutter/flutter#187122) 2026-05-28 [email protected] [iOS] Eliminate strong retain cycle from VSyncClient (flutter/flutter#187164) 2026-05-28 [email protected] Revert "[pubspec] Bump Dart SDK constraint to ^3.13.0 (#186957)" (flutter/flutter#187209) 2026-05-28 [email protected] Roll Skia from f1b8ba877c07 to 32acea791248 (3 revisions) (flutter/flutter#187220) 2026-05-27 [email protected] Roll Fuchsia Linux SDK from k9EizfEGJO4WwQN9-... to SBpmmPxqx3lAvGojE... (flutter/flutter#187211) 2026-05-27 [email protected] [Impeller] Add block-compressed texture format support (BC, ETC2, ASTC) (flutter/flutter#187077) 2026-05-27 [email protected] Disable analyzer (flutter/flutter#187205) 2026-05-27 [email protected] [Flutter GPU] Add explicit draw counts (reland) (flutter/flutter#187192) 2026-05-27 [email protected] [Flutter GPU] Inject per-backend defines into shader bundle compilation (flutter/flutter#187081) 2026-05-27 [email protected] Roll Skia from fa944af10f91 to f1b8ba877c07 (13 revisions) (flutter/flutter#187194) 2026-05-27 [email protected] Fixes bug when changing accessibilityFocusBlockType doesn't update ch… (flutter/flutter#186596) 2026-05-27 [email protected] Roll pub packages (flutter/flutter#187191) 2026-05-27 [email protected] [web, tool] Support recompiling shaders and unify asset processing (2nd try) (flutter/flutter#186902) 2026-05-27 [email protected] Fix crash if FlView is destroyed during a draw. (flutter/flutter#186848) 2026-05-27 [email protected] Roll Packages from fc795e5 to 4b424d7 (4 revisions) (flutter/flutter#187174) 2026-05-27 [email protected] Stop prefetching Swift packages in pub get (flutter/flutter#187113) 2026-05-27 [email protected] Update CI with newer android sdk package (flutter/flutter#187143) 2026-05-27 [email protected] Add a tag to the Linux platform properties in .ci.yaml that specifies x64 CPUs (flutter/flutter#187124) If this roll has caused a breakage, revert this CL and stop the roller 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
Adds the
IMPELLER_TARGET_*define per backend when compiling a shader bundle, just like the rest of ImpellerC's shader compilation modes.Tests cover the per-backend define mapping, and verify end to end that a shader guarded by
#ifdef IMPELLER_TARGET_OPENGLESis now compiled with that branch active for the OpenGLES backend.Pre-launch Checklist
///).