Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@zanderso
Copy link
Member

@zanderso zanderso commented Jul 13, 2022

This PR adds the API FragmentProgram.fromAsset, which loads a shader in .iplr format as output by impellerc directly from a bundled asset into a FragmentProgram object. Since impellerc has already compiled the shader into the correct target-specific format, there is no need for the shader to transit the Dart heap or to be transpiled by the Engine's SPIR-V -> SkSL transpiler.

@zanderso zanderso added the Work in progress (WIP) Not ready (yet) for review! label Jul 13, 2022
FOR_EACH_BINDING(DART_REGISTER_NATIVE)});
}

void FragmentProgram::initFromAsset(std::string asset_name,
Copy link
Member Author

@zanderso zanderso Jul 13, 2022

Choose a reason for hiding this comment

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

@jonahwilliams What are the changes to support hot reload? Guessing:

  • FragmentProgram retains asset_name
  • On a hot reload, reload the shader data from the asset manager
  • Make a new SkRuntimeEffect and overwrite runtime_effect_
  • Also re-setup the fields of the Dart object.
  • Other stuff?

The thing I'm not sure how to do is how to hook into a notification of a hot reload.

Copy link
Contributor

Choose a reason for hiding this comment

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

For step 2, rather than signal on a hot reload (because the reload may not have changed that particular asset)- wait for a specifc vm service notification that contains an invalidation for a particular asset. This would need to be dispatched from the tool, but it could be hooked up alongside the existing vm service listeners in service_protocol.cc .

https://github.com/flutter/engine/blob/e23c43195c6492abcb8bb87fd775d54e0d995947/runtime/service_protocol.cc

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd imagine we'd need to create some sort of shared debug mode only shader manager that could correlate the shader instance with the vm service signal

Copy link
Member Author

Choose a reason for hiding this comment

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

This seemed easier to handle on the Dart side. I added a static Map from asset keys to FragmentPrograms to FragmentProgram, and a service extension that takes the asset key, uses it to look up the FragmentProgram and reinitializes it. wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

The Map should probably hold WeakReferences to the FragmentPrograms, but I'll come back to this after the bugfixes to impellerc land.

Copy link
Contributor

Choose a reason for hiding this comment

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

That seems reasonable, also all for doing it in Dart as well!

@zanderso zanderso marked this pull request as draft July 13, 2022 23:16
@flutter-dashboard
Copy link

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

@zanderso zanderso force-pushed the fp-init-from-asset branch from c9e1601 to af8fd60 Compare July 14, 2022 05:21
@chinmaygarde chinmaygarde changed the title Adds FragmentProgram.initFromAsset [Impeller] Adds FragmentProgram.initFromAsset Jul 18, 2022
@flutter-dashboard flutter-dashboard bot added the platform-web Code specifically for the web engine label Jul 18, 2022
@zanderso zanderso force-pushed the fp-init-from-asset branch 2 times, most recently from 2b87fe0 to d18df63 Compare July 19, 2022 04:26
@zanderso zanderso force-pushed the fp-init-from-asset branch from d18df63 to a3d21be Compare July 19, 2022 15:07
@zanderso zanderso removed the Work in progress (WIP) Not ready (yet) for review! label Jul 19, 2022
@zanderso zanderso marked this pull request as ready for review July 19, 2022 15:12
@zanderso zanderso changed the title [Impeller] Adds FragmentProgram.initFromAsset [Impeller] Adds FragmentProgram.fromAsset Jul 19, 2022
impeller::RuntimeUniformType::kSampledImage) {
sampled_image_count++;
} else {
size_t size = uniform_description.dimensions.rows *
Copy link
Member Author

@zanderso zanderso Jul 19, 2022

Choose a reason for hiding this comment

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

@chinmaygarde Does this make sense? This is attempting to compute how many bytes are needed for all of the uniforms by adding up (rows * cols * bit_width) / 8.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense to me.

@zanderso zanderso requested a review from chinmaygarde July 19, 2022 15:53
Comment on lines 4095 to 4099
final WeakReference<FragmentProgram>? programRef = _shaderRegistry[assetKey];
FragmentProgram? program;
if (programRef != null) {
program = programRef.target;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:
FragmentProgram? program = _shaderRegistry[assetKey]?.target;

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

Dart side LGTM

(I wrote up flutter/flutter#107963 which when combined with some new impellerc flags should get us support in the tool)

@zanderso zanderso force-pushed the fp-init-from-asset branch from a3d21be to 8149ca9 Compare July 19, 2022 22:28
impeller::RuntimeUniformType::kSampledImage) {
sampled_image_count++;
} else {
size_t size = uniform_description.dimensions.rows *
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense to me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

e: impeller platform-web Code specifically for the web engine

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants