Commit Graph

77 Commits

Author SHA1 Message Date
Brian Osman
9eb0bb6256 Revert "Added DSL flags"
This reverts commit 71430593f0.

Reason for revert: Clang-tidy bot unhappy. (Not sure how this slipped by).

Original change's description:
> Added DSL flags
>
> This adds some basic flags to the DSL initialization which allows us to
> toggle things like optimization and validation.
>
> Change-Id: I35b10526af1678c88901eaacd5a2c4a9f5cd21a7
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/406896
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
> Reviewed-by: John Stiles <johnstiles@google.com>

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

Change-Id: I7512b8bcc6e94707949904eec42c396faa7fdaf8
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/407176
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2021-05-11 22:04:10 +00:00
Ethan Nicholas
71430593f0 Added DSL flags
This adds some basic flags to the DSL initialization which allows us to
toggle things like optimization and validation.

Change-Id: I35b10526af1678c88901eaacd5a2c4a9f5cd21a7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/406896
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-05-11 20:44:29 +00:00
Ethan Nicholas
b22fcaf627 Added DSL layout() support
Change-Id: I698dd607ff4676b6fb29be0a718c6073b66dc7c7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/406336
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2021-05-11 19:52:59 +00:00
Ethan Nicholas
722cb67b09 Improved DSL APIs in preparation for DSLParser
This includes several new array variants of existing APIs, DSLBlock now
supporting SymbolTables, and a couple of other minor changes needed by
the upcoming DSLParser.

Change-Id: I71feb268feb27cf7ff453cc59046091779bffe06
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/404779
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-05-06 15:46:47 +00:00
Brian Osman
c9125aa8f3 Reland "Better first-class shader & color filter support in runtime effects"
This is a reland of adadb95a9f
... adds a temporary workaround for some Android framework code.

Original change's description:
> Better first-class shader & color filter support in runtime effects
>
> This does a few things, because they're all intertwined:
>
> 1) SkRuntimeEffect's API now includes details about children (which Skia
>    stage was declared, not just the name). The factories verify that the
>    declared types in the SkSL match up with the C++ types being passed.
>    Today, we still only support adding children of the same type, so the
>    checks are simple. Once we allow mixing types, we'll be testing the
>    declared type against the actual C++ type supplied for each slot.
> 2) Adds sample variants that supply the input color to the child. This
>    is now the only way to invoke a colorFilter child. Internally, we
>    support passing a color when invoking a child shader, but I'm not
>    exposing that. It's not clearly part of the semantics of the Skia
>    pipeline, and is almost never useful. It also exposes users to
>    several inconsistencies (skbug.com/11942).
> 3) Because of #2, it's possible that we can't compute a reusable program
>    to filter individual colors. In that case, we don't set the constant
>    output for constant input optimization, and filterColor4f falls back
>    to the slower base-class implementation.
>
> Bug: skia:11813 skia:11942
> Change-Id: I06c41e1b35056e486f3163a72acf6b9535d7fed4
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/401917
> Commit-Queue: Brian Osman <brianosman@google.com>
> Reviewed-by: Mike Klein <mtklein@google.com>

Bug: skia:11813 skia:11942
Change-Id: I2c31b147ed86fa8c4dddefb7066bc1d07fe0d285
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/404637
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2021-05-05 22:06:46 +00:00
Ethan Nicholas
371f6e18e5 Refactored SkSL function creation and error handling
This breaks up the giant IRGenerator::convertFunction method into more-
manageable chunks, moves the functionality into FunctionDeclaration,
and funnels the DSL through it so it receives the same error checking.

Change-Id: Icf2ac650ab3d5276d8c0134062a4e7e220f9bf32
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402778
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-05-04 19:25:25 +00:00
Ethan Nicholas
a1a0b92b04 Added DSLWrapper so DSL classes can be used in containers
This will be used by the upcoming DSLParser, which needs to be able to
put DSLExpression and DSLVar into containers such as std::vector and
std::optional.

Change-Id: I8d367cfd0b3a852a368c69a5b3be6c0eaa41d74a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/404156
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-05-04 17:19:35 +00:00
Greg Daniel
c2cca5a8a0 Revert "Better first-class shader & color filter support in runtime effects"
This reverts commit adadb95a9f.

Reason for revert: breaking android

Original change's description:
> Better first-class shader & color filter support in runtime effects
>
> This does a few things, because they're all intertwined:
>
> 1) SkRuntimeEffect's API now includes details about children (which Skia
>    stage was declared, not just the name). The factories verify that the
>    declared types in the SkSL match up with the C++ types being passed.
>    Today, we still only support adding children of the same type, so the
>    checks are simple. Once we allow mixing types, we'll be testing the
>    declared type against the actual C++ type supplied for each slot.
> 2) Adds sample variants that supply the input color to the child. This
>    is now the only way to invoke a colorFilter child. Internally, we
>    support passing a color when invoking a child shader, but I'm not
>    exposing that. It's not clearly part of the semantics of the Skia
>    pipeline, and is almost never useful. It also exposes users to
>    several inconsistencies (skbug.com/11942).
> 3) Because of #2, it's possible that we can't compute a reusable program
>    to filter individual colors. In that case, we don't set the constant
>    output for constant input optimization, and filterColor4f falls back
>    to the slower base-class implementation.
>
> Bug: skia:11813 skia:11942
> Change-Id: I06c41e1b35056e486f3163a72acf6b9535d7fed4
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/401917
> Commit-Queue: Brian Osman <brianosman@google.com>
> Reviewed-by: Mike Klein <mtklein@google.com>

TBR=mtklein@google.com,bsalomon@google.com,brianosman@google.com

Change-Id: I94ba57e73305b2302f86fd0c1d76f667d4e45b92
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:11813 skia:11942
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/404117
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2021-05-04 13:36:26 +00:00
Ethan Nicholas
b83199e289 Added unsigned types and type query functions to DSL
Change-Id: I721825d1a38e9f6846b94f84d14cb8c85b7a7519
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/403601
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2021-05-04 13:14:15 +00:00
Brian Osman
adadb95a9f Better first-class shader & color filter support in runtime effects
This does a few things, because they're all intertwined:

1) SkRuntimeEffect's API now includes details about children (which Skia
   stage was declared, not just the name). The factories verify that the
   declared types in the SkSL match up with the C++ types being passed.
   Today, we still only support adding children of the same type, so the
   checks are simple. Once we allow mixing types, we'll be testing the
   declared type against the actual C++ type supplied for each slot.
2) Adds sample variants that supply the input color to the child. This
   is now the only way to invoke a colorFilter child. Internally, we
   support passing a color when invoking a child shader, but I'm not
   exposing that. It's not clearly part of the semantics of the Skia
   pipeline, and is almost never useful. It also exposes users to
   several inconsistencies (skbug.com/11942).
3) Because of #2, it's possible that we can't compute a reusable program
   to filter individual colors. In that case, we don't set the constant
   output for constant input optimization, and filterColor4f falls back
   to the slower base-class implementation.

Bug: skia:11813 skia:11942
Change-Id: I06c41e1b35056e486f3163a72acf6b9535d7fed4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/401917
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2021-05-04 01:29:57 +00:00
Ethan Nicholas
e9c2c5a4c3 Added support for DSL global variables
This adds an explicit DeclareGlobal call, which must now be called for
variables that were previously implicitly global.

Change-Id: Iaf838880d1033ee52aac9246e31e3bda9a3b36f0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402399
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-04-30 18:05:19 +00:00
Ethan Nicholas
8a6537d87e Added DSL support for static if & switch statements
Change-Id: If11443997ae29266bf46da77c1e4f9583fa3f5a5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402577
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-04-30 17:31:49 +00:00
Ethan Nicholas
a60cc3ea41 Fix DSL handling of doubles
Previously, "x = 1.0" (as opposed to 1.0f) would fail with an ambiguous
operator resolution.

Change-Id: I9bcb4115d209a2aadb3fc4c237b61c345b25ca00
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/400619
Reviewed-by: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2021-04-30 13:47:18 +00:00
Brian Osman
552fcb9a1b Remove flexible runtime effects entirely
All internal usage has migrated to MakeFor..., this removes the old
program kind, and updates some tests.

Bug: skia:11813
Change-Id: I56733b071270e1ae3fab5d851e23acf6c02e3361
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402536
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-04-29 16:02:27 +00:00
Brian Osman
bf3e9e9591 Remove sample-with-matrix from SkSL
This is completely unused - GrMatrixEffect is the only thing that deals
with matrix transforms on child sampling. Removing this makes everything
simpler to reason about.

Change-Id: I555a3fd937c064f2480b149a6d4d8e36f7ee69bc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402176
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
2021-04-28 15:44:35 +00:00
John Stiles
e3fa745a5a Add support for atan() to DSL.
Change-Id: I00cc1e89fd85fdc0ce0860fcb35ececd0eaec50a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/400540
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-04-26 15:18:18 +00:00
John Stiles
08771b00eb Add DSLVar::swap method.
This gives DSLVar the ability to be set up after initial construction.
To do this, we create a plain empty Var, then swap it with the actual
Var we want afterwards. This allows DSL to support Vars which are
`uniform half4` in some cases and `const half4` (or entirely unused) in
other cases.

This technique was adapted from similar code in Ethan's parser CL.

Change-Id: Ic54d037a0102fda77b25d4755caf77a291eaa8c6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/400716
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-04-26 14:28:48 +00:00
John Stiles
8676ebe350 Demonstrate DSL for statements with multiple vardecls.
These now work, thanks to a combination of
http://review.skia.org/398221 and
http://review.skia.org/398017.

Change-Id: Ied1d6a39803c19dfa762a45e0ca4800820bb1c0a
Bug: skia:11868
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/397219
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-04-21 15:03:37 +00:00
Ethan Nicholas
db2326b46a Comma operator on DSL statements now creates unscoped blocks
Change-Id: I9eb85f25431b2d59b26e8cf8f4a73b9e45faa916
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/398017
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2021-04-19 15:37:24 +00:00
Ethan Nicholas
a0f7654fbe SkSL For statement now enforces correct initializer type
Bug: skia:11870
Change-Id: I960800ac554e3c189d0b708fa6cabccf071fd020
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/397460
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-04-16 20:48:03 +00:00
Ethan Nicholas
624a529fbd Added an API for creating RuntimeEffects using the SkSL DSL.
Change-Id: I305016d305455e2b90fe904d8da93cf7735cc38e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/389316
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-04-16 19:36:54 +00:00
Brian Osman
debcbbf6a8 Flip the arguments to sample() when passing both coords and a color
A subset of these signatures will be available to public SkSL, and
structured in a way that really pushes the coords as the primary
argument (and color as an optional one). In any case, I find this
ordering more natural.

Change-Id: I7b3bc962c5b305b9eeed1ae11ae1dc2ce7269364
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/396021
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2021-04-13 19:06:07 +00:00
Ethan Nicholas
8455893840 SkSL DSL matrix support
Change-Id: I9d43346df1a7611726f69ea54b4236e32d11d20c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/395696
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-04-12 22:03:31 +00:00
Ethan Nicholas
ee49efcc91 Added DSL fragmentProcessor and Sample function
Change-Id: I76348d151fbf27454a6f60e4f5f7e1774731e61b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/395216
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2021-04-12 14:29:51 +00:00
Ethan Nicholas
80f6235688 Fixed an issue with passing DSLVar as a DSL function parameter
DSLVar is normally implicitly converted to DSLExpression wherever it is
used, but the naively template-ized nature of DSLFunction::operator()
meant that it was accepting DSLVar parameters directly. Since DSLVar is
non-copyable, this meant DSLVar couldn't be passed directly to a DSL
function.

The smarter templates in this change are able to pass DSLVar by
reference.

Change-Id: Id04531f909cefd29b377c46e37fc4525bb29953c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/394161
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-04-09 17:13:27 +00:00
Ethan Nicholas
b14e6b9055 Added _Type suffix to DSL Type enum
No functionality changes, just making the naming consistent with our
other enums.

Change-Id: Ic9bc4a89f8373e4dc1060067a41468fb626e5fa1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/394160
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-04-08 21:55:05 +00:00
Ethan Nicholas
961d944648 SkSL DSL now uses node pooling
Change-Id: I6404cea5267b5da5a5948f0d6246688fef1fe4c4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/383758
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-03-16 21:18:55 +00:00
John Stiles
f3a28db703 Eliminate control-flow analysis.
We no longer derive a performance benefit from this pass in practice,
and it is a very expensive compilation step. It is also prone to fuzz-
related errors.

Doc: http://go/optimization-in-sksl

Change-Id: Ief08ffac659a8fe7fe92c92b9a5da14c9f713bc2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/381261
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-03-11 13:24:54 +00:00
Ethan Nicholas
24c1772ea4 Fixed an issue with DSL includes
It turned out that everywhere we were using or testing DSL code either
directly or indirectly imported big chunks of the SkSL library. These
imports turned out to be necessary; code written using just DSL.h would
fail with various template instantiation errors.

Change-Id: Iae72d15b0d6ef14614ac1a4ff08c36bc1876cd4d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/381638
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-03-09 20:07:00 +00:00
Ethan Nicholas
b14b63623c Added unary + and - DSL operators
These were accidentally omitted from the supported operator list.

Change-Id: Idecd17adb8b3f5043e36328c65ca12be33e990f4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/381637
Auto-Submit: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-03-09 14:19:03 +00:00
John Stiles
8f440b4e1e Optimize away no-op arithmetic in ConstantFolder.
Expressions like `x * 1`, `x *= 1`, `x + 0`, `x * 0`, or `0 / x` don't
actually do anything, and can be simplified to just `x` or `0`. (The
zero case must also check that `x` doesn't have side effects, because
`0 * myFunction()` still needs to call `myFunction`.)

`0 - x` is also detected and rewritten as `-x`.
`0 / 0` is left as-is.

This logic works for scalars and vectors; matrices are left as-is.

A similar optimization also occurs in the constant-propagation pass, so
we see almost no diffs in the tests. If control-flow analysis is turned
off, we do see some improvements. (I didn't reuse the existing code at
all, since it was designed around rewriting the CFG tree, but the
concept was identical.)

Change-Id: Ia99cd81f1d4cd3dafaa43ccac6a2261e3257a185
Bug: skia:11343
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/380356
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-03-06 01:33:35 +00:00
Ethan Nicholas
fe5d6928d0 DSL var values are now specified at construction time rather than in
Declare

This solves several issues caused by the lack of ordering guarantees in
C++; it was possible for the SkSL backend to look for the value of a
variable before its Declare() call gets processed. Moving the initial
value out of Declare should fix this whole class of problems.

Change-Id: I428fe230f1c312a0128c1f00c2a36cb95f4590a6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/380358
Reviewed-by: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-03-05 21:47:28 +00:00
John Stiles
f04e09cd9b Optimize Swizzles inside Swizzle::Make.
Swizzle optimizations now occur at IR generation time. These
optimizations are redundant with the control-flow optimization phase so
they are mostly not visible in our test output, but they do affect DSL
test results. Interestingly, they do improve our test output slightly
as well, for various reasons (e.g. we do not fully optimize lvalues in
the control-flow pass).

Change-Id: I6ebe6d71a5c22d9823b5fa500e43078915cbfb45
Bug: skia:11343
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/372257
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-03-05 20:09:55 +00:00
John Stiles
b9e4f649b4 Simplify constructors at IR generation time.
This performs the same simplifications as the control-flow phase, but at
IR generation time. There's no visible difference in the tests (besides
DSL) because these aren't new optimizations; they're just happening
at a different phase of compilation.

Change-Id: I26d241167b0e690b23f8f4370339714783c8d6fd
Bug: skia:11343
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/371482
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-05 15:07:35 +00:00
John Stiles
b3dcbb12ef Detect functions that fail to return a value, without using CFG.
This check now runs at function finalization time, before constant
propagation has occurred; this affected the "DeadIfStatement" test.

Our detection isn't smart enough to realize that a loop will run zero
times, so it treats `for` and `while` loops as always running at least
once. This isn't strictly correct, but it actually mirrors how the CFG
implementation works anyway. The only downside is that we would not flag
code like `for (i=0; i<0; ++i) { return x; }` as an error.

Change-Id: I5e43a6ee3a3993045559f0fb0646d36112543a94
Bug: skia:11377
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/379056
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-03-04 22:47:05 +00:00
Ethan Nicholas
daed2592bb Made SkSL DSL into public API
In addition to the unsurprising changes to eliminate references to
src/, we also had to tighten up some C++17-isms as they are not
permitted in public headers.

Change-Id: Ie5005a33d7a135e69fb66beca5e7a5f960dbd453
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/378496
Reviewed-by: Brian Osman <brianosman@google.com>
2021-03-04 21:03:58 +00:00
John Stiles
2dda50dd50 Add return-value check to the function finalizer.
Rather than have the inliner own this responsibility, the function
finalizer now detects if a function is supposed to return a value but
never actually does. This will allow us to detect this error case even
if the inliner is disabled. The inliner should no longer encounter
functions that claim to return a value but don't, so it will now assert
if one is encountered. (The inliner still has the logic to handle this
case gracefully, just in case.)

The check is currently very simple and doesn't analyze the structure of
the function, so it won't report cases where some paths return a value
and others don't, e.g. this will pass the test:

    int func() { if (something()) return 123; }

(This is good enough to resolve the inliner issue, though, as it only
occurred in functions with no value-returns at all.)

Change-Id: I21f13daffe66c8f2e72932b320ee268ba9207bfa
Bug: oss-fuzz:31469, oss-fuzz:31525, skia:11377
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/377196
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-03-03 16:29:22 +00:00
Ethan Nicholas
34c7e11492 Revert "Revert "SkSL DSL now reports the C++ line numbers of errors""
This reverts commit 3a4e19da8e.

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

Change-Id: I5ae97aba2df5b9c3b3dcca8e30da4e5ce9009109
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/376117
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2021-02-26 12:19:45 +00:00
Ethan Nicholas
b956304bc7 Revert "Revert "Add DSL PossibleExpression & PossibleStatement""
This reverts commit 4903482a2a.

Change-Id: Ie56583344897fcb2c072bcac4d97d582edeadf07
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375660
Reviewed-by: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2021-02-25 19:50:20 +00:00
Florin Malita
4903482a2a Revert "Add DSL PossibleExpression & PossibleStatement"
This reverts commit d42932a1b5.

Reason for revert: Breaking CMake and SKQP builds.

Original change's description:
> Add DSL PossibleExpression & PossibleStatement
>
> These are currently unused, but in future CLs they will be used to
> capture line number information in DSL error handling.
>
> Change-Id: Ieee730e0ad8323043437972fedb5bec471c367e4
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375069
> Reviewed-by: John Stiles <johnstiles@google.com>

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

Change-Id: I2062c9964569c9129a2145f9e45f849310129687
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375658
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
2021-02-25 13:19:19 +00:00
Florin Malita
3a4e19da8e Revert "SkSL DSL now reports the C++ line numbers of errors"
This reverts commit 8a43a2889e.

Reason for revert: Prereq revert for https://skia-review.googlesource.com/c/skia/+/375069

Original change's description:
> SkSL DSL now reports the C++ line numbers of errors
>
> This is done a best-effort basis. Positions will only be reported in
> Clang and GCC, and may not be reported in every possible situation.
>
> Change-Id: I7efb15781546b95e667fee34e488366174bb5f36
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/374600
> Reviewed-by: John Stiles <johnstiles@google.com>
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>

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

Change-Id: I173cb355533d6f99c9561177b68f56924fe8a98f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375657
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
2021-02-25 13:17:59 +00:00
Ethan Nicholas
8a43a2889e SkSL DSL now reports the C++ line numbers of errors
This is done a best-effort basis. Positions will only be reported in
Clang and GCC, and may not be reported in every possible situation.

Change-Id: I7efb15781546b95e667fee34e488366174bb5f36
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/374600
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2021-02-24 22:20:31 +00:00
Ethan Nicholas
d42932a1b5 Add DSL PossibleExpression & PossibleStatement
These are currently unused, but in future CLs they will be used to
capture line number information in DSL error handling.

Change-Id: Ieee730e0ad8323043437972fedb5bec471c367e4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/375069
Reviewed-by: John Stiles <johnstiles@google.com>
2021-02-24 21:04:18 +00:00
John Stiles
642cde289d Optimize @switch statements in SwitchStatement::Make.
At IR generation time, this CL limits our optimizations to only
@switch statements. A regular switch statement will only be optimized
during the optimization phase even if the switch-value is a known
compile-time constant. This is done to avoid upsetting our reachability
analysis.

Most of this CL is moving existing logic from SkSLCompiler into
SkSLAnalysis and SkSLSwitchStatement. Although the diffs look large, the
actual changes are very small.

Change-Id: I90920f41bc386dfa7a980ae7510f6681231a5120
Bug: skia:11340, skia:11342, skia:11319
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/372679
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-02-23 21:36:04 +00:00
Ethan Nicholas
63f75fc1b6 SkSL DSL function objects are now callable
Change-Id: I10d561eec456a7917681d7bdf0b1bd2f5ee5ad5f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/374217
Auto-Submit: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-02-23 20:06:18 +00:00
John Stiles
e1d1b08203 Migrate convertSwitch to SwitchStatement::Make.
This splits switch() construction into two stages.

- One version of Make takes an array of case-values and case-statement
lists, and is responsible for reporting errors if the case-values are
not unique or are improperly typed. This is what the IR generator or DSL
will start with on its first encounter with the switch statement.

- The other version of Make takes an array of already-processed
SwitchCases and can assume the invariant that they're all correctly-
typed with unique values. This is what we will have when a statement
is inlined or otherwise cloned. (We still assert this invariant, for
correctness' sake, but in release mode we assume it.)

This CL doesn't perform any optimizations at Make time yet; it does work
equivalent to how `switch` works in the IR generator today. It does
improve duplicate case-label checking slightly; duplicate case labels
are now reported, and duplicate `default:` labels are detected.
(Multiple `default` labels won't pass the parser, but they can be
constructed in DSL.)

Change-Id: I537ce2c8236152d58641fb1793619d66a62c01a8
Bug: skia:11342
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/372616
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-02-23 19:16:40 +00:00
Ethan Nicholas
bd97400744 Split IRGenerator's VarDeclaration processing into two parts
This allows things to align better between the IR and DSL sides
and gives us equivalent error handling on both sides.

Change-Id: I6d5569e29df51a4d1a6cb0ad1e6611d419dfe30c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/373737
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-02-22 22:02:45 +00:00
John Stiles
54f0049ddc Move Constructor generation and type-coercion out of IRGenerator.
The IRGenerator's `convertConstructor` and `coerce` were tied at the
hip--coercion can create a constructor, and creating a constructor can
cause type-coercion. This CL migrates IRGenerator::coerce to
Type::coerceExpression, and migrates IRGenerator::convertConstructor to
Constructor::Make.

Most constructor creation should go through Constructor::Make instead of
make_unique<Constructor> for best results. There are exceptions to this
rule:

- during the Compiler's `optimize` phase, we hold raw pointers to
unique_ptrs of existing expression trees, and are manually tracking
variable usage counts, so adjusting the IR tree should be done with
extreme care. Continue to use make_unique here to avoid any "surprise
improvements."

- the Rehydrator is attempting to recreate an IR tree exactly as it used
to be and doesn't want additional optimization or fixups

There are still Constructor-related optimizations in simplifyExpression
which are not yet implemented in Constructor::Make. These are migrated
to Constructor::Make at http://review.skia.org/371482

Change-Id: I0f3876f932835fc2e347ae95414bc490085f120c
Bug: skia:11342
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/370876
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-02-19 18:53:52 +00:00
John Stiles
b4d7b58585 Improve error reporting from DSL unit tests.
Previously, a DSL unit test failure would not report the actual text
generated by the DSL, or the line number of the failure.

Added a new macro EXPECT_EQUAL which
- supports DSL statements, DSL expressions, and IR nodes equally
- reports both the expected string and actual DSL output
- reports the line number of the failure
- always compares in a whitespace-insensitive fashion
- supports passing rvalue DSL expressions directly, rather than forcing
  us to create single-use lvalues for each test

Existing DSL tests have been updated to use this macro.

A failing test looks like this:

FAILURE: ../../tests/SkSLDSLTest.cpp:107	(Failed on line 146)
Expected: float4(0.0, 1.0, 2.0, 3.0)
  Actual: float4(0.0, 1.0, 2.0, 4.0)
 [DSLFloat, Mock]

Change-Id: Ie99d449690252f289bf48a66ab9c58e19dda9a07
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/372198
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-02-19 18:09:58 +00:00
Ethan Nicholas
fa648a1be3 Renamed DSL Ternary to Select
Change-Id: Idd0d49d3564dc3a24455db3c504ffa124f34dd05
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/371336
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2021-02-17 18:26:56 +00:00