[flutter_tools] expose SKSL shader dump#53278
[flutter_tools] expose SKSL shader dump#53278jonahwilliams wants to merge 5 commits intoflutter:masterfrom
Conversation
| String packagesPath, | ||
| bool includeDefaultFonts = true, | ||
| bool reportLicensedPackages = false, | ||
| bool includeShaderFiles = false, |
There was a problem hiding this comment.
Note to self, need to make a google3 change first
| CommandHelpOption _M; | ||
| CommandHelpOption get M => _M ??= _makeOption( | ||
| 'M', | ||
| 'Write SKSL shaders to a file.', |
There was a problem hiding this comment.
Write SKSL shaders to a folder or Write SKSL shaders to files?
| throw Exception('Canvaskit not supported by this runner.'); | ||
| } | ||
|
|
||
| /// Dump the sksl shaders to a file in the project directory. |
There was a problem hiding this comment.
Same here to a folder or to files.
| return; | ||
| } | ||
| final Directory outputDirectory = globals.fs.currentDirectory | ||
| .childDirectory('shaders') |
There was a problem hiding this comment.
Maybe use directory shaders/sksl or just sksl to be more specific. There's a possibility that we can have other kind of shader artifacts (e.g., binary shaders).
There was a problem hiding this comment.
Also, maybe put the auto-captured shaders under a folder with flutter version in it (e.g., shaders/8857c4cec89164fdb6293bef69f9d62c62733efa/sksl) because SkSL is not guaranteed to be backward compatible. A Flutter app should use the SkSLs that are captured from the same framework/engine version.
There was a problem hiding this comment.
Good to know! Yeah, we can version these based on the specific engine hash that flutter is built with and refuse to include older shaders
| } | ||
| return false; | ||
| case 'M': | ||
| if (residentRunner.supportsWriteSkSl) { |
There was a problem hiding this comment.
Skia's name convention is SkSL with capitalized SL (stands for Shader Language).
| }); | ||
| } | ||
|
|
||
| Future<Map<String, Uint8List>> getSkSls() async { |
There was a problem hiding this comment.
We're limited to a single character here, and s is screenshot and S is dump semantics tree. We can also explore writing a service extension that editors/IDEs can invoke on behalf of a user, perhaps when they press a button in devtools or intellij.
FYI @jacob314 @devoncarew
There was a problem hiding this comment.
Oops, this was meant to be on the switch above
There was a problem hiding this comment.
(unless you were just taking about the member name and not the keypress...)
There was a problem hiding this comment.
@kenzieschmoll @terrylucas so they're aware of exposing Skia information to tools.
@jonahwilliams, re: the single letter overload in the CLI. Some ideas:
Change to only have single letter abbreviations for very common operations (hot reload, quit, ...). Have an overflow shortcut key which prints a menu of additional available operations - those could be numbered, or typed in by short words (skia, dump, ...)
Or, have all operations have short phrases associated with them (hot-reload, hot-restart, dump-render-tree). You'd have to type in the full text in order to select the operation, but we could offer typing completion in the console so you'd normally only have to type in a few chars manually.
There was a problem hiding this comment.
@jonahwilliams : ah yes, I was just talking about renaming getSkSls() to getSkSLs() as that's the name convention from Skia.
There was a problem hiding this comment.
I played around with this toy program:
import 'dart:io';
main() {
stdin.echoMode = false;
stdin.lineMode = false;
stdin.listen((List<int> s) {
print('> $s\n');
});
}on Linux and Windows. On both it's possible to detect when ctrl is pressed while a letter key is pressed. We'd probably have to decode stdin with a custom decoder rather than AsciiDecoder though.
(On Linux alt is sometimes part of the same List<int> as the character code when it is pressed, and sometimes not. On Windows it's not detectable.)
| final List<File> newAdditionalDependencies = <File>[]; | ||
|
|
||
| // Include the SkSl shader files in shaders/ | ||
| if (includeShaderFiles && globals.fs.directory('shaders').existsSync()) { |
There was a problem hiding this comment.
What if some Flutter project has a user-created shaders directory in the root Flutter directory? Would it be safer to put such directory under build so it's clear that the files are auto-generated and not user-created?
There was a problem hiding this comment.
Yeah thats a good idea - these should probably be versioned and in the build artifacts directory
|
Regarding the platform dependencies, the |
|
I wonder, if its fairly stable across platforms then a developer could run the shader warmup on an Android emulator and then use that output for a released iOS application right? Would the same apply to the flutter_tester shell? I realize that is headless, or mostly headless but I assume most of the same engine bits are there... |
|
@jonahwilliams : I currently don't have high hopes of having iOS use the SkSLs generated from Android emulators. But I'm certainly interested in doing such experiments and see how far it can go. Also CC @brianosman from Skia team to see his opinion about having iOS devices use SkSLs generated from Android emulators. My guess is that it won't crash the iOS app, but it's unclear how much useful warmup those SkSLs can do. |
|
Sorry, closed the wrong PR. While I'm here, though - yeah, using SkSLs from a platform that different is unlikely to be helpful. There may be some overlap, but I wouldn't recommend it. |
|
Continuing the rest of the work in #54499 |
Description
#53116
#53115
Connect
getSkSlsto theMkey, which writes the files toshaders/. This includes instructions on what to do with them (nothing!) and what to do if none are received.Updates the asset manifest logic to include any shaders under
shaders/. I'm not completely sold on this approach, but it seems like the most automatic - assuming the shaders are cross platform? If they are platform dependent we should do something else...The SkSl files are currently packaged in
flutter_assets/shaders, for example:Needs tests and cleanup.