Commit Graph

20 Commits

Author SHA1 Message Date
John Stiles
bca1b0c955 Add ReducedBlendModeInfo to shared code.
This will allow us to reuse this logic in Graphite.

Change-Id: I649dcd3893a1355af457a2583a6db3066fb87c9a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/532758
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2022-04-22 17:18:31 +00:00
John Stiles
9ef12d72cf Optimize saturation code again.
This adopts a trick from SkVM to avoid sorting entirely.

Change-Id: I586c8a3613b48241842a7d8eba1c9d68a4717f83
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/528368
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2022-04-07 21:36:07 +00:00
John Stiles
442a5d9365 Reduce complexity in set-color-saturation.
Caveat: on my machine, Nanobench doesn't detect any change (pro or con)
on this CL.

I'm working under the assumption that function calls have a non-zero
cost--they may be inlined (bloating code size), or not (incurring the
costs of a function call, register push/popping, etc). This CL avoids
making six calls to $blend_set_color_saturation by using two half3
variables. These half3s are used to swizzle the result--they contain two
zeros and a one, so multiplying them by a scalar will put the result in
the desired component. I've also made some very minor simplifications to
the math that were made possible by reordering.

Change-Id: I0c1ef88d165365376078846324be8bb723548512
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/528043
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2022-04-07 20:17:34 +00:00
John Stiles
c71922cd88 Reduce color fringes on blend_hue and blend_saturation.
Today I learned that `mix(a, b, 1)` can reduce precision. Ternaries do
not suffer from this problem.

Change-Id: I58814d00193ccbff53960030d163d31c49234f6c
Bug: skia:9320
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/528161
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
2022-04-07 13:39:08 +00:00
John Stiles
d43a882ac3 Simplify control flow in blend_set_color_luminance.
The inliner can do a better job with functions that only have a single
return by eliding a temp variable. In this case, it was simple to adapt.

Change-Id: I9a5ee26cf546db1b2647cdf95d4cdba6649ea19b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/528160
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2022-04-07 13:39:08 +00:00
John Stiles
44832b292d Revert "Fix color fringes on blend_hue and blend_saturation."
This reverts commit 2e6f60f423.

Reason for revert: draws black incorrectly in various iPhone 8 tests

Original change's description:
> Fix color fringes on blend_hue and blend_saturation.
>
> Previously, we checked for division against zero, but didn't do anything
> to prevent division against extraordinarily small values. Now, we only
> saturate if the delta between max and min is greater than 0.00001.
>
> Change-Id: I7d1df3430941c7e1a7f94e597d5449f9259612d6
> Bug: skia:9320
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/527498
> Auto-Submit: John Stiles <johnstiles@google.com>
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Commit-Queue: Greg Daniel <egdaniel@google.com>

Bug: skia:9320
Change-Id: Id83376080eed684577b3592c5e1bee3c80fc3fc9
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/528038
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Commit-Queue: Derek Sollenberger <djsollen@google.com>
2022-04-06 17:07:06 +00:00
John Stiles
72d4c6b574 Collapse darken/lighten blend functions into one.
We use multiplication by 1 or -1 to branchlessly choose one of `min` and
`max` in the same function.

Change-Id: I44cf747feeae75a9c3e00f36e112e0a429871e86
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/527596
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2022-04-05 20:27:09 +00:00
John Stiles
dc28d75792 Collapse overlay/hard-light blend functions into one.
Hard-light is just overlay with the parameters reversed.

Change-Id: I6cf5963b1252cba3a7b71a56f4094a070188f8b2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/527503
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2022-04-05 20:21:47 +00:00
John Stiles
10e21844a7 Collapse hue/saturation/luminosity/color blend functions into one.
These functions were functionally almost identical, except:
- Sometimes sda/dsa are flipped
- Sometimes the saturation is not updated

We now have one method (blend_hslc) which can do all four blend
operations. It takes two new parameters ("flip" and "saturate") to
handle these four variations.

This reduces our shader count on some of our most shader-heavy slides
(e.g. aaxfermodes, xfermodeimagefilter) at a pretty reasonable cost.

Change-Id: Ifa8a48399851a9badb5d50038de1e25e60d44ebd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/527281
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2022-04-05 20:16:54 +00:00
John Stiles
c5b381c479 Use $ prefix on built-in private functions.
This guards against any potential for conflict with user code.

Change-Id: Iecaf3ead5f8ada50b6dc159a4ad9e7f3e371edc7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/499296
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2022-01-25 15:21:42 +00:00
John Stiles
ece1d794b9 Mangle function names in GLSL.
This will be implemented in Metal and SPIR-V in followup CLs.

Change-Id: I397b4db40b15dd54cf1d8a17f414c3fe184b48d2
Bug: skia:10851
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/387638
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-03-22 17:18:26 +00:00
John Stiles
b66645830d Only run the inliner one time.
This saves a significant amount of CPU time and, now that the inliner
can handle nested expressions, still inlines almost everything.

Change-Id: I8f198630fa9627bc433ef8fb72f6bcf94595cdaa
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/386917
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-03-19 17:02:21 +00:00
John Stiles
049f0dfaba Reduce unnecessary scratch variables in Inliner.
Arguments without side-effects that aren't read from more than once can
be moved directly into the inlined function, and don't need a scratch
variable. This can allow functions like `guarded_divide` to inline
completely in more cases.

Change-Id: I0bfce35635cf9779f4af1bc0790da966ccfe4230
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/386678
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-03-19 14:10:29 +00:00
Brian Osman
8c595fed7c Change sksl tests to avoid SPIR-V validation errors
'in' variables without locations aren't allowed. Use uniforms instead.

Bug: skia:11738
Change-Id: Ic066106deb7409cff154b4be7cfb3e03a7025c7d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/385000
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-03-16 13:39:53 +00:00
John Stiles
132cfdd49d Revert "Inline functions of the form 'return (expr)' only."
This reverts commit 92748af1a5.

Reason for revert: SkSLCommaSideEffects_GPU crashing on Android

Original change's description:
> Inline functions of the form 'return (expr)' only.
>
> This drastically reduces the number of functions which we allow to be
> inlined. If this change does not hurt our performance, it will allow us
> to trivially remove hundreds of LOC. All current data leads us to
> believe that it may affect the Mali 400 but is highly unlikely to change
> results on any other device in the tree.
>
> More info: http://go/optimization-in-sksl-inliner
>
> Change-Id: Ia6b706742ce5407453e0e697b6c1f9201084c0e8
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/384858
> Auto-Submit: John Stiles <johnstiles@google.com>
> Commit-Queue: John Stiles <johnstiles@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>
> Reviewed-by: Ethan Nicholas <ethannicholas@google.com>

TBR=brianosman@google.com,ethannicholas@google.com,johnstiles@google.com

Change-Id: I6a670dacaa58fe3386ff50375ac6d1cac4fd7f2c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/385161
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-03-15 22:08:48 +00:00
John Stiles
92748af1a5 Inline functions of the form 'return (expr)' only.
This drastically reduces the number of functions which we allow to be
inlined. If this change does not hurt our performance, it will allow us
to trivially remove hundreds of LOC. All current data leads us to
believe that it may affect the Mali 400 but is highly unlikely to change
results on any other device in the tree.

More info: http://go/optimization-in-sksl-inliner

Change-Id: Ia6b706742ce5407453e0e697b6c1f9201084c0e8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/384858
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-03-15 19:46:46 +00:00
John Stiles
e8b5a73b56 Remove extraneous line-breaks in generated GLSL/Metal code.
I ran into an issue in an upcoming CL which generated a particularly
ugly switch statement:

    switch (x) {
        default:
             discard;}

So I cleaned this up, and while resolving this issue, managed to improve
a bunch of existing codegen as well. The formatting change has been
split out to a separate CL since it impacts so many golden outputs.

Change-Id: I7a6be29903c47560dcc7f6acd3ef15fd0c5c3c50
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/384179
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-03-12 18:39:57 +00:00
John Stiles
511c500ad4 Avoid generating unused variables in the Inliner.
These variables were later being eliminated by the dead-code-elimination
pass, so you can't see them directly in the final output, but removing
them affects the name mangling off all future symbols, so it causes an
enormous ripple effect in the diff. And of course, it's a waste of time
and memory to synthesize IRNodes just to destroy them later.

If we disable control-flow analysis, we lose the dead-code-elimination
pass entirely; this change is also beneficial for emitting better code
when optimizations are turned off.

Change-Id: I882b3be4f3fd99b77d99b6abe128f26bb9252c89
Bug: skia:11319
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375776
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-02-25 19:18:19 +00:00
Brian Osman
73122aa45f Use guarded_divide in more blend functions
Fixes another instance of anglebug.com/2098 with advanced blend
functions.

Change-Id: I91863723d8b4c33ab2f5a527fe0374e8947bba16
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/368813
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2021-02-10 21:59:26 +00:00
John Stiles
bfc9be0f77 Migrate SkSL test inputs to the resources/ directory.
This will allow us to load these inputs for unit testing in `dm`.

Change-Id: Id256ba7c30d3ec94b98048e47af44cf9efe580d5
Bug: skia:11009
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/357282
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-01-22 18:57:29 +00:00