-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[encoding] Bump estimate for segments #454
Conversation
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 looks good to me. I am finding myself perhaps a bit nerd-sniped by trying to figure out better estimation heuristics, but I think the right way to approach that is empirical. Of course, the Euler changes will probably require some re-tuning, but I'm pretty hopeful it won't cause the estimations to need to go up substantially. Thanks!
7bfca34
to
ac079c1
Compare
The segments (and segment counts) buffers contain intermediate data structures that associate lines (post-flatten, post-binning) with tiles. Their overall count depends on the number tile crossings for each line. These counts are now estimated as follows: 1. Explict lines with known endpoints are estimated precisely by guessing the worst case rasterization of the hypothenuse (i.e. the sum of the tiling estimate for the x and y coordinates. 2. Explicit lines with unknown endpoints (e.g. the caps on a stroke) are estimated based on the length of the segment. 3. Flattened curves are estimated by tiling a line whose length is derived based on a conservative estimate of the curve's arc length. The segment count is forced to be at least as large as the Wang's estimate used for the LineSoup count. This implementation currently has two major shortcomings: I. Clipping is not taken into account, so the count is overstimated when layers are present or when geometry lies outside the viewport. There are ways to address this but they will require some changes: a) Most of the count accummulation happens at encode time but the bounds of the viewport are only known at render time. This could be changed so that most of the accummulation happens at render time and additional data (like the bounding box of each shape) get tracked during encoding. b) It might make sense to track the clip stack to test each shape's bounding box against the clip geometry while resolving the counts and use that as input to a heuristic. It is also possible to discard shapes that lie completely outside the bounds of the clip geometry. All of this would require additional tracking that impacts CPU time and memory usage. II. A rotation that is present in the transform has an impact on tile crossings. We can precisely account for this for explicit lines with known endpoints but we have to use a heuristic for curves. The estimator doesn't track detailed shape data, so a heuristic must be used when appending a scene fragment. We currently inflate all segment counts as if they have a 90 degree rotation whenever a transform should apply. Overall the segment count tends to be overestimated 3x-10x. There is one known failure mode when the count is underestimated with _very_ small scale factors ("conflation artifacts" test scene).
45888a9
to
c4e60dc
Compare
The bump allocation estimator computes a conservative estimate of the required buffer allocations based on heuristics over the encoded path data. See the description of vello PR #454 for some examples scenes and the current factors of overestimation: linebender/vello#454 Bug: b/285193099 Change-Id: I131305914307591ad04d6158f24a94235826ac10 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/828997 Commit-Queue: Arman Uguray <[email protected]> Reviewed-by: Jim Van Verth <[email protected]> Reviewed-by: James Godfrey-Kittle <[email protected]>
This reverts commit d63b489. Reason for revert: path_huge_crbug_800804 is causing overflow due to multiply in the estimator code. This requires a fix in a third_party repo so fixing forward will take time. Original change's description: > [vello] Enable the bump allocation estimator > > The bump allocation estimator computes a conservative estimate of the > required buffer allocations based on heuristics over the encoded path > data. See the description of vello PR #454 for some examples scenes and > the current factors of overestimation: linebender/vello#454 > > Bug: b/285193099 > Change-Id: I131305914307591ad04d6158f24a94235826ac10 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/828997 > Commit-Queue: Arman Uguray <[email protected]> > Reviewed-by: Jim Van Verth <[email protected]> > Reviewed-by: James Godfrey-Kittle <[email protected]> Bug: b/285193099 Change-Id: I3604d62d5b55dd4680ee2a8dc49e37cfdac01500 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/c/skia/+/835421 Auto-Submit: Arman Uguray <[email protected]> Commit-Queue: Arman Uguray <[email protected]> Bot-Commit: Rubber Stamper <[email protected]>
The segments (and segment counts) buffers contain intermediate data structures that associate lines (post-flatten, post-binning) with tiles. Their overall count depends on the number tile crossings for each line.
These counts are now estimated as follows:
Explict lines with known endpoints are estimated precisely by guessing the worst case rasterization as the sum of the tiling estimate for the x and y coordinates.
Explicit lines with unknown endpoints (e.g. the caps on a stroke) are estimated based on the length of the segment that is near-diagonal.
Flattened curves are estimated by tiling a line whose length is derived based on a conservative estimate of the curve's arc length. The segment count is forced to be at least as large as the Wang's estimate used for the LineSoup count.
This implementation currently has two major shortcomings:
I. Clipping is not taken into account, so the count is overstimated when
layers are present or when geometry lies outside the viewport. There
are ways to address this but they will require some changes:
a) Most of the count accummulation happens at encode time but the
bounds of the viewport are only known at render time. This could
be changed so that most of the accummulation happens at render
time and additional data (like the bounding box of each shape) get
tracked during encoding.
b) It might make sense to track the clip stack to test each shape's
bounding box against the clip geometry while resolving the counts
and use that as input to a heuristic. It is also possible to
discard shapes that lie completely outside the bounds of the clip
geometry. All of this would require additional tracking that
impacts CPU time and memory usage.
II. A rotation that is present in the transform has an impact on tile
crossings. We can precisely account for this for explicit lines with
known endpoints but we have to use a heuristic for curves. The
estimator doesn't track detailed shape data, so a heuristic must be
used when appending a scene fragment. We currently inflate all
segment counts as if they have a 90 degree rotation whenever a
transform should apply.
Overall the segment count tends to be overestimated 3x-10x. There is one known failure mode when the count is underestimated with very small scale factors ("conflation artifacts" test scene).
This PR is based on #436
Some examples: