Adds macro for fragment shaders to support flutter <= 3.44#187316
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds a temporary macro IMPELLER_OPENGLES_UNFLIPPED_DEPRECATED to the Impeller compiler for OpenGLES targets, along with associated unit tests and a test shader fixture. The reviewer suggests renaming this macro to IMPELLER_OPENGLES_FLIP_DEPRECATED across the compiler, tests, and shader fixture to improve readability, as the coordinate flipping behavior is what has been deprecated.
| // A temporary macro that allows fragment shader authors to target | ||
| // Flutter <= 3.44 before the OpenGLES flip was removed. | ||
| spirv_options.macro_definitions.push_back( | ||
| "IMPELLER_OPENGLES_UNFLIPPED_DEPRECATED"); |
There was a problem hiding this comment.
The macro name IMPELLER_OPENGLES_UNFLIPPED_DEPRECATED can be confusing because 'unflipped' is the new, correct behavior (which is not deprecated), whereas the 'flip' behavior is what has been deprecated/removed. Naming the macro IMPELLER_OPENGLES_FLIP_DEPRECATED makes the intent much clearer when used in shaders:
#if defined(IMPELLER_TARGET_OPENGLES) && !defined(IMPELLER_OPENGLES_FLIP_DEPRECATED)
// Flip y coordinate for older Flutter versions
uv.y = 1.0 - uv.y;
#endifThis reads naturally as 'if targeting OpenGLES and GLES flipping is not yet deprecated, perform the flip'.
| // A temporary macro that allows fragment shader authors to target | |
| // Flutter <= 3.44 before the OpenGLES flip was removed. | |
| spirv_options.macro_definitions.push_back( | |
| "IMPELLER_OPENGLES_UNFLIPPED_DEPRECATED"); | |
| // A temporary macro that allows fragment shader authors to target | |
| // Flutter <= 3.44 before the OpenGLES flip was removed. | |
| spirv_options.macro_definitions.push_back( | |
| "IMPELLER_OPENGLES_FLIP_DEPRECATED"); |
References
- Optimize for readability: Code is read more often than it is written. (link)
There was a problem hiding this comment.
Naming this is a challenge. How about something like IMPELLER_OPENGLES_UNFLIPPED_Y_AXIS?
If IMPELLER_OPENGLES_UNFLIPPED_Y_AXIS is defined, then the Y axis is not flipped. So the block would look like:
#if defined(IMPELLER_TARGET_OPENGLES) && !defined(IMPELLER_OPENGLES_UNFLIPPED_Y_AXIS)
uv.y = 1.0 - out_v_norm;
#else
uv.y = out_v_norm;
#endif
indicating that the flip is done if GLES is in use but UNFLIPPED_Y_AXIS is not.
I'm wary of putting DEPRECATED in the macro's name given that the macro is defined when using the new behavior that we intend to adopt permanently. It's unclear if there will ever be a point when we can stop defining the macro.
There was a problem hiding this comment.
I'm wary of putting DEPRECATED in the macro's name given that the macro is defined when using the new behavior that we intend to adopt permanently
I think the intention is to warn people not to use it, but instead just migrate their frag code directly.
There was a problem hiding this comment.
Yes, I want DEPRECATED in there because the intention is to remove it. When we remove it we can modify the compiler to make its usage an error.
| // Test that IMPELLER_OPENGLES_UNFLIPPED_DEPRECATED is defined on | ||
| // TargetPlatform::kRuntimeStageGLES. | ||
| { | ||
| options.target_platform = TargetPlatform::kRuntimeStageGLES; | ||
| reflector_options.target_platform = TargetPlatform::kRuntimeStageGLES; | ||
| Compiler compiler = Compiler(fixture, options, reflector_options); | ||
| // Should fail as the shader has a compilation error in it. | ||
| EXPECT_EQ(compiler.GetSPIRVAssembly(), nullptr); | ||
| } | ||
|
|
||
| // Test that IMPELLER_OPENGLES_UNFLIPPED_DEPRECATED is defined on | ||
| // TargetPlatform::kRuntimeStageGLES3. | ||
| { | ||
| options.target_platform = TargetPlatform::kRuntimeStageGLES3; | ||
| reflector_options.target_platform = TargetPlatform::kRuntimeStageGLES3; | ||
| Compiler compiler = Compiler(fixture, options, reflector_options); | ||
| // Should fail as the shader has a compilation error in it. | ||
| EXPECT_EQ(compiler.GetSPIRVAssembly(), nullptr); | ||
| } |
There was a problem hiding this comment.
Update the test case to use the clearer macro name IMPELLER_OPENGLES_FLIP_DEPRECATED to match the compiler implementation.
| // Test that IMPELLER_OPENGLES_UNFLIPPED_DEPRECATED is defined on | |
| // TargetPlatform::kRuntimeStageGLES. | |
| { | |
| options.target_platform = TargetPlatform::kRuntimeStageGLES; | |
| reflector_options.target_platform = TargetPlatform::kRuntimeStageGLES; | |
| Compiler compiler = Compiler(fixture, options, reflector_options); | |
| // Should fail as the shader has a compilation error in it. | |
| EXPECT_EQ(compiler.GetSPIRVAssembly(), nullptr); | |
| } | |
| // Test that IMPELLER_OPENGLES_UNFLIPPED_DEPRECATED is defined on | |
| // TargetPlatform::kRuntimeStageGLES3. | |
| { | |
| options.target_platform = TargetPlatform::kRuntimeStageGLES3; | |
| reflector_options.target_platform = TargetPlatform::kRuntimeStageGLES3; | |
| Compiler compiler = Compiler(fixture, options, reflector_options); | |
| // Should fail as the shader has a compilation error in it. | |
| EXPECT_EQ(compiler.GetSPIRVAssembly(), nullptr); | |
| } | |
| // Test that IMPELLER_OPENGLES_FLIP_DEPRECATED is defined on | |
| // TargetPlatform::kRuntimeStageGLES. | |
| { | |
| options.target_platform = TargetPlatform::kRuntimeStageGLES; | |
| reflector_options.target_platform = TargetPlatform::kRuntimeStageGLES; | |
| Compiler compiler = Compiler(fixture, options, reflector_options); | |
| // Should fail as the shader has a compilation error in it. | |
| EXPECT_EQ(compiler.GetSPIRVAssembly(), nullptr); | |
| } | |
| // Test that IMPELLER_OPENGLES_FLIP_DEPRECATED is defined on | |
| // TargetPlatform::kRuntimeStageGLES3. | |
| { | |
| options.target_platform = TargetPlatform::kRuntimeStageGLES3; | |
| reflector_options.target_platform = TargetPlatform::kRuntimeStageGLES3; | |
| Compiler compiler = Compiler(fixture, options, reflector_options); | |
| // Should fail as the shader has a compilation error in it. | |
| EXPECT_EQ(compiler.GetSPIRVAssembly(), nullptr); | |
| } |
| #ifdef IMPELLER_OPENGLES_UNFLIPPED_DEPRECATED | ||
| fail | ||
| #else |
| TargetPlatform::kRuntimeStageGLES3) { | ||
| spirv_options.macro_definitions.push_back("IMPELLER_TARGET_OPENGLES"); | ||
| // A temporary macro that allows fragment shader authors to target | ||
| // Flutter <= 3.44 before the OpenGLES flip was removed. |
There was a problem hiding this comment.
Once people are onboard, we should have a todo with a linked issue to remove it
bdero
left a comment
There was a problem hiding this comment.
Yeah makes sense.
This issue impacts FragmentProgram shaders which sample from a backdrop texture specifically (ImageFilters). Will document this migration option for the breaking change comms in flutter/website#13419 once it lands. 👍
On second thought, maybe we should just use this to bridge the Material widgets and discourage its use elsewhere. We should just tell users to pin the minimum SDK version to the prerelease ID where the y-flip fix was introduced for new releases of packages that involve ImageFilter shaders which employ the y-flip hackery. |
Yea, that's what I was thinking too. I have a draft for the flutter-announce email and I'm thinking I don't mention |
|
friendly ping @jason-simmons @justinmc @chunhtai I'd like wider approval before we go down this route. |
justinmc
left a comment
There was a problem hiding this comment.
LGTM, but to be sure we're on the same page:
- The point of the recent changes to this PR that include IMPELLER_OPENGLES_UNFLIPPED_DEPRECATED is to avoid needing to make a change to the material overscroll stretch shader.
- I will release material_ui 1.0.0 with SDK dependency
>= 3.44.0, and I will not need to release a followup 1.0.1, because there is no change that needs to happen to the shader in the material library. - This PR will be included in all SDK versions that include #186556 (the PR that caused the bug, which is still unpublished).
- Therefore, the only SDK versions that will contain the bug will be the SHAs between the landing of #186556 and the landing of this PR. Those SHAs will express the bug whether a user is using flutter/flutter's material or material_ui. They are also in between published versions, so only users on the master channel could ever end up using them.
| TargetPlatform::kRuntimeStageGLES3) { | ||
| spirv_options.macro_definitions.push_back("IMPELLER_TARGET_OPENGLES"); | ||
| // A temporary macro that allows fragment shader authors to target | ||
| // Flutter <= 3.44 before the OpenGLES flip was removed. |
I think this is incorrect. The shader will need to change logic based on IMPELLER_OPENGLES_UNFLIPPED_DEPRECATED e.g. https://gist.github.com/chunhtai/24f06316721731cc132a9f0b9256c215 We need to make sure 1.0.0 include this change |
|
I pushed an empty commit, ci was in a bad state looking for the CICD label when it was already there |
|
Ok updating my list:
What is the benefit of the macro that needs to be removed later then? It seems like material_ui is in the same situation as the earlier version of this PR. I guess 3.44.x will theoretically work with material_ui 1.0.0, but that won't happen thanks to Pub's version resolution. |
|
@justinmc that's not quite what we had in mind. We want
It allows material_ui 1.0.0 to support the |
|
autosubmit label was removed for flutter/flutter/187316, because - The status or check suite Mac mac_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
Ok one more try:
If this is true then I think this is good enough for users and a revert of #186556 is not necessary.
|
…11832) Manual roll requested by tarrinneal@google.com flutter/flutter@701665b...2ba5420 2026-06-03 engine-flutter-autoroll@skia.org Roll Packages from 818b310 to b11504f (8 revisions) (flutter/flutter#187511) 2026-06-03 mdebbar@google.com Add new file patterns for team-web labeler (flutter/flutter#187397) 2026-06-03 engine-flutter-autoroll@skia.org Roll Skia from 279b17fe9fc1 to d625048c853a (12 revisions) (flutter/flutter#187483) 2026-06-03 chris@bracken.jp [SwiftPM] Fix prefer_initializing_formals lint (flutter/flutter#187502) 2026-06-03 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from q27k7_um1GvVrySZS... to ap7MhLX4TdpWRrLS_... (flutter/flutter#187478) 2026-06-03 bkonyi@google.com [SwiftPM] Fix concurrent directory/file/symlink creation crashes (flutter/flutter#186953) 2026-06-03 flar@google.com [Impeller] Fix positioning of text shadow masks (flutter/flutter#187460) 2026-06-02 burak.karahan@mail.ru Remove Material imports from painting tests (flutter/flutter#186937) 2026-06-02 awolff@google.com Add android_hardware_smoke_test integration tests (flutter/flutter#187130) 2026-06-02 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#187471) 2026-06-02 pq@users.noreply.github.com [flutter tool] propagate analytics env to sub-tools (flutter/flutter#186780) 2026-06-02 30870216+gaaclarke@users.noreply.github.com Adds macro for fragment shaders to support flutter <= 3.44 (flutter/flutter#187316) 2026-06-02 116356835+AbdeMohlbi@users.noreply.github.com Small clean-up in different java files under `engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/` (flutter/flutter#186631) 2026-06-02 1961493+harryterkelsen@users.noreply.github.com refactor(web): Unify ui.Path code for CanvasKit and Skwasm (flutter/flutter#187331) 2026-06-02 engine-flutter-autoroll@skia.org Roll Packages from f5d50ca to 818b310 (2 revisions) (flutter/flutter#187441) 2026-06-02 faheemabbas766@gmail.com Allow selecting multi-digit device options (flutter/flutter#186184) 2026-06-02 puneetkukreja98@gmail.com Improve error message for type mismatch in Navigator.pop and maybePop. (flutter/flutter#186571) 2026-06-02 sanaullah.383@hotmail.com Remove semantics_tester import from material_button_test.dart (flutter/flutter#184807) 2026-06-02 bkonyi@google.com [flutter_tools] Refactor hostPlatform to use Abi.current() (flutter/flutter#185369) 2026-06-02 mvincentong@gmail.com Clean up avoid_type_to_string suppressions (flutter/flutter#186869) 2026-06-02 202459002+Lukes-Lair@users.noreply.github.com Update Flutter documentation links in flutter_console.bat (flutter/flutter#187354) 2026-06-02 154381524+flutteractionsbot@users.noreply.github.com Revert "[Impeller] Allow attaching specific texture mip levels and slices" (flutter/flutter#187445) 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 stuartmorgan@google.com,tarrinneal@google.com 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
#186556 was a breaking change that removed the necessity of flipping y coordinates when sampling in opengles. This was a good improvement but it left fragment shader api users in a prediciment where they had to bump their required flutter SDK. This was particularly unfortunate timing for the framework team's releases. This new temporary macro allows people to author shaders that support flutter 3.44.0 and above.
before
after (support > 3.44.0)
after (support >= 3.44.0)
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.