Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flutter_tools] support bundling SkSL shaders in flutter build apk/appbundle #56059

Merged
merged 8 commits into from
Apr 30, 2020

Conversation

jonahwilliams
Copy link
Member

@jonahwilliams jonahwilliams commented Apr 30, 2020

Description

upport bundling SkSL shaders into an android APK or appbundle via the --bundle-sksl-path command line options. If provided, these are validated for platform engine revision and then placed in flutter_assets/io.flutter.shaders.json

#53115 (Not marked as fixed since there are other platforms too)

Change in version logic broke PR: #54499

This is currently only supported for Android, but will be expanded to all platforms as a follow up

@jonahwilliams
Copy link
Member Author

I confirmed shader loading success too :)

@jonahwilliams jonahwilliams added the tool Affects the "flutter" command-line tool. See also t: labels. label Apr 30, 2020
Comment on lines 35 to 36
final ManifestAssetBundle assetBundle = AssetBundleFactory.instance.createBundle()
as ManifestAssetBundle;
Copy link
Member

Choose a reason for hiding this comment

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

I don't love this cast, I think we get way too cute with factory patterns in flutter_tools--sometimes it's better to just make what you need if you need to understand the internal details of it anyway.

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!

bundle = json.decode(skSLBundleFile.readAsStringSync())
as Map<String, Object>;
} on FormatException {
logger.printError('"$bundle" was not a JSON object.');
Copy link
Member

Choose a reason for hiding this comment

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

Print some of the FormatException details to give the user a hint.

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

logger.printError('"$bundle" was not a JSON object.');
throw Exception('SkSL bundle was invalid.');
} on TypeError {
logger.printError('"$bundle" was not a JSON object.');
Copy link
Member

Choose a reason for hiding this comment

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

Same

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, also rearranged this to use an is check instead of catching the type error.

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

LGTM

argParser.addOption(FlutterOptions.kBundleSkSLPathOption,
help: 'A path to a file containing precompiled SkSL shaders generated '
'during "flutter run". These can be included in an application to '
'impove the first frame render times.',
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: improve

Copy link
Contributor

@liyuqian liyuqian left a comment

Choose a reason for hiding this comment

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

RSLGTM with one nit comment. Can't wait this to merge, and having this on iOS soon too!

@@ -834,8 +834,21 @@ abstract class ResidentRunner {
'sksl',
);
final Device device = flutterDevices.first.device;

// Convert android sub-platforms to single target platform.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: is this conversion just to reduce the number of platform-mismatch warnings? If so, I'd probably prefer to not convert, and print warnings if one tries to use the SkSL bundle from android_x64 on android_arm64.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure how this would be possible today. When building an apk or appbundle, the tool builds for all ABIs simultaneously and assumes that assets are shared. It would take a significant amount of refactoring to support ABI-specific assets.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are the SkSL files ABI specific? If so this needs a lot more work :(

Copy link
Contributor

Choose a reason for hiding this comment

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

No, they're not ABI specific. I was only thinking about giving them warnings as platform-mismatch may make them less efficient. But there's absolutely no problem of cross-ABI compatibility (as I've used x64 SkSLs on arm).

Copy link
Member Author

Choose a reason for hiding this comment

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

This might be something we could fix long term then, would you file an issue with some more details on the efficiency loss from the current implementation?

Copy link
Contributor

Choose a reason for hiding this comment

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

Here's an experiment on the efficiency loss: #53607 (comment)

I don't think the current implementation has any issues. If we truly want to be 100% effective across different ABIs/devices, we probably have to rely on our medium-term solution "Test-based shader warmup #53609".

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants