Commit Graph

382 Commits

Author SHA1 Message Date
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
David Neto 468c26b233 [spirv-reader] Emit control flow: if/then/else
Bug: tint:3
Change-Id: Ief0544415f27842913a6234a962d163ecedb48df
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21821
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-02 13:25:06 +00:00
dan sinclair e2be489756 Fix merge conflict
Change-Id: Idd941099241e9310fea13932c3ef4fcf5083730a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22441
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-01 19:00:41 +00:00
dan sinclair dadd149d9b [spirv-writer] Add fallthrough support
This CL adds support for the fallthrough statement in a `case` block.

Bug: tint:5
Change-Id: I282643a304846a19212d41bd8bd20a60398bd793
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22220
Reviewed-by: David Neto <dneto@google.com>
2020-06-01 18:56:56 +00:00
dan sinclair 916b408111 [spirv-writer] Add switch support
This CL adds switch support to the SPIR-V writer.

Bug: tint:5
Change-Id: I8a6ad40cb2d344c87abdf842194b60afb1b4c96e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22165
Reviewed-by: David Neto <dneto@google.com>
2020-06-01 18:56:34 +00:00
David Neto 7768f5b308 [spirv-reader] use stack of statement lists
This is preparation for emitting nested control flow.

Bug: tint:3
Change-Id: I90fc7edba8cb9937f722e6f5e94c7f222d34c403
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21801
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-01 18:51:06 +00:00
David Neto b83c651654 [spirv-reader] Add problematic CFG case as disabled test
In this case, a basic block is a continue target
for both an outer loop and is also for itself as a
single-block loop.

Bug: Tint:3
Change-Id: If361004a4b871966674ca972922c45e712ce7c9c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22420
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-06-01 16:59:24 +00:00
dan sinclair 1aadbd4e47 Add case_selectors update
This CL adds the missing case_selectors option from the grammar updates.

Change-Id: Ia6c110e917dd574711d396fb34ad53a2a67cf1fe
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22306
Reviewed-by: David Neto <dneto@google.com>
2020-06-01 16:56:46 +00:00
dan sinclair 59fc026bcf [spirv-writer] Generate kill statements.
This Cl adds preliminary support for generating Kill commands. This may
change in the future if the semantics of kill are set in WGSL to not
match OpKill.

Bug: tint:5
Change-Id: Id466a1b26b37867a26373b93f56d627a0491f47f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22240
Reviewed-by: David Neto <dneto@google.com>
2020-06-01 13:44:43 +00:00
dan sinclair 091b2b5fc8 Updating to match WGSL spec.
This CL updates a few names, addeds a return_stmt method and re-orders
some code to closer match the current WGSL specification.

Change-Id: I388be1c22d5d10229fdfcdb2ff929c410f5ae638
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22305
Reviewed-by: David Neto <dneto@google.com>
2020-06-01 13:44:06 +00:00
dan sinclair 46e959da39 Update intrinsics in the grammar.
The intrinsic methods were removed from the WGSL grammar and are treated
as builtin functions. This Cl updates Tint to match.

Bug: tint:41
Change-Id: I3f9ff6c17f1ca57ad159d883fd5a966657caeb4f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22301
Reviewed-by: David Neto <dneto@google.com>
2020-06-01 13:43:22 +00:00
dan sinclair 1d2ad81eb9 Update WGSL grammar builtins to match spec.
This CL removes the builtin_decoration from the parser in favour of
using IDENT tokens for builtins. We still convert to an enum in the
parser and validate the value provided.

Bug: tint:41
Change-Id: If5dc3844e3325c75951e7b320c123cf66cb8e106
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22300
Reviewed-by: David Neto <dneto@google.com>
2020-06-01 13:43:11 +00:00
dan sinclair 0647d23607 [spirv-writer] Remove stpq support.
This CL removes conversion of stpq to indexes for a vector swizzle as
they are not supported by WGSL.

Change-Id: I3fde18a8a4205cae83b32ce2830a6df48a8f22f4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22162
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-05-27 13:08:29 +00:00
dan sinclair 5370390096 Remove NOP.
The NOP command was added for complete SPIR-V bijectivity which is no
longer a goal of WGSL. The NOP command has been removed from the spec,
so remove from Tint.

Change-Id: Ic640d9d3b987a19668dc169ff549444921c5bbb8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22160
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-05-26 15:05:54 +00:00
dan sinclair 53f2026fc5 Add if with else continue test.
This Cl adds a test for a continue inside an else case.

Bug: tint:5
Change-Id: If9606b18ff8c2af6eb271aa37c404f36097f592e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22060
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-05-21 17:46:02 +00:00
dan sinclair 615aaed508 [spirv-writer] Fill out cast code.
This Cl adds tests for more of the cast code along with adding a few
missing cast cases.

Bug: tint:5
Change-Id: I417d46661bb310f27329f3e2459b76aa61a49d31
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/22040
Reviewed-by: David Neto <dneto@google.com>
2020-05-21 13:57:07 +00:00
David Neto 7e5e02f805 [spirv-reader] Support access chain
Bug: tint:3
Change-Id: Ibdb6698c4a97ce66ed533a9bf007bc352a09244e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21641
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-05-20 20:36:18 +00:00
David Neto 91c5a496d2 [wgsl-writer] Function var decls don't mention storage class
From WGSL decision in https://github.com/gpuweb/gpuweb/issues/654

Change-Id: I570475cf0d069043d70794d7b92626798963bfdc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21363
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-05-20 18:33:54 +00:00
David Neto 1bbc1cb2c1 [spirv-reader] Support null vector, matrix, arr, struct
Bug: tint:3
Change-Id: I2fa25e5d28b965de4a419719e37bc999be8489ea
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21581
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-05-19 14:46:41 +00:00
David Neto b275fd2f0e [spirv-reader] Systematic bad construct exit tests
Do so systmatically. Before we had tested some as a side effect
of other objectives.

Fix the error message for when we have a bad exit from a loop construct
that bypasses not only the continue construct but the loop merge block
itself.

Bug: tint:3
Change-Id: Iaf8fc9bcd3162002aa906efa90a244ef5f439911
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21580
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-05-19 14:43:19 +00:00
David Neto e3d235662a [spirv-reader] Remove TODO about nested selections
Remove TOOD about special code for finding badly nested selections.
This is already adequately covered by the dominance-violation checks,
and related tests:

  ClassifyCFGEdges_DomViolation_BeforeIfToSelectionInterior
  ClassifyCFGEdges_DomViolation_BeforeSwitchToSelectionInterior
  ClassifyCFGEdges_DomViolation_BeforeLoopToLoopBodyInterior
  ClassifyCFGEdges_DomViolation_BeforeContinueToContinueInterior
  ClassifyCFGEdges_DomViolation_AfterContinueToContinueInterior

Bug: tint:3
Change-Id: I8c547474d1422a54078d748b39a7d22a500d5d1d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21482
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-05-19 14:37:10 +00:00
David Neto c02de8fc45 [spirv-reader] remove redundant disabled test
ClassifyCFGEdges_Forward_LoopToContinue is already covered via
ClassifyCFGEdges_LoopContinue_LoopBodyToContinue and ...ConditionalFromNestedIf
and other LoopContinue cases

Bug: tint:3
Change-Id: I4a89a82c0c9a08939036a20f13932c18e1f90df6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21560
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-05-19 14:34:27 +00:00
David Neto 9f7297c766 [spirv-reader] Unordered float compares
Unordered float compares are not supported directly by WGSL.
Translate them as negated ordered compares.

Bug: tint:3
Change-Id: I4fea7c924054cffc9a39a8be3b3d9f088d302114
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21540
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-05-14 21:43:27 +00:00
Ryan Harrison 0bbf1e7460 Small fix for BUILD.gn
Change-Id: I1a43eeebff6d952e76a7247754dc2a89694ab064
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21500
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-05-11 15:45:51 +00:00
David Neto cad427e787 [spirv-reader] Find if-selection internal headers
Finds the "then", the "else", and "premerge" nodes.
The premerge node, if it exists, is the first block where
the normal forward flow of the "then" and "else" clauses
converge, but before the merge block.

Finds error case where there a block has both an if-break
edge and a forward-to-premerge.  There is no good way
to model that in a high level language.

Bug: tint:3
Change-Id: I759fc539f3480e38d091041db6a9abd15f3df769
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21240
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-05-07 20:27:42 +00:00
David Neto d8082d27a3 [spirv-reader] Rename Edge::kToMerge to kIfBreak
Change-Id: I187b88cb68a04e46a16b6391013bdaf148191cc2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21221
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-05-07 20:20:05 +00:00
David Neto 15fd7366cc [spirv-reader] Classify kSwitchBreak from deep in control flow
This also refactors break detection.

Bug: tint:3
Change-Id: I3a3e01c8d76d7c6fc2a14b3dbff136acd487e802
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21220
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-05-07 20:20:05 +00:00
dan sinclair 4dfda012b2 Rename brace and bracket to match spec
The names for brace and bracket got flipped in the spec, update Tint to
match.

Change-Id: Ifbad5f239834b77b9aa27ef21b9d704cab742f4f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21260
Reviewed-by: David Neto <dneto@google.com>
2020-05-07 19:47:39 +00:00
Ryan Harrison ace7a13662 Fixes to unbreak the BUILD.gn build
Change-Id: I0077bb103fc6940c1af029a65b7069cb6fbec3d9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21201
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-05-06 21:49:55 +00:00
dan sinclair a4e6858b94 Remove push constants.
Push constants won't be supported by WebGPU. This CL removes them from
Tint.

For the SPIR-V reader case, this means the push constant will cause a
unknown storage class error.

Bug: tint:19
Change-Id: I10b09ce589b6b370fc828af0cd56e6213c5bc694
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21180
Reviewed-by: David Neto <dneto@google.com>
2020-05-06 21:48:23 +00:00
David Neto ab56088ae7 [spirv-reader] Classify kSwitchBreak edges
These used to be classified as kToMerge

Bug: tint:3
Change-Id: I63fb286c371582676e5943a3082c0614b9c8d5d0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21081
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-05-06 18:32:38 +00:00
David Neto 920bdcd0aa [spirv-reader] Refine selection construct concept
Distinguish between selections constructs starting with with
OpBranchConditional and those starting with OpSwitch.

We'll use this in a followup CL to track break from a switch.

Bug: tint:3
Change-Id: I8d000cb42325535a4937c84f83a83c98a9b8d4c5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21080
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-05-06 18:32:29 +00:00
David Neto 054927d7eb [spirv-reader] Classify CFG edges
Classify CFG edges:
 - loop backedge
 - a structured exit:
   - loop break
   - loop continue
   - selection break
 - fallthrough
 - forward (any of the rest)

Also error out when there should have been a merge instruction.
(More than one unique fallthrough or forward edge).

Includes lots of tests.

Bug: tint:3
Change-Id: I70f27680bdf098213056522abf04ac58a6b478ab
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20481
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-05-05 21:17:13 +00:00
dan sinclair b1870eff04 [spirv-writer] Add a LocalSize execution mode.
In SPIR-V a compute entry point requires a WorkGroup Size constant or a
LocalSize execution mode. This CL adds a 1,1,1 execution mode as a
starting point.

Bug: tint:74
Change-Id: Ie5bf639472033dca9ffe333548e7f31d4d318768
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21020
Reviewed-by: David Neto <dneto@google.com>
2020-05-05 14:21:28 +00:00
dan sinclair 2287f33424 [spirv-writer] Add null initializers where needed.
The WGSL spec requires initializers for Output, Private and Function
variables. This CL adds initializers where needed.

Bug: tint:75
Change-Id: Id97f85a67ead2ffc41d6bdd1b71bf7034b04502a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20980
Reviewed-by: David Neto <dneto@google.com>
2020-05-05 14:21:19 +00:00
dan sinclair 5b43c58f02 [spirv-writer] First pass at entry point interface
This CL adds the first simple pass at adding interface variables into
the entry point command. It simply lists all Input/Output module scoped
variables onto all entry points.

Bug: tint:28
Change-Id: I962462d783f3b97bb3da32fd9890ceb90808942b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20963
Reviewed-by: David Neto <dneto@google.com>
2020-05-04 19:42:43 +00:00
dan sinclair 6ca2699eaf Windows fixes.
This CL fixes up some issues which give compile errors when building
with Visual Studio.

Change-Id: Ib76644d869dd2adccd579621d18804d84b65a74c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20940
Reviewed-by: David Neto <dneto@google.com>
2020-05-04 18:58:24 +00:00
dan sinclair 253ee1b3ef Fixup IntLiteral names.
This CL fixes the IntLiteral name to contain the type of the literal.
This keeps i32 and u32 from fighting over a given name. Now, the name
ends up being __int__i32_0 instead of __int_0.

Change-Id: Ifb9f0516139d25f34312c75c77318eccbe076ef8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20941
Reviewed-by: David Neto <dneto@google.com>
2020-05-04 18:58:19 +00:00
dan sinclair 6164da26b7 [spirv-writer] Handle load of array accessors if needed.
In some cases the array access must generate a load if there is a
following swizzle. This CL adds the needed load.

Bug: tint:71
Change-Id: Ib6ca6284af993962d9d573b323d54be7ce0e726c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20920
Reviewed-by: David Neto <dneto@google.com>
2020-05-04 17:06:17 +00:00
dan sinclair 8a669aabeb [spirv-builder] Generate load for cast expression.
If the value being casted is a pointer it must be loaded first. This CL
adds the needed load.

Bug: tint:72
Change-Id: Ia019b7976db6b97c811f6424db8fe4f07a3d11f3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20900
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@google.com>
2020-05-04 17:06:05 +00:00
David Neto c8c10e83df [spirv-writer] Generate load for var initializer, if needed
Change-Id: I609860bb05fae3e6e5eb21a471f869030f384ad0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20721
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-05-01 19:09:08 +00:00
dan sinclair abd472e45a [spirv-writer] Add start of cast support.
This CL starts support for the cast expression. It adds the i32 to f32
conversion path.

Bug: tint:5
Change-Id: Id1eafc38592060c4b5b91964302d79a847e2edaf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20628
Reviewed-by: David Neto <dneto@google.com>
2020-05-01 19:05:55 +00:00
dan sinclair cf3517812c [spirv-writer] Load array accessors if required.
If an array accessor index is a variable it needs to be loaded before we
can use it to access the array. This CL adds the call to generate the
load for the index.

Bug: tint:5
Change-Id: I74143d2eb746727e857218d54126e1f5fd785bdf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20780
Reviewed-by: David Neto <dneto@google.com>
2020-05-01 19:05:21 +00:00