-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Polyline generation optimization. #36759
Conversation
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.
|
Argh. One of these commits had a ncie message I'll try to lift into the body of the PR... |
|
This is ready for review. |
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.
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)?
impeller/tessellator/c/tessellator.h
Outdated
| int fill_type, | ||
| Scalar scale, | ||
| Scalar tolerance, | ||
| // Unused, remaining for ABI stability. |
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 clean this up at all?
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.
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.
impeller/geometry/path_component.h
Outdated
|
|
||
| std::vector<Point> Extrema() const; | ||
|
|
||
| std::vector<QuadraticPathComponent> ToQuadratics(Scalar accuracy) 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.
ToQuadraticPathComponent?
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, but with the s still :)
impeller/geometry/path_component.cc
Outdated
| auto a0 = ApproximateParabolaIntegral(x0); | ||
| auto a2 = ApproximateParabolaIntegral(x2); | ||
| Scalar val = 0.f; | ||
| if (isfinite(scale)) { |
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.
std::isfinite
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
|
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 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.
|
…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)
The proposed approach has several advantages:
elevate them to cubics.
more accurate points on average, which results in faster
tessellation and a net decrease in CPU time.
easier to use on the GPU without significant changes.
Before this change:
After:
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.