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

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Mar 5, 2024

Work towards flutter/flutter#144617

The primary trick here is making sure that the transient attachments for the onscreen (MSAA and Depth/Stencil) are effectively recycled. In fact, I think we can actually make a single Onscreen MSAA and Onscreen Depth/Stencil and share them across the swapchain images - as they should be effectively synchronized already.

Fixes flutter/flutter#141750

@jonahwilliams jonahwilliams changed the title Onscreen improvements [Impeller] More efficient usage of transient onscreen attachments. Mar 5, 2024
jonahwilliams added 2 commits March 5, 2024 12:07
Copy link
Contributor

@matanlurey matanlurey left a comment

Choose a reason for hiding this comment

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

Someone with more context on the implications of this change should give final LGTM - I mostly reviewed agnostically (though I remember some words!)

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to go and add a comment to SurfaceVK::WrapSwapchainImage (in the .h).

Based on what you told me, maybe something like:

Wraps a swapchain image for rendering with MSAA and depth/stencil support.

This function takes an device(?)-provided swapchain image (which is the resolve target
of a potential MSAA render process) and prepares it for use by creating necessary
supporting textures. This includes the MSAA texture (if enabled) and the depth/stencil
texture for rendering.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doc comment added

Copy link
Contributor

Choose a reason for hiding this comment

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

Out of scope of this PR, but why do we have this code:

if (!context || !swapchain_image || !swap_callback) {
  return nullptr;
}

When is it valid not to have these things? I'm in particular confused about swap_callback, because below:

bool SurfaceVK::Present() const {
  return swap_callback_ ? swap_callback_() : false;
}

It's impossible for this to be null, right?


RenderTarget render_target_desc;
render_target_desc.SetColorAttachment(color0, 0u);
render_target_desc.SetupDepthStencilAttachments(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we expand this with /*=param*/ comments?

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

vk::Image image_ = VK_NULL_HANDLE;
vk::UniqueImageView image_view_ = {};
std::shared_ptr<Texture> msaa_tex_;
std::shared_ptr<Texture> msaa_texture_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for spelling out texture.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one was my fault initially

TextureDescriptor msaa_desc;
msaa_desc.storage_mode = StorageMode::kDeviceTransient;
msaa_desc.type = TextureType::kTexture2DMultisample;
msaa_desc.sample_count = SampleCount::kCount4;
Copy link
Contributor

Choose a reason for hiding this comment

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

How are all these values picked/known?

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 added a comment, but mostly it matches the swapchain + the convention we use.

///
virtual bool IsSwapchainImage() const = 0;

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

Choose a reason for hiding this comment

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

Could friend be used instead of a comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would have to be friend for the class and all of the test classes. TBH I haven't figured out how to do that consistently for test classes, since the name is macro generated?


auto texture = render_target.GetRenderTargetTexture();
auto& texture_vk = TextureVK::Cast(*texture);
EXPECT_EQ(texture_vk.GetFramebuffer(), nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the caching behavior truly imply these should start null?

If so, I wonder if the name is misleading (i.e. should be GetCachedFramebuffer). I might be missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes these start null, I updated the name to GetCachedFramebuffer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does the test directly verify the "primary trick" outlined in the change context (recycling a single MSAA and Depth/Stencil attachment)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does now


EXPECT_TRUE(swapchain->IsValid());

// We should create 3 swapchain images with the current mock setup. However,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this enforced in the test somehow or an implied assumption?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can actually be fixed now. There were some global state problems, but @jason-simmons fixed up parts of the mock vulkan when he was doing the ASAN changes that make this easier to implemented.

Updated the test so we create all 3 swapchain images and can make assertions on them.

auto texture = render_target.GetRenderTargetTexture();
auto& texture_vk = TextureVK::Cast(*texture);

EXPECT_NE(texture_vk.GetFramebuffer(), nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should improve the mocks if we're not able to make a more definitive assertion (i.e. if, as I think you are trying to do, assert that the frame buffer stays the same).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh yeah, I can go through once more and verify they are the same.

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

@jonahwilliams jonahwilliams force-pushed the onscreen_improvements branch from 7c4b31e to e7b3a1b Compare March 7, 2024 17:21
@jonahwilliams jonahwilliams requested a review from matanlurey March 7, 2024 17:21
Copy link
Contributor

@matanlurey matanlurey left a comment

Choose a reason for hiding this comment

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

LGTM from a purely this is code and I think it is good (TM) perspective.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

Let's Get This Moving

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 8, 2024
@auto-submit auto-submit bot merged commit 05fdf94 into flutter:main Mar 8, 2024
@jonahwilliams jonahwilliams deleted the onscreen_improvements branch March 8, 2024 17:36
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 8, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Mar 8, 2024
…144839)

flutter/engine@bc4abcd...05fdf94

2024-03-08 [email protected] [Impeller] More efficient usage of transient onscreen attachments. (flutter/engine#51206)
2024-03-08 6844906[email protected] [Fuchsia] Providing FUCHSIA_SDK_PATH env var for fuchsia lsc (flutter/engine#51234)
2024-03-08 [email protected] Migrate vulkan_memory_allocator to flutter/third_party (flutter/engine#51275)
2024-03-08 [email protected] Update CI scripts to use either src/flutter/third_party/dart or src/third_party/dart (flutter/engine#51276)
2024-03-08 [email protected] Add fuchsia_gn_sdk GN variable pointing to //flutter/tools/fuchsia/gn-sdk (flutter/engine#51287)
2024-03-08 [email protected] Roll Skia from 993a88a663c8 to a4fb847f47d9 (1 revision) (flutter/engine#51283)
2024-03-08 [email protected] Roll Skia from 15f8d03a9594 to 993a88a663c8 (1 revision) (flutter/engine#51282)
2024-03-08 [email protected] Roll Skia from 093994f8f078 to 15f8d03a9594 (1 revision) (flutter/engine#51280)
2024-03-08 [email protected] Roll Skia from bf3f9c5f0edb to 093994f8f078 (1 revision) (flutter/engine#51278)

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] 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
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

None yet

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