Commit Graph

48 Commits

Author SHA1 Message Date
John Stiles
0b84159e3b Improve array-indexing tests.
Previously, we didn't have tests which leveraged constant-evaluation of
array indexing (because we didn't support it), and our test files
commingled constant-indexing into vectors with constant-indexing into
arrays.

The test files now separate vector- and array-handling into separate
tests, and a ton of new cases have been added to ArrayFolding. The
ArrayFolding tests now require constant-evaluation of array indexing,
so they fail in this CL, but will be fixed in the followup CL.

Change-Id: I3b663e743d97d6db80627bc9b7808f88c99917a7
Bug: skia:12472
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/469528
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-11-10 18:31:28 +00:00
John Stiles
9e952b379b Allow const int variables to be used for array sizes.
See http://review.skia.org/460037 for an example of the existing
behavior. Const variables are constant-expressions and should be allowed
here.

Change-Id: I41383d79668785f270b7825485e9f6fa56c553c1
Bug: skia:12549
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/460036
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-10-18 14:23:33 +00:00
John Stiles
980169a5b5 Allow non-trivial constant expressions for array sizes.
This fixes GLSL ES2 conformance test `array`.

Change-Id: I6ebee9253e1e8c394d9ddb6899e3a0940b7a38ef
Bug: skia:12495
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/458718
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-10-12 21:04:33 +00:00
John Stiles
c332739531 Remove 0/x arithmetic simplification.
If x is a known compile-time constant value, it can already be optimized
to a final value.
If x is not known, it could be zero, and 0/0 should result in a NaN.

Change-Id: I643a7c6da0a43ec366235c4df39fc78d3b361de7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/441580
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-08-24 19:18:41 +00:00
John Stiles
878d8fbf2f Improve constant folding for boolean vectors.
The additional tests from http://review.skia.org/441238 uncovered a gap
in the constant folder's abilities; it was not able to fold away
boolean vector comparisons even when they were constant. These are ES2
constant-expressions, so folding them properly is a requirement.

Change-Id: Ia0b4d5d1215c5fc2b247ac3f0dec4c8747d2153e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/441579
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-08-24 18:12:12 +00:00
John Stiles
55dc5c8325 Fix assertion in constant-folder when using float4(mat2) casts.
The no-op-arithmetic simplifier was written before we allowed casting a
mat2x2 to a float4, and did not expect a matrix inside a vector ctor.
The expression `float4(myMat2) * float4(anything)` would assert when we
tried to determine if `myMat2` was a constant zero or constant one.

The code has been rewritten to use getConstantSubexpression and now
allows matrices inside.

Change-Id: Id625141256bf89d816c57d2d21f16b0ec252c158
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/440858
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-08-20 14:04:52 +00:00
John Stiles
639e812d9f Remove usage of sqrt() as an optimization barrier in tests.
In the majority of cases, a uniform is an equally good substitute, and
replacing `sqrt(N)` with `unknownInput` actually makes the test clearer.

Change-Id: I7bcb477571972d7aa2ce8c49b3674471f7310748
Bug: skia:12034
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/411306
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-05-24 17:18:54 +00:00
John Stiles
7bb100ec04 Optimize not() intrinsic.
This is similar to the intrinsic optimization for any() and all(). Tests
for all three intrinsics have been bulked up a bit as well.

Change-Id: I262b9448e543b4709d1e7c8585f74a206c4b5abd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/406576
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-05-11 14:08:39 +00:00
John Stiles
dabb2891c4 Fold casts of known values at compile time.
A cast like `float(five)` or `int4(colorGreen)` will now detect const
variables and replace the expression with its compile-time constant
equivalent value. This can unblock further constant folding
opportunities.

(This CL is very similar in spirit to http://review.skia.org/404676)

Change-Id: If78a2091770777b0caaaec696fe15a0f55d88c24
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/405683
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-05-07 22:04:48 +00:00
John Stiles
27193d4bce Add test demonstrating missed opportunities with casts.
A cast like `float(five)` or `int4(colorGreen)` should detect const
variables and replace the expression with its compile-time constant
equivalent value. At present, this replacement is missed, which inhibits
further optimization opportunities on the expression.

(This CL is very similar in spirit to http://review.skia.org/404676)

Change-Id: I04b5c435a30d2afcdbdb3d020adc15e9c651cc31
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/405682
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-05-07 22:04:16 +00:00
John Stiles
1dc2d0fe0f Allow compile-time intrinsic evaluation to read const variables.
Previously, the code neglected to resolve constant variables into
values. This meant that expressions like `lessThan(zero, one)` could not
be compile-time evaluated even when `zero` and `one` have known values.

Change-Id: I2f5ce303e3dcc682be14e4d2485e24dd7c59212e
Bug: skia:10835
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/405536
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-05-07 13:36:08 +00:00
John Stiles
28181e70ce Optimize away intrinsics any() and all() when their inputs are known.
If every argument passed to any() or all() is a compile-time constant,
we now detect this and optimize away the function call entirely.

Future CLs will perform a similar optimization on other intrinsic calls
which can be detected and eliminated at compile time, like lessThan().

Change-Id: Ie55aff538b1ccaf2b3bcf9a69573a85f081b7ade
Bug: skia:10835
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/404417
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-05-06 12:43:57 +00:00
John Stiles
18607b442c Reland "Optimize away swizzles of constant variables."
This is a reland of 7b253d34ee

http://review.skia.org/402781 must land first, to resolve the assertions
we were getting on the Android bots.

Original change's description:
> Optimize away swizzles of constant variables.
>
> Change-Id: I49807f18ea54e85c2b8f1419278c54aa2d6f8fac
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402581
> Commit-Queue: John Stiles <johnstiles@google.com>
> Auto-Submit: John Stiles <johnstiles@google.com>
> Reviewed-by: Ethan Nicholas <ethannicholas@google.com>

Change-Id: Ib4f494b16a89ff744d4384db95a8a86d9653c190
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402644
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-04-30 13:12:18 +00:00
John Stiles
a6cc82e3cf Revert "Optimize away swizzles of constant variables."
This reverts commit 7b253d34ee.

Reason for revert: asserting on some bots

Original change's description:
> Optimize away swizzles of constant variables.
>
> Change-Id: I49807f18ea54e85c2b8f1419278c54aa2d6f8fac
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402581
> Commit-Queue: John Stiles <johnstiles@google.com>
> Auto-Submit: John Stiles <johnstiles@google.com>
> Reviewed-by: Ethan Nicholas <ethannicholas@google.com>

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

Change-Id: I530e6923e3c56f503508c70258c25f160f8985bc
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402640
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-04-29 17:41:08 +00:00
John Stiles
7b253d34ee Optimize away swizzles of constant variables.
Change-Id: I49807f18ea54e85c2b8f1419278c54aa2d6f8fac
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402581
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-04-29 16:04:42 +00:00
John Stiles
fb7d378a1a Add test demonstrating swizzled constant folding.
At present, this is a missed optimization opportunity. These will be
optimized in a followup CL.

Change-Id: I8882058900cdc12c8ab0df03e36ebfb9d8022f01
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402580
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-04-29 15:59:37 +00:00
John Stiles
5abb9e1426 Represent matrix resizes as a dedicated expression type.
This shook out a long-standing bug; constant folding would treat a
matrix resize as if the cells not covered by the original matrix were
all zero. This is wrong; GLSL populates the unknown cells with an
identity matrix. We actually tested for the wrong behavior, so the tests
were updated to match the correct behavior, and an equivalent test was
added that does not constant-fold (to verify that our constant folder
matches reality).

Change-Id: I03df10ce646fbef0a36e9c1a841a7637182de122
Bug: skia:11032
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/392916
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-04-06 18:35:06 +00:00
John Stiles
22a54543a8 Add support for constant-folded array inequality checks.
This isn't something I expect to occur often. However, we have always
reported that array-ctors with constant arguments are compile-time
constants, and `compareConstant` is supposed to be implemented for all
compile-time constants.

Change-Id: I0bbfe2a3f78c29c14f69c3b6faca71067a0e45c8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/391116
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-03-31 15:50:02 +00:00
John Stiles
8037c9e2ed Add test for folding of == and != for arrays.
We don't directly support this today at all. In practice, though, simple
constant arrays are detected as equal in the constant-folding pass
because they hit the `x == x` self-equality check (using
`IsSameExpressionTree`).

This does not work for our inequality tests, though, so those do not
fold.

Change-Id: I6730a9a2d1da9ac613ee58889d651f3ff65b1d2d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/391057
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-03-31 15:32:03 +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
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
5676c57220 Optimize away self-comparison in the constant folder.
Expressions like `value == value` or `color.a != color.a` can be
replaced by `true` or `false` on sight. The GLSL spec makes it clear
that checking for NaN is optional:

4.7.1 Range and Precision
"... NaNs are not required to be generated. Support for signaling NaNs
is not required and exceptions are never raised. Operations and built-in
functions that operate on a NaN are not required to return a NaN as the
result."

Change-Id: I2ad9f2dc505b638ea2904bef41b7a79a2b329551
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/381262
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-03-08 23:38:29 +00:00
John Stiles
7a3f5506b6 Performance experiment: disable control-flow analysis.
This CL will be used to test for potential performance regressions (or
improvements) that we might cause by disabling this optimization pass.

It will be reverted in ~1 day.

Change-Id: I26b7687c341eb6d81231406381c39869cfccf6d6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/381259
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-03-08 19:41:19 +00:00
John Stiles
03467a53e6 Revert "Disable control-flow analysis in SkSL. (Performance experiment)"
This reverts commit 50b1b2b90d.

Reason for revert: ending experiment

Original change's description:
> Disable control-flow analysis in SkSL. (Performance experiment)
>
> This CL will be used to test for potential performance regressions (or
> improvements?) that we might incur by disabling this optimization pass.
>
> It will be reverted in ~1 day.
>
> Change-Id: I775cdb0c95df81fa25ebbd66e4ff01f64c660f68
> Bug: skia:11319
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/378456
> 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: Ie385a82db237ff5651348d82b9651f8ba09375b9
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:11319
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/379581
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-03-04 15:20:09 +00:00
John Stiles
50b1b2b90d Disable control-flow analysis in SkSL. (Performance experiment)
This CL will be used to test for potential performance regressions (or
improvements?) that we might incur by disabling this optimization pass.

It will be reverted in ~1 day.

Change-Id: I775cdb0c95df81fa25ebbd66e4ff01f64c660f68
Bug: skia:11319
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/378456
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-03-03 22:08:56 +00:00
John Stiles
95d0badecf Support self-assignment elimination in the constant-folder.
Interestingly, this improves our codegen even with the optimizer fully
enabled, as apparently statement chains like:
	`x = true; x = x; x = x;`
were getting transformed by constant-propagation into:
	`x = true; x = true; x = true;`
making them no longer candidates for self-assignment elimination.

Change-Id: I6d94a809e94b01a00fd92459fcbce898b3cbbb11
Bug: skia:11343
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/377100
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-03-01 22:46:01 +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
John Stiles
9cfcb07d7a Fix alpha channel in SelfAssignment test.
This was being set to zero instead of one by mistake. Interestingly,
this was undetected by the CPU backend, but appears to matter sometimes
on the GPU side.

Change-Id: If827863f69c140f933696c6ff55c8a7095620c29
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/368858
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2021-02-11 14:41:15 +00:00
John Stiles
0ac6c15075 Reduce self-assignment expressions (x = x) into just x.
Change-Id: I44356aa781f208f4941dbeb617a30318e36c1081
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/367062
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-02-10 20:00:05 +00:00
John Stiles
34c098d7f8 Add SkSL test demonstrating missed optimization with +=.
Currently, SkSL is able to constant-propagate `x = x + constant` into
`x = constant` when the starting value of x is known. However, it is not
able to do the same optimization for `x += constant`. This test
demonstrates that once += is encountered, we lose track of x's value and
can no longer propagate its value.

(This is equally true of all the op-assignment operators, += -=
*= /= etc.)

Change-Id: I3523e96baf9a73982cf3b09f0d23b95adacf106b
Bug: skia:11192
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/368248
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-02-09 19:17:26 +00:00
John Stiles
a793f4f6fc Add additional cases to folding tests.
These cover new ground; when combined with some additional optimization
work, they can cause crashes in the optimizer that we don't see from any
existing test.

Change-Id: I3958a5522cfe0929d0753e6e617d72e032c7f5a3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/367063
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-02-08 16:17:18 +00:00
John Stiles
4d6310ab20 Support half4 return values from main() in the SPIR-V code generator.
This creates a helper function, _entrypoint, which invokes main() and
assigns its result into sk_FragColor. We also make sure to prevent
sk_FragColor from being dead-stripped from the code during IR
generation.

At present this is useful for allowing our SkSL test shaders to compile.

Change-Id: I2d7fab0e1959a77778ffdb18ca569e869bcaeece
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/358525
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-01-27 02:46:03 +00:00
John Stiles
b41d5bb3a7 Add helper uniforms to Runtime Effect tests.
This lets us use descriptive names like `colorRed` and `colorGreen`
instead of `half4(1,0,0,1)` and `half4(0,1,0,1)`. It also lets us use
actual unknown values instead of synthesizing sorta-kinda-unknowns by
calling sqrt.

Change-Id: I61481c33b7ff42182955777b05cfa5fcc13e0efc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/359567
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-01-27 00:53:46 +00:00
John Stiles
053f785903 Avoid relying on bit-perfect irrational numbers in test code.
Comparing sqrt(5) against a variable containing sqrt(5) was not working
properly in some versions of Android running Vulkan.

Change-Id: I4f6bbff78a9ba56ec6e222f2037d66b13e3cd635
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/358530
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-01-25 21:27:19 +00:00
John Stiles
232dd2b61b Reland "Run unit tests to verify SkSL folding behavior."
This is a reland of 4ecab92584

This reland folds in subsequent code cleanups and disables a test that
failed on Android + Vulkan.

Original change's description:
> Run unit tests to verify SkSL folding behavior.
>
> The unit test loads SkSL source files from `resources/sksl`, compiles
> the code, and uses SkRuntimeEffect to render a pixel using the effect.
> If solid green is rendered, the test passes.
>
> Change-Id: I2ccb427a907975ae84aee19d8e68d774b2cb638c
> Bug: skia:11009
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/355983
> Commit-Queue: John Stiles <johnstiles@google.com>
> Auto-Submit: John Stiles <johnstiles@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>

Bug: skia:11009
Change-Id: I09196c8ca3041e8957324a0cbb7f7d6963c6e4e7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/358523
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-01-25 17:49:36 +00:00
Greg Daniel
95c2994048 Revert "Run unit tests to verify SkSL folding behavior."
This reverts commit 4ecab92584.

Reason for revert: breaking all the vulkan bots

Original change's description:
> Run unit tests to verify SkSL folding behavior.
>
> The unit test loads SkSL source files from `resources/sksl`, compiles
> the code, and uses SkRuntimeEffect to render a pixel using the effect.
> If solid green is rendered, the test passes.
>
> Change-Id: I2ccb427a907975ae84aee19d8e68d774b2cb638c
> Bug: skia:11009
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/355983
> Commit-Queue: John Stiles <johnstiles@google.com>
> Auto-Submit: John Stiles <johnstiles@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>

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

Change-Id: Ife32f6c33d9ba7a9580b66eb312cffb249c43cb2
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:11009
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/357780
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
2021-01-23 00:01:23 +00:00
John Stiles
4ecab92584 Run unit tests to verify SkSL folding behavior.
The unit test loads SkSL source files from `resources/sksl`, compiles
the code, and uses SkRuntimeEffect to render a pixel using the effect.
If solid green is rendered, the test passes.

Change-Id: I2ccb427a907975ae84aee19d8e68d774b2cb638c
Bug: skia:11009
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/355983
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-01-22 20:34:28 +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
John Stiles
7938717797 Update folding tests to return pass/fail status.
A passing test returns solid green. Failing tests are written to
return solid red, but drawing any other color than green can be
interpreted as a test failure.

Additionally, tests which cannot compile as RuntimeEffects (due to
non-ES2-compatible features) have been split into an ES2-compatible part
and an ES3 part.

Change-Id: I3f53121d9de0ae4c4e7f1de3177d067811980b55
Bug: skia:11009
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/356999
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-01-22 16:44:22 +00:00
John Stiles
8d3642e200 Add checkpointing functionality to the Parser.
This allows us to roll the Parser back to an earlier state if we need
to do so. This includes:
- rewinding the lexer
- restoring the previous Pushback node
- backing out AST nodes
- backing out errors

This functionality is used to back out of parsing a vardecl if we
discover mid-stream that it is actually an expression statement that
coincidentally starts with the name of a type.

Change-Id: Ia5feb45019693931c1e6870e3ff7a5398924c863
Bug: skia:11198
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/356997
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-01-22 16:42:33 +00:00
John Stiles
8a9da73687 Fix overzealous optimization of short-circuits.
The previous implementation assumed that SkSL expressions do not have
side effects and so treated either side of a Boolean expression as
short-circuitable. That is, `foo() && false` and `false && foo()` would
both be optimized to `false`, eliminating the `foo()` call.

We now check for side effects first. An expression like `expr && false`
can only be optimized to `false` if `expr` has no side effects. (If
`expr` does have side effects, the expression is left as-is.)

Change-Id: I473cf026a8afe35d6a8d9518498f2b26d8996e60
Bug: skia:11162
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/356357
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-01-20 20:24:27 +00:00
John Stiles
81bfabeb18 Optimize (boolExpr == true) and (boolExpr != false) into boolExpr.
Additionally, restructure the unit test to return a color (green for
pass, red for fail).

Change-Id: Ib1bb6bd8771c72cc751d8d2c65cc14a693166d4c
Bug: skia:11112
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/356301
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-01-20 18:08:26 +00:00
John Stiles
26fdcbb38b Implement constant folding for (bool == bool) and (bool != bool).
We already had support for &&, ||, ^^ but somehow the common cases of
== and != were not implemented in the constant-folder.

This CL also updates the test to return a green/red color on success or
failure, instead of assigning arbitrary numbers into sk_FragColor that
don't mean anything. The long-term plan is to signal success or failure
of each test by color code; we can display these colors as swatches in a
GM slide for testing purposes.

Change-Id: I0810108b3c6b656a60cd8aa64ceefd765eff0157
Bug: skia:11112
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/355984
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-01-20 14:22:35 +00:00
John Stiles
a65441b3c4 Update tests which mix int and float types without casts.
These need to change because type coercion in SkSL is about to become
more strict in a followup CL; we are disallowing expressions that mix
ints and floats without a cast.

Change-Id: I0f6c3cba53fb67078f447345338262c153236c51
Bug: skia:11164
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/353102
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-01-13 19:47:13 +00:00
John Stiles
508eba7578 Implement constant folding for vector*scalar ops.
Change-Id: I96b547de4fe4b73096fb26d0ef21a4e7555ca06a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/352238
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-01-11 21:03:55 +00:00
John Stiles
74192fde0d Migrate constant folding tests into a separate directory.
This CL also adds tests for vector*scalar and scalar*vector folding.
We currently do not constant-fold these, but support will be added in a
followup CL.

Change-Id: I68d7374ae15ab2f4d805a095803b645c92fb03d9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/352237
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-01-11 18:05:18 +00:00