[Flutter GPU] Add automation to make importing Flutter GPU shaders easy. #144259
Labels
c: proposal
A detailed proposal for a change to Flutter
flutter-gpu
P2
Important issues not at the top of the work list
r: fixed
Issue is closed as already fixed in a newer version
team-engine
Owned by Engine team
tool
Affects the "flutter" command-line tool. See also t: labels.
triaged-engine
Triaged by Engine team
Milestone
Uh oh!
There was an error while loading. Please reload this page.
Part of #130921
Option 1: Offer a library for making
native_asset
build hooks easy.Proof of concept build hook lib: https://github.com/bdero/test_native_assets/blob/master/hook/build.dart#L9-L138
To set up automated shaderbundle compilation, the user would:
hook/build.dart
file that invokes an imported function from theflutter_gpu
package:Option 2: Use an Asset Transformer.
Make a simple transformer package that just ingests a manifest text file and finds/invokes impellerc, replacing this temp solution.
A few thoughts:
packages
directory in the flutter/flutter repo with an integration test ensuring that it doesn't break against the version of impellerc shipping in the engine artifacts.flutter_gpu
SDK package automatically. Without this, I believe users of Flutter GPU will need to both depend on and activate the asset transformer by adding configuration similar to the following inpubspec.yaml
:Option 3: Add support directly to the Flutter tool.
Flutter GPU shaders are stored in libraries, and these libraries can be deserialized from "shader bundle" files.
For this task, add support to the Flutter tool for importing a collection of shader files as a shader bundle.
Here's an example of a shader bundle defined in a package
pubspec.yaml
file:This creates one shader bundle called "CoolShaderBundle" with two shader inputs: "FlatShadeVertex" and "FlatShadeFragment".
To produce this shader bundle asset, the flutter tool should run
impellerc
with the--shader_bundle
parameter. Taking the example above, the call should look like this:If any of the input source shader files have change, then the output shader bundle file (
CoolShaderBundle.shaderbundle
) needs to be rebuilt.See also the Flutter GPU doc.
The shader bundle spec
For Flutter GPU's MVP, ImpellerC's
--shader_bundle
accepts a JSON string in the following form:Later on, other per-shader parameters can be supported, such as ("language" and "entry_point").
Building shader bundles manually
Up until now, I've been building shader bundles manually in order to bootstrap some renderer projects. These bundles are produced using the
impellerc
executable shipped in the engine artifacts.Here's an example of a valid invocation of ImpellerC, which builds a shader bundle asset named "assets/base.shaderbundle" with 5 builtin shaders:
Note that the actual names of the shaders in the bundle (SimpleVertex, SimpleFragment, etc) are entirely the user's choice.
How manually built shader bundles are imported.
Here's a simplified example of a Flutter GPU ShaderLibrary being deserialized from a shader bundle (as seen in the
flutter_scene
package):From here, a ShaderBundle can be used by looking up shader names
The text was updated successfully, but these errors were encountered: