Skip to content

Support transformers for flutter.shaders entries in pubspec.yaml #181888

Description

@Laurie-Lin

Use case

flutter.assets entries can declare transformers for build-time processing. flutter.shaders historically only accepted a list of paths, which makes it hard to apply the same build-time transformation pipeline to fragment shaders.

When porting existing shaders (e.g. Shadertoy/GLSL Sandbox style sources) to Flutter runtime effects, developers often need to inject Flutter-specific boilerplate (headers/uniforms + an entrypoint bridge) while keeping the upstream shader logic intact.

Without build-time transformers for shaders, developers must either:

  • manually edit shader sources (hard to keep in sync with upstream), or
  • maintain duplicated “Flutterized” copies (noise + churn).

Implemented (PR)

PR: #181889

This PR extends flutter.shaders to support the same map form used by assets entries, including transformers.

YAML sketch:
...
flutter:
shaders:
# Legacy string format (backwards compatible)
- shaders/simple.frag

# New map format with transformers
- path: assets/shaders/shadertoy_port.frag
  transformers:
    - package: shadertoy_transpiler
      # args: [...] (optional, same as assets)

...

Semantics:

  • If a shader entry declares transformers, the transformer pipeline runs first.
  • The shader compiler (impellerc) is then invoked on the transformed output.

Backwards compatibility:

  • The legacy string-list format remains supported.
  • Only shader entries that explicitly declare transformers are transformed.

Non-goals:

  • No change to impellerc / shader language compatibility.
  • No Shadertoy-specific behavior in Flutter itself — this only enables a build-time hook.
  • No change to built-in/material shaders.

Tests

Added flutter_tools unit tests to verify:

  • transformers are invoked for shader entries that declare them
  • impellerc compiles the transformed output
  • built-in/material shaders are not affected

Local verification command:

cd $FLUTTER_ROOT/packages/flutter_tools
FLUTTER_ROOT=$FLUTTER_ROOT ../../bin/cache/dart-sdk/bin/dart pub get
FLUTTER_ROOT=$FLUTTER_ROOT ../../bin/cache/dart-sdk/bin/dart test \
  test/general.shard/flutter_manifest_test.dart \
  test/general.shard/build_system/targets/assets_test.dart \
  -r expanded

Optional example

I also put together a minimal example repo demonstrating how to declare shader transformers in pubspec.yaml and how the transformer output is used during shader compilation:

This is optional reference material; the implementation and tests live entirely in the Flutter repo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions