Skip to content

[flutter_tools] support bundling SkSL shaders into Android applications#54499

Closed
jonahwilliams wants to merge 10 commits intoflutter:masterfrom
jonahwilliams:bundle_sksl_2
Closed

[flutter_tools] support bundling SkSL shaders into Android applications#54499
jonahwilliams wants to merge 10 commits intoflutter:masterfrom
jonahwilliams:bundle_sksl_2

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Apr 10, 2020

Description

Support 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/sksl/io.flutter.shaders.json

Fixes #53115

@fluttergithubbot fluttergithubbot added tool Affects the "flutter" command-line tool. See also t: labels. work in progress; do not review labels Apr 10, 2020
@liyuqian
Copy link
Contributor

liyuqian commented Apr 10, 2020

@jonahwilliams : for iOS, the tool may need to send an extra arg --disable-metal to engine if SkSLs are packaged. The SkSL warm-up currently don't have much effect on Metal.

@jonahwilliams
Copy link
Contributor Author

@liyuqian that seems counter productive, shouldn't we be encouraging users to move to metal?

@liyuqian
Copy link
Contributor

Yes, we encourage Metal.

In the short term, however, we may not be able to bring Metal's performance on par with OpenGL on every aspect. So we could allow developers to choose based on their needs. If shader compilation jank is their blocker, then they probably would choose SkSL with OpenGL. If average rasterization performance is more important, they'd choose the default option with Metal without any SkSL warmup.

Fixing the shader compilation jank on Metal needs our medium term solution "Test-based shader warmup #53609" to be implemented.

@jonahwilliams jonahwilliams marked this pull request as ready for review April 23, 2020 17:49
@jonahwilliams jonahwilliams requested a review from liyuqian April 23, 2020 17:53
@jonahwilliams
Copy link
Contributor Author

@liyuqian I believe we discussed ways to validate this before by looking at the verbose logging, but I don't quite remember

@liyuqian
Copy link
Contributor

@jonahwilliams : add --verbose-system-log to flutter run or flutter drive will print out the logs in PersistentCache::LoadSkSLs. Is that what you're trying to remember?

@jonahwilliams
Copy link
Contributor Author

Ahh yeah, thats the one!

@jonahwilliams jonahwilliams changed the title [wip][flutter_tools] support bundling SkSL shaders into app [flutter_tools] support bundling SkSL shaders into Android applications Apr 24, 2020
@jonahwilliams
Copy link
Contributor Author

I hit some issue with rebasing, so continuing here: https://github.com/jonahwilliams/flutter/pull/new/bundle_sksl_3

I'm not able to get the persistent cache to find the shader file. Interestingly looking through the logs from both flutter run and adb, I cannot see a place where setting the persistent cache directory gets logged:

Specifically I'm looking for https://github.com/flutter/engine/blob/31ecf878aa1f12ee7f3a22c424673751db3100da/shell/common/persistent_cache.cc#L338

Logs:

I/flutter (19584): [INFO:persistent_cache.cc(158)] No sksl asset file found.
I/flutter (19584): [INFO:gpu_surface_gl.cc(88)] Found 0 SkSL shaders; precompiled 0
I/flutter (19584): [INFO:persistent_cache.cc(228)] PersistentCache::load failed: CAZACAECBUAAAAIAAAAAAAAAAAJQAAIADQABCAH777776FAAN4AAAAAAAAAAAAAAEAABUAAAAAAAAAAAAAACYABGAAAAAAAABUAACAAAAAAAAPAAA4AAAAAAAAAAAAAABUAACAAAAAAAAUAALQAAAAAAAAAAAAAAAIAAAADAABLQA
I/flutter (19584): [INFO:persistent_cache.cc(228)] PersistentCache::load failed: CAZACAECBUAAAAIACAAAAAAAAAJQAAIADQABCAH777776FAAN4AAAAAAAAAAAAAAEAABUAAAAAAAAAAAAAACYABGAAAAAAAABUAACAAAAAAAAPAAA4AAAAAAAAAAAAAABUAACAAAAAAAAUAALQAAAAAAAAAAAAAAAIAAAADAABLQA
I/flutter (19584): [INFO:persistent_cache.cc(228)] PersistentCache::load failed: CAZAAAECAUAAAAAAAAABGAABAAOAAEIADQAAGAAQABMQAAAAAAAAAAAAAABAAAAAEAAFOAA
I/flutter (19584): [INFO:persistent_cache.cc(228)] PersistentCache::load failed: CAZAAAECAYAAAAYAAAAACAAAAAJQAAIADQABCAAPAAKAAAAAAAABIABLAAAAAAAAAAAAAAACAAAAAKAAK4AA
I/flutter (19584): [INFO:persistent_cache.cc(228)] PersistentCache::load failed: CAZAAAECAYAAAAAAAAAACAAAAAJQAAIADQABCAAPAAKAAAAAAAABIAAZAAAAAAAAAAAAAAACAAAAAKAAK4AA
I/flutter (19584): [INFO:persistent_cache.cc(228)] PersistentCache::load failed: GMZQAAEBA4AAAAAAAAAEOAIAAAJQAAIACIAAAAA4AAIQB7777777777777777777EAAFUAAAAAAAAAAAAAAACAAAAAYAACIA
I/flutter (19584): [INFO:persistent_cache.cc(228)] PersistentCache::load failed: GMZQCAEBBEAAAAAAAAACOAAAAAJQAAIA7777777777776EYAAEAP777777777777EAAFUAAAAAAAABAEAAAAAAAAAAWAATIAAIAAAAAAAAAAAAQAAAAEAACXAA

Flutter run key commands.
h Repeat this help message.
c Clear the screen
q Quit (terminate the application on the device).
An Observatory debugger and profiler on Pixel 4 is available at: http://127.0.0.1:60778/TsLNHw50k4k=/
I/flutter (19584): [INFO:persistent_cache.cc(228)] PersistentCache::load failed: GMZQCAEBBMAAAAAAAAACOAAAAAJQAAIA7777777777776EYAAEAP777777777777EAAFUAAAAAAAABAEAAAAAAAAAAWAATIAAEAAAAAJAAAAABAEAAAEAABRAABAAAAAAAAAAAACAAAAAUAAK4AA
I/flutter (19584): [INFO:persistent_cache.cc(228)] PersistentCache::load failed: GMZQCAEBBMAAAAAAAAACOAAAAAJQAAIA7777777777776EYAAEAP777777777777EAAFUAAAAAAAAAAAAAAAAAAAAAWAATIAAEAAAAAJAAAAAAAAAAAEAABRAABAAAAAAAAAAAACAAAAAUAAK4AA
I/flutter (19584): [INFO:persistent_cache.cc(228)] PersistentCache::load failed: GMZQCAEBBEAAAAAAAAACOAAAAAJQAAIA7777777777776EYAAEAP777777777777EAAFUAAAAAAAAAAAAAAAAAAAAAWAATIAAIAAAAAAAAAAAAQAAAAEAACXAA
I/flutter (19584): [INFO:persistent_cache.cc(228)] PersistentCache::load failed: CAZAAAMCBEAAAAAAAAAGOAAAAAJQAAIA777777Y4AAIQAEYAAEAP777777777777EAAFUAAAAAAAABAEAAAAAAAAAAWAATIAAIAAAAAAAAAAAAQAAAAEAACXAA
I/flutter (19584): [INFO:persistent_cache.cc(228)] PersistentCache::load failed: CAZAAAECA4AAAAAAAAAEOAQAAAJQAAIA777777Y4AAIQB7777777777777777777EAAFUAAAAAAAAAAAAAAAEAAAAAYAAVYA
I/flutter (19584): [INFO:persistent_cache.cc(228)] PersistentCache::load failed: CAZAAAACBAAAAAAAAAAGKAAAAAJQAAIA777777Y4AAIQAEYAAEAP777777777777AAAAAABAABNAAAAAAAAAAAAAAABAAAAAGQAFOAA

@liyuqian
Copy link
Contributor

@jonahwilliams : thanks for discovering this issue! The root cause of this issue and its fix are described in flutter/engine#17948. Before that PR gets rolled, you can try your tools on iOS.

@liyuqian
Copy link
Contributor

FYI @jonahwilliams: I just found one more issue on Android so now I completely moved from reading files from a path to directly calling the AssetManager (flutter/engine#17948 (comment)). As a result, you no longer need to put the file in sksl/io.flutter.shaders.json. Simply put the file in the root asset directory as io.flutter.shaders.json is what the engine needs.

@jonahwilliams
Copy link
Contributor Author

That works, thanks @liyuqian !

@jonahwilliams
Copy link
Contributor Author

Success!

Installing build\app\outputs\flutter-apk\app-release.apk...         3.6s
I/flutter (27872): [INFO:persistent_cache.cc(160)] Found sksl asset. Loading SkSLs from it...
I/flutter (27872): [INFO:gpu_surface_gl.cc(88)] Found 27 SkSL shaders; precompiled 27

@jonahwilliams
Copy link
Contributor Author

Closing in favor of #56059

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
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.

Add support for --sksl-shader-warmup to package sksl files into flutter_assets

4 participants