Commit Graph

117 Commits

Author SHA1 Message Date
John Stiles
318ad4bb19 Improve control-flow support in early-return detection.
Previously, early-return detection worked by ensuring that a function
had a maximum of one return statement, positioned at the end of the
function. However, this technique did not support if-else statements:

   if (a) { ...; return x; } else { ...; return y; }

This meant that many simple cases were unnecessarily wrapped in a do-
while loop to handle control flow issues that didn't actually occur.

Our early-return detection logic is now more flexible and looks for any
return statements that aren't at an exit point in the control flow,
instead of looking for exactly one return at the end of the code.

Change-Id: Iffe71adf2b9349ce8de42ba8301ccc52abe2882b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313418
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-08-27 16:04:58 +00:00
John Stiles
735a5a7e82 Allow .fp files to return a color from main().
Existing .fp files that assign their output to sk_OutColor will continue
to work as before. An error will be generated if an .fp file tries to
mix-and-match return statements and sk_OutColor assignment; only one or
the other is allowed within a single .fp file.

Change-Id: I53bc0e8b79b2fdd64a020a7e5b35a905f9b05c94
Bug: skia:10549
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313197
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-08-26 17:17:24 +00:00
John Stiles
3be08b6dc6 Add unit tests for early-return detection.
Two cases are added to the tests:
- We wrap early returns in a do-while block.
- We wrap `if (x) { return y; } else { return z; }` in a do-while block.

In a followup CL, the second case will be detected as "not an early
return" because all returns occur at an exit point. This means that the
first unit test will remain the same, and the second test will no longer
wrap its body in a do-while block or add breaks.

Change-Id: Id1ed880c6fb4b3fd2c373e32b7447f74d0901ab8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313417
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-08-26 16:41:03 +00:00
Ethan Nicholas
765d2feaa7 optimized SkSL inlining output
We were previously defensively copying the arguments to inline functions
into temporary values in all cases. We now detect some cases where that
is not necessary and use the arguments directly.

Change-Id: I9739643157743fdbcefbac9f36be93ea6ecde6f7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/312489
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2020-08-26 13:08:53 +00:00
John Stiles
2064111d55 Fix early-return misdetection in the inliner.
The IR generator was previously unable to see inside sub-blocks when
checking for early return statements, so a function like this:

half fn() {
  {
    return 0.0;
  }
}

Would be wrapped with an unnecessary `do { ...; break; } while (false)`
construct during the inlining process.

Change-Id: Ie804261643b0bab38a08787d0b9d168a03faf070
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313206
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-08-25 22:51:31 +00:00
John Stiles
c37d551167 Add unit test for return statements wrapped in a block.
The inlining output for these statements is optimized in a followup CL.

Change-Id: I3a9a0fdca27e6a0ce80fe80b8869b1be677a8443
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313207
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>
2020-08-25 21:47:41 +00:00
Ethan Nicholas
7018bcfbc9 Reland "SkSL now supports uniform array types"
This is a reland of 284f2c4bea

Original change's description:
> SkSL now supports uniform array types
> 
> Change-Id: I809e9c424ee92b05f0a87d75d1384c92849e1474
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308498
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
> Reviewed-by: John Stiles <johnstiles@google.com>

Change-Id: I176f7fbdcbf3700e51e2303b06a4e906d22b2300
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/312244
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2020-08-20 20:39:12 +00:00
Ethan Nicholas
95b24b9a9d Revert "SkSL now supports uniform array types"
This reverts commit 284f2c4bea.

Reason for revert: leak is angering ASAN

Original change's description:
> SkSL now supports uniform array types
> 
> Change-Id: I809e9c424ee92b05f0a87d75d1384c92849e1474
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308498
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
> Reviewed-by: John Stiles <johnstiles@google.com>

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

Change-Id: I614f2f5cbe8bba7fc8678143fe059c7b69866254
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/312077
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2020-08-20 00:08:14 +00:00
Ethan Nicholas
284f2c4bea SkSL now supports uniform array types
Change-Id: I809e9c424ee92b05f0a87d75d1384c92849e1474
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/308498
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2020-08-19 21:50:56 +00:00
John Stiles
1f02286ea6 Remove sk_InColor from unit tests.
It's been replaced with a `uniform half4` in tests where it was needed,
which tends to generate similar code overall.

Change-Id: Iacc062efaeae37ebecf78505abe0fc563b69ceb0
Bug: skia:10619
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/311099
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>
2020-08-19 21:26:54 +00:00
John Stiles
9d944236e8 Fix simplification of switch statements with casts.
The original code assumed that the switch value and case value would
both be IntLiterals, and asserted if this were not true. However, in
sufficiently complicated cases, the switch value can sometimes be a
Constructor containing a scalar.

It's possible that there's a fix to constant propagation which would
flatten out this Constructor to just a scalar, but that has eluded me
for today, and this approach does seem to solve the issue. (Also, it's
surprising that the optimizer does not notice that it can simplify
`half4(1.0, 2.0, 3.0, 4.0).yyyy`.)

Change-Id: Id490b15c724dd174c448665a19242cc80cdce213
Bug: skia:10623
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/311636
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-08-19 18:43:27 +00:00
John Stiles
0e8149c6bd Add support for more basic types in SkSLCPPCodeGenerator.
While writing test code for skia:10623, I encountered a separate bug in
the SkSL compiler. Specifically, the codegen would assert when trying to
emit a function that returned an int. There were several basic types
missing from `glsltype_string`. I've added them, and created a unit
tests to exercise a subset of them.

Change-Id: Ied6aaacc67f472998cb6673490c4d98ce98886d2
Bug: skia:10631
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/311453
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>
2020-08-18 17:19:16 +00:00
John Stiles
48bdf6ddb1 Use a scoped block for inlined return statements.
Inlined return statements emit two statements--an assignment, then a
break. If scope braces are otherwise missing, the break statement will
end up in the wrong place. i.e.:

Mistranslated:
	if (foo) return bar;  --> if (foo) out = bar; break;

Translated properly:
	if (foo) return bar;  --> if (foo) { out = bar; break; }

Change-Id: Id992abf64ad09e6752f64c71cb556f05c868a453
Bug: skia:10607
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/310177
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-08-14 13:05:16 +00:00
John Stiles
8c91c93dce Refuse to inline SkSL with returns inside breakable constructs.
We do not have a good mechanism to break out of a nested for/while loop
or switch statement. Our inlining approach generates incorrect code in
those cases, and there's no apparent fix, since we don't have a
mechanism for subverting control flow like 'goto'. When we detect this
case, disable inlining for that function.

Change-Id: Ic4180b367a3895806b0cc36872155185138826e1
Bug: skia:10606
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/310063
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-08-13 19:10:02 +00:00
John Stiles
776c2841f8 Move onDumpInfo calls in gencode to the private section.
`onXxxxx` methods in Skia generally appear to be non-public, which I did
not realize until after originally implementing this task.

Followup CLs will update the non-gencode `onDumpInfo` methods to be
private as well.

Change-Id: I807eee132b080f72f6b040e1ca7f687be25dff11
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309883
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
2020-08-13 14:48:51 +00:00
John Stiles
cab588677b Add GrProcessor::onDumpInfo for subclass info dumps.
This CL also marks `GrProcessor::dumpInfo` as final. This prevents a
subclass from mistakenly overriding `dumpInfo` instead of `onDumpInfo`.

`onDumpInfo` is responsible for providing the same data as `dumpInfo`,
except that the FP name is automatically prepended.

Change-Id: I2b44c30a01bc65e9d88321cc21651a94e20074c6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309793
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
2020-08-12 20:20:51 +00:00
John Stiles
8d9bf6467b Reland "Guard dumpInfo() calls with GR_TEST_UTILS, instead of SK_DEBUG."
and
"Guard gencode dumpInfo() calls with GR_TEST_UTILS, instead of SK_DEBUG"
and
"Remove dumpInfo() entirely when GR_TEST_UTILS is off."

This is a reland of 26900788ef
and b5e8a2533a
and d7b09c4c3a
and unit tests are now fixed.

Original change's description:
> Guard dumpInfo() calls with GR_TEST_UTILS, instead of SK_DEBUG.
>
> (One exception: the `dumpInfo` in GrVkCommandPool is wrapped with
> SK_TRACE_MANAGED_RESOURCES to match its peers in GrVkManagedResource.)
>
> Change-Id: I6cf55fa2bb5687f79a2cc0c2a9c02a629bfd4f8e
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309556
> Commit-Queue: John Stiles <johnstiles@google.com>
> Auto-Submit: John Stiles <johnstiles@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>

Change-Id: I16e6606082a814b4fa5ef58d1096fc915f5ac704
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309721
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
2020-08-12 19:46:41 +00:00
John Stiles
47b4e22303 Reland "Implement dumpInfo for .fp files."
This is a reland of a1df23c8b7

Original change's description:
> Implement `dumpInfo` for .fp files.
>
> Change-Id: I40f6c1a02e194f090e67a0e3f2d7d83cd2317efd
> Bug: skia:8434
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309139
> Commit-Queue: Brian Osman <brianosman@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>
> Auto-Submit: John Stiles <johnstiles@google.com>

Bug: skia:8434
Change-Id: If485635440b800f8a282c871a1c5f2801608d3c7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309660
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>
2020-08-12 14:26:36 +00:00
Brian Osman
9487e9b2a0 Revert "Implement dumpInfo for .fp files."
This reverts commit a1df23c8b7.

Reason for revert: Needs c++17 library as written

Original change's description:
> Implement `dumpInfo` for .fp files.
> 
> Change-Id: I40f6c1a02e194f090e67a0e3f2d7d83cd2317efd
> Bug: skia:8434
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309139
> Commit-Queue: Brian Osman <brianosman@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>
> Auto-Submit: John Stiles <johnstiles@google.com>

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

Change-Id: I09b98e83735bc30ec8a2e313e4b76a9eb6a7631a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:8434
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309656
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2020-08-12 13:19:48 +00:00
John Stiles
a1df23c8b7 Implement dumpInfo for .fp files.
Change-Id: I40f6c1a02e194f090e67a0e3f2d7d83cd2317efd
Bug: skia:8434
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309139
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-08-12 13:08:46 +00:00
John Stiles
fbd050bd0b Enable ClangTidy check modernize-make-unique.
The majority of existing call sites were automatically updated using
clang-tidy -fix. A small handful required a manual update,
e.g. CppCodeGen.

This check is a bit lenient, and in particular will not flag cases like
`std::unique_ptr<Base>(new Derived())` which is still pretty common
throughout our codebase. This CL does not attempt to replace all the
cases that ClangTidy does not flag.

Change-Id: I5eba48ef880e25d22de80f321a68c389ba769e36
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/307459
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2020-08-03 17:53:52 +00:00
Brian Osman
82329004d0 SkSL: Disallow fragmentProcessor variables in several places
We only want SkSL to contain fp variables at global scope, and to sample
directly from references to those global variables. Anything else will
confuse our sample-usage analysis, and often leads to asserts in the CPP
or pipeline-stage generators.

Bug: skia:10514
Change-Id: Ie1ef10821c1b2a946a92d050fea45d95569bc934
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/304599
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2020-07-31 20:09:14 +00:00
Ethan Nicholas
c18bb51735 SkSL include files are now stored in a binary format
This speeds up compiler construction, because we no longer have to parse
and process a bunch of SkSL source code during startup.

Change-Id: I6d6bd9b5ce78b1661be691708ab84bf399c6df8b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305717
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2020-07-31 13:48:25 +00:00
John Stiles
b3038f8cb5 Remove layout(key) support for rects and points.
It's hard to imagine a scenario where it makes sense to recompile a
shader for every possible point or rect.

Change-Id: Ic4ca9a4826c4ae4b604705549170503c8ec580a6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/306075
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-07-28 00:26:34 +00:00
John Stiles
45f5b031b3 Allow GLSL processor keys to use floats with full precision.
Previously, floats would be converted to int32 using a C-style cast when
added to a processor key, truncating any fractional component of the
value. This would cause two processors compiled with different floats to
generate the same key.

The float is now sk_bit_cast to a uint32 instead; this will preserve the
uniqueness of all values.

Additionally, the CPP generator will now abort if asked to add an
unsupported type to the processor key. Previously, it would do a C-style
cast to int32 for all unrecognized types and hope for the best.

Change-Id: I270ae8b3036497a9e9a77747255f763d9aad1927
Bug: skia:10486
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305572
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2020-07-27 22:14:50 +00:00
Brian Osman
b5f0f52831 SkSL: Salt inline identifiers in PipelineStage and FragmentProcessor passes
Fixes a bug with name conflicts in the final SkSL.

Bug: skia:10526
Change-Id: Ic238f89dd778c186e775ecbaabfbaed9e426274f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305563
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
2020-07-24 19:23:20 +00:00
Brian Osman
12c5d29ba6 In FPs, store pointers for all child slots, even nullptr
This simplifies things like ConstantOutputForConstantInput and
invokeChild. It also removes the need for child indices: generated
FPs now directly refer to their children by slot number.

Change-Id: I69bbb042d5d72d21b999256f969c467702d0774d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302436
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2020-07-14 15:43:56 +00:00
Brian Osman
1298bc46ac Change SampleMatrix to SampleUsage
It now tracks all sample calls of a child (matrix, explicit coords,
pass through). There is now just one registerChild() call, and the
sampling pattern of that child is fully determined by the SampleUsage
parameter.

Change-Id: Iaadcd325fca64a59f24192aadd06923c66362181
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299875
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2020-07-01 16:37:43 +00:00
Michael Ludwig
fc2fdf025e Support sample coords in .fp main()
This removes the code generation support for @coordTransform and sk_TransformedCoords2D
when processing .fp files. Instead, the main() function can optionally add a float2
parameter. This is marked as the SK_MAIN_COORDS builtin, just like the main function
for a runtime pipeline stage.

Bug: skia:10416
Change-Id: I0c192d890bb798a1167bc445003f6ddffe6118f0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299687
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-06-30 15:18:03 +00:00
Michael Ludwig
fbe28593e5 Remove GrFragmentProcessor::addCoordTransform()
At this point, every created instance of GrCoordTransform is an identity
so can be removed. Adding it manually using addCoordTransforms() is no
different than relying on the (current) implicitly returned coord
transform if the FP calls setUsesSampleCoordsDirectly().

Removing the addCoordTransform() lets us enforce that this remains the
case and this CL also deletes all of those members that were previously
used to provide access to the sample coordinates.

As part of this, GrFragmentProcessor.h and many other files no longer
need to include GrCoordTransform.h. This exposed a surprising popularity on
SkMatrixPriv.h so I updated those files to include that header directly.

Technically, a .fp file can still have an @coordTransform section and
the sksl generator will try and call addCoordTransform, which will then
fail to build. A follow up CL removes that support in .fp generation.

Bug: skia:10416
Change-Id: I5e4d2bb49ee6d7e56ac75ca00be5631106fec20b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299291
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-06-29 16:58:54 +00:00
Michael Ludwig
e88320baec Update how sample(matrix) calls are invoked in SkSL
This removes the kMixed type of SkSL::SampleMatrix. All analysis of FP
sampling due to parent-child relationships is tracked in flags on
GrFragmentProcessor now.

The sample strategy is tracked as follows:
- An FP marks itself as using the local coordinate builtin directly (automatically done for .fp code based on reference to sk_TransformedCoords2D[0]).
- This state propagates up the parent towards the root, marking FPs as using coordinates indirectly. We stop the propagation when we hit a parent FP that explicitly samples the child because it becomes the source of the child's coordinates.
   - If that parent references its local coordinates directly, that kicks off its own upwards propagation.
- Being sampled explicitly propagates down to all children, and effectively disables vertex-shader evaluation of transforms.
   - A variable matrix automatically marks this flag as well, since it's essentially a shortcut to (matrix expression) * coords.
- The matrix type also propagates down, but right now that's only for whether or not there's perspective.
   - This doesn't affect FS coord evaluation since each FP applies its action independently.
   - But for VS-promoted transforms, the child's varying may inherit perspective (or other more general matrix types) from the parent and switch from a float2 to a float3.
- A SampleMatrix no longer tracks a base or owner, GrFragmentProcessor exposes its parent FP. An FP's sample matrix is always owned by its immediate parent.
   - This means that you can have a hierarchy from root to leaf like: [uniform, none, none, uses local coords], and that leaf will have a SampleMatrix of kNone type. However, because of parent tracking, the coordinate generation can walk up to the root and detect the proper transform expression it needs to produce, and automatically de-duplicate across children.

Currently, all FP's that are explicitly sampled have a signature of (color, float2 coord). FP's that don't use local coords, or whose coords are promoted to a varying have a signature of (color).
   - In this case, the shader builder either updates args.fLocalCoords to point to the varying directly, or adds a float2 local to the function body that includes the perspective divide.

GrFragmentProcessor automatically pretends it has an identity coord transform if the FP is marked as referencing the local coord builtin. This allows these FPs to still be processed as part of GrGLSLGeometryProcessor::collectTransforms, but removes the need for FP implementations to declare an identity GrCoordTransform.
   - To test this theory, GrTextureEffect and GrSkSLFP no longer have coord transforms explicitly.
   - Later CLs can trivially remove them from a lot of the other effects.
   - The coord generation should not change because it detects in both cases that the coord transform matrices were identity.

GrGLSLGeometryProcessor's collectTransforms and emitTransformCode has been completely overhauled to recurse up an FP's parent pointers and collect the expressions that affect the result. It de-duplicates expressions between siblings, and is able to produce a single varying for the base local coord (either when there are no intervening transforms, or the root FP needs an explicit coordinate to start off with).


This also adds the fp_sample_chaining GM from Brian, with a few more configurations to fill out the cells.

Bug: skia:10396
Change-Id: I86acc0c34c9f29d6371b34370bee9a18c2acf1c1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/297868
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2020-06-25 14:48:34 +00:00
Michael Ludwig
9861b7ca22 Switch inline variables to use a counter
Bug: skia:10424
Change-Id: Ic329b7de3a02034541094cd7b0cb4e458631e26f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/298556
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-06-25 00:49:49 +00:00
Michael Ludwig
9aba625ec3 Move setSampleMatrix and setSampledWithExplicitCoords into child registration
Bug: skia:10396
Change-Id: I0c117ab4d95737b76dec5bce16103b9058218fb8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/297065
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2020-06-22 21:20:20 +00:00
John Stiles
5081942c0d Optimize CPP code generation.
Previously, we were limiting our calls to appendVAList to 512-byte
chunks to avoid a potential buffer overflow. This had two problems:
1 - it did not avoid the buffer overflow :(
    see chromium:1092743
2 - every call to appendVAList is expensive; it incurs a resize of the
    code buffer (alloc new, memcpy, free old)

This CL removes the 512-byte cap as the buffer overflow issue was
resolved at http://review.skia.org/297276

This CL also includes a few more minor improvements.
- `codeAppendf` now uses a raw string so the gencode is easier to read.
- Optimized `SkStringPrintf("%s", foo)` to `SkString(foo)`.
- Optimized `strA = strB` to `strA.swap(strB)` where safe to do so.

Change-Id: Ia0909a68719848dd2ca655066a9bc6929c8fd09f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/297358
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2020-06-19 13:25:05 +00:00
John Stiles
3779f448ca Add helper method to clone and register a child FP.
This will remove common boilerplate from our gen-code, and gives us a
place to put common child-cloning boilerplate.

Change-Id: I6101655af89d4c5844ec908b81ce4f6e5d59f834
Bug: skia:10217
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/296177
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2020-06-15 15:43:05 +00:00
John Stiles
88183900a5 Honor return value of registerChildProcessor when creating child FPs.
The current implementation ignores return value from
`registerChildProcessor` and, surprisingly, assumes that a cloned FP
index will match the original FP index. This version honors the return
value.

(In practice, I have not seen any cases where the current implementation
has caused actual breakage.)

Updating common code-gen had large ripple effects in the SkSL unit
tests. While repairing the tests, I also took the opportunity to use
raw-strings to pass the source SkSL text, and annotated the `expectedH`
and `expectedCPP` blocks to make the tests easier to understand at a
glance.

Change-Id: I71be69d9e4620963b3ef49ad8e0dba3b40af7f4f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/295452
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2020-06-11 17:46:54 +00:00
Ethan Nicholas
e8ad02c6e9 Revert "Reland "Revert "Omit dead SkSL functions"""
This reverts commit a15f2bfb6f.

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

Change-Id: I64cc7830281ee69bf3377c5b6daa3d96ccf4769e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293976
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2020-06-04 02:46:55 +00:00
Ethan Nicholas
a15f2bfb6f Reland "Revert "Omit dead SkSL functions""
This reverts commit fd1173ac71.

Reason for revert: TSAN failure: https://chromium-swarm.appspot.com/task?id=4c93823229fa6a10

Original change's description:
> Revert "Revert "Omit dead SkSL functions""
> 
> This reverts commit 7c969f26bc.
> 
> Change-Id: I8fb99f271e2ecaeb83d570cc2d2cf8851bc776f0
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293338
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>

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

# Not skipping CQ checks because this is a reland.

Change-Id: Iab3ee5a336074676ebd0b761922ececf189752ef
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293843
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2020-06-03 17:14:18 +00:00
Ethan Nicholas
fd1173ac71 Revert "Revert "Omit dead SkSL functions""
This reverts commit 7c969f26bc.

Change-Id: I8fb99f271e2ecaeb83d570cc2d2cf8851bc776f0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293338
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2020-06-03 14:22:18 +00:00
Ethan Nicholas
7c969f26bc Revert "Omit dead SkSL functions"
This reverts commit 97fe0cbed2.

Reason for revert: ASAN failures

Original change's description:
> Omit dead SkSL functions
> 
> Now that SkSL inlines functions, dead functions are very common. This
> change causes them to be omitted from the final output.
> 
> Change-Id: Ie466a3f748812eff1a368498365c89d73ab0b7be
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292684
> Reviewed-by: Brian Osman <brianosman@google.com>
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>

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

Change-Id: Id20c5be67dd574d30d6f978ba610e43aa5018416
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293241
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2020-06-01 15:00:00 +00:00
Ethan Nicholas
97fe0cbed2 Omit dead SkSL functions
Now that SkSL inlines functions, dead functions are very common. This
change causes them to be omitted from the final output.

Change-Id: Ie466a3f748812eff1a368498365c89d73ab0b7be
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292684
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2020-06-01 14:27:38 +00:00
Ethan Nicholas
70728ef8e7 Revert "Reland "Revert "SkSL function inlining"""
This reverts commit 04ff61faae.

Change-Id: Ieb69c76b161ec9e003982d36bb2e28d055ad47a6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292266
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2020-05-28 13:27:58 +00:00
Ethan Nicholas
04ff61faae Reland "Revert "SkSL function inlining""
This reverts commit 2dd272bf15.

Reason for revert: breaking angle

Original change's description:
> Revert "Revert "SkSL function inlining""
> 
> This reverts commit 1b63b4ac69.
> 
> Change-Id: I8120bb10cecc6889f4f4fd7b4c3a61d250e49219
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/291358
> Reviewed-by: Brian Osman <brianosman@google.com>
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>

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

# Not skipping CQ checks because this is a reland.

Change-Id: Ib3117efd1b77e97899e636bcbc4d84200118bc36
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292264
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2020-05-27 19:57:58 +00:00
Ethan Nicholas
2dd272bf15 Revert "Revert "SkSL function inlining""
This reverts commit 1b63b4ac69.

Change-Id: I8120bb10cecc6889f4f4fd7b4c3a61d250e49219
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/291358
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2020-05-27 18:26:47 +00:00
Robert Phillips
1b63b4ac69 Revert "SkSL function inlining"
This reverts commit b65024b5f2.

Reason for revert: Shader compilation failures

Original change's description:
> SkSL function inlining
> 
> This first pass adds "one size fits all" function inlining, without any
> allowances for simple functions that don't need all of this machinery
> in place. Followup CLs will simplify common cases by e.g. not storing
> arguments in variables if they're already variables and not wrapping
> the function body in a loop when it isn't necessary.
> 
> Change-Id: I4fd8c1655ff48b9e4708bcca03a506df34ceadd9
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290127
> Reviewed-by: Brian Osman <brianosman@google.com>
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>

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

Change-Id: Ia6e643e0dcb66a4f0c2a377b89117047bbc5d058
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290801
Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-05-19 16:10:51 +00:00
Ethan Nicholas
b65024b5f2 SkSL function inlining
This first pass adds "one size fits all" function inlining, without any
allowances for simple functions that don't need all of this machinery
in place. Followup CLs will simplify common cases by e.g. not storing
arguments in variables if they're already variables and not wrapping
the function body in a loop when it isn't necessary.

Change-Id: I4fd8c1655ff48b9e4708bcca03a506df34ceadd9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290127
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2020-05-19 14:22:10 +00:00
Ethan Nicholas
5843012837 Add sample(child, matrix) to SkSL.
This allows fragment processors to sample their children with their
local coordinate system transformed by a matrix.

Change-Id: Ifa848bbd85b939bbc5751fec5cf8f89ee904bf39
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/282590
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2020-04-14 16:07:34 +00:00
Ethan Nicholas
16464c3232 Tracking uniform ownership
This is a prerequisite change for the upcoming sample(child, matrix)
function. By itself, this CL doesn't really change anything; it just
adds an ownership tracking feature which sample(child, matrix) depends
on.

Change-Id: I98b12e5fb062a2535af367931e7a932ea9c63a59
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/281337
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2020-04-06 19:02:37 +00:00
Greg Daniel
456f9b5fe9 Reland "Move GrGpuResource GrSurface and GrTexture into src."
This reverts commit f6ed96d1c2.

Reason for revert: google3 change landed

Original change's description:
> Revert "Move GrGpuResource GrSurface and GrTexture into src."
> 
> This reverts commit e5a06ce678.
> 
> Reason for revert: Need to make change in google3 first
> 
> Original change's description:
> > Move GrGpuResource GrSurface and GrTexture into src.
> > 
> > Must land https://chromium-review.googlesource.com/c/chromium/src/+/2087980
> > before this can land.
> > 
> > Bug: skia:7966
> > Change-Id: I60bbb1765bfbb2c96b2bc0c9826b6b9d57eb2a03
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275077
> > Commit-Queue: Greg Daniel <egdaniel@google.com>
> > Reviewed-by: Robert Phillips <robertphillips@google.com>
> 
> TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
> 
> Change-Id: Id39e0a351e49a87209de88a6ad9fadb0219db72c
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: skia:7966
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275216
> Reviewed-by: Greg Daniel <egdaniel@google.com>
> Commit-Queue: Greg Daniel <egdaniel@google.com>

TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com

Change-Id: I746ce739cb084cefc46f9dab24ef773e7c3cc621
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:7966
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275436
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2020-03-05 19:16:21 +00:00
Greg Daniel
f6ed96d1c2 Revert "Move GrGpuResource GrSurface and GrTexture into src."
This reverts commit e5a06ce678.

Reason for revert: Need to make change in google3 first

Original change's description:
> Move GrGpuResource GrSurface and GrTexture into src.
> 
> Must land https://chromium-review.googlesource.com/c/chromium/src/+/2087980
> before this can land.
> 
> Bug: skia:7966
> Change-Id: I60bbb1765bfbb2c96b2bc0c9826b6b9d57eb2a03
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275077
> Commit-Queue: Greg Daniel <egdaniel@google.com>
> Reviewed-by: Robert Phillips <robertphillips@google.com>

TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com

Change-Id: Id39e0a351e49a87209de88a6ad9fadb0219db72c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:7966
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/275216
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2020-03-05 01:46:51 +00:00