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

[Impeller] Fallback to no index buffer when tesselation count is large, split up nonZero contours. #46282

Merged
merged 11 commits into from
Sep 27, 2023

Conversation

jonahwilliams
Copy link
Member

@jonahwilliams jonahwilliams commented Sep 25, 2023

See example app in flutter/flutter#135458

Because tessellation is generally nlogn best case (with allocation complexity as well), we can actually make it faster by breaking it into smaller pieces. For non zero fill modes, the contours can be tessellated individually without losing fidelity.

In cases where this isn't possible, we need to check if we exceed the max uint16 index and fall back to no index buffer.

Fixes flutter/flutter#135458

I Benchmarked signing my name.

Before

worst raster time 3+ seconds. Visual glitches

flutter_03

After

worst raster time 30 ms, looks correct (though my signature is still wrong)

flutter_04

@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 Hixie or stuartmorgan on 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

This comment was marked as off-topic.

@jonahwilliams jonahwilliams changed the title [Impeller] fallback to no index buffer when tesselation count is large. [Impeller] fallback to no index buffer when tesselation count is large, split up nonZero contours. Sep 26, 2023
polyline.points.data() + start_point_index, //
sizeof(Point), //
end_point_index - start_point_index //
if (polyline.contours.size() > 30 && fill_type == FillType::kNonZero) {
Copy link
Member

Choose a reason for hiding this comment

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

Consider pulling 30 out to a named constant, and as much as might be possible, explain why 30 was chosen.

Copy link
Member

Choose a reason for hiding this comment

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

I'd also add a comment about not using indices since there is a lot of code to read through to understand that's the case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added more comments here.

}
} else {
std::vector<Point> points;
std::vector<uint16_t> indices;
Copy link
Member

Choose a reason for hiding this comment

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

This value is generated, but never used.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

polyline.points.data() + start_point_index, //
sizeof(Point), //
end_point_index - start_point_index //
if (polyline.contours.size() > 30 && fill_type == FillType::kNonZero) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd also add a comment about not using indices since there is a lot of code to read through to understand that's the case.

@chinmaygarde chinmaygarde changed the title [Impeller] fallback to no index buffer when tesselation count is large, split up nonZero contours. [Impeller] Fallback to no index buffer when tesselation count is large, split up nonZero contours. Sep 26, 2023
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.

Code looks good, awesome surprising performance results. The only thing that should change is the overloaded parameter that can mean 2 different things.

return Result::kTessellationError;
}

int vertexItemCount = tessGetVertexCount(tessellator) * kVertexSize;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
int vertexItemCount = tessGetVertexCount(tessellator) * kVertexSize;
int vertex_item_count = tessGetVertexCount(tessellator) * kVertexSize;

These variable names don't conform to the c++ style guide.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

{
Tessellator t;
PathBuilder builder = {};
for (auto i = 0; i < 60; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using a hardcoded 60, you can use the variable you created now to make this test a bit more robust to changes in that number.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -48,10 +49,16 @@ GeometryResult FillPathGeometry::GetPositionBuffer(
size_t indices_count) {
Copy link
Member

Choose a reason for hiding this comment

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

The variable name here belies the fact that it actually can represent 2 different things.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

using BuilderCallback = std::function<bool(const float* vertices,
size_t vertices_size,
const uint16_t* indices,
size_t indices_size)>;
size_t vertex_or_index_count)>;
Copy link
Member

Choose a reason for hiding this comment

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

Overloading this variable doesn't seem prudent. Can't it just be indices_size and be zero if indices == nullptr? We didn't need vertex count in the past

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 reason this is overloaded is a bit of an issue yes, I should just fix it. Really the problem is that these variables aren't counts, they are the value to multiply with sizeof(float)/sizeof(uint16_t) to compute offsets. But I just make them counts, then this problem goes away.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

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!

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 27, 2023
@auto-submit auto-submit bot merged commit 35ba2a3 into flutter:main Sep 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 27, 2023
@jonahwilliams jonahwilliams deleted the no_index_fallback branch September 27, 2023 18:31
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 28, 2023
zanderso pushed a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 28, 2023
zanderso pushed a commit to flutter/flutter that referenced this pull request Sep 28, 2023
…sions) (#135637)

Manual roll Flutter Engine from f70f65f7a622 to be32dcc9117a (31
revisions)

Manual roll requested by [email protected]

Cannot build log URL because revision "be32dcc9117a" is invalid: Luci
builds of "Linux linux_unopt" for
be32dcc9117a462760cb52c18d0d050f067f2463 was STARTED

2023-09-28 [email protected] Rollback Dart SDK to 3.2.0-119.
(flutter/engine#46339)
2023-09-28 [email protected] [canvaskit]
Do not double-apply ImageFilter transform to children
(flutter/engine#46336)
2023-09-28 [email protected] Reland "Reverts "[ios] Fix app extension
not able to find assets from… (flutter/engine#46329)
2023-09-27 [email protected] Revert "[Impeller]
Fixes stroke path geometry that can draw outside o…
(flutter/engine#46334)
2023-09-27 [email protected] Roll Fuchsia Mac SDK from
jQHACBU4Fi2wMElkm... to U334SygIkffMJVmdu... (flutter/engine#46333)
2023-09-27 [email protected] Roll Skia from 952e8dd66560 to
b048b468d641 (1 revision) (flutter/engine#46332)
2023-09-27 [email protected] [Impeller] Destroy all
per-thread command pools tied to a context before deleting the context
(flutter/engine#46286)
2023-09-27 [email protected] Roll Skia from d78aba2524b3 to
952e8dd66560 (1 revision) (flutter/engine#46331)
2023-09-27 [email protected] [Impeller] Match Skia gradient
clamping behavior (and document). (flutter/engine#44825)
2023-09-27 [email protected] Roll Dart SDK from
97647bb1666b to 80a965ee48ab (1 revision) (flutter/engine#46330)
2023-09-27 [email protected] Roll Skia from ff5474eed6b4 to
d78aba2524b3 (3 revisions) (flutter/engine#46327)
2023-09-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts
"[ios] Fix app extension not able to find assets from unloaded bundle"
(flutter/engine#46328)
2023-09-27 [email protected] [Windows] Improve
logic to update swap intervals (flutter/engine#46172)
2023-09-27 [email protected] [Impeller] Fallback to no index
buffer when tesselation count is large, split up nonZero contours.
(flutter/engine#46282)
2023-09-27 [email protected] Roll Skia from 4731ccd6342c to
ff5474eed6b4 (1 revision) (flutter/engine#46325)
2023-09-27 [email protected] Declare native wrapper
classes in Fuchsia packages as base classes (flutter/engine#46305)
2023-09-27 [email protected] Remove fuchsia from recipes cq.
(flutter/engine#46324)
2023-09-27 [email protected] Roll Dart SDK from
c2a455113e39 to 97647bb1666b (1 revision) (flutter/engine#46323)
2023-09-27 [email protected] [macOS] Synchronise modifiers from
mouse events for RawKeyboard (flutter/engine#46230)
2023-09-27 [email protected] Roll Fuchsia Linux SDK from
Lg6FR6iDnZeV6y-E8... to 6Y22MutFhgL7ua18F... (flutter/engine#46322)
2023-09-27 [email protected] Roll Skia from 2991bb799d3f to
4731ccd6342c (1 revision) (flutter/engine#46321)
2023-09-27 [email protected] Declare native wrapper
classes in the GPU package as base classes (flutter/engine#46304)
2023-09-27 [email protected] Do not call
DrawTextBlob for performance overlay text when using Impeller
(flutter/engine#46307)
2023-09-27 [email protected] Update to use
GrDirectContexts::MakeGL (flutter/engine#46308)
2023-09-27 [email protected] Roll Skia from 0f4f31127ac5 to
2991bb799d3f (1 revision) (flutter/engine#46319)
2023-09-27 [email protected] Roll Skia from fc629215398f to
0f4f31127ac5 (1 revision) (flutter/engine#46318)
2023-09-27 [email protected] Roll Dart SDK from
6c4eb86ecd25 to c2a455113e39 (1 revision) (flutter/engine#46317)
2023-09-27 [email protected] Roll Fuchsia Mac SDK from
OMrTgAfDg9PKXTzq0... to jQHACBU4Fi2wMElkm... (flutter/engine#46314)
2023-09-27 [email protected] Roll Skia from 960325c13009 to
fc629215398f (1 revision) (flutter/engine#46313)
2023-09-27 [email protected] Roll Skia from 76aecbaea259 to
960325c13009 (2 revisions) (flutter/engine#46311)
2023-09-27 [email protected] Roll Dart SDK from
7c3588c05f87 to 6c4eb86ecd25 (3 revisions) (flutter/engine#46310)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from Lg6FR6iDnZeV to 6Y22MutFhgL7
  fuchsia/sdk/core/mac-amd64 from OMrTgAfDg9PK to U334SygIkffM

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

...
Mairramer pushed a commit to Mairramer/flutter that referenced this pull request Oct 10, 2023
…sions) (flutter#135637)

Manual roll Flutter Engine from f70f65f7a622 to be32dcc9117a (31
revisions)

Manual roll requested by [email protected]

Cannot build log URL because revision "be32dcc9117a" is invalid: Luci
builds of "Linux linux_unopt" for
be32dcc9117a462760cb52c18d0d050f067f2463 was STARTED

2023-09-28 [email protected] Rollback Dart SDK to 3.2.0-119.
(flutter/engine#46339)
2023-09-28 [email protected] [canvaskit]
Do not double-apply ImageFilter transform to children
(flutter/engine#46336)
2023-09-28 [email protected] Reland "Reverts "[ios] Fix app extension
not able to find assets from… (flutter/engine#46329)
2023-09-27 [email protected] Revert "[Impeller]
Fixes stroke path geometry that can draw outside o…
(flutter/engine#46334)
2023-09-27 [email protected] Roll Fuchsia Mac SDK from
jQHACBU4Fi2wMElkm... to U334SygIkffMJVmdu... (flutter/engine#46333)
2023-09-27 [email protected] Roll Skia from 952e8dd66560 to
b048b468d641 (1 revision) (flutter/engine#46332)
2023-09-27 [email protected] [Impeller] Destroy all
per-thread command pools tied to a context before deleting the context
(flutter/engine#46286)
2023-09-27 [email protected] Roll Skia from d78aba2524b3 to
952e8dd66560 (1 revision) (flutter/engine#46331)
2023-09-27 [email protected] [Impeller] Match Skia gradient
clamping behavior (and document). (flutter/engine#44825)
2023-09-27 [email protected] Roll Dart SDK from
97647bb1666b to 80a965ee48ab (1 revision) (flutter/engine#46330)
2023-09-27 [email protected] Roll Skia from ff5474eed6b4 to
d78aba2524b3 (3 revisions) (flutter/engine#46327)
2023-09-27 98614782+auto-submit[bot]@users.noreply.github.com Reverts
"[ios] Fix app extension not able to find assets from unloaded bundle"
(flutter/engine#46328)
2023-09-27 [email protected] [Windows] Improve
logic to update swap intervals (flutter/engine#46172)
2023-09-27 [email protected] [Impeller] Fallback to no index
buffer when tesselation count is large, split up nonZero contours.
(flutter/engine#46282)
2023-09-27 [email protected] Roll Skia from 4731ccd6342c to
ff5474eed6b4 (1 revision) (flutter/engine#46325)
2023-09-27 [email protected] Declare native wrapper
classes in Fuchsia packages as base classes (flutter/engine#46305)
2023-09-27 [email protected] Remove fuchsia from recipes cq.
(flutter/engine#46324)
2023-09-27 [email protected] Roll Dart SDK from
c2a455113e39 to 97647bb1666b (1 revision) (flutter/engine#46323)
2023-09-27 [email protected] [macOS] Synchronise modifiers from
mouse events for RawKeyboard (flutter/engine#46230)
2023-09-27 [email protected] Roll Fuchsia Linux SDK from
Lg6FR6iDnZeV6y-E8... to 6Y22MutFhgL7ua18F... (flutter/engine#46322)
2023-09-27 [email protected] Roll Skia from 2991bb799d3f to
4731ccd6342c (1 revision) (flutter/engine#46321)
2023-09-27 [email protected] Declare native wrapper
classes in the GPU package as base classes (flutter/engine#46304)
2023-09-27 [email protected] Do not call
DrawTextBlob for performance overlay text when using Impeller
(flutter/engine#46307)
2023-09-27 [email protected] Update to use
GrDirectContexts::MakeGL (flutter/engine#46308)
2023-09-27 [email protected] Roll Skia from 0f4f31127ac5 to
2991bb799d3f (1 revision) (flutter/engine#46319)
2023-09-27 [email protected] Roll Skia from fc629215398f to
0f4f31127ac5 (1 revision) (flutter/engine#46318)
2023-09-27 [email protected] Roll Dart SDK from
6c4eb86ecd25 to c2a455113e39 (1 revision) (flutter/engine#46317)
2023-09-27 [email protected] Roll Fuchsia Mac SDK from
OMrTgAfDg9PKXTzq0... to jQHACBU4Fi2wMElkm... (flutter/engine#46314)
2023-09-27 [email protected] Roll Skia from 960325c13009 to
fc629215398f (1 revision) (flutter/engine#46313)
2023-09-27 [email protected] Roll Skia from 76aecbaea259 to
960325c13009 (2 revisions) (flutter/engine#46311)
2023-09-27 [email protected] Roll Dart SDK from
7c3588c05f87 to 6c4eb86ecd25 (3 revisions) (flutter/engine#46310)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from Lg6FR6iDnZeV to 6Y22MutFhgL7
  fuchsia/sdk/core/mac-amd64 from OMrTgAfDg9PK to U334SygIkffM

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

...
harryterkelsen pushed a commit that referenced this pull request Oct 23, 2023
…e, split up nonZero contours. (#46282)

See example app in flutter/flutter#135458

Because tessellation is generally nlogn best case (with allocation complexity as well), we can actually make it faster by breaking it into smaller pieces. For non zero fill modes, the contours can be tessellated individually without  losing fidelity.

In cases where this isn't possible, we need to check if we exceed the max uint16 index and fall back to no index buffer.

Fixes flutter/flutter#135458

I Benchmarked signing my name.

### Before

 worst raster time 3+ seconds. Visual glitches

![flutter_03](https://github.com/flutter/engine/assets/8975114/7be57bd2-744f-4f0a-af0a-d2bd4fc9efaf)

### After
worst raster time 30 ms, looks correct (though my signature is still wrong)

![flutter_04](https://github.com/flutter/engine/assets/8975114/1fdf504e-7b4e-447a-8c29-063dd0ff34d0)
auto-submit bot pushed a commit that referenced this pull request Nov 27, 2023
harryterkelsen pushed a commit to harryterkelsen/engine that referenced this pull request Nov 27, 2023
jonahwilliams added a commit to jonahwilliams/engine that referenced this pull request Nov 28, 2023
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
Archived in project
Development

Successfully merging this pull request may close these issues.

[Impeller] Poor performance with large nonzero fill paths.
3 participants