Commit Graph

8311 Commits

Author SHA1 Message Date
John Stiles
759880ab05 Pass non-temporary Program::Settings to convertProgram.
This will fix ASAN errors such as these:
https://logs.chromium.org/logs/skia/4e924a3651708511/+/steps/symbolized_dm/0/stdout

Change-Id: I49756df6e077cc8813f51f70082c88d861fa337f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/316451
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2020-09-11 16:37:34 +00:00
John Stiles
a003e8184e Fix inline code generation when literals appear in the argument list.
We don't expect raw literals to ever appear here; this is a defensive
maneuver. See http://review.skia.org/316440 for an example case where
raw literals accidentally made it all the way to the inlining pass, due
to a missing `coerce`.

Change-Id: I80198f2f135791931aa53e0d6d92f1edfe4fb3b5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315970
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-09-11 14:57:14 +00:00
Greg Daniel
d358cbebd4 Add support for plumbing GrDstSampleType through Ops and Pipeline creation.
This CL adds a new type GrDstSampleType to say how we will sample the dst.

We add tracking of the GrDstSampleType in the recording of GrOps and
then during execution passing the information along to the GrPipeline.

In general the tracking of GrDstSampleType is a global state of a GrOpsTask
so it is kept separate fro the DstProxyView which is more specific to a
single Op on the GrOpsTask.

Bug: skia:10409
Change-Id: Ie843c31f2e48a887daf96cee99ed159b196cb545
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315645
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-09-11 14:42:34 +00:00
Ethan Nicholas
1d88152de6 Fixed an SkSL optimizer error around constant propagation
Constant propagation wasn't performing type coercions, so we'd end up
propagating a constant into its final location and using the constant's
type rather than the destination type. This allowed things like
$floatLiteral to sneak into final output.

Change-Id: I5b63c70370095e291dea6374e139329b695fa0b0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/316440
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Auto-Submit: Ethan Nicholas <ethannicholas@google.com>
2020-09-11 14:02:44 +00:00
Brian Osman
c4cb3a6140 Refactoring determine_binary_type to fix some bugs
Four of the first 12 cases in the new unit test previously failed (the
logic to reduce from vector to scalar type coercion didn't test the
reverse order, so (half * float4) would only test if (half * float) was
possible going right-to-left.

Also, the matrix multiplication logic was missing a check when doing *=,
allowing things like (matrix *= vector) to compile (then fail later in
GL, etc.)

Finally, we were never checking if the op was valid for vectors when
doing the vector/scalar combination. Added test cases to
BinaryTypeMismatch that previously failed, and now work.

Change-Id: I1e2709e3ba4df31f9300672189826151eabe017a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315964
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2020-09-10 18:34:08 +00:00
John Stiles
73a6bff204 Run the optimizer until we stop finding improvements.
This will be especially important once more aggressive inlining is
enabled, as the optimizer will need to run dead-function elimination
passes after inlining.

Change-Id: I8ccd5d6a9a041ee2b0a3ec5ef305e5df875b6947
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315738
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-09-09 18:16:47 +00:00
Mike Klein
215d2b0fa4 impl SkMulDiv255Round with SkMul16ShiftRound
Inlining shift=8 is trivial for any compiler.
This eliminates the need to unit test the two functions are the same.

Change-Id: Icd181ff11eab73fba26755a9fbecd57260c38bbf
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315887
Commit-Queue: Mike Reed <reed@google.com>
Auto-Submit: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Reed <reed@google.com>
2020-09-09 17:01:17 +00:00
Michael Ludwig
04b9443274 Fix SkRRect::ConservativeIntersect when inputs share corner
Encountered while debugging new GrClipStack.

Basically, with the old checks, if aCorner == bCorner but A was a rect,
we'd end up rejecting it as not a viable intersection (failing the
testCorner == aCorner checks), but wouldn't fall through to the
testCorner == bCorner checks.

Instead of splitting the if-elseif-else into separate ifs, I chose to
add an additional if case that lets the ellipse containment check match
a few more cases when we know the two ellipses share an anchor point.

Change-Id: I6c8bc9a30d19a56f25da7d9be7832ff72dde1765
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315636
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-09-08 21:01:16 +00:00
Florin Malita
26c24eda3e SkArenaAlloc aligned under-allocation
We cannot rely on natural allocation alignment (8) after footer
installation.  Always compute and apply explicit alignment.

Bug: chromium:1124776
Change-Id: I5ff880409df83284b1f9668a771c2a750f72c148
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315646
Commit-Queue: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Herb Derby <herb@google.com>
2020-09-08 19:34:36 +00:00
Ethan Nicholas
e659214bc6 Revamped handling of SkSL node kinds
Moved the actual field into the base class, changed all of the enums
into non-overlapping enum classes, and finally renamed Type::Kind to
fix the ambiguity there.

Change-Id: I4e6c24d2dbbc7b1d12b7b7bf12e77c651eea7ed9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315318
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2020-09-08 15:00:10 +00:00
John Stiles
6eadf13783 Change Inliner signature in preparation for analyzer pass.
These changes don't seem to add much value in isolation, but they will
smooth our transition to inline analysis during optimization.

- The passed-in FunctionCall no longer needs to be a unique_ptr.
- The fInlinedBody is guaranteed to be a Block now. (This change caused
  a slight ripple effect in unit test output; in some cases it creates
  an additional newline in the final code. This is harmless.)
- has_early_return is checked earlier, before we've made any mutations
  to the FunctionCall. This should work around errors that can occur if
  a function is trying to inline itself. (Ideally we wouldn't be trying
  to do this at all, but either way, we shouldn't crash.)

Change-Id: I0a565d477f680c0ba061df2686a36e42aa75de95
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315599
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-09-08 14:52:30 +00:00
Brian Salomon
59c60b0cb3 Reland "Add idea of DataType to SkYUVAPixmapInfo."
This is a reland of ed63444587

Original change's description:
> Add idea of DataType to SkYUVAPixmapInfo.
> 
> DataType describes the data type of YUVA channels
> independent of how they are grouped into planes.
> 
> Adds mapping functions between SkColorType/channel count
> and DataType.
> 
> SkYUVAPixmapInfo can be constructed from DataType and will
> choose appropriate SkColorTypes for each plane.
> 
> Valid SkYUVAPixmapInfos now have the same DataType for each
> plane (could relax this in the future, esp for alpha plane).
> 
> SkYUVAPixmapInfo::SupportedDataTypes specifies the supported
> combinations of SkYUVAInfo::PlanarConfig and
> kYUVAPixmapInfo::DataType supported by a GrContext (based on
> supported texture formats).
> 
> SkImageGenerator/SkCodec YUVA query API now takes a
> SupportedDataTypes.
> 
> Change-Id: I8791234638e6ba3396d1e7960b7bc210edc6dd57
> Bug: skia:10632
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314276
> Reviewed-by: Leon Scroggins <scroggo@google.com>
> Reviewed-by: Robert Phillips <robertphillips@google.com>
> Commit-Queue: Brian Salomon <bsalomon@google.com>

Bug: skia:10632
Change-Id: I35b55b7477c11c822fdb3729a9f84acff1eb785d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/315284
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2020-09-03 18:05:17 +00:00
John Stiles
7571f9e490 Replace 'typedef xxxxx INHERITED' with 'using INHERITED = xxxx;'.
Mechanically updated via Xcode "Replace Regular Expression":

  typedef (.*) INHERITED;
    -->
  using INHERITED = $1;

The ClangTidy approach generated an even larger CL which would have
required a significant amount of hand-tweaking to be usable.

Change-Id: I671dc9d9efdf6d60151325c8d4d13fad7e10a15b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314999
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-09-03 03:41:26 +00:00
John Stiles
683beccf67 Migrate inliner-related tests to a separate unit-test file.
All tests are now GLSL-based instead of .fp based, for ease of
readability. DEF_TESTs which called test() more than once have been
split up into a separate individual DEF_TEST for each test() call, to
simplify fixups going forward.

Change-Id: I9202e95e9cafff3efc0c32aa3f3ca2eea04719fe
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314886
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-09-02 21:31:45 +00:00
Michael Ludwig
c7fa895e50 Revert "Add idea of DataType to SkYUVAPixmapInfo."
This reverts commit ed63444587.

Reason for revert: trying to unblock android roller, which incorrectly thinks this has a merge conflict: https://b.corp.google.com/issues/167576324

Original change's description:
> Add idea of DataType to SkYUVAPixmapInfo.
> 
> DataType describes the data type of YUVA channels
> independent of how they are grouped into planes.
> 
> Adds mapping functions between SkColorType/channel count
> and DataType.
> 
> SkYUVAPixmapInfo can be constructed from DataType and will
> choose appropriate SkColorTypes for each plane.
> 
> Valid SkYUVAPixmapInfos now have the same DataType for each
> plane (could relax this in the future, esp for alpha plane).
> 
> SkYUVAPixmapInfo::SupportedDataTypes specifies the supported
> combinations of SkYUVAInfo::PlanarConfig and
> kYUVAPixmapInfo::DataType supported by a GrContext (based on
> supported texture formats).
> 
> SkImageGenerator/SkCodec YUVA query API now takes a
> SupportedDataTypes.
> 
> Change-Id: I8791234638e6ba3396d1e7960b7bc210edc6dd57
> Bug: skia:10632
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314276
> Reviewed-by: Leon Scroggins <scroggo@google.com>
> Reviewed-by: Robert Phillips <robertphillips@google.com>
> Commit-Queue: Brian Salomon <bsalomon@google.com>

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

Change-Id: I72c39539a4766f10cac3ca3cdef6c503a8319ff1
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:10632
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314895
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
2020-09-02 21:26:39 +00:00
John Stiles
ad2319f7c4 Ensure that inlined if/else blocks are properly scoped.
The bulk of the diff is just reordering existing code; the logical
changes are very small.

Change-Id: I3b918e64f5229da43d43f0922e8b59a007a6ad3e
Bug: skia:10687
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314882
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>
2020-09-02 19:07:55 +00:00
Ethan Nicholas
da6320ca11 Disallow a bare ';' at the top level of SkSL files
It turns out the parser was accepting empty declarations, turning them
into an empty modifiers declaration. This was causing problems with a
CL that was going to disallow declarations in contexts where they
weren't allowed. Since this was never the intended behavior, we now
disallow it.

Change-Id: Iea56529c76a946e8002ce1e929790aec488fd4f5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314879
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2020-09-02 18:46:05 +00:00
John Stiles
2099ac7b48 Add unit tests for inlining if/else blocks.
The following tests show incorrect results from the inliner:
- SkSLFPInlinedIfBodyMustBeInAScope
- SkSLFPInlinedElseBodyMustBeInAScope

Change-Id: Iafc567f9a97f67f9b734edd348ee25a14939592a
Bug: skia:10687
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314880
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-09-02 18:31:05 +00:00
John Stiles
c0dd06d0cb Ensure that inlined statements are properly scoped.
Change-Id: I43479d8543ea4860be45614a65cf8ad4cec307d8
Bug: skia:10687
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314877
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-09-02 17:50:35 +00:00
John Stiles
8fa3b4e8cd Disallow inlining ternary true/false branches.
This prevents unnecessary work from being done, and also prevents us
from executing side-effects from the wrong side.

Change-Id: I4dbf3974388807f15e9eadb2abf1b1243d047ce2
Bug: skia:10688
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314797
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-09-02 16:14:35 +00:00
John Stiles
648a81e5e8 Add unit tests for the inliner.
Some of these tests worked perfectly, but others expose latent inlining
bugs. The following tests show incorrect results from the inliner:
- SkSLFPTernaryExpressionsShouldNotInlineResults
- SkSLFPInlinedWhileBodyMustBeInAScope
- SkSLFPInlinedDoWhileBodyMustBeInAScope
- SkSLFPInlinedForBodyMustBeInAScope

Change-Id: I523e2e3272dea01d5c194a478df6f39ecadf2f5c
Bug: skia:10687, skia:10688
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314796
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2020-09-02 15:39:35 +00:00
Brian Salomon
ed63444587 Add idea of DataType to SkYUVAPixmapInfo.
DataType describes the data type of YUVA channels
independent of how they are grouped into planes.

Adds mapping functions between SkColorType/channel count
and DataType.

SkYUVAPixmapInfo can be constructed from DataType and will
choose appropriate SkColorTypes for each plane.

Valid SkYUVAPixmapInfos now have the same DataType for each
plane (could relax this in the future, esp for alpha plane).

SkYUVAPixmapInfo::SupportedDataTypes specifies the supported
combinations of SkYUVAInfo::PlanarConfig and
kYUVAPixmapInfo::DataType supported by a GrContext (based on
supported texture formats).

SkImageGenerator/SkCodec YUVA query API now takes a
SupportedDataTypes.

Change-Id: I8791234638e6ba3396d1e7960b7bc210edc6dd57
Bug: skia:10632
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314276
Reviewed-by: Leon Scroggins <scroggo@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2020-09-02 13:21:45 +00:00
Brian Salomon
a0d913bef3 Separate our use of sampler object from GL support.
When sampler objects exist but we're not using them we bind 0.

Speculatively disable use on ANGLE to see effect on performance.

Change-Id: I5c76bd812760a5ac67a4327f2d02f4f831155029

Bug: skia:10644
Change-Id: I7ef23704b2ca11d92806f196589ec561a3ac9435
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314462
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2020-09-01 18:55:11 +00:00
John Stiles
cf936f9af1 Replace salting process in SkSLInliner with a symbol table check.
Ideally, we wouldn't need a counter at all here, and we could just rely
on the symbol table to check for name collisions. Unfortunately, this
fails in practice on a couple of tests, because we don't construct
programs in a strict top-to-bottom order--particularly when inlining.
However, by checking the symbol table before using a name, we can at
least solve cases where the inliner reuses a name that was taken in a
previous pass, which was why salt was originally added. This makes the
generated code much easier to read.

Change-Id: Ib69611c8df457fbd03b31e52158113ad4a8735d5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314277
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-09-01 13:30:29 +00:00
John Stiles
39616ec7c9 The inlined function body is now returned as a single Statement.
If only a single statement is necessary, it is returned as-is.
If multiple statements are needed, they are wrapped in a non-scoped
Block statement. If no statements at all are needed (!), null will be
returned.

Change-Id: I6ba373f73d339b8c2e7b8d39dfb28f13655e3d03
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313911
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-08-31 18:51:46 +00:00
Mike Reed
85f51b2a40 Simplify firstdirection
Change-Id: I30d3056dc97a16c08b85fd77120485ef07b18d96
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314037
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2020-08-30 15:01:02 +00:00
Mike Reed
3872c98951 Move convexity enum out of public
Also, move first-direction into SkPathRef.h so it can be referenced
by name in SkPath (instead of using uint8_t)

No functional change expected.

Change-Id: Ica4a8357a8156fd9a516118f23599a965b0fdd47
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313980
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2020-08-30 13:04:22 +00:00
Mike Reed
6052c0bee0 Only expose isConvex on path publicly.
Subsequent CLs can work on combining convexity and direction

Bug: skia:10670
Change-Id: Ia44769ea88ffd99a56d4c6729a80a2044e790ec2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313837
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
2020-08-28 16:56:29 +00:00
Brian Salomon
280fa3d303 Remove use of texture swizzle in GL backend.
This has always been a potential source of a bug. If the same texture is
used twice in a shader with different swizzles we would overwrite the
swizzle for the first use by that of the second use since there is
only one fixed function swizzle per texture. It's not part of the
sampler state.

We set the swizzle when it is a feature, but always to RGBA.

Also, highly speculative that this may improve ANGLE D3D11 ES3
performance compared to ES2.

Bug: skia:10644
Change-Id: I8877afc3043c5ddaafd26ea9f9bd372303328c71
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313682
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
2020-08-28 15:22:29 +00:00
Mike Reed
43c78abe04 Remember to track convexity/direction for IsA shapes (e.g. oval, rrect)
In a follow-up, I will explore more clearly tying together convexity
and direction internally -- perhaps a unified enum?
    [ unknown, convex_cw, convex_ccw, concave ]

Change-Id: I9fc2a2205f40050f4c24c5bec7fc25c8b6d2461c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313680
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2020-08-28 12:51:57 +00:00
Greg Daniel
638b2e8594 Add GrInternalSurfaceFlag for vulkan input attachment.
This also includes all the plumbing of this flag throughout our proxy
and surface system.

Bug: skia:10409
Change-Id: I48d40012049240cfa80e045ea090f68ce2d2ff0d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313676
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2020-08-27 20:05:29 +00:00
Adlai Holler
bcfc554fde Add GrDirectContext arg to SkImage::readPixels
Note: The polarity of the staging flag is inverted from usual because
a G3 dependency with no SkUserConfig.h relies on the legacy API.

Once this lands, we will migrate them and others, then remove the
staging API. The inverted staging flag is kind of nice, actually - I may
use that pattern in the future. It means less total CLs and it's just as
easy to flip the bit on or off during debugging.

Bug: skia:104662
Change-Id: I48cba1eeae3e2e6f79918c6d243e0666e68ec71b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/310656
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
2020-08-27 19:26:29 +00:00
Brian Osman
b6bd0d2094 Make SkRuntimeShaderBuilder safe for reuse
Previously, if you snapped off a shader and then changed uniforms
(without drawing & flushing), we'd trigger the SkData assert about
calling writeable_data when not-uniquely-owned. Now we lazily copy the
SkData when necessary.

Includes unit test that previously failed.

Bug: skia:10667
Change-Id: If8d9dd8106d41e66560d760cb36ed83371791fc7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313678
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2020-08-27 16:09:37 +00:00
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
Brian Salomon
be0e42cb8f New helpers for SkYUVAInfo when used with pixmaps.
SkYUVAPixmapInfo is a SkYUVAInfo with per-plane color types and row
bytes. It describes a set of pixmaps that make up a planar image.
Consolidates validity checks of the SkYUVAInfo with the color types
and row bytes. It can provide SkImageInfos for each plane and also
assist with configuring planes to share a common allocation.

SkYUVAPixmaps is a collection of SkPixmaps that are valid for a
SkYUVAInfo. It can either wrap existing SkPixmaps or allocate and
own the memory. It consolidates validity checking of SkPixmaps with
the SkYUVAInfo. Replaces sk_gpu_test::YUVAPixmaps.

Minor tweaks to SkYUVAInfo naming, parameter order consistency, adds a
hasAlpha() method.

Bug: skia:10632
Change-Id: Ib0f48b8448fff22805fd0c04e07887d0b7338b76
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/312886
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Leon Scroggins <scroggo@google.com>
2020-08-27 15:39:56 +00:00
Greg Daniel
398ecf1876 Remove unused factories that take characterizations.
Change-Id: I871319ee663261c06f9f9270813ee2908e38fecb
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313576
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2020-08-26 21:29:44 +00:00
Mike Reed
f2845ac499 Always (pre)compute path bounds when using a builder
Change-Id: I42ce8d2c7e6852a85b3aa798c772a2a0b1ce6c3b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313477
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2020-08-26 19:24:34 +00:00
Greg Daniel
c113f004de Remove renderable flag from texture createLazyProxy.
Besides some tests, we always set the renderable flag to kNo for this
function. No need to keep supporting a code path we don't actually use.
Tests that use to pass in kYes here have been converted to calling
createLazyRenderTargetProxy instead.

Change-Id: I91efe6cc51fd7ba04b711509ca26f18eba2af333
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313425
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-08-26 18:10:03 +00:00
Mike Reed
06d7c9d798 Revert "Revert "use pathbuilder""
This reverts commit 43e3e91883.

Change-Id: I43f6c195f96b1601225801ffaa05a3133c236eba
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313421
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Reed <reed@google.com>
2020-08-26 17:35:34 +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
Mike Reed
43e3e91883 Revert "use pathbuilder"
This reverts commit 4b25d41d96.

Reason for revert: grrrr, broke some layout test (a little)

https://test-results.appspot.com/data/layout_results/linux-blink-rel/40609/blink_web_tests%20%28with%20patch%29/layout-test-results/results.html

Original change's description:
> use pathbuilder
> 
> Change-Id: I4b7cd6aed0c8da44e6065bb171332e25988ec8cc
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313376
> Reviewed-by: Mike Reed <reed@google.com>
> Commit-Queue: Mike Reed <reed@google.com>

TBR=reed@google.com

Change-Id: I7a073aafcfddc398ab9a761719230f2427c987c6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313420
Reviewed-by: Mike Reed <reed@google.com>
2020-08-26 16:35:37 +00:00
Mike Reed
4b25d41d96 use pathbuilder
Change-Id: I4b7cd6aed0c8da44e6065bb171332e25988ec8cc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313376
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2020-08-26 14:58:13 +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
Mike Reed
ad5494d1d9 use pathbuilder
Change-Id: I11c18d4ff0e60cc33d742cf49359039395abc6b4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313256
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2020-08-25 22:27:20 +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
Mike Reed
92f6eb1602 use pathbuilder
Change-Id: I2bca419a3273a9cc8a984b0f4159f518968c6652
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/313077
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2020-08-25 16:29:48 +00:00
Robert Phillips
8025507f74 Simplify SkComputeBlurredRRectParams
Although cool, I don't know if this is worth the increased complexity
for an unused feature.

Change-Id: Id229beab176cebf5b7810fd1e44a5d1e25abcabc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/312848
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
2020-08-25 15:04:08 +00:00
Brian Osman
767f444feb SkRuntimeEffect SkSL has a new signature for main()
There is no more 'inout half4 color'. Effects return their output color.
If an effect wants the input color, it must use the (already existing)
approach of sampling a nullptr input shader.

The change is guarded for Chromium (so we can update their runtime color
filters in skia_renderer.cc).

For the GPU backend, FPs can now override usesExplicitReturn to indicate
that their emitCode will generate a return statement. If that's true,
then writeProcessorFunction doesn't inject the automatic return of the
output color, and emitFragProc will *always* wrap that FP in a helper
function, even as a top-level FP. GrSkSLFP opts in to this behavior, so
that the user-supplied return becomes the actual return in the FP's
emitCode.

Adapting the skvm code to this wasn't too bad: It looks fragile (what
happens if there are multiple returns?), but that's not really possible
today, without varying control flow.

Bug: skia:10613

Change-Id: I205b81fd87dd32bab30b6d6d5fc78853485da036
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/310756
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2020-08-25 13:36:28 +00:00