Commit Graph

43 Commits

Author SHA1 Message Date
Brian Osman
886af0dae3 Allow defined functions in the SkSL .inc files
Use that to implement many intrinsics in SkSL for the interpreter.

Change-Id: I3762867781cb1a053429fd37b12ae3cf7739cb3c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/230134
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-07-29 17:10:48 +00:00
Brian Osman
b380e71cfe Interpreter: Add radians and normalize builtins
Change-Id: I2c76d8cbcfc3f36448127de5a3e1a22f76eda863
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/229489
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-07-25 14:23:37 +00:00
Brian Osman
869a3e81ea Reland "Interpreter: Bounds check array access, add bool return from run"
This is a reland of f42de9e1e5

Original change's description:
> Interpreter: Bounds check array access, add bool return from run
> 
> Out of bounds access with constant indices is a compile error.
> At runtime, causes the interpreter to fail. Made several other
> conditions trigger the same failure logic, and updated all
> uses of the interpreter to validate success.
> 
> Change-Id: I3720b3c83903220b010ec574121fc64dbe102378
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228256
> Commit-Queue: Brian Osman <brianosman@google.com>
> Reviewed-by: Mike Reed <reed@google.com>

Change-Id: I8849de815f7efb730ac9c55b6edd296cb9ca7599
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228353
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2019-07-18 21:38:20 +00:00
Mike Reed
634c9417bd add inverse() intrinsic function to sksl
Change-Id: Ic30f6e0345e851ea8a942996b9eaf2c894455e3e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228236
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2019-07-18 19:07:49 +00:00
Brian Osman
52c1bf12b8 Interpreter: Fix code-gen for postfix ++/-- used only for side effect
Add a test case that previously asserted (due to incorrect code-gen
underflowing the stack).

Change-Id: I9df7a08b9ac5c7b5bc246129f3383dc723173351
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228351
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-07-18 18:48:04 +00:00
Brian Osman
3e6aa9f528 Revert "Interpreter: Bounds check array access, add bool return from run"
This reverts commit f42de9e1e5.

Reason for revert: All the SANs

Original change's description:
> Interpreter: Bounds check array access, add bool return from run
> 
> Out of bounds access with constant indices is a compile error.
> At runtime, causes the interpreter to fail. Made several other
> conditions trigger the same failure logic, and updated all
> uses of the interpreter to validate success.
> 
> Change-Id: I3720b3c83903220b010ec574121fc64dbe102378
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228256
> Commit-Queue: Brian Osman <brianosman@google.com>
> Reviewed-by: Mike Reed <reed@google.com>

TBR=mtklein@google.com,brianosman@google.com,ethannicholas@google.com,reed@google.com

Change-Id: I434601960d54fbd7d00e2af2dc6269a83a768c5b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228352
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-07-18 17:22:41 +00:00
Brian Osman
f42de9e1e5 Interpreter: Bounds check array access, add bool return from run
Out of bounds access with constant indices is a compile error.
At runtime, causes the interpreter to fail. Made several other
conditions trigger the same failure logic, and updated all
uses of the interpreter to validate success.

Change-Id: I3720b3c83903220b010ec574121fc64dbe102378
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228256
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Reed <reed@google.com>
2019-07-18 16:24:57 +00:00
Brian Osman
4a47da7357 Interpreter: Disallow return statements inside loops or conditionals
These didn't work correctly, and they're extremely tricky to get right
in the vectorized execution model (vs. structured control flow). As a
side effect, determine the maximum stack depth used for the execution
masking - the same idea will be used for the primary stack in a later
CL. Add a unit test to verify the new restriction, and fix two places
that were relying on this feature before.

In addition, boolean external values need to be masks. I may implement
this in the code-gen at some point, but this is already a fringe
feature, so just fix the one unit test for now.

Change-Id: I9607ffaf67c7795dbf42e4009180aea8f3e65c44
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/226849
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-07-12 16:07:16 +00:00
Brian Osman
6f5358f505 Interpreter: Disallow recursion
I think this is the minimum rule that's easy to understand when writing
SkSL for the interpreter that ensures we'll be able to statically
determine total stack usage of a particular function.

While writing the new test, I also noticed that we still return
(invalid) byte code, even when there are errors. Fixed that.

Change-Id: I625a8592c9ba1656074e5f0d4227d41968af7b37
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/226218
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-07-10 16:08:39 +00:00
Brian Osman
1a79f0be15 ByteCode: Improved ExternalValue interface
Use float* to match the ByteCode run API (and make the sizing of data
clearer). Add a lane index to all external value calls. My upcoming
overhaul of the particle code needs this, but I wanted to break that
(large) CL up.

Change-Id: I0588cd7769a1dced9f088de5756947bb744c146b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/223178
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2019-06-25 02:57:24 +00:00
Brian Osman
d3494ede8d ByteCode: Support out params in local function calls
Change-Id: I1d133259264adfdc872b0f4aeaa9390363c46341
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/222040
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-06-21 13:55:15 +00:00
Brian Osman
fba386b940 ByteCode: Allow calls to functions that return void
Change-Id: Ia2e21bc984c509cd2405499f93ee5e19941cc492
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/222499
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2019-06-20 19:29:40 +00:00
Brian Osman
8d56457f77 ByteCode: Fix subtle bug with nested loops and lanes re-activating
When starting a nested loop, we can't rely on the condition mask to keep
dead lanes dead, because of conditional breaks/continues that may have
happened earlier. So always narrow the loop mask by inheriting the
previous one.

Change-Id: I5bb076e6467fe1b6a2f682a590e8ae972a440b03
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/222098
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-06-19 15:28:05 +00:00
Brian Osman
08a8496135 Interpreter: Simplify interface quite a bit.
Slightly sharper, but far easier to hold:

- Remove Value union from interface, everything is a 32-bit
  value type, or a collection thereof.
- Collapse to one version of Run (that takes count), and make
  it a member on ByteCode.
- Similarly, move disassemble to ByteCodeFunction.

Change-Id: I07c85e65991178b3f52e20e815c25f36bc9c4257
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/220753
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2019-06-14 16:04:58 +00:00
Brian Osman
569f12f0e5 Interpreter: Vectorized interpreter
This converts the SkSL interpreter to operate in SIMT fashion. It handles
all the same features as the previous scalar implementation, but operates
on N lanes at a time. (Currently 8).

It's modeled after GPU and other parallel architectures, using execution
masks to handle control flow, including divergent control-flow.

Change-Id: Ieb38ffe2f55a10f72bdab844c297126fe9bedb6c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/217122
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2019-06-13 15:50:55 +00:00
Brian Osman
8016441e20 Interpreter: Refactor interface and lifetime management
Interpreter is now just a namespace with Run and Disassemble. This hides
all of the implementation details. In addition, the interpreter only used
the Program because of a few details in FunctionDeclarations - scrape that
when constructing a ByteCodeFunction, and we don't need to keep the entire
Program alive, just the ByteCode. Adjust tests to ensure that this works.

Change-Id: I61efe4fe986476afedbd295d3d55b2a326fea4e3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219521
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-06-07 18:47:22 +00:00
Brian Osman
5bdf525b9c Fix divide by zero in interpreter test
Change-Id: I43f8663b70aaa7c0a006f61b1194475fc11e0846
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/216692
Commit-Queue: Brian Osman <brianosman@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Auto-Submit: Brian Osman <brianosman@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
2019-05-29 21:30:06 +00:00
Brian Osman
909231c8de Interpreter: Matrix/Vector multiplication
Change-Id: I3dc5e5be1cf12c581cce3854d0db7e73db6e1fd9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/216681
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2019-05-29 20:32:31 +00:00
Brian Osman
1e855b22b7 Interpreter: Support component-wise ops for matrices
The linear algebra cases are more complex, coming in separate CL.

Change-Id: I5bbc25a126b61eee6f5b9775ab142e103c00f837
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/216612
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-05-29 20:24:02 +00:00
Brian Osman
16e6fd53a1 Interpreter: Fix vector/matrix equality and inequality
Need to compare all elements, then fold the result to a single bool.

Change-Id: I0ebfaa9d518f29a782701246ada247cb55c01c2e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/216607
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-05-29 17:42:58 +00:00
Brian Osman
29e013deb4 Interpreter: Fix construction of Matrices
Per GLSL, constructing a matrix from a scalar produces a matrix
with the scalar value along the diagonal, and zero elsewhere.
Constructing a matrix from another matrix copies the overlapping
values, and fills in the remainder with the identity matrix.

Doing either of these with existing opcodes was going to be quite
verbose and tricky, so I just made new opcodes.

I've also got some (currently disabled) test cases for other
matrix behavior, all of which fail in various ways today.

Change-Id: Ia86a183395f1ac7e2f23ee1d6bb4af461f5ba93a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/215823
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-05-29 13:03:02 +00:00
Ethan Nicholas
ae9633b352 add SkSL support for mix, cross, and dot
Bug: skia:
Change-Id: Ic6c16f363c5f2aedaf1aee9b3b8ee23e37ea24e4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/215448
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2019-05-24 17:17:27 +00:00
Brian Osman
07c117b6f8 Support larger compound types in the interpreter
Field access and array indexing are supported, including
dynamic indices. Larger types (> 4 slots) can be used as
lvalues, rvalues, etc.

Change-Id: I9bb4ed850be4259c05c8952c6c0a17b71f813772
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/214443
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2019-05-23 20:19:30 +00:00
Brian Osman
c51d791ab9 Interpreter: Fix scalar -> vector constructors
We were never replicating scalar values when constructing vector types
from a single argument.

Change-Id: I5bdeeb91f5a10c151b18561de6c275f2db2898fe
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/215526
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: Brian Osman <brianosman@google.com>
2019-05-23 14:51:58 +00:00
Ethan Nicholas
82162eead5 SkSL interpreter intrinsics
Bug: skia:
Change-Id: I418fb05444f9c1ee076ace41a24072c4a5e7ef6c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/214691
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2019-05-21 20:38:20 +00:00
Ethan Nicholas
9e6a39356e support for SkSL interpreter external function calls
Bug: skia:
Change-Id: Ie8c873bf7fc795567ad812f56c37bee4c06213bb
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/214307
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2019-05-20 13:49:56 +00:00
Mike Klein
b6a6f0829e disassemble on unit test failure
Change-Id: I072f5d72f64eb683cc90c2890313ee289487cff3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/214403
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2019-05-17 20:36:48 +00:00
Brian Osman
f3fa60010e Implement postfix ++/--, and use the correct 1 for floats
Change-Id: I0e6e8205998f3058cb59e279704e23989bccc66b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/214192
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-05-17 19:01:05 +00:00
Brian Osman
4e93feba40 Interpreter: Implement ternary operator
Change-Id: If05661224d4a53e1854180d9b280ebb7a7ac2793
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/214191
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-05-17 14:29:23 +00:00
Brian Osman
1091f02b40 Interpreter: Change all Load/Store ops to use immediate indices
Avoids the need for a PushImmediate (which usually also required
a Nop for alignment) on every load/store. And it makes the codegen
for local vs. global identical, which simplifies the byte-code
generator in a few spots.

This means that places previously using DupDown now need something that
dupes the *top* N elements of the stack. Just use Vector + Dup, and
remove the (now unused) DupDown instruction.

Also add/implement kStoreSwizzleGlobal, which was the last missing
load/store op (and add a test case).

Change-Id: Id450272c11f4f1842c9d57bc5114e7f81e9e926e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/214062
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-05-16 14:19:51 +00:00
Ethan Nicholas
91164d1c01 added external value support to SkSL interpreter
Bug: skia:
Change-Id: I1806e1f6abaef322ecd3ba0d9bfaa9d7ca7a44c1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/212983
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2019-05-15 20:05:45 +00:00
Brian Osman
b745129ceb Interpreter: Implement/fix vectorized load/store of globals
Also has swizzled loads of globals. Swizzle stores are still broken.

Change-Id: I0c01a309592c0aa460e1459de2636a2e1ef2ee6c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/213830
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-05-15 17:40:45 +00:00
Brian Osman
226668a146 Add support for calling functions within the interpreter
Change-Id: Id009aa32faa40e9847dcf3668f1fd15e8b95dc56
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/213134
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-05-15 13:36:16 +00:00
Brian Osman
4167215daf Fix stack indexing bug in vectorized unsigned -> float conversion
Also add a test of all three conversions (scalar & vector).

Change-Id: I1671e992760ad538304d2602e37cd9792a49e9cb
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/213660
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-05-14 18:09:50 +00:00
Brian Osman
44d44761c7 Interpreter: Fix bool literals
Change-Id: I0cf8e12d5ddb9b89aff39f484d8a017f61e4a20f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/213465
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-05-13 18:54:16 +00:00
Brian Osman
d369a5e9cf Add setInputs to SkSL::Interpreter
Allows updating the global inputs of a cached Interpreter object.

Change-Id: I626e63294a441a7f52ae484755c99f5d04bb614f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/212980
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-05-09 17:46:41 +00:00
Brian Osman
3b41bafc2c Add support for float remainder to interpreter
Change-Id: I267c99c8c36b1d39abe9cf196996db43edb2b839
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/212721
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2019-05-08 14:13:06 +00:00
Ethan Nicholas
354ecf3693 fixed SkSL interpreter negate op
Bug: skia:
Change-Id: I76ff729a887948119ec1ef58221433a6d91e98a8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/212484
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2019-05-07 20:49:21 +00:00
Ethan Nicholas
444aa12c84 fixed SkSL interpreter test
Bug: skia:
Change-Id: I8ddb017994cd9e4ad01163da07888c431a5b1276
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/212416
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
2019-05-07 19:27:20 +00:00
Ethan Nicholas
dfcad064e9 more SkSL interpreter performance work
Bug: skia:
Change-Id: I21da1f1473fb73e8ba1371e7301f3fff2e33e8cc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/212199
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Mike Reed <reed@google.com>
2019-05-07 17:29:50 +00:00
Mike Klein
c0bd9f9fe5 rewrite includes to not need so much -Ifoo
Current strategy: everything from the top

Things to look at first are the manual changes:

   - added tools/rewrite_includes.py
   - removed -Idirectives from BUILD.gn
   - various compile.sh simplifications
   - tweak tools/embed_resources.py
   - update gn/find_headers.py to write paths from the top
   - update gn/gn_to_bp.py SkUserConfig.h layout
     so that #include "include/config/SkUserConfig.h" always
     gets the header we want.

No-Presubmit: true
Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2019-04-24 16:27:11 +00:00
Ethan Nicholas
746035afeb added support for interpreting generic SkSL functions
Bug: skia:
Change-Id: I575b91c654393cc6cfedea617852598e8595d5ed
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209809
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
2019-04-23 18:46:36 +00:00
Ethan Nicholas
0e9401dafe Initial checkin of new SkSL interpreter.
Not quite feature complete yet, but at a point where it's worth checking
in.

Bug: skia:
Change-Id: I21141d30e8582a79e94450d84e56bacc067249e0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/201685
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
2019-03-21 15:41:10 +00:00