-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] avoid heap allocation in RenderTarget object. #56829
Conversation
return false; | ||
} | ||
|
||
#ifndef NDEBUG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is actually crazy expensive and I don't think we should be running it in any modes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach is looking good to me. I'd rather see this detail abstracted away from RenderTarget's clients instead of changing its interface.
vk::AttachmentReference color_ref; | ||
color_ref.attachment = attachments.size(); | ||
color_ref.layout = vk::ImageLayout::eGeneral; | ||
color_refs[0] = color_ref; | ||
attachments.push_back(color0_.value()); | ||
|
||
if (color0_resolve_.has_value()) { | ||
vk::AttachmentReference resolve_ref; | ||
resolve_ref.attachment = attachments.size(); | ||
resolve_ref.layout = vk::ImageLayout::eGeneral; | ||
resolve_refs[0] = resolve_ref; | ||
attachments.push_back(color0_resolve_.value()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove duplication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you use the Iterate method here to avoid the duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't the render_target, this is the internal implementation of the RenderPassBuilderVK
std::optional<vk::AttachmentDescription> color0_resolve_; | ||
std::optional<vk::AttachmentDescription> depth_stencil_; | ||
|
||
std::map<size_t, vk::AttachmentDescription> colors_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a comment here that colors_[0] is really at color0_.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
.GetColorAttachments() | ||
.find(0u) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we instead change this to .GetColorAttachment(0u)
. That way the way the render target is storing the first color attachment isn't being leaked to its clients.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
impeller/renderer/render_target.cc
Outdated
return ColorAttachment{}; | ||
} | ||
|
||
bool RenderTarget::HasColor0() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here. Let's just make HasColorAttachment(0)
look into this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
So the way to do that would be to remove the GetColorAttachments function that returns a map and instead have an iterator like approach. I can do that. |
I don't think you need need an iterator, deleting |
I don't need an iterator exactly, I just can't have a method that returns a app. I can't just have a length query because I think its possible to have combinations like color0 and color2 with color1 not set to anything. |
app -> map |
Updated so that we use a new IterateColorAttachments function to avoid making callers handle color0 as a special case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a couple of remaining niggles. I think this is a lot cleaner.
vk::AttachmentReference color_ref; | ||
color_ref.attachment = attachments.size(); | ||
color_ref.layout = vk::ImageLayout::eGeneral; | ||
color_refs[0] = color_ref; | ||
attachments.push_back(color0_.value()); | ||
|
||
if (color0_resolve_.has_value()) { | ||
vk::AttachmentReference resolve_ref; | ||
resolve_ref.attachment = attachments.size(); | ||
resolve_ref.layout = vk::ImageLayout::eGeneral; | ||
resolve_refs[0] = resolve_ref; | ||
attachments.push_back(color0_resolve_.value()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you use the Iterate method here to avoid the duplication?
// Visible for testing. | ||
std::optional<vk::AttachmentDescription> GetColor0() const; | ||
|
||
// Visible for testing. | ||
std::optional<vk::AttachmentDescription> GetColor0Resolve() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make the test a friend instead of making these public (example
FML_FRIEND_TEST(testing::BufferBindingsGLESTest, BindUniformData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Listing out each test name seems like a pretty big step down, given that this is an internal library of an internal library.
…159805) flutter/engine@29d6640...1f7f37e 2024-12-04 [email protected] [Impeller] avoid heap allocation in RenderTarget object. (flutter/engine#56829) 2024-12-04 [email protected] Manual roll dart to 470117150f34d712ee6d8c4558b3c656d973f656 (flutter/engine#56915) 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
…ine#56829) All render targets created by flutter have a single color attachment. Lets specialize that case in impeller::RenderTarget by creating a field for that attachment description instead of placing it in a hashmap.
All render targets created by flutter have a single color attachment. Lets specialize that case in impeller::RenderTarget by creating a field for that attachment description instead of placing it in a hashmap.