Commit Graph

569 Commits

Author SHA1 Message Date
Brian Osman
64b50bc708 Disallow most modifiers in runtime effects
Bug: skia:11301
Change-Id: Ib644235ef35f9fb37a1373ada6a6896005dc4451
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/558537
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2022-07-13 18:22:23 +00:00
Brian Osman
101ad96b34 Disallow all layout qualifiers (other than 'color') in runtime effects
Bug: skia:11301
Change-Id: Ie6a5ef920093b63983d8dbbdbaa94960fa7af83c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/558304
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2022-07-13 15:51:01 +00:00
John Stiles
5186379e5e Disallow function calls to main().
In practice, calls to main are not meaningful:
- If main is called in live code, it's recursive
- If main is called in dead code, it's eliminated

However, if optimization/dead-stripping is turned off, the dead-code
case emits bad code in our GLSL/Metal backends. Rather than add a
special case to the backends to work around an error in a meaningless
edge case, we now reject the function call entirely.

Prototyping main() is, as far as I can tell, harmless, so this
continues to be allowed.

Change-Id: I69916840c06810cd948bd74ff168ada1c4fc74f8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/557578
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Arman Uguray <armansito@google.com>
Commit-Queue: Arman Uguray <armansito@google.com>
2022-07-11 20:55:12 +00:00
John Stiles
efa098c2f0 Require newlines after directives.
The fuzzer has noticed that we didn't enforce this. Now we issue an
error if directives don't have a newline at the end.

Change-Id: I29064bec2a2be628d87b7286cd16ac0089713413
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/557380
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2022-07-11 15:37:29 +00:00
Arman Uguray
9c242fff99 [sksl] Eliminate unreachable blocks inside switch cases
Added code to remove code within switch statements due to break, return,
and continue statements. The logic is applied conservatively and only
among the statements of an individual switch-case statement without
affecting other cases.

Bug: skia:13484
Change-Id: Id5b936ca91e562a5180a31a039a85de9e093961d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/556376
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Arman Uguray <armansito@google.com>
2022-07-07 21:23:54 +00:00
Brian Osman
680633d465 Runtime effects: Restrict uniform matrices to be square
The fuzzer figured out that #version 300 would let you declare a
nonsquare matrix uniform. Quite a bit of downstream code isn't ready for
that, yet. For now, just tighten things up so the var declaration checks
match the types supported by SkRuntimeEffect::Uniform.

Bug: oss-fuzz:48829
Change-Id: I63daf3dfa7deb795901f19553805cf2351378620
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/556359
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2022-07-07 15:21:01 +00:00
John Stiles
db253e24a2 Do not optimize away intrinsics with non-finite results.
Previously, we would treat double values outside [-FLT_MAX, FLT_MAX]
as finite. In practice, this introduces many hazards; any place in the
code which handled the double value as a float would silently convert
the value to infinity. This includes high-traffic calls like
Literal::MakeFloat.

Note that the if checks are structured in a slightly awkward way to
ensure that NaNs are treated as non-finite.

The original buggy behavior can be seen at http://review.skia.org/556078

Change-Id: Ic126afe57c3d6c7aa3edf9c8f7e339abc5f77739
Bug: oss-fuzz:48592
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/556080
Reviewed-by: Arman Uguray <armansito@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2022-07-06 20:37:29 +00:00
John Stiles
48b27317b4 Fix fuzzer-discovered error with range checks.
The fuzzer managed to create a NaN using a carefully-crafted mix of
intrinsics and constant folding. (`cosh(421)` is a very large double,
which becomes +Inf when cast to float, which is then multiplied by 0;
zero times infinity is NaN.)

Our code which checked to see if a value is in range of an int did not
consider NaNs and their always-false behavior, so it incorrectly
decided that NaN was in range. This CL reverses the check so that a NaN
will not pass, but all other values will behave the same.

Followup CLs should probably also tighten up the folding/optimizer
behavior so that NaNs/Infs are not created at all.

Change-Id: Idd2b0447ebe115e00bdba63ca7ff655f6c902fc6
Bug: oss-fuzz:48592
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/555009
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2022-07-06 14:24:59 +00:00
Ethan Nicholas
26afe80a62 Fix assertion failure with 'uniform texture2D'
Bug: oss-fuzz:48371
Change-Id: Ia92a652022985ea738791f3e2e57d360a04b05bd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/554517
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2022-06-30 14:48:48 +00:00
Ethan Nicholas
4d378b4b9f Added threadgroup modifier to compute shaders
Change-Id: I3a244bcd25994217d5107de98c24c144f2dabdf0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/543076
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2022-06-29 18:06:28 +00:00
Ethan Nicholas
0360b2798b Require compute shader in/out arrays to be unsized
Turns out sized arrays don't work currently; the path of least
resistance is simply disabling them for now. See bug for explanation.

Bug: skia:13471
Change-Id: I90e321ccae199ac5697d1d9a63f73e30554e2981
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/553583
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Arman Uguray <armansito@google.com>
2022-06-28 20:03:12 +00:00
Ethan Nicholas
4144b8abb4 Added preliminary SkSL Metal compute shader support
This adds mostly-functional compute shader output to SkSL. This does not
add overall compute shader support to Skia; it still needs to be
integrated into the Skia pipeline before it is possible to actually use
compute shaders in practice.

Change-Id: Ic5c69863704f141d16bb191224a817e44f4a8565
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/539060
Reviewed-by: Arman Uguray <armansito@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2022-06-15 18:52:42 +00:00
Iliyan Dinev
f65a8fa59e Fix UnitTest_SkSLVectorScalarMath_GPU FP16 precision-issue
Bug: skia:13420
Change-Id: I4b99a5d75e9fa4ce87b3f0bcb1210d2ec47ae112
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/548996
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2022-06-10 17:20:59 +00:00
John Stiles
8481c5fca7 Fix fuzzer-discovered error with positions when casting arrays.
We were returning Expressions from ConstructorArrayCast which didn't
match the passed-in Position. We now make sure to set the position of
the returned expression properly.

Change-Id: I2099d006e7dff2c94a9590c7159c4b0947c91257
Bug: oss-fuzz:47935
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/548483
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>
2022-06-10 13:59:26 +00:00
John Stiles
a75ee2620b Optimize away field accesses to known structs.
This is necessary for proper constant-folding, and can help us generate
better code. Most examples are pretty contrived, but a realistic benefit
can be found in inlined code (see TrivialArgumentsInlineDirectly.glsl).

Change-Id: I86aac9d48a70ae35a15109fd0b04400ae39a3b47
Bug: skia:13387
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/547277
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2022-06-06 20:38:43 +00:00
John Stiles
ad06265b37 Reland "Add unit test covering struct field folding."
This reverts commit 3ba37e1d38.

Reason for revert: disabled test on Win+Intel/Android+Adreno6xx GPUs
(skia:13393)

Broke out non-folding tests to a separate test due to failures on
Quadro/RTX3060. (skia:13395)

Original change's description:
> Revert "Add unit test covering struct field folding."
>
> This reverts commit 0cbba91940.
>
> Reason for revert: returns red on Adreno and Intel
>
> Original change's description:
> > Add unit test covering struct field folding.
> >
> > At present, we don't try to optimize away `myStruct.myField` accesses
> > even when `myStruct` is known or constant, so the output from the test
> > is not too impressive.
> >
> > Change-Id: I563559e5cdc6c2669d69ec78ad8ca09d3be02a68
> > Bug: skia:13387
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/547276
> > Auto-Submit: John Stiles <johnstiles@google.com>
> > Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
> > Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
> > Commit-Queue: John Stiles <johnstiles@google.com>
>
> Bug: skia:13387
> Change-Id: I2e651ddb82fac08cdc16fa8b77696cdd314e805f
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/547438
> Auto-Submit: John Stiles <johnstiles@google.com>
> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>

Change-Id: Ic86ff6b1034363d1343793f94e3ba707adb2fcc3
Bug: skia:13387, skia:13393, skia:13395
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/547439
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2022-06-06 20:38:26 +00:00
John Stiles
3ba37e1d38 Revert "Add unit test covering struct field folding."
This reverts commit 0cbba91940.

Reason for revert: returns red on Adreno and Intel

Original change's description:
> Add unit test covering struct field folding.
>
> At present, we don't try to optimize away `myStruct.myField` accesses
> even when `myStruct` is known or constant, so the output from the test
> is not too impressive.
>
> Change-Id: I563559e5cdc6c2669d69ec78ad8ca09d3be02a68
> Bug: skia:13387
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/547276
> Auto-Submit: John Stiles <johnstiles@google.com>
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
> Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
> Commit-Queue: John Stiles <johnstiles@google.com>

Bug: skia:13387
Change-Id: I2e651ddb82fac08cdc16fa8b77696cdd314e805f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/547438
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2022-06-06 16:00:07 +00:00
John Stiles
0cbba91940 Add unit test covering struct field folding.
At present, we don't try to optimize away `myStruct.myField` accesses
even when `myStruct` is known or constant, so the output from the test
is not too impressive.

Change-Id: I563559e5cdc6c2669d69ec78ad8ca09d3be02a68
Bug: skia:13387
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/547276
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2022-06-06 14:09:32 +00:00
Brian Osman
47b6b5897b Remove various sk_Caps settings
"canUseAnyFunction" was totally unused. All of the others that I removed
are only used from C++ code to control higher level logic (not within
shaders). A few of the remainders don't have sk_Caps references today,
but adding usage seems plausible.

Change-Id: I196f7d8abacde9dc6903d792cd18b58a34dc19f3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/546858
Reviewed-by: Arman Uguray <armansito@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2022-06-06 14:08:38 +00:00
John Stiles
9fd18cc6c2 Add ES3 test for trivially inlinable arguments.
This lets us test non-constant array indexing and array ctors (which ES2
doesn't allow at all).

I also added some cast-related tests to the non-ES3 test which were
accidentally missed the first time around.

Change-Id: Ib03aa53f57702141a8852154d584a31ab75f96e8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/547017
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2022-06-06 13:45:13 +00:00
John Stiles
1713e69fe8 Improve TrivialArgumentsInlineDirectly test cases.
Test cases were added for matrix-resize-ctor, diagonal-matrix-ctor and
struct-ctor. These were originally absent because the original trivial-
expression code did not distinguish between each individual ctor type.
Unfortunately, array-ctor is not included because ES2 does not support
array-ctors.

Comments were added to make it a bit easier to understand why some cases
are trivial but others are not. In some cases, the compiler applies
relevant transformations that might not be apparent at first glance--
e.g. unary + is eliminated so that case is still trivial.

Change-Id: Ie6756fc01736d28035f3965ae18f3482bd030871
Bug: skia:13378
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/546864
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Arman Uguray <armansito@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2022-06-04 21:23:42 +00:00
Ethan Nicholas
f8c1c459b1 Revert "Revert "Restored unsized array support to SkSL""
This reverts commit 5270322b46.

Change-Id: If594d04dc657126dce48d69dcc67d1a5e3b0cc8a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/546856
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2022-06-03 19:03:13 +00:00
John Stiles
871476a9b2 Improve constructor handling in Analysis::IsTrivialExpression.
This code was originally written before our constructor IR types were
split apart, so its treatment of constructors was pretty simplistic. The
new code handles each type of constructor separately, and makes better
decisions as a result.

Compound constructors are now only considered to be trivial when they
are compile-time constants; this causes vector<->matrix conversion
constructors to be detected as non-trivial.

Change-Id: I534fcf69f5d5f43ac705d68ae00f97fce8496c2a
Bug: skia:13378
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/546555
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
2022-06-03 18:59:06 +00:00
John Stiles
d29d446a7d Fix layout alignment bug with half2x2 matrices.
GrSPIRVUniformHandler and GrVkUniformHandler had special-case handling
of float2x2 matrices, but neglected to put in the same handling for
half2x2 matrices (which are identical at the uniform level).

There are likely to be deeper issues here, but this is a step in the
right direction compared to where we were.

Bug: skia:13380
Change-Id: I035f707d1f3831c0057934fe16b2f96ea4847578
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/546550
Reviewed-by: Arman Uguray <armansito@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2022-06-03 17:43:29 +00:00
John Stiles
2d2d2b4d1a Add test demonstrating that matrix/vector casts are considered trivial.
This version dodges skia:13380 by reordering the list of uniforms.
Disabled on Win10 with older Intel GPUs due to crashes when performing
vector/matrix casts in GLSL.

Change-Id: If053908fd1a6921257e5af0abdce1ff69a03297f
Bug: skia:13378, skia:12179
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/546551
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2022-06-03 17:02:08 +00:00
Brian Osman
5270322b46 Revert "Restored unsized array support to SkSL"
This reverts commit 9583759bbd.

Reason for revert: MSAN failure

Original change's description:
> Restored unsized array support to SkSL
>
> This is a prerequisite for compute shaders. As of this CL, there isn't
> yet a way to use unsized arrays, as it is a compute-only feature and
> compute shaders are coming in a followup CL, but this adds the basic
> framework and error tests.
>
> Change-Id: I390c0961e324dd474474563bf9a8f6b34c9552a9
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/538900
> Reviewed-by: John Stiles <johnstiles@google.com>
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>

Change-Id: Id10b48ef24c0e6219b65b0a201d13fea9632620f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/546552
Auto-Submit: Brian Osman <brianosman@google.com>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2022-06-03 15:56:10 +00:00
Brian Osman
2ef2cbcce1 Revert "Add test demonstrating that matrix/vector casts are considered trivial."
This reverts commit c18fb9c8a2.

Reason for revert: Red on the tree.

Original change's description:
> Add test demonstrating that matrix/vector casts are considered trivial.
>
> These casts are not particularly lightweight Metal (they invoke a helper
> function) so they are going to be marked as non-trivial in a followup
> CL.
>
> Change-Id: Ic88e6b3889f6d4f4751d7ebfc740229b7530930b
> Bug: skia:13378, skia:13380
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/546417
> Reviewed-by: Arman Uguray <armansito@google.com>
> Auto-Submit: John Stiles <johnstiles@google.com>
> Commit-Queue: John Stiles <johnstiles@google.com>

Bug: skia:13378, skia:13380
Change-Id: Iee60fcc0d9d56912268777a9fa4d2aa18154f157
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/546548
Auto-Submit: Brian Osman <brianosman@google.com>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2022-06-03 14:59:17 +00:00
John Stiles
c18fb9c8a2 Add test demonstrating that matrix/vector casts are considered trivial.
These casts are not particularly lightweight Metal (they invoke a helper
function) so they are going to be marked as non-trivial in a followup
CL.

Change-Id: Ic88e6b3889f6d4f4751d7ebfc740229b7530930b
Bug: skia:13378, skia:13380
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/546417
Reviewed-by: Arman Uguray <armansito@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2022-06-03 14:11:20 +00:00
Ethan Nicholas
9583759bbd Restored unsized array support to SkSL
This is a prerequisite for compute shaders. As of this CL, there isn't
yet a way to use unsized arrays, as it is a compute-only feature and
compute shaders are coming in a followup CL, but this adds the basic
framework and error tests.

Change-Id: I390c0961e324dd474474563bf9a8f6b34c9552a9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/538900
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2022-06-03 13:58:35 +00:00
Arman Uguray
bd969a089d [sksl] Disallow boolean uniforms
Booleans and structs/interface blocks that transitively contain a
boolean member are no longer allowed to be used as a uniform. This is
because SPIR-V and WGSL currently disallow OpTypeBool in host-shareable
storage classes.

Change-Id: I10315c7f261ff10a07636265968a91d9c421da55
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/542776
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Arman Uguray <armansito@google.com>
2022-06-01 18:07:08 +00:00
Arman Uguray
839a0b64fa [sksl][wgsl] Field access and test for vertex stage builtins
* Added support for field access expressions, excluding user-defined
  interface blocks.
* Added a test case for vertex stage builtin declarations.
* Added a NOP workaround for sk_PointSize which does not have a
  WGSL/WebGPU equivalent.

Bug: skia:13092
Change-Id: I46fd7bb0a9fe55d2e3ed2b3b72f63376c1ed4f31
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/539082
Commit-Queue: Arman Uguray <armansito@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
2022-05-18 15:01:59 +00:00
Arman Uguray
02888a6f0a [sksl][wgsl] Support simple assignment
- Add support for simple assignment expressions, as well as swizzle,
  variable references, and type conversion constructors to support
  simple assignment test cases that reference built-ins and local variables.

- Handle a case where the type of a SkSL built-in differs from its WGSL
  counterpart and emit a type cast when such a variable gets referenced.

- Add additional test cases for supported WGSL features that could not
  be tested without simple assignment support.

Bug: skia:13092
Change-Id: Ib1ff3bcef60e436c9be5c08236c9fe4de02dd005
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/538420
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Arman Uguray <armansito@google.com>
2022-05-18 02:25:29 +00:00
Arman Uguray
5235b3df42 [sksl][wgsl] Add @interpolate(flat) annotation to integer IO
WGSL requires that pipeline stage IO parameters that are scalar or
vector integers be annotated with the "flat" interpolation attribute.

Bug: skia:13092
Change-Id: I2930da6cf468ac8cd9ccaca0004e5849065411dd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/538419
Commit-Queue: Arman Uguray <armansito@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2022-05-17 21:43:23 +00:00
Arman Uguray
b2b1d6553e [sksl][wgsl] Prevent empty pipeline stage structs
1. It is illegal to declare an empty struct in WGSL. The codegen no longer
declares an empty struct for pipeline stage inputs and outputs if the
program does not reference them.

2. WGSL requires that every vertex program declare a @builtin(position) output.
The codegen now emits this pipeline stage output even for an empty
program that doesn't assign to sk_Position. This allows unit tests for
vertex programs to be authored without unnecessary boilerplate.

Bug: skia:13092

Change-Id: Ib023200e2ba13acf96859817249686d7f815cb00
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/538418
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Arman Uguray <armansito@google.com>
2022-05-17 19:23:32 +00:00
Brian Osman
c2d42fe243 Add #version directive to SkSL
ProgramSettings now has a fRequiredVersion, based on the #version
directive (if any). There is plenty more to do, and this is an
intermediate state where the "fEnforceES2Restrictions" bool still
exists. Eventually, that will go away, or change into a check between
the required version and the SkCapabilities supplied (also in
ProgramSettings).

As a proof-of-concept, this migrates some use-cases to insert the new
version directive, and unlock ES3 features in some tests and benches.

Bug: skia:11209
Change-Id: I964975931039588d7a302bfedd09246e3d4a79d2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/540037
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2022-05-17 15:42:31 +00:00
John Stiles
353e2c65c9 Prevent comma operator constant-folding or constant-expression-usage.
OpenGL docs specifically insist that the sequence (comma) operator
should not be treated as a constant-expression so that attempts to
declare multidimensional arrays with a comma will fail:
http://screen/vJEpAe9yNmbzZTm

(See "12.43 Sequence operator and constant expressions" in the OpenGL
ES3 documentation or read skia:13311 for details.)

In practice, we don't get much benefit from optimizing away unused
comma-expressions; it improves some synthetic tests, but realistically
this will not help Skia in any real-world scenario. The constant folder
no longer attempts this optimization, and comma-expressions are now
rejected in a constant-expression context.

Change-Id: Ic5dea6ff90e36614b548c1ce89a444e81da944ae
Bug: skia:13311
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/539565
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Arman Uguray <armansito@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2022-05-11 22:52:24 +00:00
John Stiles
3c2997cacc Disable no-op arithmetic simplification when optimization is off.
We will continue to fold expressions like `10 + 0` or `5 * 1` or
`PI * 1` (assuming PI is a const float) because both sides are known,
but non-constant-expressions like `x + 0` (assuming x is not a constant)
or `foo *= 1` will be left as-is when the optimizer is off.

This improves the accuracy of the Viewer shader tab, because a runtime
effect expression like `color *= scale` will be preserved in the final
output when optimization is off, instead of being replaced with a Nop
when scale equals one.

Change-Id: I218b327cb0cd12654dca446dee8a5baa96f589b8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/539197
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2022-05-11 14:39:42 +00:00
John Stiles
2f13b32f79 Add dedicated golden test for enabling/disabling fOptimize.
Previously we didn't have any mechanism for disabling the optimizer when
building golden outputs, so every golden output always had optimizations
applied.

Change-Id: I8f370b06daab6cb50bb4339eab0d39578621413b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/539198
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2022-05-11 13:37:12 +00:00
John Stiles
cfcc11bd98 Move recursion tests into general /errors/ directory.
We enforce no-recursion in all programs now, not just Runtime Effects.

Change-Id: I3737329e4526fa1b7fdbb47ccb959f78f507f665
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/535119
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2022-04-28 21:25:41 +00:00
John Stiles
c6b2e7115a Limit sksl_rt_shader to internal usage only.
We now have a new type of ProgramKind, private runtime shaders.
`sksl_rt_effect.sksl` is now only loaded for these kinds of program.

Rather than having a special-case check for sk_FragCoord in
SkRuntimeEffect, the symbol will no longer exist at all unless a private
options flag is set.

Change-Id: I9223baaf59d74c44d64f322cd57fc841625342b7
Bug: skia:12202
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/532784
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2022-04-22 21:06:31 +00:00
John Stiles
20718d3547 Add test demonstrating sk_FragCoord usage in a runtime shader.
Right now nothing prevents it from working. (skslc doesn't use
SkRuntimeEffect::MakeInternal.) This will be fixed in a followup.

Change-Id: Ib8479220e1f194b035516d976a7369d926a07f5d
Bug: skia:12202
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/532783
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2022-04-22 21:06:31 +00:00
Brian Osman
46aad8435a Move runtime effect uniform type checking into the compiler
This has two benefits:
1) We get detailed error messages with accurate positions
2) We can actually test these in our golden .rts files.

Thanks to #2, add a new unit test file, and adjust some existing files
that were breaking these rules.

Change-Id: I0b65e2f06f79ce8cbea9bad4c3d27062ec9b6e6c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/532769
Reviewed-by: Arman Uguray <armansito@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2022-04-22 20:54:26 +00:00
John Stiles
b966ea2177 Fix update-fuzzer script to allow non-UTF8 data.
Some of our oss-fuzz tests contain garbage data which isn't in any
encoding. This throws an error unless the files are opened in binary
mode.

Change-Id: I5caf307f3c79fba5b177496fd8ced8381205b97e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/530679
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
2022-04-18 12:10:05 +00:00
Brian Osman
9fe0e3d4e7 SkSL: Add unit tests for new ForceNoRTFlip code-gen option
This removes the assert from the SPIR-V generator so the
tests compile. The generated SPIR-V is incorrect. The next
CL fixes the generator, and restores the assert.

Change-Id: I77b507cf7fb5eac481322887000bd1c73cd5c899
Bug: skia:13219
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/530336
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2022-04-15 12:59:07 +00:00
John Stiles
8397365524 Optimize away same-value ternaries.
A ternary of the form `anything ? value : value` can be reduced to a
comma-expression of the form `anything, value`. This seems like a rare
case in real code, but it's easy enough to detect with our existing
toolbox.

The `anything` test-expression will be eliminated from the expression
if it has no side effects, using our existing constant-folding rules
for the comma expression.

Change-Id: I1285b04cd6a08f1bed614aa1aa6f37ea2447de91
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/528439
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2022-04-07 19:37:00 +00:00
John Stiles
b617bced6e Use OpConstantComposite when vectorizing in SPIR-V.
Previously, when we vectorized scalars, we would not place them in the
constant buffer, so we could emit simple vectors like (0,0,0) or (1,1,1)
more than once. Now, we use `writeConstructorSplat` to vectorize, which
knows how to write constants.

Change-Id: Ic97c0ce5415fd46ff8c7fb7dac9205844633ef3a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/527921
Reviewed-by: Arman Uguray <armansito@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2022-04-07 18:28:18 +00:00
Ethan Nicholas
b69a292dca Improved position reporting for various SkSL constructs
This cleans up a lot of positions produced by DSLParser to make them
actually match the ranges of the elements being parsed.

Change-Id: Ic3a9d62c99c4b5f92b84a597a2ceba386bbcc334
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/527501
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2022-04-06 16:20:45 +00:00
John Stiles
0e3a248cbe Add new folding tests involving prefix expressions.
Followup CLs will improve their output.

Change-Id: I07059348f68cd6cd3154c31a41f81018b26a44e5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/527616
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2022-04-05 19:52:07 +00:00
Ethan Nicholas
b47a67ab75 Fixed SkSL positioning error with double negation
We were not propagating the position into a double-negated expression,
leading to an assertion failure in PrefixExpression.

Change-Id: I1970ff1a06d9631582626c68e151f12f6b3ef278
Bug: oss-fuzz:46381
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/527507
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2022-04-05 17:10:23 +00:00
John Stiles
e1eec147f4 Add test for fuzzer-discovered error with ^^ operator.
We didn't have any existing tests that exercised this path; it is
separate from most operators since it has no C++ equivalent.

Change-Id: I95b538dad01f8c8b122954fb5f66337371a398a8
Bug: oss-fuzz:46289
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/527196
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2022-04-04 15:41:08 +00:00