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

Conversation

@dnfield
Copy link
Contributor

@dnfield dnfield commented Oct 14, 2022

The proposed approach has several advantages:

  • It is much faster for quadratics, since we no longer have to
    elevate them to cubics.
  • It is slightly slower for cubics, but also produces fewer and
    more accurate points on average, which results in faster
    tessellation and a net decrease in CPU time.
  • The core of the algorithm is parallelizable, which should make it
    easier to use on the GPU without significant changes.

Before this change:

2022-10-14T11:11:14-07:00
Running out/host_release/geometry_benchmarks
Run on (10 X 2400 MHz CPU s)
CPU Caches:
  L1 Data 64 KiB (x10)
  L1 Instruction 128 KiB (x10)
  L2 Unified 4096 KiB (x5)
Load Average: 7.00, 5.70, 5.09
------------------------------------------------------------------------------------------
Benchmark                                Time             CPU   Iterations UserCounters...
------------------------------------------------------------------------------------------
BM_Polyline/cubic_polyline           22642 ns        22585 ns        31151 SinglePointCount=251 TotalPointCount=7.8189M
BM_Polyline/cubic_polyline_tess      78041 ns        77847 ns         9114 SinglePointCount=251 TotalPointCount=2.28761M
BM_Polyline/quad_polyline            22622 ns        22562 ns        31047 SinglePointCount=236 TotalPointCount=7.32709M
BM_Polyline/quad_polyline_tess       74762 ns        74563 ns         9318 SinglePointCount=236 TotalPointCount=2.19905M

After:

2022-10-14T11:12:26-07:00
Running out/host_release/geometry_benchmarks
Run on (10 X 2400 MHz CPU s)
CPU Caches:
  L1 Data 64 KiB (x10)
  L1 Instruction 128 KiB (x10)
  L2 Unified 4096 KiB (x5)
Load Average: 4.32, 5.21, 4.96
------------------------------------------------------------------------------------------
Benchmark                                Time             CPU   Iterations UserCounters...
------------------------------------------------------------------------------------------
BM_Polyline/cubic_polyline           35580 ns        35574 ns        19980 SinglePointCount=155 TotalPointCount=3.0969M
BM_Polyline/cubic_polyline_tess      70250 ns        70240 ns         9998 SinglePointCount=155 TotalPointCount=1.54969M
BM_Polyline/quad_polyline            15065 ns        15062 ns        46802 SinglePointCount=144 TotalPointCount=6.73949M
BM_Polyline/quad_polyline_tess       48014 ns        47992 ns        14644 SinglePointCount=144 TotalPointCount=2.10874M

I want the benchmark to land first.

Bottom line is that creating polylines for quadratics gets much faster/leaner/more accurate. Creating polylines for cubics gets slightly slower but creates fewer more accurate points. This is a big win for quadratics, and a small win for cubics once you include tessellation.

The other nice property is that these algorithms are more translatable to shaders than the recursive algorithm.

The proposed approach has several advantages:

- It is _much_ faster for quadratics, since we no longer have to
  elevate them to cubics.
- It is slightly slower for cubics, but also produces fewer and
  more accurate points on average, which results in faster
  tessellation and a net decrease in CPU time.
- The core of the algorithm is parallelizable, which should make it
  easier to use on the GPU without significant changes.

I do not intend to land the changes to the benchmark in this patch,
but it was helpful for local testing. Before landing this I will
update/add appropriate benchmarks.
@chinmaygarde chinmaygarde changed the title Polyline opt [Impeller] Polyline generation optimization. Oct 14, 2022
@dnfield
Copy link
Contributor Author

dnfield commented Oct 14, 2022

Argh. One of these commits had a ncie message I'll try to lift into the body of the PR...

@dnfield dnfield marked this pull request as ready for review October 14, 2022 20:56
@dnfield
Copy link
Contributor Author

dnfield commented Oct 14, 2022

This is ready for review.

Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

I have definitely not dedicated the time needed to understand and appreciate the technique in detail. Will definitely do so over the weekend. I did play around with the results. Perhaps, as a followup, add sections about this to the wiki (go/impeller-docs) or references to the reading list (go/impeller-reading-list)?

int fill_type,
Scalar scale,
Scalar tolerance,
// Unused, remaining for ABI stability.
Copy link
Member

Choose a reason for hiding this comment

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

Can we clean this up at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

vector_graphics is potentially using these parameters and would crash without them. Although I don't think we actually have anything using them right now - I'll just drop them for now and we can clean up vg separately.


std::vector<Point> Extrema() const;

std::vector<QuadraticPathComponent> ToQuadratics(Scalar accuracy) const;
Copy link
Member

Choose a reason for hiding this comment

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

ToQuadraticPathComponent?

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, but with the s still :)

auto a0 = ApproximateParabolaIntegral(x0);
auto a2 = ApproximateParabolaIntegral(x2);
Scalar val = 0.f;
if (isfinite(scale)) {
Copy link
Member

Choose a reason for hiding this comment

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

std::isfinite

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

@dnfield dnfield added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 19, 2022
@dnfield
Copy link
Contributor Author

dnfield commented Oct 19, 2022

I had already added some sources to the reading list related to this, and there are some links in the comments - definitely let me know if there's still something missing, because I spent a few days immersed in this and probably missed adding something.

@auto-submit
Copy link
Contributor

auto-submit bot commented Oct 19, 2022

auto label is removed for flutter/engine, pr: 36759, due to - The status or check suite Mac iOS Engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

  • The status or check suite Mac Host Engine has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Linux linux_host_engine has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Linux linux_arm_host_engine has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Linux Android AOT Engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Oct 19, 2022
@dnfield dnfield added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 19, 2022
@auto-submit auto-submit bot merged commit 3f58c97 into flutter:main Oct 19, 2022
@dnfield dnfield deleted the polyline_opt branch October 19, 2022 05:21
@dnfield
Copy link
Contributor Author

dnfield commented Oct 19, 2022

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 20, 2022
zanderso pushed a commit to flutter/flutter that referenced this pull request Oct 20, 2022
…113761)

* 9f09f4ce8 Roll Dart SDK from f21024945abf to 99f266a404bd (1 revision) (flutter/engine#36860)

* 3f58c9743 [Impeller] Polyline generation optimization. (flutter/engine#36759)

* d6ccb2d67 Roll Skia from af544866f04d to 161637433767 (1 revision) (flutter/engine#36861)

* f32d29056 Add DOM TouchEvent modifiers accessors (flutter/engine#36836)

* dd9159958 Roll Fuchsia Linux SDK from oMrS1TjaSIjntnBvR... to IvN-WLezL2sS_wSzZ... (flutter/engine#36862)

* cfe164f66 [fuchsia][scenic] Fix invalid viewRef error in pointer injection. (flutter/engine#36850)

* bd15adf16 Roll Skia from 161637433767 to 50363183d1c7 (3 revisions) (flutter/engine#36864)

* e351b05c7 Roll Fuchsia Mac SDK from XZV0Cqcpiv74L7ric... to M5-c50jCcV0ypwYcT... (flutter/engine#36865)

* a89ed7a72 Roll Skia from 50363183d1c7 to 572d4e85f83e (1 revision) (flutter/engine#36867)

* cca0812cf Roll Skia from 572d4e85f83e to 8928b024556f (1 revision) (flutter/engine#36868)

* 488b76725 Roll Skia from 8928b024556f to 025ae7eec03e (6 revisions) (flutter/engine#36869)

* 7997edc4f [web] Some cleanup for text tests (flutter/engine#36425)

* a831dd269 Roll Skia from 025ae7eec03e to a9255bc938bf (1 revision) (flutter/engine#36870)

* 80847c95f [fuchsia][input] Delete legacy pointer handler (flutter/engine#36857)

* e4c27fc90 Roll Skia from a9255bc938bf to 4fa600316d1d (6 revisions) (flutter/engine#36872)

* 9e635b177 Roll Fuchsia Linux SDK from IvN-WLezL2sS_wSzZ... to zw_jyeiHfJtAXF_qp... (flutter/engine#36875)

* a5c5c25ba Roll Skia from 4fa600316d1d to 723ccd171e37 (3 revisions) (flutter/engine#36876)

* 2f235c4ba Roll Fuchsia Mac SDK from M5-c50jCcV0ypwYcT... to 7lmBrmhOLwrqoqXk0... (flutter/engine#36877)

* 0f0739651 [fuchsia] Bump the Fuchsia target API level to 10 (flutter/engine#36858)

* 490b06d13 Roll Skia from 723ccd171e37 to fc7d5c9ee970 (1 revision) (flutter/engine#36878)
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.

2 participants