Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] Vulkan runtime effects/fragment program API #49543

Merged
merged 19 commits into from
Jan 11, 2024

Conversation

dnfield
Copy link
Contributor

@dnfield dnfield commented Jan 4, 2024

Fixes flutter/flutter#122823
Fixes flutter/flutter#129659
Fixes flutter/flutter#123741

This patch makes runtime stage/fragment program stuff work on Vulkan for Android.

It will need flutter/flutter#140976 for that to become a reality for flutter_tools users.

Compiling with relaxed Vulkan semantics still has an issue: shaders that use sampler2D with an explicitly set location on the layout will fail to compile with an error documented in flutter/flutter#141219.

I think there might still be some issues with fragment programs on Vulkan, but this should at least be a good starting point and unblocks ink_sparkle.frag usage in the framework.

I've deleted some runtime_stage related code that would never get used - for example, enum related code that indicates we might support a bunch of data types that we do not and probably never will support in this API.

@dnfield dnfield marked this pull request as ready for review January 9, 2024 23:41
@dnfield dnfield changed the title [Impeller] Vulkan runtime effects started [Impeller] Vulkan runtime effects/fragment program API Jan 9, 2024
@@ -79,15 +68,6 @@ static std::shared_ptr<ShaderMetadata> MakeShaderMetadata(
bool RuntimeEffectContents::Render(const ContentContext& renderer,
Copy link
Member

Choose a reason for hiding this comment

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

A nit on the current design. We should be able to pull together the descriptor set layouts when registering the shader/pipeline somehow. i'm not 100% certain how PipelineDescriptor equality works and I'd be slightly worredi that we would recreate pipelines on each frame.

This isn't blocking of course, but a follow up issue to make this more efficient would be appreciated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

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

LGTM with nit

@dnfield dnfield added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 10, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 10, 2024
Copy link
Contributor

auto-submit bot commented Jan 10, 2024

auto label is removed for flutter/engine/49543, due to - The status or check suite Mac mac_host_engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@jonahwilliams
Copy link
Member

We talked a bit offline and found that the runtime effect wasn't caching the compiled pipeline, which needs to be kept alive for Vulkan. I suggested a RuntimeEffect pipeline cache on the content context that could be used with a cache key composed of descriptor + shader name.

@dnfield
Copy link
Contributor Author

dnfield commented Jan 10, 2024

Implemented the cache and updated a test for it in 2b1d8c2


struct Hash {
std::size_t operator()(const RuntimeEffectPipelineKey& key) const {
return fml::HashCombine(key.unique_entrypoint_name,
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we should just have std::hash specializations for fml::HashCombine and friends can work without having to specify the Hash struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would that be a specialization on impeller::Comparable<T>? Or did you have something else in mind?

@@ -141,7 +141,7 @@ void ShaderLibraryGLES::UnregisterFunction(std::string name,
const auto key = ShaderKey{name, stage};

auto found = functions_.find(key);
if (found != functions_.end()) {
if (found == functions_.end()) {
Copy link
Member

Choose a reason for hiding this comment

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

Whoa

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 this code was just not tested lol

#include "flutter/testing/testing.h"
#include "gmock/gmock.h"
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean to import this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed for EXPECT_THAT to make it easier to compare vectors.

@@ -18,6 +18,8 @@ namespace impeller {

class RuntimeStage {
public:
static const char* kVulkanUBOName;
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a docstring for this? Something like "The made-up name of the struct used to the contain the non-opaque uniforms specified directly by the user in the custom runtime fragment stage. Vulkan cannot support non-opaque uniforms which is why these must be moved into a UBO with this name."

Copy link
Member

Choose a reason for hiding this comment

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

Or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -729,10 +729,42 @@ class ContentContext {
return render_target_cache_;
}

std::shared_ptr<Pipeline<PipelineDescriptor>> GetCachedRuntimeEffectPipeline(
Copy link
Member

Choose a reason for hiding this comment

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

The immediate thought that came to mind was, "Aren't all runtime stage entrypoints just called 'main'?" I suppose we mangle taking into account the name of the stage. But that still means that different stages with the same name will collide. I am not sure if that issue is purely hypothetical but it will be hard to debug if we run into it.

I suppose we could hash the name and the structure of the inputs before in the compiler and include that in the fbs. Or just generate a UUID.

Copy link
Member

Choose a reason for hiding this comment

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

How the uniqueness of the entrypoint is guaranteed today would be good to add to a docstring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try to document this. We build up the entrypoint name from the file name in the compiler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was going to try to plumb through the asset name for this but realized we basically already have that in the entrypoint name.

Copy link
Member

Choose a reason for hiding this comment

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

A single type-4 UUID would be fine honestly. But I suspect this works fine for now. Filing a followup works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dnfield dnfield added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 10, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 10, 2024
Copy link
Contributor

auto-submit bot commented Jan 10, 2024

auto label is removed for flutter/engine/49543, due to - The status or check suite Windows windows_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label.

  • The status or check suite Mac mac_clang_tidy has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Linux linux_android_aot_engine has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Linux linux_host_desktop_engine has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Linux linux_arm_host_engine has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Linux linux_clang_tidy has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Linux Framework Smoke Tests has failed. Please fix the issues identified (or deflake) before re-applying this label.

@dnfield dnfield added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 10, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 10, 2024
Copy link
Contributor

auto-submit bot commented Jan 10, 2024

auto label is removed for flutter/engine/49543, due to Pull request flutter/engine/49543 is not in a mergeable state.

@dnfield dnfield added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 10, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 10, 2024
Copy link
Contributor

auto-submit bot commented Jan 10, 2024

auto label is removed for flutter/engine/49543, due to - The status or check suite Linux linux_web_engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@dnfield dnfield added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 11, 2024
@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

Changes reported for pull request #49543 at sha 7f597b1

@auto-submit auto-submit bot merged commit ade9f18 into flutter:main Jan 11, 2024
30 checks passed
@dnfield dnfield deleted the impellerc branch January 11, 2024 02:29
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 11, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jan 11, 2024
…141337)

flutter/engine@42e3e02...ade9f18

2024-01-11 [email protected] [Impeller] Vulkan runtime effects/fragment program API (flutter/engine#49543)
2024-01-11 [email protected] Roll Dart SDK from 9f5a6a2ccace to 3245b92a5930 (1 revision) (flutter/engine#49700)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
dnfield added a commit that referenced this pull request Jan 16, 2024
I broke this in #49543

While investigating flutter/flutter#141235 I
realized that the specific things that were wrong there were probably
artifacts of some intermediate issue in the previous patch - they no
longer appear. However, I had broken hot reload.

This patch fixes it and updates the `EntityTest.RuntimeEffect` to
artificially run the rendering callback a few times simulating a hot
reload. The test fails without my changes here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App e: impeller will affect goldens
Projects
No open projects
Status: ✅ Done
3 participants