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

Use Pathfinder's more accurate area approximation for distance AA. #2445

Merged
merged 2 commits into from Feb 22, 2018

Conversation

@pcwalton
Copy link
Collaborator

pcwalton commented Feb 20, 2018

Smoothstep is not a very good approximation because it has zero
derivatives at 0.0 and 1.0. It makes edges too sharp (i.e. more
aliased).

From the comments in prim_shared.glsl:

This cubic polynomial approximates the area of a 1x1 pixel square under a
line, given the signed Euclidean distance from the center of the square to
that line. Calculating the exact area would require taking into account
not only this distance but also the angle of the line. However, in
practice, this complexity is not required, as the area is roughly the same
regardless of the angle.

The coefficients of this polynomial were determined through least-squares
regression and are accurate to within 2.16% of the total area of the pixel
square 95% of the time, with a maximum error of 3.53%.

Happy to answer any questions you might have.

r? @glennw


This change is Reviewable

@pcwalton pcwalton requested a review from glennw Feb 20, 2018
@pcwalton
Copy link
Collaborator Author

pcwalton commented Feb 21, 2018

Here's an image showing the difference. "New" is with this patch, while "old" is the master branch.

border-radii-difference

Notice that the pixels inside the red box have a smoother look with this patch, especially the top row.

@glennw
Copy link
Member

glennw commented Feb 21, 2018

Looks like the same two Linux-specific tests as the ellipse PR need updating again. I'll update those and do a try run later today.

@bors-servo
Copy link
Contributor

bors-servo commented Feb 21, 2018

The latest upstream changes (presumably #2441) made this pull request unmergeable. Please resolve the merge conflicts.

@pcwalton pcwalton force-pushed the pcwalton:aa-curve branch from d4a0e41 to 954c491 Feb 21, 2018
@pcwalton
Copy link
Collaborator Author

pcwalton commented Feb 21, 2018

Fixed the merge conflict and rebased.

@kvark
kvark approved these changes Feb 21, 2018
Copy link
Member

kvark left a comment

the reftest images are certainly improved with the PR 👍

float distance_aa(float aa_range, float signed_distance) {
return 1.0 - smoothstep(-aa_range, aa_range, signed_distance);
float dist = 0.5 * signed_distance / aa_range;
if (dist <= -0.5 + EPSILON)

This comment has been minimized.

@kvark

kvark Feb 21, 2018

Member

why do we need to take EPSILON into account here?

This comment has been minimized.

@pcwalton

pcwalton Feb 21, 2018

Author Collaborator

If the EPSILON fudge factor isn't taken into account, reftests/clip/custom-clip-chains.yaml has some minor 1 pixel differences on the sides due to what I presume to be floating point error.

@glennw
Copy link
Member

glennw commented Feb 22, 2018

I think this is fine, but I'm going to wait until #2454 lands to fix the intermittents, and then do another try run with this to be safe.

pcwalton and others added 2 commits Feb 20, 2018
Smoothstep is not a very good approximation because it has zero
derivatives at 0.0 and 1.0. It makes edges too sharp (i.e. more
aliased).

From the comments in `prim_shared.glsl`:

This cubic polynomial approximates the area of a 1x1 pixel square under a
line, given the signed Euclidean distance from the center of the square to
that line. Calculating the *exact* area would require taking into account
not only this distance but also the angle of the line. However, in
practice, this complexity is not required, as the area is roughly the same
regardless of the angle.

The coefficients of this polynomial were determined through least-squares
regression and are accurate to within 2.16% of the total area of the pixel
square 95% of the time, with a maximum error of 3.53%.
@glennw glennw force-pushed the pcwalton:aa-curve branch from 954c491 to fa602e9 Feb 22, 2018
@glennw
Copy link
Member

glennw commented Feb 22, 2018

I checked each of the failures in the reftest analyzer, and they are all subpixel AA differences. So we can land this and fuzz those, since this is clearly an improvement in quality.

@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Feb 22, 2018

📌 Commit fa602e9 has been approved by glennw

@bors-servo
Copy link
Contributor

bors-servo commented Feb 22, 2018

Testing commit fa602e9 with merge 8a19316...

bors-servo added a commit that referenced this pull request Feb 22, 2018
Use Pathfinder's more accurate area approximation for distance AA.

Smoothstep is not a very good approximation because it has zero
derivatives at 0.0 and 1.0. It makes edges too sharp (i.e. more
aliased).

From the comments in `prim_shared.glsl`:

This cubic polynomial approximates the area of a 1x1 pixel square under a
line, given the signed Euclidean distance from the center of the square to
that line. Calculating the *exact* area would require taking into account
not only this distance but also the angle of the line. However, in
practice, this complexity is not required, as the area is roughly the same
regardless of the angle.

The coefficients of this polynomial were determined through least-squares
regression and are accurate to within 2.16% of the total area of the pixel
square 95% of the time, with a maximum error of 3.53%.

Happy to answer any questions you might have.

r? @glennw

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/2445)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 22, 2018

☀️ Test successful - status-appveyor, status-taskcluster, status-travis
Approved by: glennw
Pushing 8a19316 to master...

@bors-servo bors-servo merged commit fa602e9 into servo:master Feb 22, 2018
3 checks passed
3 checks passed
Taskcluster (pull_request) TaskGroup: success
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
homu Test successful
Details
@staktrace
Copy link
Contributor

staktrace commented Feb 22, 2018

@pcwalton @glennw Any theories as to why the box-decoration-break-with-inset-box-shadow-1.html reftest (in R4) is behaving nondeterministically? In opt it seems to always have 8924 differing pixels but on debug occasionally there's only 8772 differing pixels. This is the case in both the try push from #2445 (comment) and the one at https://treeherder.mozilla.org/#/jobs?repo=try&revision=f2c0d91c2fef35bea888505733b98c824c92110c (I did some retriggers on both).

@pcwalton pcwalton deleted the pcwalton:aa-curve branch Feb 22, 2018
@pcwalton
Copy link
Collaborator Author

pcwalton commented Feb 22, 2018

@staktrace Very strange. This is a GPU-code-only change, which shouldn't be affected by debug vs. release…

I would guess the issue is likely some sort of race in the CPU-side code that debug vs. release triggers.

@staktrace
Copy link
Contributor

staktrace commented Feb 22, 2018

It's likely not specific to debug vs release, but just a race somewhere that happens to get hit on debug more frequently.

@glennw
Copy link
Member

glennw commented Feb 22, 2018

@staktrace I think this is probably yet another instance of #1943 occurring, since box shadows are involved. I've assigned that bug to me, since it seems to be the main cause of non-determinism we have. I'll see if I can get it fixed next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.