Commit Graph

524 Commits

Author SHA1 Message Date
David Neto 2c11bd6b68 [spirv-reader] Refactor bookkeeping for localy defined values
Bug: tint:3
Change-Id: Ibe26b802ae61c6271f8a75e641ac31db36df6000
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24124
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-30 19:03:17 +00:00
dan sinclair e88c0f6f8a [msl-writer] Emit loop statements.
This CL adds the code to convert a loop/continuing statement into MSL.

Bug: tint:8
Change-Id: I9fa595908c6d834d9543b583c8baf8c19f8cae6c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24122
Reviewed-by: David Neto <dneto@google.com>
2020-06-30 17:40:28 +00:00
David Neto e91325956d [spirv-reader] Hoist definitions as needed
Compensate for the fact that dominance does not correspond
exactly to scoping. A definition can dominate a use, but when mapped
in a naive way to constant definitiion and its use, the definition
name goes out of scope by the time you reach the use.

This is correct for storable types.

Bug: tint:3
Change-Id: I03e6c5ba68393151485ed4cdbe6b2b3d7773d1ad
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24141
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-30 15:16:18 +00:00
David Neto de7b15ebb9 [spirv-reader] Don't move combinatorial values across control flow
Avoid sinking expensive operations into control flow such as loops.
The heuristic way to achieve that is to avoid moving combinatorial
values across *any* structured construct boundaries.

Bug: tint:3
Change-Id: I91502b01166a0db64c0e652331591850df75f9d4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24140
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-30 13:59:43 +00:00
dan sinclair 57b3b1d117 [msl-writer] Add break and continue emission.
This CL adds writting of break and continue statements to the MSL
backend.

Bug: tint:8
Change-Id: If2443c036fa82f54708d209d924192ee7a159e76
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24121
Reviewed-by: David Neto <dneto@google.com>
2020-06-29 21:17:54 +00:00
dan sinclair fa1659a3ef [msl-writer] Emit member accessors.
This CL adds emission of member accessor expressions to the MSL writer.

Bug: tint:8
Change-Id: I21d8564880c44d719c89dca2a10cd97ccb1e2cd7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24120
Reviewed-by: David Neto <dneto@google.com>
2020-06-29 21:17:44 +00:00
dan sinclair 48bb366991 [spirv-writer] Allow casting of vectors along with scalars.
The current `cast` conversion code only handles scalar types and fails
if provided with vectors. This CL updates the logic to accept scalars
along with the provided scalar cases.

Bug: tint:96
Change-Id: I60772e75286fc3ee7a9dfba6634db069062b22d0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23820
Reviewed-by: David Neto <dneto@google.com>
2020-06-29 17:58:09 +00:00
dan sinclair d4eafb631d [msl-writer] Emit alias types.
This CL adds emission of alias types to the MSL writer. They are output
as `typedef`s.

Bug: tint:8
Change-Id: I18b839ed0238c4636e3975f35f5d88badd412fe4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24001
Reviewed-by: David Neto <dneto@google.com>
2020-06-26 21:27:59 +00:00
dan sinclair dc841f1bf2 [msl-writer] Add array accessors.
This CL adds the code to emit array accessors from the MSL backend..

Bug: tint:8
Change-Id: Ia6b49c11602d39aa559feac31fcfd592ab54928c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24000
Reviewed-by: David Neto <dneto@google.com>
2020-06-26 21:27:59 +00:00
dan sinclair d1bf87b9d8 [msl-writer] Add unary op emission.
This CL adds emission of the unary `-` and `!` operators.

Bug: tint:8
Change-Id: I9dda066111cc8f115b593127cf070c6ca37bdc66
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23842
Reviewed-by: David Neto <dneto@google.com>
2020-06-26 21:27:59 +00:00
dan sinclair 24a46e8e69 [msl-writer] Emit kill statement.
This Cl adds emission of the Kill statement as `discard_fragment`. This
may need to be revised when the semantics of Kill are agreed upon.

Bug: tint:8
Change-Id: I2d09f09143b2acd0139d876e873e3c70abbc84a3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23841
Reviewed-by: David Neto <dneto@google.com>
2020-06-26 21:27:59 +00:00
dan sinclair 28d4a94bee [msl-writer] Add emission of if statements.
This Cl adds emission of `if`, `else if` and `else` statements to the
MSL backend.

Bug: tint:8
Change-Id: I8c22d70f2afa0a1d86cf475f5c98127504a6dc0e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23840
Reviewed-by: David Neto <dneto@google.com>
2020-06-26 21:27:59 +00:00
dan sinclair b1de84316c [msl-writer] Add cast conversion.
This CL adds conversion of casts to MSL.

Bug: tint:8
Change-Id: Iecfb9a5b413b1d10372b4d2fec31c0956b1475a0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23822
Reviewed-by: David Neto <dneto@google.com>
2020-06-26 21:27:59 +00:00
dan sinclair 3dbc8378fa [msl-writer] Add generation of as casts.
This CL adds the MSL conversion of as casts to `as_cast`.

Bug: tint:8
Change-Id: Iaa8ee1fa3077e4471bbead9d24fcf1e2d68998b0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23821
Reviewed-by: David Neto <dneto@google.com>
2020-06-26 21:27:59 +00:00
David Neto 7fe3c36376 [spirv-reader] Weaken input validation to Vulkan 1.0
The process of passing the module through this reader, the WGSL semantics,
and the SPIR-V writer will sanitize the module such that the end result
should satisfy SPV_ENV_WEBGPU_0 requirements.

Being more forgiving about the input SPIR-V will be a quality-of-life
improvement.

Bug: tint:3
Change-Id: Ib54cbf729b9e078d797a1ef31422bad497daa5a0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23942
Reviewed-by: dan sinclair <dsinclair@google.com>
Commit-Queue: dan sinclair <dsinclair@google.com>
2020-06-26 15:47:03 +00:00
dan sinclair ec3e2d4abd [metal-writer] Add entry point support.
This CL adds preliminary entry point support to the Metal backend.

Bug: tint:8
Change-Id: I7b904621d706d4503d5054711de64872f79cf2fa
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23708
Reviewed-by: David Neto <dneto@google.com>
2020-06-23 18:22:28 +00:00
dan sinclair 6366f68121 [metal-writer] Emit constructors.
This Cl adds the code to emit scalar and type constructors from the
Metal backend.

Bug: tint:8
Change-Id: I95c713568ae3a73b82f8c9e10119e29e3469893e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23707
Reviewed-by: David Neto <dneto@google.com>
2020-06-23 18:22:21 +00:00
dan sinclair 7f269e5bcb [metal-writer] Emit binary operations.
This CL adds emission of binary operations to the Metal backend.

Bug: tint:8
Change-Id: I797daadd238b718b081842b63ccefab3294bc20c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23706
Reviewed-by: David Neto <dneto@google.com>
2020-06-23 18:22:05 +00:00
dan sinclair 70c605fc47 [metal-writer] Emit assignment statements.
This CL adds assignment statements to the Metal backend.

Bug: tint:8
Change-Id: Iaf4faa62124948fd0e785d5bebd20aae778ba050
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23705
Reviewed-by: David Neto <dneto@google.com>
2020-06-23 17:54:33 +00:00
dan sinclair e66d6a6745 [metal-writer] Emit functions
This Cl adds the code to emit functions from the metal writer. Note,
this does not handle entry points yet.

Bug: tint:8
Change-Id: Ie665771169261f6839de5eb1b66dc511bf47616a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23704
Reviewed-by: David Neto <dneto@google.com>
2020-06-23 17:54:25 +00:00
dan sinclair 646fb23c1f [metal-writer] Add identifier expression.
This CL adds the start of identifier expressions to the Metal backend.
Identifiers with paths are currently not supported.

Bug: tint:8
Change-Id: I4df8b6a3c32251d454d3dae5fa8933dad36094f8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23703
Reviewed-by: David Neto <dneto@google.com>
2020-06-23 17:49:08 +00:00
dan sinclair 8cd87513b3 [metal-writer] Add return generation.
This CL adds generation of the return statement.

Bug: tint:8
Change-Id: Iffee600e77a485649b987d39aab47742968e438e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23702
Reviewed-by: David Neto <dneto@google.com>
2020-06-23 17:49:00 +00:00
dan sinclair 5dd37b2e6c [metal-writer] Add basic type emission.
This CL adds the start of type emission for the Metal backend. A few
types like pointers and structs aren't complete yet.

Bug: tint:8
Change-Id: I648e9275ef1b9dc6fa63b6ab328fe018a5f620ea
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23701
Reviewed-by: David Neto <dneto@google.com>
2020-06-23 17:48:53 +00:00
dan sinclair 2a59901483 [metal-writer] Stub out the Metal Shading Language backend.
This CL adds the basis of the Metal Shading Language backend.

Bug: tint:8
Change-Id: I85976250eb41ac12203a5db116444e993c3d09d4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23700
Reviewed-by: David Neto <dneto@google.com>
2020-06-23 17:48:40 +00:00
Ryan Harrison 9a452c11ae Fix BUILD.gn issues for TypeDeterminerTest
Change-Id: Iba35145fcba04ecaf2cb411c5e87d2e7f8ecea50
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23740
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-23 16:38:47 +00:00
David Neto 1ca5382749 [spirv-reader] Simplify null composites
Use the shortcut for zero-values: a type constructor without
any parameters.  Scalars still use plain literals like false, 1u, 1.0.

Change-Id: Ie436f1af28cbab0b4c87a07b057deb04632eb534
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23680
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-22 23:15:52 +00:00
dan sinclair 13d2a3b96c [spirv-writer] Only add used variables to entry point.
This Cl updates the entry point code to only output Input/Output
variabes which are referenced by the function instead of all
Input/Output variables.

Bug: tint:28
Change-Id: Idc429e02cac8dac7fc7b609cbd7f88039695829e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23623
Reviewed-by: David Neto <dneto@google.com>
2020-06-22 20:52:24 +00:00
David Neto 194e0cca3b [spirv-reader] Support OpNop
An OpNop maps to nothing

Bug: tint:3
Change-Id: Id73601d481971954dd4de706202b5229dcf39871
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23561
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-22 20:49:34 +00:00
David Neto fd3700c0a7 [spirv-reader] Support Undef, mapping to null
Bug: tint:3
Change-Id: I1549f0445c92312b0d20292ff9d60736300d5378
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23600
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-22 20:48:59 +00:00
David Neto cb8e0bae00 [spirv-reader] Use type aliases pervasively
When a type alias is created, map the SPIR-V type ID to the
type alias, not the underlying type. Only unpack the alias as
needed when inspecting the content structure to make values.

Bug: tint:3
Change-Id: I11011ddd190d89c81d3323f684a5e13f17dde09d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23582
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-22 20:45:43 +00:00
dan sinclair 5b853eebc6 Support the zero initializer syntax.
This Cl updates the system to allow zero initializers. This allows:

```
var a : vec3<f32> = vec3<f32>();
```

Bug: tint:34
Change-Id: I84d6b431914c4ddf112ed375fae028d912f4a080
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23660
Reviewed-by: David Neto <dneto@google.com>
2020-06-22 20:44:27 +00:00
David Neto 9c88ea5988 type determine accessor on aliased array
Change-Id: I8084bf6c30649acb2d6d7639fa6bf78cdd0a4a6a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23581
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-22 20:33:12 +00:00
David Neto 32a4f957b4 Add type alias unwrapping methods
Change-Id: I8dbd3bba48ae95d76f75a5eba3e97ed4e091ed01
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23580
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-22 20:30:33 +00:00
dan sinclair e87ba1fd37 [spirv-writer] Add Operand and Instruction list aliases.
This CL adds OperandList and InstructionList aliases.

Bug: tint:5
Change-Id: I74263e937ed6007bb44c8d502b122d55af4c7b21
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23622
Reviewed-by: David Neto <dneto@google.com>
2020-06-22 20:18:26 +00:00
dan sinclair 011aed9b82 [spirv-writer] Add function calls
This CL adds calls to functions to the SPIR-V writer.

Bug: tint:5
Change-Id: Id6f3e41deba937edb85fa6ec2f2db8d1f4241944
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23621
Reviewed-by: David Neto <dneto@google.com>
2020-06-22 20:18:17 +00:00
dan sinclair 7fe4d02ca1 [spirv-writer] Generate function parameters.
This CL adds generation of OpFunctionParameter entries for function
parameters.

Bug: tint:5
Change-Id: I7af6cb756e20674f32737f2ef362fda12c9d2ef2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23620
Reviewed-by: David Neto <dneto@google.com>
2020-06-22 20:09:23 +00:00
dan sinclair be66f9faf9 [spirv-writer] Emit logical and and logical or
This CL adds support for the &&  and || operators to the SPIR-V backend.

Bug: tint:5
Change-Id: I63b23d9904b5b8027e189034d24949df71cbbe42
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23501
Reviewed-by: David Neto <dneto@google.com>
2020-06-19 19:44:38 +00:00
David Neto 6b6e6a16ea [spirv-reader] Remove orphaned TODOs
TODOs in the test file are or were in the function_arithmetic_test.cc

Change-Id: I679dbf0019e12e26488ccc310dfb03a535628e0b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23462
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-18 19:42:24 +00:00
dan sinclair e9598d697a Add support for sclamp and uclamp GLSL methods.
This CL adds support for type determination of the SClamp and UClamp
GLSL methods.

Change-Id: I974e80127f0e256285f126136270ac5131334a92
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23500
Reviewed-by: David Neto <dneto@google.com>
2020-06-18 18:03:00 +00:00
dan sinclair 8b48b26f73 [spirv-writer] Add as casts.
This CL adds the conversion of `as<f32>(b)` to SPIR-V.

Bug: tint:5
Change-Id: If1e04db2fe5520940527f4dcf52a89628b11b518
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23461
Reviewed-by: David Neto <dneto@google.com>
2020-06-18 18:02:46 +00:00
David Neto d7868e34c2 [spirv-reader] Add ConvertFToU, ConvertFToS
Bug: tint:3
Change-Id: I9f3188e0aac64e98da785c4df2e8b2aa42b71cf8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23402
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-18 17:57:23 +00:00
dan sinclair 206d7401ae [wgsl-reader] Fixup off by 1 bug.
When parsing the `u` in `1024u` we were not advancing the lexer to the
next token which would give parse errors.

Change-Id: I8473b55992ff01d24f9d961878afa6b54d855e68
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23460
Reviewed-by: David Neto <dneto@google.com>
2020-06-18 14:10:58 +00:00
David Neto e12c5ff42e [spirv-reader] Add mixed scalar/vector/matrix multiply
Bug: tint:3
Change-Id: I5875bf453b05c5d5c96f90122206da04f6799976
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23401
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-17 23:33:35 +00:00
David Neto b961e0069b [spirv-reader] Add ConvertSToF, ConvertUToF
Bug: tint:3
Change-Id: I28bcc109a207ef6f5225b9ea707bff11b1b6fd50
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23420
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-17 20:48:56 +00:00
dan sinclair 3238eaa3b1 Add GLSL MatrixInverse type determination.
This CL adds type determination for the MatrixInverse GLSL method call.

Change-Id: I976beb00bb5c869407a0c9f522789112ff22bf6a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23400
Reviewed-by: David Neto <dneto@google.com>
2020-06-17 20:22:08 +00:00
David Neto 7df946d7aa [spirv-reader] Add vector shuffle
Use composite-construct from decomposed singly-named operands.

Bug: tint:3
Change-Id: I8536c5f8e87de312460c3d5c6164e090d79bb4a9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23380
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-17 20:07:49 +00:00
dan sinclair 3819c260de Add type determination for GLSL determinant.
This CL adds the type determination code for the GLSL determinant call.

Change-Id: I46bc57f4fd5f4f43021b20ee511b0b8fc809f4f8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23360
Reviewed-by: David Neto <dneto@google.com>
2020-06-17 18:39:17 +00:00
David Neto 1650af2c86 [spirv-reader] Add OpCopyObject
Bug: tint:3
Change-Id: Ie389c825ddcc8ea6f110997e9b8f39ebbb1e1e0d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23340
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-17 17:46:23 +00:00
dan sinclair 05e73db4ef [spirv-writer] Only extract composites for non-const constructors.
Currently we will attempt to extract composite values for constant
constructors which may happen outside of a function. This causes issues
as the extract requires us to be in a function.

Change-Id: I5724987542cc7d9d86493363ed4d9a44a391a52f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23221
Reviewed-by: David Neto <dneto@google.com>
2020-06-17 13:27:12 +00:00
David Neto 0e0979e89b [spirv-reader] Add ArrayStride
Bug: tint:3
Change-Id: Ib174795d1b055b33bfc94205173dbc5a88bb92cb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23262
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-16 23:47:05 +00:00
dan sinclair c7b66da6ad Cleanup formatting and linter.
This CL cleans up various formatting and lint errors.

Change-Id: Ieee14db90e36acc8b469d58abb84fcf3595321bb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23224
Reviewed-by: David Neto <dneto@google.com>
2020-06-16 15:02:50 +00:00
David Neto 93e39b451b [spirv-reader] Support ifbreak with other forward edge
Add a guard variable for flow control within that if-selection.

Also, the premerge blocks are always surrounded by an if-selection,
to ensure we cause reconvergence at the end of the original if-selection
construct, just like in the original SPIR-V.

Bug: tint:3
Change-Id: I614c6840e539bf9a338058beb5b6f70484e3320a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23182
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-16 01:03:39 +00:00
David Neto ad2f7ccc55 [spirv-reader] Add Namer::MakeDerivedName
Bug: tint:3
Change-Id: I4dc3049c577049bb4ad0d1e42ec80f7d82cdb4a4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23181
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-16 01:02:59 +00:00
David Neto 318ae59f4d [spirv-reader] Update TODOs in test matrix
We've already written those tests.

Bug: tint:3
Change-Id: Ic836be43b5f1220e3563e4d27abd9b5e2ab54460
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23180
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-16 01:02:27 +00:00
David Neto b2b0dfefa9 [spirv-reader] Add OpCompositeExtract
Bug: tint:3
Change-Id: I9d8c1cf2545e28ef0ddf89e55ce45ec19c50022a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23161
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-16 01:02:21 +00:00
dan sinclair 6941c5354c [spirv-writer] Allow emitting an array stride.
This CL adds the ability to attach a stride to an array type and have it
emitted during SPIR-V generation.

Bug: tint:5
Change-Id: I9c0f0a6afef6ae6662b64f4da2c150ba3f8da29f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23223
Reviewed-by: David Neto <dneto@google.com>
2020-06-15 20:58:28 +00:00
dan sinclair 7be237aa8f Determine types for module scoped variable constructors.
This CL updates the type determination code to determine the types of
module scoped variable constructors.

Bug: tint:89
Change-Id: Icd5d65409fcf17a0cbf0b34b9919f8d9e1577354
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23220
Reviewed-by: David Neto <dneto@google.com>
2020-06-15 20:55:09 +00:00
David Neto c7d1ac3361 [spirv-reader] Add OpCompositeConstruct
Bug: tint:3
Change-Id: Ibb1a4124e7e7b7a5b95bdd4e7c7e7f1c570e641c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23127
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-12 15:09:56 +00:00
David Neto 0335adbc9a [spirv-reader] First GLSL.std.450 instructions
This supports the extended instructions used by the compute_boids
example.

Bug: tint:3
Change-Id: I364c343217139e489377dd2a9330058114023caa
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23126
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-12 15:09:14 +00:00
David Neto 709b62528c [spirv-reader] Add fallthrough
Bug: tint:3
Change-Id: Ib2d337156d419ed13ef9c67aa94ac3ee90f79548
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23041
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-11 20:53:39 +00:00
David Neto 416be308fc [spirv-reader] Add switch-selection
- Avoid redundant switch-break.
  WGSL does an implicit break at the end of a switch case, because
  it has fallthrough.

TODO: Emit fallthrough

Bug: tint:3
Change-Id: Ida44b13181a01a2c1459c0447dac496ba5b97ffc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22961
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-11 20:39:06 +00:00
Ryan Harrison be45ff5081 Create tint.h for external users
tint.h selectively includes headers depending on what features are enabled. It
is based off of the original sample code, so should give users access to all of
the functionality demonstrated in there.

This is located in include/tint/, so that users can have a pretty include of
tint/tint.h.

BUG=tint:87

Change-Id: I8659c789c154349e4e8e7730dc334da4fb6eba70
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23124
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-11 19:35:20 +00:00
David Neto 8ca0aa710d [spirv-reader] Simplify if-selection bookkeeping
In BlockInfo, remove the backpointers from true-head, false-head, and
premerge-head to the if-selection header block.

Convert the forward references from if-selection to its internal heads
from pointers to IDs.

Bug: tint:3
Change-Id: Ic931df519795e14374bff4f60ad37a4b32f79c91
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23140
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-11 18:11:15 +00:00
David Neto 046c2b7c4c [spirv-reader] remove exclusive_false_head_for
Code cleanup

Bug: tint:3
Change-Id: I8d1c4e8a486b3c3cccb13e0a265269606278fb97
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23080
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-11 14:19:07 +00:00
Ryan Harrison 3f3483be14 Fix BUILD.gn based builds
Change-Id: Iec5c7ee8d6f614f7a7301c023703650d4c4068d3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/23061
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-10 19:45:00 +00:00
David Neto 39e83353f0 [spirv-reader] Avoid emitting empty elses
Produce less noise in ASTs for a common case.

Also test that an empty continuing construct doesn't show up in the
AST.  That's currently handled by the AST code. We want to keep this
behaviour even if the AST implementation changes. Right now
code change is needed when emitting the start of a continuing
construct.

Bug: tint:3
Change-Id: I96a12087e305c64647561f65d87acda907ae9c42
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22844
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-09 20:07:48 +00:00
dan sinclair af5df70c7b Add GLSL FindILsb, FindUMsb, FindSMsb and InterpolateAtCentroid.
This CL adds the type determination for the GLSL methods FindILsb,
FindUMsb, FindSMsb and InterpolateAtCentroid.

Change-Id: I2b1e9d021e6799ffe6b5b71c5cca947b8e6ccfa0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22843
Reviewed-by: David Neto <dneto@google.com>
2020-06-08 23:48:26 +00:00
dan sinclair ee39225c0b Add support for GLSL cross.
This CL adds support for the GLSL cross method.

Change-Id: Ib2e83a2ef2e580c6ca257851a76f3f66fa377d6f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22842
Reviewed-by: David Neto <dneto@google.com>
2020-06-08 23:48:15 +00:00
dan sinclair 92bb55777c Add GLSL umin, umax, smin and smax support.
This CL adds type determination for the umin, umax, smin and smax GLSL
methods.

Change-Id: Ib301da41baf718e309a940f4a3560088daa10741
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22841
Reviewed-by: David Neto <dneto@google.com>
2020-06-08 23:48:07 +00:00
dan sinclair 5e5fb9cf37 Add ssign and sabs GLSL support.
This CL adds the SSign and SAbs GLSL methods to the type determination.

Change-Id: If0e25cd153bd3aaef1cb031d647a86e98ff917bf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22840
Reviewed-by: David Neto <dneto@google.com>
2020-06-08 19:01:07 +00:00
dan sinclair 53352044df Refactor GLSL type determination code.
This Cl cleanups and simplifies the type determination for the GLSL
imports.

Change-Id: I9dd85ac390ef37c91d9493f840f81ceb6736fc06
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22820
Reviewed-by: David Neto <dneto@google.com>
2020-06-08 18:49:31 +00:00
David Neto b0d308c9fe [spirv-reader] Emit non-header OpBranchConditional
This emits the equivalent of break-if, break-unless, continue-if,
continue-unless.  But we do it via a regular if-then-else.

Adds a test matrix.
Adds all required tests except for those needing OpSwitch.

Bug: tint:3
Change-Id: I960a40aa00f95f394a92a099c8b12104010ad49f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22603
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-08 18:26:03 +00:00
David Neto bff3b78313 [spirv-reader] Add cases for mergeless OpSwitch
This is a bit pathological.

Bug: tint:3
Change-Id: I448796c712049f88cef9a592c218d94a0daddb75
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22760
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-08 15:26:18 +00:00
David Neto 783938d173 [spirv-reader] Fix typo in test name
Prefix should match a method name on FunctionEmitter

Bug: tint:3
Change-Id: I0af9fb33210d09a59e5cacdade986668fe685682
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22681
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-08 15:14:22 +00:00
David Neto bdcd04b1a2 [spirv-reader] Check some merge block dominance
A merge block must be dominated by its own header.
This CL checks the cases where that fails because the
merge block is also the:
- the default or case header for a switch (a different header)
- the true-head, false-head, or premerge-head for an if-selection
  with a different header

Bug: tint:3
Change-Id: I6dd1fae162e9d33bd9a0b43d3ca9558cebed058b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22680
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-08 15:14:22 +00:00
David Neto dc8efd4095 [spirv-reader] Add mergeless OpSwitch case
This is a bit pathological.

Bug: tint:3
Change-Id: I820d7d1bfd298a22be6c6014e7d4d00f1097759e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22740
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-08 14:53:34 +00:00
David Neto 5d4c35f96e [spirv-reader] kIfBreak edge counts toward divergence
This fixes the pathological cases nobody wants, and arguably
should be added to the SPIR-V spec.

If we really really want to support these cases, we can revisit.

Bug: tint:3
Change-Id: I0a75490d451676caa0933e3761098ba1fe3f8b60
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22664
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-08 14:37:05 +00:00
dan sinclair 7615d9468c [spirv-writer] Cleanup capabilities code.
This CL simplifies the capabilities code in the SPIR-V builder.

Bug: tint:5
Change-Id: Iff99350b2d6a2534c82ea3d47a0a9186d0dcb6ac
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22661
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-06-04 17:29:54 +00:00
dan sinclair 65cd5a8e0d [spirv-writer] Add support for outer_product
This CL adds support for generating OpOuterProduct.

Bug: tint:5
Change-Id: Iefbc91807850b7caf5dba393124f97417b7b0b09
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22660
Reviewed-by: David Neto <dneto@google.com>
2020-06-04 17:17:37 +00:00
dan sinclair 36471fe3eb [spirv-writer] Add support for derivatives.
This CL adds support for generating the various dpdx, dpdy and fwidth
instructions.

Bug: tint:5
Change-Id: I6d12c738b93931d1e740659d9c1871892b801f71
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22625
Reviewed-by: David Neto <dneto@google.com>
2020-06-04 17:14:43 +00:00
dan sinclair 2cbbb5d7c2 [spirv-writer] Add support for dot call.
This CL adds support for generating OpDot.

Bug: tint:5
Change-Id: I5a77e49ff26ff12b4ed7b2b01665f0928e51a568
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22624
Reviewed-by: David Neto <dneto@google.com>
2020-06-04 17:06:06 +00:00
dan sinclair 3c3cf3cc21 [spirv-writer] Add support for is_inf
This CL adds support for generating OpIsInf.

Bug: tint:5
Change-Id: Ia208695d78f9914000e893435f37be45adb81022
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22623
Reviewed-by: David Neto <dneto@google.com>
2020-06-04 17:05:55 +00:00
dan sinclair c31903d2ad [spirv-writer] Add is_nan support.
This Cl adds support for generating OpIsNan.

Bug: tint:5
Change-Id: If35e46c6cb2719771abdd425ff6116b539da0be0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22622
Reviewed-by: David Neto <dneto@google.com>
2020-06-04 17:05:49 +00:00
dan sinclair 0bcb50b04a [spirv-writer] Add support for all intrinsic.
This CL adds support for generating an OpAll .

Bug: tint:5
Change-Id: I70a92bc68064625324d6c7b59220a901ced76f96
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22621
Reviewed-by: David Neto <dneto@google.com>
2020-06-04 17:05:43 +00:00
dan sinclair 3e7dc82b35 [spirv-writer] Generate any intrinsic
This CL adds the necessary code to generate an OpAny instruction.

Bug: tint:5
Change-Id: I558b2cbf4bade3b4ab17997d24dcffddc32e2b41
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22620
Reviewed-by: David Neto <dneto@google.com>
2020-06-04 17:05:35 +00:00
David Neto 06d49471a0 [spirv-reader] Refactor emission for OpBranch
Bug: tint:3
Change-Id: If1d603990f133f8ba0b3a305f7f7f3db4623e9ce
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22602
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-04 15:28:10 +00:00
David Neto 3bbc45ded3 [spirv-reader] Update test to show error caught
This is the case where a block can't be a "continue block"
for more than one header.  It can only be a continue block for
the innermost loop it's inside of.

Bug: tint:3
Change-Id: Ic19ca544ab8a30cb1ff16d2c828abb260facba90
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22601
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-04 15:27:05 +00:00
David Neto 90d6b2d94f [spirv-reader] Update test to show error is caught
In this example, a branch escapes an if-selection.
This is caught by ClassifyCFGEdges

Bug: tint:3
Change-Id: I5586e8bb5f9de0cdf57ad46708fcee12cd31f6aa
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22600
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-04 15:26:31 +00:00
dan sinclair ccb699eb00 Remove right shift arithmetic operand.
The `>>>` symbol was folded into the `>>` symbol in WGSL. This CL
removes `>>>` from Tint.

Change-Id: I9d900de9a6026a8099796b94aad44483f0c6813f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22582
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-06-03 16:11:44 +00:00
dan sinclair 2b23e4bd70 Remove unless_stmt
The `unless` statement was removed from the WGSL grammar so remove it
from Tint.

Change-Id: I31a185f5c5e3e88b667caea1c9a88aee80c0b810
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22581
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-06-03 16:11:37 +00:00
dan sinclair 6bd7061a2e Remove conditional break/continue.
This CL removes the conditional forms of the break and continue
statements as they are no longer in the WGSL spec.

Change-Id: I46224d6cb5ce706cfc95d35ab0a4eea46abf62a9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22580
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-06-03 16:11:28 +00:00
David Neto 27d42ede4e [spirv-reader]: Support OpBranch
Bug: tint:3
Change-Id: I39d03f4fc29c7b60dc09d0bafc3afaec754671a0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22425
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-03 13:43:03 +00:00
dan sinclair 579d33c528 Make case selectors an integer value
Change-Id: I819983701ed6cca4eba1a05b4edc5fdff10fa88d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22542
Reviewed-by: David Neto <dneto@google.com>
2020-06-02 20:12:02 +00:00
dan sinclair e009c2058d Add IntLiteral parent for Sint and Uint literals.
This CL adds a parent class for the type types of interger literals for
the cases where we can have either.

Change-Id: I61b540bedd49a6cf5a899e6864e2ea6f140cd2be
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22541
Reviewed-by: David Neto <dneto@google.com>
2020-06-02 20:11:54 +00:00
dan sinclair c6f2947ceb Rename the IntLiteral to SintLiteral.
This Cl clarifies that IntLiteral is a signed value, which matches with
the usage of UintLiteral.

Change-Id: Ic8f0e2382cb66eb6b09daed096886dcc55e6b0f0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22540
Reviewed-by: David Neto <dneto@google.com>
2020-06-02 20:11:44 +00:00
David Neto 1649dfadd7 [spirv-reader] Support unreachable, as a return
Bug: tint:3
Change-Id: Ia1384f84f7851a9e155c1536a624213ef51ee0a1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22521
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-02 19:56:07 +00:00
David Neto 91332dc475 [spirv-reader] Support kill
Bug: tint:3
Change-Id: I91472b98c9977a5bdce6fc2ab4880e8312881fcf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22500
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-02 19:56:07 +00:00
dan sinclair 1d69915155 Rename case statement conditions to selectors.
The name conditions isn't quite correct for the case statement. This CL
updates the code to use selectors instead of conditions.

Change-Id: I98b8050b11e2328f97e4443469572ab47d7c1555
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22520
Reviewed-by: David Neto <dneto@google.com>
2020-06-02 17:18:56 +00:00
David Neto cb48e79fa5 [spirv-reader] Support return, return-value
Bug: tint:3
Change-Id: Iaaf6ace739ac30e7f9f0bd4ddcef209ab1b71ed8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22480
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-02 16:48:27 +00:00
David Neto d8613596e2 [spirv-reader] Emit loop and continuing
Bug: tint:3
Change-Id: Iaced5ee41f6b27ab350432fc1c2cdff6042ba191
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22423
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-02 16:46:51 +00:00