Skip to content

[Flutter GPU] Inject per-backend defines into shader bundle compilation#187081

Merged
auto-submit[bot] merged 5 commits into
flutter:masterfrom
bdero:bdero/shaderbundle-defines
May 27, 2026
Merged

[Flutter GPU] Inject per-backend defines into shader bundle compilation#187081
auto-submit[bot] merged 5 commits into
flutter:masterfrom
bdero:bdero/shaderbundle-defines

Conversation

@bdero

@bdero bdero commented May 26, 2026

Copy link
Copy Markdown
Member

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_OPENGLES is now compiled with that branch active for the OpenGLES backend.

Pre-launch Checklist

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 26, 2026
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels May 26, 2026
@bdero bdero marked this pull request as ready for review May 26, 2026 06:22
@bdero bdero changed the title [Impeller] Inject per-backend defines into shader bundle compilation [Flutter GPU] Inject per-backend defines into shader bundle compilation May 26, 2026
@github-project-automation github-project-automation Bot moved this to 🤔 Needs Triage in Flutter GPU May 26, 2026
@bdero bdero moved this from 🤔 Needs Triage to ⚙️ In Progress in Flutter GPU May 26, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread engine/src/flutter/impeller/compiler/shader_bundle.cc
Comment thread engine/src/flutter/impeller/compiler/shader_bundle.h
Comment thread engine/src/flutter/impeller/compiler/shader_bundle.h Outdated
Comment thread engine/src/flutter/impeller/compiler/shader_bundle.cc Outdated
Comment thread engine/src/flutter/impeller/compiler/shader_bundle_unittests.cc Outdated
@github-actions github-actions Bot removed flutter-gpu CICD Run CI/CD labels May 26, 2026
@bdero bdero added the CICD Run CI/CD label May 26, 2026
@bdero bdero requested a review from gaaclarke May 26, 2026 10:12
@github-actions github-actions Bot removed the CICD Run CI/CD label May 26, 2026
@bdero bdero added the CICD Run CI/CD label May 26, 2026

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good. I just have questions about what we want to do about opengles vs opengl.

Comment on lines +98 to +99
case TargetPlatform::kOpenGLDesktop:
return {"IMPELLER_TARGET_OPENGLES"};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to conflate opengl and opengles.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a verb to this function name, please?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

- kOpenGLDesktop now emits IMPELLER_TARGET_OPENGL instead of sharing
  IMPELLER_TARGET_OPENGLES with kOpenGLES.
- Rename ShaderBundleTargetPlatformDefines to
  GetShaderBundleTargetPlatformDefines.
@github-actions github-actions Bot removed the CICD Run CI/CD label May 26, 2026
@bdero bdero added the CICD Run CI/CD label May 26, 2026
@bdero bdero requested a review from gaaclarke May 26, 2026 19:35

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, this is timely for me, thanks

@github-actions github-actions Bot removed the CICD Run CI/CD label May 26, 2026
@bdero

bdero commented May 26, 2026

Copy link
Copy Markdown
Member Author

@gaaclarke Using Flutter GPU for something? :)

@bdero bdero added the CICD Run CI/CD label May 26, 2026
@gaaclarke

Copy link
Copy Markdown
Member

@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.

@bdero bdero added the autosubmit Merge PR when tree becomes green via auto submit App label May 26, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 27, 2026
@auto-submit

auto-submit Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

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.

@bdero bdero added the autosubmit Merge PR when tree becomes green via auto submit App label May 27, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue May 27, 2026
Merged via the queue into flutter:master with commit 1013e78 May 27, 2026
212 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 27, 2026
@github-project-automation github-project-automation Bot moved this from ⚙️ In Progress to ✅ Done in Flutter GPU May 27, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request May 28, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels.

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants