Skip to content

[flutter_tools] expose SKSL shader dump#53278

Closed
jonahwilliams wants to merge 5 commits intoflutter:masterfrom
jonahwilliams:expose_service_protocol_sksl
Closed

[flutter_tools] expose SKSL shader dump#53278
jonahwilliams wants to merge 5 commits intoflutter:masterfrom
jonahwilliams:expose_service_protocol_sksl

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Mar 25, 2020

Description

#53116
#53115

Connect getSkSls to the M key, which writes the files to shaders/. 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:

unzip app.apk
...
  inflating: assets/flutter_assets/shaders/CAZAAAACAUAAACIAAAABGAABAAOAAAYABQAECAAAAAAAAAAAAAAAEAAAAAOAAVYA  
  inflating: assets/flutter_assets/shaders/CAZAAAACAYAABAAAAAABGAABAD7777777777777777776FAABYAAAAAAAAAAAAAAAIAAAABEABLQA  
  inflating: assets/flutter_assets/shaders/CAZAAAACAYAABCAAAAABGAABAD777777777777YZAAAAAFAABYAAAAAAAAAAAAAAAIAAAABEABLQA  
  inflating: assets/flutter_assets/shaders/CAZAAAACAYAABGIAAAABGAABAAOAAFAA777777YZAAAAAFAABYAAAAAAAAAAAAAAAIAAAABEABLQA  

Needs tests and cleanup.

@fluttergithubbot fluttergithubbot added tool Affects the "flutter" command-line tool. See also t: labels. work in progress; do not review labels Mar 25, 2020
String packagesPath,
bool includeDefaultFonts = true,
bool reportLicensedPackages = false,
bool includeShaderFiles = false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note to self, need to make a google3 change first

CommandHelpOption _M;
CommandHelpOption get M => _M ??= _makeOption(
'M',
'Write SKSL shaders to a file.',
Copy link
Contributor

Choose a reason for hiding this comment

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

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here to a folder or to files.

return;
}
final Directory outputDirectory = globals.fs.currentDirectory
.childDirectory('shaders')
Copy link
Contributor

Choose a reason for hiding this comment

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

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).

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Skia's name convention is SkSL with capitalized SL (stands for Shader Language).

});
}

Future<Map<String, Uint8List>> getSkSls() async {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here for SkSLs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, this was meant to be on the switch above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(unless you were just taking about the member name and not the keypress...)

Copy link
Contributor

@devoncarew devoncarew Mar 27, 2020

Choose a reason for hiding this comment

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

@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.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jonahwilliams : ah yes, I was just talking about renaming getSkSls() to getSkSLs() as that's the name convention from Skia.

Copy link
Member

Choose a reason for hiding this comment

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

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()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah thats a good idea - these should probably be versioned and in the build artifacts directory

@liyuqian
Copy link
Contributor

Regarding the platform dependencies, the SkSL (Skia shader language) is by itself platform independent. It can be used for Skia CPU backend, OpenGL backend, Vulkan backend, or Metal backend. One can write an SkSL shader and run it in all platforms. However, the actual content in the SkSL file that we captured may depend on platforms (e.g., either for performance optimizations, or because some platforms have bugs in certain areas). I'll experiment how robust our captured SkSLs are.

@jonahwilliams
Copy link
Contributor Author

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...

@liyuqian
Copy link
Contributor

@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.

@brianosman brianosman closed this Mar 31, 2020
@brianosman brianosman reopened this Mar 31, 2020
@brianosman
Copy link

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.

@jonahwilliams
Copy link
Contributor Author

Continuing the rest of the work in #54499

@jonahwilliams jonahwilliams deleted the expose_service_protocol_sksl branch April 10, 2020 23:14
@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.

7 participants