Skip to content

Conversation

@bdero
Copy link
Member

@bdero bdero commented Oct 19, 2022

Fixes the compiler flags for runtime stages.

The ios.dart change is a hack that needs to be replaced. Is there a good way to snake the Impeller flag into build_system/targets/*.dart so that we can set the shaderTarget based on it?

@bdero bdero added the e: impeller Impeller rendering backend issues and features requests label Oct 19, 2022
@bdero bdero self-assigned this Oct 19, 2022
@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Oct 19, 2022
Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

There are two ways to get the flag through to the build, and probably two different scenarios we need to handle:

  1. User types flutter run --enable-impeller or has updated the info.plist.

In this case we need to both pass the flag through and read the info.plist options. The current behavior is the info.plist wins over the flag.

  1. User types flutter build X

Hopefully we don't support passing --enable-impeller to this option, but in this case we only check the plist, since the flag would not be persisted anyway.

Supporting the info.plist option is much easier. I would use the build directory and create a FlutterProject, and then access the iOS subproject and read the value of FLTEnableImpeller from the plist. We should already have the file path and ability to parse that file supported in the framework. See flutter/packages/flutter_tools/lib/src/build_system/targets/ios.dart L530 and then use the PlistParser class.


Separately, there is the runtime flag. I never really made adding new runtime flags easy to pass unfortunately. I think the best way to trace it would be to follow the path of a previous change to plumb through something like the SKSL bundle path. See #58879

@bdero
Copy link
Member Author

bdero commented Oct 20, 2022

Alrighty, I took a first pass at pulling FLTEnableImpeller. It's working, but does require wiping the build when switching backends at the moment.

@bdero bdero marked this pull request as ready for review October 20, 2022 00:54
@bdero bdero changed the title [Impeller] Build Impeller iOS runtime stage [Impeller] Build Impeller iOS runtime stage shaders when Impeller is enabled Oct 20, 2022
@jonahwilliams
Copy link
Contributor

To get that to work, I think all you'll need to do is to get that plist file into the list of inputs for that target. Try something like:

diff --git a/packages/flutter_tools/lib/src/build_system/targets/assets.dart b/packages/flutter_tools/lib/src/build_system/targets/assets.dart
index d719a1c3fd..4d7ff2a1b9 100644
--- a/packages/flutter_tools/lib/src/build_system/targets/assets.dart
+++ b/packages/flutter_tools/lib/src/build_system/targets/assets.dart
@@ -32,6 +32,7 @@ Future<Depfile> copyAssets(
   required TargetPlatform targetPlatform,
   BuildMode? buildMode,
   required ShaderTarget shaderTarget,
+  List<File> additionalInputs = const <File>[],
 }) async {
   // Check for an SkSL bundle.
   final String? shaderBundlePath = environment.defines[kBundleSkSLPath] ?? environment.inputs[kBundleSkSLPath];
@@ -65,6 +66,7 @@ Future<Depfile> copyAssets(
     // An asset manifest with no assets would have zero inputs if not
     // for this pubspec file.
     pubspecFile,
+    ...additionalInputs,
   ];
   final List<File> outputs = <File>[];
 
diff --git a/packages/flutter_tools/lib/src/build_system/targets/ios.dart b/packages/flutter_tools/lib/src/build_system/targets/ios.dart
index 644d48aff0..266e6fb019 100644
--- a/packages/flutter_tools/lib/src/build_system/targets/ios.dart
+++ b/packages/flutter_tools/lib/src/build_system/targets/ios.dart
@@ -515,6 +515,9 @@ abstract class IosAssetBundle extends Target {
       assetDirectory,
       targetPlatform: TargetPlatform.ios,
       shaderTarget: ShaderTarget.sksl,
+      additionalInputs: <File>[
+          // path to plist
+      ]
     );
     final DepfileService depfileService = DepfileService(
       fileSystem: environment.fileSystem,

@bdero
Copy link
Member Author

bdero commented Oct 20, 2022

Nice, that's working!

Another thing: I think shader hot reloading doesn't work with Impeller at the moment because we use the shader function entry point as the identifier and there's no way to "unregister" a shader function yet in the shader library. I'm gonna try to fix this when addressing #113719.

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM with nit

final FlutterProject flutterProject = FlutterProject.fromDirectory(environment.projectDir);

bool isImpellerEnabled() {
final PlistParser plistParser = PlistParser(fileSystem: globals.fs, logger: environment.logger, processManager: globals.processManager);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, if you're using the cursed globals, might as well use globals. plistParser

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, done.

}
final Map<String, Object> info = plistParser.parseFile(flutterProject.ios.infoPlist.path);

if (!info.containsKey('FLTEnableImpeller')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need this condition with the next condition, if they key is missing you'll get null back from the map

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed. I also made a cast below this less spicy.


final Object? enableImpeller = info['FLTEnableImpeller'];

if (enableImpeller is bool?) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe enableImpeller is bool ? enableImpeller : false

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. The linter also dropped some wisdom and this ended up at enableImpeller is bool && enableImpeller

Copy link
Member Author

Choose a reason for hiding this comment

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

Question marks gone. I guess there's no question about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e: impeller Impeller rendering backend issues and features requests tool Affects the "flutter" command-line tool. See also t: labels.

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants