Skip to content
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

CPU-side dashing for GPU strokes & encoding-time filtering of zero-length segments #412

Merged
merged 4 commits into from
Nov 22, 2023

Conversation

armansito
Copy link
Collaborator

@armansito armansito commented Nov 15, 2023

  • When GPU-side stroking is enabled, a stroke with a dash style now gets converted to a series of regular strokes which then get encoded separately and in sequence.

  • Zero-length segments lead to numerical errors and lead to extra complexity and wasted work (in the form of thread
    allocation) for GPU flattening. We now detect and drop them at encoding time.

    Currently, a path segment is considered zero-length if all of its control points (in local coordinates) are within EPSILON (1e-12) of each other. This may not be the desired behavior under transform.

    Also since the length here isn't in terms of the actual arc length, this won't detect all curves that are within an EPSILON sized bounding box (which may have a larger distance between their control points).

    For stroking purposes, the distance between the control points is what matters most as that's what's used to compute a curve's tangent.

This PR is based on #410

#303

@armansito armansito requested a review from dfrg November 16, 2023 23:44
Base automatically changed from stroke-join-styles to main November 21, 2023 18:35
Copy link
Collaborator

@dfrg dfrg left a comment

Choose a reason for hiding this comment

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

LGTM modulo small style suggestion. Thanks!

Comment on lines 772 to 777
fn start_tangent_for_curve(
p0: (f32, f32),
p1: (f32, f32),
p2: (f32, f32),
p3: (f32, f32),
p2: Option<(f32, f32)>,
p3: Option<(f32, f32)>,
) -> Option<(f32, f32)> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Small style suggestion: making this a method of PathEncoder and dropping the p0 parameter (since it always appears to be PathEncoder::first_point?) should simplify the call sites a bit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

Comment on lines 72 to 73
let missing_movetos = [
MoveTo((0., 0.).into()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find this more amusing than is reasonable :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🙃 It's probably a good idea to fix these up and remove the MoveTo(0, 0)s when we fix the path encoding.

When GPU-side stroking is enbled, a stroke with a dash style now gets
converted to a series of undashed strokes which then get encoded
separately and in sequence.

To support this, `Encoding` now accepts an iterator over `PathEl` as an
alternative to `Shape`.
Zero-length segments lead to numerical errors and lead to extra
complexity and wasted work (in the form of thread allocation) for GPU
flattening. We now detect and drop them at encoding time.

Currently, a path segment is considered zero-length if all of its
control points (in local coordinates) are within EPSILON (1e-12) of
each other. This may not be the desired behavior under transform.

Also since the length here isn't in terms of the actual arc length,
this won't detect all curves that are within an EPSILON sized bounding
box (which may have a larger distance between their control points).

For stroking purposes, the distance between the control points is what
matters most as that's what's used to compute a curve's tangent.
@armansito armansito merged commit 4ac2db3 into main Nov 22, 2023
4 checks passed
@armansito armansito deleted the gpu-strokes-1-cpu-dashing branch November 22, 2023 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants