Skip to content

[Impeller] Provide an API for loading FragmentPrograms at runtime (and tooling support for producing them). #124759

@jezell

Description

@jezell

Use case

We would like to be able to dynamically load shaders at runtime like https://www.shadertoy.com or https://www.alma.sh/. Currently FragmentProgram only has a static method for loading assets, which seems a bit limiting as it is just shader bytecode that is being put into the bundle. For instance, web implements this as such:

 @override
  Future<ui.FragmentProgram> createFragmentProgram(String assetKey) {
    if (_programs.containsKey(assetKey)) {
      return _programs[assetKey]!;
    }
    return _programs[assetKey] = assetManager.load(assetKey).then((ByteData data) {
      return CkFragmentProgram.fromBytes(assetKey, data.buffer.asUint8List());
    });
  }

Proposal

The functionality already exists behind the scenes, so I just suggest it becomes part of the top level FragmentProgram api:

For instance this already exists:

static Future<CkFragmentProgram> fromBytes(String name, Uint8List data)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecte: impellerImpeller rendering backend issues and features requestsengineflutter/engine related. See also e: labels.team-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions