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

[Impeller] Cache RenderPass/Framebuffer objects on the resolve texture sources. #50142

Merged
merged 11 commits into from
Feb 6, 2024

Conversation

jonahwilliams
Copy link
Member

@jonahwilliams jonahwilliams commented Jan 29, 2024

Cache vk::RenderPass and vk::Framebuffer objects on the resolve texture of any render target attachments. Use these on the next frame unconditionally.

Fixes flutter/flutter#141750

@jonahwilliams jonahwilliams changed the title [Impeller] hacking caching of onscreen render pass. [Impeller] Cache RenderPass/Framebuffer objects on the resolve texture sources. Feb 1, 2024
@jonahwilliams jonahwilliams marked this pull request as ready for review February 1, 2024 22:05
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@jonahwilliams
Copy link
Member Author

I guess this isn't directly tested but a test did fail until I fixed it 🤔

@@ -44,9 +44,20 @@ class TextureVK final : public Texture, public BackendCast<TextureVK, Texture> {

bool IsSwapchainImage() const { return source_->IsSwapchainImage(); }

// These methods should only be used by render_pass_vk.h
void SetFramebuffer(const SharedHandleVK<vk::Framebuffer>& framebuffer);
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to save this on the RenderTarget, not the Texture? This isn't applicable to every Texture, right?

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 RenderTarget itself is const/immutable whereas the Texture is stateful.

Copy link
Member

Choose a reason for hiding this comment

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

That's not a problem though. We can make the frame buffer and render pass when we create the RenderTarget. We shouldn't ever have a RenderTarget without a render pass and it will never change, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately that is all constructed above the backend layer, and there are no metal or gles analogs for these objects.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

This looks good, I just have a style nit and the obligatory question on testing. Great job finding a place to cache these relatively easily. I would have preferred this lives on the RenderTarget but I understand that would be a pretty invasive change.

You should be able to add a test for this in AiksTests. There is an example in GaussianBlurMipMapSolidColor where we render something and check the texture cache.

I was thinking you could render once, then inspect the texture cache and if it's vulkan make sure the GetRenderPass and GetFramePass are non-null for a texture that is IsSwapchainImage. Something like that.

You could then render a second frame and make sure that texture cache size is still 1. So we could presume that it was reused. We can't assert it however. That would make sure it doesn't crash and generates output.

Alternatively, or in addition, you could make a test directly on render_pass_vk.cc. This has a higher upfront cost but is easier to maintain and can be more precise than AiksTests.

Right now, someone could just comment out the call to SetRenderPass and no tests would fail. Presumably the benchmarks would catch that, but catching things in benchmarks is more expensive and less trustworthy. We may not even have an automated test that checks that a second render will not crash. I have one blur test that does that (GuassianBlurUpdatesMipmapContents). Maybe we'd benefit from something more apropos though.

/// May be nullptr if no previous framebuffer existed.
SharedHandleVK<vk::Framebuffer> GetFramebuffer() const;

/// @brief Retrieve the last render pass object used with this texture.
Copy link
Member

Choose a reason for hiding this comment

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

fyi: @brief is redundant here since the first section is implicitly the brief section.

}

SharedHandleVK<vk::RenderPass> TextureVK::GetRenderPass() const {
return renderpass_;
Copy link
Member

@gaaclarke gaaclarke Feb 2, 2024

Choose a reason for hiding this comment

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

These are inconsistent about wether render pass is 2 words or one. It should be RenderPass and render_pass_ or Renderpass and renderpass_.

Same for "frame buffer".

Copy link
Member Author

@jonahwilliams jonahwilliams Feb 2, 2024

Choose a reason for hiding this comment

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

Yeah, render pass is two words, framebuffer is one word.

@@ -44,9 +44,37 @@ class TextureVK final : public Texture, public BackendCast<TextureVK, Texture> {

bool IsSwapchainImage() const { return source_->IsSwapchainImage(); }

// These methods should only be used by render_pass_vk.h
Copy link
Member

Choose a reason for hiding this comment

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

Comments look good 👍

@jonahwilliams
Copy link
Member Author

Unfortunately I don't think we can import the Vulkan types into any of the aiks tests. 🤔

@jonahwilliams
Copy link
Member Author

best bet is probably a vulkan unit test that creates real objects for the most part. Should be doable via playground. I'll give that a shot.

auto resolve_texture =
render_target.GetColorAttachments().find(0u)->second.resolve_texture;
auto& texture_vk = TextureVK::Cast(*resolve_texture);

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 test appears to run with validations locally. There were no validation errors I believe

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

LGTM! Exciting change, thanks.

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 6, 2024
@auto-submit auto-submit bot merged commit 319ff6c into flutter:main Feb 6, 2024
@jonahwilliams jonahwilliams deleted the render_pass_cache branch February 6, 2024 04:35
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 6, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 6, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Feb 6, 2024
…143005)

flutter/engine@8088863...07cdaab

2024-02-06 skia-flutter-autoroll@skia.org Roll Dart SDK from 29265c94a6e8 to 35269fa71956 (1 revision) (flutter/engine#50402)
2024-02-06 54558023+keyonghan@users.noreply.github.com Add use_rbe to gclient variables for Framework Smoke Tests (flutter/engine#50403)
2024-02-06 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Revert "Revert "[Fuchsia] Execute most of the testing/fuchsia/test_suites.yaml on debug and release builds""" (flutter/engine#50407)
2024-02-06 matanlurey@users.noreply.github.com Skip flaking test on Windows nobody is fixing. (flutter/engine#50401)
2024-02-06 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[web] Fix Scene clip bounds. Trigger resize on DPR Change." (flutter/engine#50404)
2024-02-06 6844906+zijiehe-google-com@users.noreply.github.com Revert "Revert "[Fuchsia] Execute most of the testing/fuchsia/test_suites.yaml on debug and release builds"" (flutter/engine#50295)
2024-02-06 chinmaygarde@google.com [Impeller] Specify if Angle or SwiftShader is being used in the title. (flutter/engine#50376)
2024-02-06 matanlurey@users.noreply.github.com Run all Android `scenario_app` tests, not just the smoke test. (flutter/engine#50400)
2024-02-06 skia-flutter-autoroll@skia.org Roll Dart SDK from b62066b42af0 to 29265c94a6e8 (10 revisions) (flutter/engine#50398)
2024-02-06 matanlurey@users.noreply.github.com Capture `FAILURES!!!` when running Android `scenario_app` tests. (flutter/engine#50255)
2024-02-06 jonnywang@google.com [fuchsia] Bump Fuchsia's API level to 16 (flutter/engine#50358)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from 9e68ed6caf6d to 44106ee8edea (1 revision) (flutter/engine#50393)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from c29a20702356 to 9e68ed6caf6d (1 revision) (flutter/engine#50392)
2024-02-06 jonahwilliams@google.com [Impeller] Cache RenderPass/Framebuffer objects on the resolve texture sources. (flutter/engine#50142)
2024-02-06 jason-simmons@users.noreply.github.com [Impeller] Do not skip the GLES render pass if the command list is empty (flutter/engine#50381)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from cdf214adfb4d to c29a20702356 (54 revisions) (flutter/engine#50382)
2024-02-06 ditman@gmail.com [web] Fix Scene clip bounds. Trigger resize on DPR Change. (flutter/engine#50161)
2024-02-06 xilaizhang@google.com [github actions] add cherry pick workflow for engine repo (flutter/engine#50265)

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 chinmaygarde@google.com,rmistry@google.com,zra@google.com 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
auto-submit bot added a commit to flutter/flutter that referenced this pull request Feb 6, 2024
…visions)" (#143025)

Reverts #143005

Initiated by: vashworth

Reason for reverting: `Linux technical_debt` started failing on this commit: https://ci.chromium.org/ui/p/flutter/builders/prod/Linux%20technical_debt__cost/16684/overview

Original PR Author: engine-flutter-autoroll

Reviewed By: {fluttergithubbot}

This change reverts the following previous change:
Original Description:

flutter/engine@8088863...07cdaab

2024-02-06 skia-flutter-autoroll@skia.org Roll Dart SDK from 29265c94a6e8 to 35269fa71956 (1 revision) (flutter/engine#50402)
2024-02-06 54558023+keyonghan@users.noreply.github.com Add use_rbe to gclient variables for Framework Smoke Tests (flutter/engine#50403)
2024-02-06 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Revert "Revert "[Fuchsia] Execute most of the testing/fuchsia/test_suites.yaml on debug and release builds""" (flutter/engine#50407)
2024-02-06 matanlurey@users.noreply.github.com Skip flaking test on Windows nobody is fixing. (flutter/engine#50401)
2024-02-06 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[web] Fix Scene clip bounds. Trigger resize on DPR Change." (flutter/engine#50404)
2024-02-06 6844906+zijiehe-google-com@users.noreply.github.com Revert "Revert "[Fuchsia] Execute most of the testing/fuchsia/test_suites.yaml on debug and release builds"" (flutter/engine#50295)
2024-02-06 chinmaygarde@google.com [Impeller] Specify if Angle or SwiftShader is being used in the title. (flutter/engine#50376)
2024-02-06 matanlurey@users.noreply.github.com Run all Android `scenario_app` tests, not just the smoke test. (flutter/engine#50400)
2024-02-06 skia-flutter-autoroll@skia.org Roll Dart SDK from b62066b42af0 to 29265c94a6e8 (10 revisions) (flutter/engine#50398)
2024-02-06 matanlurey@users.noreply.github.com Capture `FAILURES!!!` when running Android `scenario_app` tests. (flutter/engine#50255)
2024-02-06 jonnywang@google.com [fuchsia] Bump Fuchsia's API level to 16 (flutter/engine#50358)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from 9e68ed6caf6d to 44106ee8edea (1 revision) (flutter/engine#50393)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from c29a20702356 to 9e68ed6caf6d (1 revision) (flutter/engine#50392)
2024-02-06 jonahwilliams@google.com [Impeller] Cache RenderPass/Framebuffer objects on the resolve texture sources. (flutter/engine#50142)
2024-02-06 jason-simmons@users.noreply.github.com [Impeller] Do not skip the GLES render pass if the command list is empty (flutter/engine#50381)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from cdf214adfb4d to c29a20702356 (54 revisions) (flutter/engine#50382)
2024-02-06 ditman@gmail.com [web] Fix Scene clip bounds. Trigger resize on DPR Change. (flutter/engine#50161)
2024-02-06 xilaizhang@google.com [github actions] add cherry pick workflow for engine repo (flutter/engine#50265)

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 chinmaygarde@google.com,rmistry@google.com,zra@google.com 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
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 7, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 7, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Feb 7, 2024
…sions) (#143039)

Manual roll requested by zra@google.com

flutter/engine@8088863...1ac6beb

2024-02-07 skia-flutter-autoroll@skia.org Roll Skia from fd55a6bd3580 to 1b266b36a4c8 (1 revision) (flutter/engine#50423)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from 44106ee8edea to fd55a6bd3580 (17 revisions) (flutter/engine#50420)
2024-02-06 bdero@google.com [Impeller] Fix pipeline attachment layout in CanRenderToTexture. (flutter/engine#50413)
2024-02-06 ian@hixie.ch Provide toStrings for Native objects (flutter/engine#50168)
2024-02-06 skia-flutter-autoroll@skia.org Roll Dart SDK from 29265c94a6e8 to 35269fa71956 (1 revision) (flutter/engine#50402)
2024-02-06 54558023+keyonghan@users.noreply.github.com Add use_rbe to gclient variables for Framework Smoke Tests (flutter/engine#50403)
2024-02-06 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Revert "Revert "[Fuchsia] Execute most of the testing/fuchsia/test_suites.yaml on debug and release builds""" (flutter/engine#50407)
2024-02-06 matanlurey@users.noreply.github.com Skip flaking test on Windows nobody is fixing. (flutter/engine#50401)
2024-02-06 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[web] Fix Scene clip bounds. Trigger resize on DPR Change." (flutter/engine#50404)
2024-02-06 6844906+zijiehe-google-com@users.noreply.github.com Revert "Revert "[Fuchsia] Execute most of the testing/fuchsia/test_suites.yaml on debug and release builds"" (flutter/engine#50295)
2024-02-06 chinmaygarde@google.com [Impeller] Specify if Angle or SwiftShader is being used in the title. (flutter/engine#50376)
2024-02-06 matanlurey@users.noreply.github.com Run all Android `scenario_app` tests, not just the smoke test. (flutter/engine#50400)
2024-02-06 skia-flutter-autoroll@skia.org Roll Dart SDK from b62066b42af0 to 29265c94a6e8 (10 revisions) (flutter/engine#50398)
2024-02-06 matanlurey@users.noreply.github.com Capture `FAILURES!!!` when running Android `scenario_app` tests. (flutter/engine#50255)
2024-02-06 jonnywang@google.com [fuchsia] Bump Fuchsia's API level to 16 (flutter/engine#50358)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from 9e68ed6caf6d to 44106ee8edea (1 revision) (flutter/engine#50393)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from c29a20702356 to 9e68ed6caf6d (1 revision) (flutter/engine#50392)
2024-02-06 jonahwilliams@google.com [Impeller] Cache RenderPass/Framebuffer objects on the resolve texture sources. (flutter/engine#50142)
2024-02-06 jason-simmons@users.noreply.github.com [Impeller] Do not skip the GLES render pass if the command list is empty (flutter/engine#50381)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from cdf214adfb4d to c29a20702356 (54 revisions) (flutter/engine#50382)
2024-02-06 ditman@gmail.com [web] Fix Scene clip bounds. Trigger resize on DPR Change. (flutter/engine#50161)
2024-02-06 xilaizhang@google.com [github actions] add cherry pick workflow for engine repo (flutter/engine#50265)

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 chinmaygarde@google.com,rmistry@google.com,zra@google.com 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
@gaaclarke
Copy link
Member

Did we ever look into 2024-01-30 jonahwilliams@google.com [Impeller] Reland: add interface for submitting multiple command buffers at once. (flutter/engine#50180)? That seemed to regress that benchmark. It looks good now after this.

@jonahwilliams
Copy link
Member Author

No, but that is a good point. I'd like the keep the interface there, but I could adjust the batching down to 1 (immediately submit) and see if the numbers improve further or if it does nothing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App e: impeller
Projects
No open projects
Status: 🤔 Needs Triage
Development

Successfully merging this pull request may close these issues.

[Impeller] Consider caching or at least trying to reuse VkFramebuffer and RenderPass objects
3 participants