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

Switch box-shadows to use brush masks (and add basic brush prim). #1841

Merged
merged 1 commit into from Oct 17, 2017

Conversation

@glennw
Copy link
Member

glennw commented Oct 10, 2017

This introduces a new brush primitive type. Right now, this is
extremely basic and doesn't provide much new functionality. As
more items are ported to use it, the functionality of the brush
shader type will expand (mostly the VS parts).

The major change in this patch is to remove the old box-shadow
shader and switch box shadows to be drawn via a brush mask +
gaussian blur approach.

This is a performance regression for small / simple box shadows
compared to previously, but this is only temporary. The goal of
this (large) patch is to switch over to a different box-shadow
technique and address correctness issues first, and then we can
apply a number of optimizations on top of that. It is a performance
win on very large box shadows, which was the performance worst
case for the previous box shadow shader.

The changes included:

  • Extend blur shader to support both A8 and RGBA8 blurs.
  • Basic brush shader and primitive code.
  • Brush mask shader.
  • Remove old box shadow shader.
  • Move some common clip functions to ellipse.glsl.
  • Extend cache image shader to support both A8 and RGBA8 sources.
  • Support clip masks in cache image shader.
  • Remove box shadow primitive type.
  • Add reftests for spread, offset, blur, border radius box-shadow variations.
  • Support adjusting the border radii of box shadows as defined by spec.

Next steps:

  • Extend the mask shader to support arbitrary border radii per corner.
  • Apply various optimizations to the brush and blur code.

This change is Reviewable

@glennw
Copy link
Member Author

glennw commented Oct 10, 2017

r? @kvark

There's a couple of blockers before this can be merged - but it can probably be reviewed now.

The main issue is that the clip mask shader used for fast path box shadows (with zero blur) introduces a faint line of AA in some cases where it shouldn't. I'm a little unsure if I should leave this here until @nical finishes up his work on the AA changes, which may just resolve that problem. That causes a few test failures in the Servo WPT suite. @nical Do you think your AA work is likely to fix that, and how soon do you think it will be ready?

@glennw glennw force-pushed the glennw:brush-bs-6 branch 2 times, most recently from ddf3e56 to 718901a Oct 10, 2017
@kvark
Copy link
Member

kvark commented Oct 12, 2017

Reviewed 30 of 30 files at r1.
Review status: all files reviewed at latest revision, 8 unresolved discussions.


webrender/res/brush.glsl, line 63 at r1 (raw file):

    // will be expanded to support transform picture types (the common kind).
    vec2 pos = pic_task.target_rect.p0 + aPosition.xy * pic_task.target_rect.size;
    vLocalPos = aPosition.xy * pic_task.target_rect.size / uDevicePixelRatio;

I'm concerned that this makes vLocalPos to live in a separate space from vLocalRect, which is confusing


webrender/res/cs_text_run.glsl, line 23 at r1 (raw file):

    int picture_address = prim.user_data2;

    // Fetch the parent text-shadow for this primitive. This allows the code

nit: comment still implies the shadow


webrender/res/ellipse.glsl, line 70 at r1 (raw file):

float clip_against_ellipse_if_needed(vec2 pos,
                                     float current_distance,

nit: would be nicer with the new formatting style


webrender/res/ps_cache_image.glsl, line 68 at r1 (raw file):

        // Apply the clip mask
        color.a = min(color.a, do_clip());

I guess this will now become easier as @mstange convinced us to use multiplication ;)


webrender/res/ps_line.glsl, line 102 at r1 (raw file):

#ifdef WR_FEATURE_CACHE
    int picture_address = prim.user_data0;
    PrimitiveGeometry shadow_geom = fetch_primitive_geometry(picture_address);

should shadow_geom be renamed to picture_geom?


webrender/src/frame_builder.rs, line 1330 at r1 (raw file):

                        shadow_rect,
                        BorderRadius::uniform(shadow_radius),
                        ClipMode::ClipOut

Shouldn't this be ClipIn?


webrender/src/frame_builder.rs, line 1341 at r1 (raw file):

                    );

                    self.add_primitive(

add_primitive could possibly go outside the match


webrender/src/frame_builder.rs, line 1431 at r1 (raw file):

                    ));

                    self.add_primitive(

similarly, this could possibly be moved out of the match


Comments from Reviewable

@glennw
Copy link
Member Author

glennw commented Oct 12, 2017

Review status: 26 of 30 files reviewed at latest revision, 8 unresolved discussions.


webrender/res/brush.glsl, line 63 at r1 (raw file):

Previously, kvark (Dzmitry Malyshau) wrote…

I'm concerned that this makes vLocalPos to live in a separate space from vLocalRect, which is confusing

Now that I look at this again, I'm not sure it correctly accounts for multiple text shadows with different offsets. I'll take a detailed look in the morning and either explain further with more comments, or fix if incorrect.


webrender/res/cs_text_run.glsl, line 23 at r1 (raw file):

Previously, kvark (Dzmitry Malyshau) wrote…

nit: comment still implies the shadow

Done.


webrender/res/ellipse.glsl, line 70 at r1 (raw file):

Previously, kvark (Dzmitry Malyshau) wrote…

nit: would be nicer with the new formatting style

Done.


webrender/res/ps_line.glsl, line 102 at r1 (raw file):

Previously, kvark (Dzmitry Malyshau) wrote…

should shadow_geom be renamed to picture_geom?

Done.


webrender/src/frame_builder.rs, line 1330 at r1 (raw file):

Previously, kvark (Dzmitry Malyshau) wrote…

Shouldn't this be ClipIn?

I think ClipOut is named somewhat confusingly - it is the opposite of Clip (that is, it allows pixels outside the specific region).


webrender/src/frame_builder.rs, line 1341 at r1 (raw file):

Previously, kvark (Dzmitry Malyshau) wrote…

add_primitive could possibly go outside the match

Done.


webrender/src/frame_builder.rs, line 1431 at r1 (raw file):

Previously, kvark (Dzmitry Malyshau) wrote…

similarly, this could possibly be moved out of the match

Done.


Comments from Reviewable

@glennw
Copy link
Member Author

glennw commented Oct 12, 2017

@kvark Thanks for the review! I've addressed most of those comments. The remaining issues blocking this are:

  • I need to revisit the shadow offset comment above.
  • I have a local fix for the AA edge + reftest issue I mentioned above. I think I'll wait until the clip chain stuff from @mrobinson lands first though, to make sure I don't break anything there.
  • I still need to do a gecko try run once I get all the Servo tests passing with the AA fix mentioned above.
vec2(1.0, -1.0),
afwidth);

return smoothstep(0.0, afwidth, 1.0 - current_distance);

This comment has been minimized.

@nical

nical Oct 12, 2017

Collaborator

This implementation has a few bugs (see my ramblings in #1882), you should replace it by the corrected rounded_rect implementation from #1822.
I don't know if that's related to the aa glitch you referred to, though.

This comment has been minimized.

@glennw

glennw Oct 13, 2017

Author Member

Yes, the patch in #1822 fixes the test failures in this patch - it's due to the change in init_transform_fs.

This comment has been minimized.

@glennw

glennw Oct 13, 2017

Author Member

If we land #1822 soon-ish, I'll rebase this patch on top of that.

@bors-servo
Copy link
Contributor

bors-servo commented Oct 13, 2017

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

@glennw glennw force-pushed the glennw:brush-bs-6 branch from b451688 to 2385eb6 Oct 13, 2017
@glennw
Copy link
Member Author

glennw commented Oct 13, 2017

Fixes #130
Fixes #1831

Makes it trivial to implement #1430 once this lands.

@bors-servo
Copy link
Contributor

bors-servo commented Oct 13, 2017

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

@glennw glennw force-pushed the glennw:brush-bs-6 branch from 2385eb6 to 218b865 Oct 15, 2017
@glennw
Copy link
Member Author

glennw commented Oct 16, 2017

I've rebased this over the AA change from @nical.

Gecko try run is here:
https://hg.mozilla.org/try/pushloghtml?changeset=58922e35932a38a0e9247e6f3a50845d67b02774
https://treeherder.mozilla.org/#/jobs?repo=try&revision=58922e35932a38a0e9247e6f3a50845d67b02774

There are 6 new passes, and 6 new fails.

It's likely some of these are related to other recent changes in WR (I don't think the fuzziness has been updated for the AA patch yet).

I'll do some further investigation on those failures and see if they are fuzziness issues or bugs that need to be resolved before landing this.

@glennw
Copy link
Member Author

glennw commented Oct 16, 2017

Looking at the unexpected passes / fails:

Probably related to @gankro 's text-shadow change:
background-clip-text-2.html PASS.
basic-opacity.html PASS.

Probably related to @nical 's AA change:
preserve3d-6a.html FAIL (more fuzziness needed)
backface-visibility-2.html FAIL (more fuzziness needed)
split-intersect1.html PASS
bugs/289480.html#top PASS

New box-shadow PASS from this patch:
boxshadow-inner-basic.html PASS
boxshadow-border-radius-int.html PASS

New box-shadow FAIL from this patch:
box-shadow/boxshadow-large-border-radius.html
boxshadow-color-rounding-middle.html
boxshadow-inset-neg-spread.html
boxshadow-inset-large-offset.html
box-decoration-break-with-inset-box-shadow-1.html

None of those box-shadow fails looks drastically wrong, but some of them have more fuzziness than I would expect to need (although most of them have fuzziness on skia / d2d too). I'll investigate some of those now.

@Gankra
Copy link
Contributor

Gankra commented Oct 16, 2017

Can confirm those two passes are what I was targeting with my patch.

@glennw glennw force-pushed the glennw:brush-bs-6 branch 4 times, most recently from 152cdef to 65d6ba7 Oct 17, 2017
This introduces a new brush primitive type. Right now, this is
extremely basic and doesn't provide much new functionality. As
more items are ported to use it, the functionality of the brush
shader type will expand (mostly the VS parts).

The major change in this patch is to remove the old box-shadow
shader and switch box shadows to be drawn via a brush mask +
gaussian blur approach.

This *is* a performance regression for small / simple box shadows
compared to previously, but this is only temporary. The goal of
this (large) patch is to switch over to a different box-shadow
technique and address correctness issues first, and then we can
apply a number of optimizations on top of that. It *is* a performance
win on very large box shadows, which was the performance worst
case for the previous box shadow shader.

The changes included:
 * Extend blur shader to support both A8 and RGBA8 blurs.
 * Basic brush shader and primitive code.
 * Brush mask shader.
 * Remove old box shadow shader.
 * Move some common clip functions to ellipse.glsl.
 * Extend cache image shader to support both A8 and RGBA8 sources.
 * Support clip masks in cache image shader.
 * Remove box shadow primitive type.
 * Add reftests for spread, offset, blur, border radius box-shadow variations.
 * Support adjusting the border radii of box shadows as defined by spec.

Next steps:
 * Extend the mask shader to support arbitrary border radii per corner.
 * Apply various optimizations to the brush and blur code.
@glennw glennw force-pushed the glennw:brush-bs-6 branch from 65d6ba7 to 5c3b489 Oct 17, 2017
@glennw
Copy link
Member Author

glennw commented Oct 17, 2017

New try run:

https://hg.mozilla.org/try/rev/007c2de84545170b1b25b627c8a0149d6cff5350
https://treeherder.mozilla.org/#/jobs?repo=try&revision=007c2de84545170b1b25b627c8a0149d6cff5350&selectedJob=137389129

New PASSes related to this change:
boxshadow-inner-basic.html
boxshadow-border-radius-int.html

New FAILs related to this change:
box-decoration-break-with-inset-box-shadow-1.html - imperceptible differences. Already marked fuzzy - needs a bit more.
boxshadow-large-border-radius.html - blur has changed slightly. Already marked fuzzy - needs a bit more.
boxshadow-inset-neg-spread.html - imperceptible differences. Already marked fuzzy - needs a bit more.
boxshadow-inset-large-offset.html - Looks odd - already has a huge fuzzy range on WR, D2D and Skia. I think we could mark this with extra fuzziness, or as an expected FAIL for now.

Test differences unrelated to this change:
PASS - background-clip-text-2.html
PASS - fallback-mark-stacking-1.html
PASS - basic-opacity.html
PASS - 289480.html#top
PASS - split-intersect1.html
PASS - 615121-2.html
FAIL - preserve3d-6a.html
FAIL - backface-visibility-2.html

@staktrace @nical @kvark Given the above, I think this is probably ready to go now. Are you happy with the fuzziness changes described above?

@staktrace
Copy link
Contributor

staktrace commented Oct 17, 2017

@glennw I agree with your reftest analysis and am fine with this landing. Thanks for doing the try push!

@staktrace
Copy link
Contributor

staktrace commented Oct 17, 2017

Also for future reference, if you look at the most recent try runs in the wr-future-update bug the links to try pushes there will show which reftest differences were caused by stuff already landed and that I'm aware of. So in this case all the unrelated reftest failures that you were seeing I already have patches to adjust the fuzziness for.

@kvark
Copy link
Member

kvark commented Oct 17, 2017

@staktrace @glennw thanks for being extremely cautious here!
:shipit: 🚀 🎢
@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Oct 17, 2017

📌 Commit 5c3b489 has been approved by kvark

@bors-servo
Copy link
Contributor

bors-servo commented Oct 17, 2017

Testing commit 5c3b489 with merge 6a7b538...

bors-servo added a commit that referenced this pull request Oct 17, 2017
Switch box-shadows to use brush masks (and add basic brush prim).

This introduces a new brush primitive type. Right now, this is
extremely basic and doesn't provide much new functionality. As
more items are ported to use it, the functionality of the brush
shader type will expand (mostly the VS parts).

The major change in this patch is to remove the old box-shadow
shader and switch box shadows to be drawn via a brush mask +
gaussian blur approach.

This *is* a performance regression for small / simple box shadows
compared to previously, but this is only temporary. The goal of
this (large) patch is to switch over to a different box-shadow
technique and address correctness issues first, and then we can
apply a number of optimizations on top of that. It *is* a performance
win on very large box shadows, which was the performance worst
case for the previous box shadow shader.

The changes included:
 * Extend blur shader to support both A8 and RGBA8 blurs.
 * Basic brush shader and primitive code.
 * Brush mask shader.
 * Remove old box shadow shader.
 * Move some common clip functions to ellipse.glsl.
 * Extend cache image shader to support both A8 and RGBA8 sources.
 * Support clip masks in cache image shader.
 * Remove box shadow primitive type.
 * Add reftests for spread, offset, blur, border radius box-shadow variations.
 * Support adjusting the border radii of box shadows as defined by spec.

Next steps:
 * Extend the mask shader to support arbitrary border radii per corner.
 * Apply various optimizations to the brush and blur code.

<!-- 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/1841)
<!-- Reviewable:end -->
@glennw
Copy link
Member Author

glennw commented Oct 17, 2017

@staktrace A heads up - you need to update the bindings for this enum change - https://github.com/servo/webrender/pull/1841/files#diff-937670fa1a68b9bb7dab70622773f50d - otherwise, you get serde panics when sending a display list with box shadows.

@jrmuizel Also a heads up - this does add a perf regression for box shadows. If you see large pink lines in the GPU profiler, don't worry, it's only temporary. I'll be working on the optimizations on top of this PR this week.

@bors-servo
Copy link
Contributor

bors-servo commented Oct 17, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: kvark
Pushing 6a7b538 to master...

@bors-servo bors-servo merged commit 5c3b489 into servo:master Oct 17, 2017
4 of 5 checks passed
4 of 5 checks passed
code-review/reviewable 24 files, 9 discussions left (glennw, kvark, nical)
Details
Taskcluster (pull_request) TaskGroup: success
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@staktrace
Copy link
Contributor

staktrace commented Oct 18, 2017

So in the try push that included this update the reftest results are slightly different. There was no change to boxshadow-inner-basic.html which was supposed to be a PASS. And looking at the analyzer results I feel like boxshadow-inset-neg-spread.html and boxshadow-inset-large-offset.html should both be marked as failing as the difference between the test and reference cases is quite visible. For the former there's a light grey rect that's visible once you see the diff and know what to look for, and for the latter even though there's already a large fuzz applied, the files look visibly the same when I load them in non-WR firefox.

boxshadow-large-border-radius.html already had a visible difference and it's made worse but I'll fuzz it, and same with box-decoration-with-inset-box-shadow-1.html. In terms of gecko reftests it seems like this change overall made things worse and only fixed one reftest.

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

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