-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Improve atlas blending performance by reducing size of subpass. #39669
[Impeller] Improve atlas blending performance by reducing size of subpass. #39669
Conversation
7d423a9 to
81a6de7
Compare
81a6de7 to
9756fc9
Compare
|
|
||
| struct Hash { | ||
| std::size_t operator()(const AtlasBlenderKey& key) const { | ||
| return fml::HashCombine(key.color.red, key.color.green, key.color.blue, |
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 is probably safe
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.
thinking about this more, there could be some inconsistencies with the hash function and equality implementation given that the latter uses nearly equal. Instead i'll keep the int representation of the color around and use that for both the hash and equality.
|
Could file a bug for this or write a short doc. Performance issue is apparent in wonderous on iPad. |
|
Bug filled |
| key.rect.size.height); | ||
| auto sub_transform = Matrix::MakeTranslation(Vector2(x_offset, y_offset)); | ||
|
|
||
| x_offset += (key.rect.size.width + 1.0); |
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.
actually this logic is probably wrong if the sample rect doesn't have an integral width. I should probably just ceil the width here too.
chinmaygarde
left a comment
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.
The optimization makes sense to me and it neatly isolated in the atlas contents. cc @bdero too in case he has thoughts.
| struct AtlasBlenderKey { | ||
| Color color; | ||
| Rect rect; | ||
| int32_t color_key; |
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.
uint32_t?
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
| int32_t color_key; | ||
|
|
||
| static int32_t ToColorKey(Color color) { | ||
| return (((std::lround(color.alpha * 255) & 0xff) << 24) | |
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.
Ah, the kEhCloseEnough of the color world. Perhaps we should have an IColor in color.h that does this for us?
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.
I added a static helper for this, I don't have a use for the type itself yet.
bdero
left a comment
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!
…pass. (flutter#39669) [Impeller] Improve atlas blending performance by reducing size of subpass.
Previously, the subpass for draw atlas with a blend mode would be as large as the final coverage needed to perform the draw. This was wasteful for a number of reasons, especially if many of the sample rect + color combinatons were repeated. I also suspect that drawing everything in its final position would lead to different rendering when colors would overlap. Finally, we need to use FramebufferBlendContents on iOS to avoid two subpasses.
This PR attempts to solve all of these problems by compressing (via color + sample rect) the drawAtlas call into a second atlas which has no overlapping and positions the sample rects in a very simple lightly packed atlas, decreasing the size of the subpass. In the wonderous app on iPads, this makes the artifact discovery confetti stuff substantially less jank.
Fixes flutter/flutter#120925
flutter/flutter#118914
After:
Anywhere from 2x to 3x as fast as before.