Commit Graph

1904 Commits

Author SHA1 Message Date
Antonio Maiorano e0448d3d64 ProgramBuilder: make Const helpers require a constructor arg
This was originally used to find and fix tests that were not
initializing constants, but these were independently fixed by jrprice@
recently (see https://dawn-review.googlesource.com/c/tint/+/50042)
recently. Still, this change is useful to avoid this happening again.

Bug: tint:792
Change-Id: I0119a1a6ade7a70a0d110ef0aac80f4eaf37a7b4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50560
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-05-10 20:42:56 +00:00
David Neto a083f329a7 spirv-reader: import tests: make valid SPIR-V
Bug: tint:765
Change-Id: If6dc558a86bb64dfb7f61d237e774f41f735c732
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50442
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-05-10 20:34:26 +00:00
Ben Clayton ad19a63c54 Add sem::Reference
Bug: tint:727
Change-Id: I904d33b6c0678f478b4687fcc08589dc3cfd379d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50541
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-05-10 19:45:46 +00:00
Ben Clayton 3f968e7b05 Resolver: Validate resource binding decorations
Validate that:
* That resource variables have resource bindings
* Only resource variables have resource bindings
* That a [[binding]] decoration is paired with a [[group]]
* That binding points are not reused in the same entry point

Fixed: tint:235
Fixed: tint:645
Bug: tint:645
Change-Id: I2542934b4c6a2b4bbde48242932c04c796033a90
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50500
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-05-10 19:16:46 +00:00
Ben Clayton 6ba446fa5e Remove "Is" tests
These originate from a time before Castable, and there were hand-written Is<T>() methods on each of the base types.

Castable has its own tests that ensure the Is<T>() and As<T>() work as expected.
We don't need to check that this logic works for every type that derives from castable.

Change-Id: Iaa376dc4b4b5ee413a83fc5f9113cd3ef91dfe4a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50540
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-05-10 18:27:31 +00:00
Ben Clayton eebf0c97d9 Fix lint errors
Change-Id: Ia31d9fed7c9695e7f3e4d26fc3acf073ef42002d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50308
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-05-10 18:21:36 +00:00
Ben Clayton f14e0e1c8c Rename all type UnwrapXXX() methods
Give them sensible names.
Make them act consistently.
Remove those that were not used.

Change-Id: Ib043a4093cfae9f81630643e1a0e4eae7bca2440
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50305
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-05-10 18:06:31 +00:00
Ben Clayton fcda15ef67 Move storage_class validation from wgsl to resolver
We don't want the WGSL parser to have to maintain type lookups.
If the WGSL language is updated to allow module-scope variables to be declared in any order, then the single-pass approach is going to fail horribly.

Instead do the check in the Resovler.
With this change, the AST nodes actually contain the correctly declared storage class.

Fix up the SPIR-V reader to generate StorageClass::kNone for handle types.
Fix all tests.

Bug: tint:724
Change-Id: I102e30c9bbef32de40e123c2676ea9a281dee74d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50306
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-05-10 18:01:51 +00:00
Ben Clayton a34fa0ecb7 Remove sem::Alias
With the parsers now using ast::Types, nothing should be producing these any more.

This change also removes Resolver::Canonical(), which is now unneeded as there are no sem::Aliases to remove.

Bug: tint:724
Change-Id: I0c1a49f49372c1fcc37864502f07c5c76328d471
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50304
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-05-10 17:38:01 +00:00
Ben Clayton cbbe576415 reader/spirv - add type hierarchy
Don't create disjoint AST type nodes.
Instead use a new bespoke type hierarchy that can Build() the required
AST nodes.

Change-Id: I523f97054de2c553095056c0bafc17c48064cf53
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49966
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-05-10 17:25:21 +00:00
Brandon Jones c705b6caac Add external_texture_transform to backend writers
Adds the external texture transform to always run in the spirv, msl, and hlsl writers.

Bug: dawn:728
Change-Id: I15a96e877e1e88f9a4a4b015cf47251b41b18e35
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50024
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Brandon Jones <brandon1.jones@intel.com>
2021-05-10 16:15:31 +00:00
Ben Clayton 8f96595540 ExternalTextureTransform: Fix undefined behavior
WGSL now supports type inferencing with `let` declarations, so `var->type()` may return nullptr.
Calling a method (`Is<T>()`) on a nullptr object is UB. Instead used the free-function form which can handle nullptr objects.

Change-Id: I8faf875e1550eac1306ad731a65f3662bc4e5b43
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50307
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Brandon Jones <brandon1.jones@intel.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-05-10 16:06:51 +00:00
David Neto 1f68519dee spirv-reader: make valid SPIR-V for derivative tests
Bug: tint:765
Change-Id: I81a905e73d7435d85cffab4ff804934015de065b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50441
Reviewed-by: Alan Baker <alanbaker@google.com>
Commit-Queue: David Neto <dneto@google.com>
2021-05-10 16:01:11 +00:00
David Neto 799cecedb7 spirv-reader: rename test class for GetDecorationsFor
Bug: tint:765
Change-Id: I2b9a78baf45ba20168e23209f5d4cbf9bb231c7c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50440
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: Alan Baker <alanbaker@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-05-10 13:54:06 +00:00
Antonio Maiorano 9fdfa1e323 Resolver: validate else condition is boolean
Bug: tint:786
Change-Id: I5e4987e4eeb0608c640fc5c8ea035c8dca0ef187
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50461
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-05-10 13:46:06 +00:00
David Neto 6a56744b55 spirv-reader: make valid SPIR-V for memory tests
Bug: tint:765
Change-Id: I0760a46d2a4409dca0d8873fd87d815f7d0cbaab
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50023
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-05-07 22:59:24 +00:00
David Neto 24fdbf9ec8 spirv-reader: named type tests are deliberately invalid SPIR-V
Bug: tint:765
Change-Id: I1a1a6fb6eef3fe7d0d7fbe5e6ce819ae89978f3f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50022
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-05-07 22:22:34 +00:00
David Neto 92ba7ee75c spirv-reader: logical instruction test validity
Bug: tint:765
Change-Id: Idcba9020f16987f6ed63a03b1fc560872aa7a1c5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50021
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-05-07 21:45:04 +00:00
David Neto 9b26923b63 spirv-reader: validity for user name tests
Bug: tint:765
Change-Id: Iad711d911137e2f66be28ac8238389f5b68c1d20
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50020
Commit-Queue: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-05-07 21:35:54 +00:00
Ben Clayton 2e1a284cbb writer/spirv: Simplify member accesses
Using semantic info.

Change-Id: Iec9a592d9d66930535ead78fab69a6085a57a941
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50302
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-05-07 21:05:54 +00:00
Ben Clayton 4cd5eea87e sem: Fold together sem::Array and sem::ArrayType
There's now no need to have both.
Removes a whole bunch of Sem().Get() smell, and simplifies the resolver.

Also fixes a long-standing issue where an array with an explicit, but equal-to-implicit-stride attribute would result in a different type to an array without the decoration.

Bug: tint:724
Fixed: tint:782
Change-Id: I0202459009cd45be427cdb621993a5a3b07ff51e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50301
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-05-07 20:58:34 +00:00
David Neto 6732e8561c spirv-reader: CFG tests: make valid SPIR-V
Bug: tint:765
Change-Id: I84ea018478feafc4a5c03052832acae8cf3f15b9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49940
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-05-07 20:33:05 +00:00
Ryan Harrison 74490e118e Test that entry point IO attributes are of valid types
BUG=tint:773

Change-Id: I94e8624647c645efe7ed558caa3d3bd05dd72f63
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50260
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-05-07 20:28:04 +00:00
David Neto ff7a5f8dc9 spriv-reader: CFG tests: end with OpFunctionEnd
Bug: tint:765
Change-Id: Ib72c2fcd94bd8058ddfbd7e1fc7b1d968d0429ec
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49843
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-05-07 19:47:04 +00:00
David Neto 25df959dad spirv-reader: Rename test class for CFG tests
This makes it easier to triage test failures.

Bug: tint:765
Change-Id: I72d12e9eff3466d3d02952edce14499a61a4782b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49842
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-05-07 19:05:54 +00:00
Ben Clayton fb13f025a3 writer/wgsl: Only generate from the AST types
Remove the legacy generation path that uses the semantic types.

Bug: tint:724
Change-Id: I38128ab2049cb1dcea333c24453d6636b0ebb8c6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50300
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-05-07 15:05:44 +00:00
Ben Clayton ba6ab5e6bd sem: Fold together sem::Struct and sem::StructType
There's now no need to have both.
Removes a whole bunch of Sem().Get() smell, and simplifies the resolver.

Bug: tint:724
Fixed: tint:761
Change-Id: I756a32680ac52441fd6eebf6fc53dd507ef5e538
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49961
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-05-07 14:49:34 +00:00
Ben Clayton 33d0f6aa08 Fix UBSAN error
As() was being called on a nullptr object.

Change-Id: Iedd7f1c57d12f1ad5ea2af60317817841f5d1392
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50303
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-05-07 14:15:14 +00:00
James Price 698d01383c writer/spirv: Fix dynamic array accessors
If the initial array accessor in a chain uses a non-literal index, use
the path that copies the source to a function variable, and then
perform a load from the OpAccessChain result if necessary.

Fixed: tint:426
Change-Id: Ie2f3f388170c02c1d6b73355f0b3bc49c3d3a4e5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49800
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-05-06 21:45:03 +00:00
Antonio Maiorano a2580d6720 spirv reader: replace typ::Type with ast::Type
Bug: tint:724
Change-Id: Idaf807dd1ff75af8e0044731e7362c0915ae7e54
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50200
Reviewed-by: Ben Clayton <bclayton@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-05-06 21:23:13 +00:00
Ben Clayton 467184fb06 reader/spirv: Remove debug spew
Change-Id: I2e3c9e681f2d33aaa83a27525e5e0f231f6a8973
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50221
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
2021-05-06 20:40:33 +00:00
Ben Clayton fe5c305891 Fix all doxygen warnings
Fixed: tint:776
Change-Id: I26e7dc36b19cf38612f6d530a9e774ac519d70e7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50220
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-05-06 16:26:53 +00:00
David Neto e21ad1438e spirv-reader: fix signedness for shifts
Fixed: tint:675
Change-Id: Ib754191284a62b9f4be56dc8d38e5319345ab9bf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49824
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-05-06 16:21:53 +00:00
Ben Clayton b82acac68e Resolver: Clean up diagnostics
Don't have a separate diagnostic list, just put the errors straight into the ProgramBuilder's diagnostics.
This also fixes an issue where we were taking the stringified diagnostic list and creating a single error on resolution failure. This was the cause of the `error: error:` messages sometimes seen.

Also fix a stupid negated-logic bug around the "resolving failed, but no error was raised" ICE.

Change-Id: Iddf1f61e4be21137731dfc204210562abbf612b0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49963
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-05-06 16:04:03 +00:00
Ben Clayton 0600796092 ast::Struct: Remove Clone() hack
Semantic types are no longer cloneable, entirely avoiding the issue this hack was working around.

Bug: tint:724
Change-Id: Iec876beccfda476a5539fb4d669eeba24d263500
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49962
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-05-06 16:03:33 +00:00
Ben Clayton b7bd0e12d1 reader/wgsl: Migrate to AST types
Bug: tint:724
Change-Id: I484813dd139122244cd09829ab5b035cec9981e6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49960
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-05-06 15:57:13 +00:00
Ben Clayton 58750eab19 sem: Have sem::Type derive from sem::Node
Having a common base class will tighten up some of the dynamic casting that we do.

Bug: tint:724
Change-Id: I45c6f200e1ec242ddb08ce75bd1c4c037a21a38d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49882
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-05-06 15:52:33 +00:00
Ryan Harrison a0174e613f Add fuzzing for transform::VertexPulling
Includes a significant refactoring of helper functions in
tint_common_fuzzer.cc/.h

BUG=tint:722

Change-Id: I1fdab0113bae02c4a0bf8da0d1b7729f05a2fc5b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49902
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-05-06 15:43:33 +00:00
David Neto 4f34e7897b spirv-reader: bit tests: make valid SPIR-V
Bug: tint:765
Change-Id: I79474aa959165b2b54eea352c4d71a04fea6ba51
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49823
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-05-06 15:35:33 +00:00
James Price d2be7cea90 reader/wgsl: Allow constants without initializers
This is valid when they are overridable constants. The resolver will
validate whether or not this is the case.

Change-Id: Ic6659c58e5046117f64794efec3300b0245a5e91
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50043
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-05-06 13:42:03 +00:00
James Price 08df57a75c validator: Require constants to have initializers
Unless they are pipeline overridable.

Fixed several tests that were violating this.

Change-Id: Ibb10e03bb150086a4d9e68a3f7b2d3e21f282918
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50042
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-05-06 13:37:13 +00:00
James Price ab3a9218b7 validator: Disallow [[override]] on non-const vars
Only allow them on constants, where no other decoration is valid.

Change-Id: I83f19667adb1dd4ebbba86827324a45a8f1a80a4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50041
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
2021-05-06 12:36:52 +00:00
James Price a67f8a44bb writer/spirv: Fix constant initialization
The code to auto-generate initializers for overridable pipeline
constants was in the non-const code path, so move it to the right
place and fix the tests that were wrongly testing non-const variables.

Bug: tint:254
Change-Id: Ifc96681492768ecf844f67e114377cc643ef7609
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50040
Auto-Submit: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-05-06 09:30:42 +00:00
Ryan Harrison 0aeb77c40f Fix GCC builds
BUG=tint:778

Change-Id: If06e453b6fd58b8c74bed996532b3b9f9f7804ee
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50044
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-05-06 08:20:52 +00:00
David Neto b4a8a15bd2 spirv-reader: arithmetic tests: make valid SPIR-V
Bug: tint:765
Change-Id: I8994647edd29513d48d5154c15e7dd429771c2ca
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49822
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-05-05 23:27:52 +00:00
David Neto 922779bcf5 spirv-reader: conversion tests: make valid SPIR-V
Bug: tint:765
Change-Id: I18ed7f007fc9b15c51cddbb6b0edbca79ed1569c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49821
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-05-05 21:24:34 +00:00
David Neto ba08d7bca3 spirv-reader: update tests to use valid SPIR-V
This CL: all SPIR-V modules in parser_impl_module_var_test.cc

Bug: tint:765
Change-Id: I2e8427aea729793a4e34e2ac0c6fc689f65bda04
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49645
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-05-05 20:54:02 +00:00
James Price 202d97d846 writer/spirv: Add type to constructor cache key
This prevents two initializers with different types from incorrectly
using the same OpConstantComposite instruction.

Fixed: tint:777
Change-Id: I2cdef9d5b0a83c26cbd4be318fed218e6f3e93b0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49981
Commit-Queue: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-05-05 19:38:12 +00:00
Ben Clayton 58f93c9e26 Build fixes
Two incompatible changes landed simultaniously.
Also fix a warning about variable shadowing.

Change-Id: I84c9ba48fb87a348a5b0e622ca2fdb191f95a6b2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49964
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-05-05 18:00:52 +00:00
Ben Clayton 8e1d177590 Remove Clone() from sem::Types
These should always be generated by the resolver, not manually constructed by transforms.

This also fixes duplicate intrinsic output from DecomposeStorageAccess.

Bug: tint:724
Change-Id: I979d55f7b141f38c0504dc72cc3c63e8353ac14f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49881
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-05-05 16:55:22 +00:00
James Price 8c6808fa13 transform/Spirv: Add EmitVertexPointSize logic
This is disabled by default and can be enabled via transform data. The
separate EmitVertexPointSize transform will be removed once Dawn
starts using the Spirv sanitizer to do this.

Bug: tint:753
Change-Id: I676c4cef5bc53f2dbf2330645faa4a0f2bfe11bd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49980
Auto-Submit: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-05-05 16:54:52 +00:00
Ben Clayton 6c1cf6569e sem::Matrix: Pass the column type to the constructor
It's common to want this when indexing matrices.

Change-Id: Ic60a3a8d05873119d78a3cb0860d129e33ac3525
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49880
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2021-05-05 16:48:32 +00:00
Brandon Jones b432f232b5 Add Transform For External Textures
Adds a transform to reclassify single-plane texture_external types into 2d sampled textures. Adds a unit test for the transform.

Bug: dawn:728
Change-Id: Id1f88565aeacbfea47b140181c78ad122edbdae8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49641
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-05-05 16:38:12 +00:00
Ben Clayton c9ee7ebd93 Prepare for having TypesBuilder return ast::Types
Instead of a typ::TypePair.

Bug: tint:724
Change-Id: Ife8fac86093eb128bc98974e1f6614a73c42a9e6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49753
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-05-05 16:19:22 +00:00
David Neto dee76fff44 spirv-reader: update tests to valid SPIR-V
Bug: tint:765
Change-Id: I4312f9aa94fd813aeb9b388c10303f967057066f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49644
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-05-05 16:12:32 +00:00
David Neto 6e2461096a spirv-reader: set failure bit when SPIR-V validation fails
The error message was already being logged, but the status
flag was not being set.

Change-Id: I7f6f2f45c15a64dd089e221c62218afe9e774edd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49643
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-05-05 16:03:02 +00:00
Ben Clayton bd7e8442b8 sem: Add constructor nullptr assertions
Catch the nullptrs early.

Change-Id: Ie8ee30355c79c6cbd589831f6587752b125d45c0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49754
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-05-05 10:48:22 +00:00
Ben Clayton a67583cde3 ast: Remove ProgramIDOf(ast::Type*)
This was a stub implementation copypasta'd from the semantic types.
By removing this, ProgramIDOf(ast::Node*) will be used instead, and these checks will actually work.

Bug: tint:724
Change-Id: I72f2fc5d89d81fb485b3549cb8138517c83c9482
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49752
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-05-05 10:26:51 +00:00
Ben Clayton 563cb58078 ast: ModuleCloneTest - check cloned program is valid
Helps catch brokenness before asking the developer to stare at AST dumps.

Change-Id: Id39602225ad2d4a1b72dcdf998b164feda870cf1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49751
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-05-05 10:23:11 +00:00
David Neto 58a3624935 Add --dump-spirv option to tint_unittests
The --dump-spirv option tells tint_unittests to output the
SPIR-V assembly text for a module which did not make the SPIR-V reader
fail.  This lets us get extract a corpus of SPIR-V modules, and
lets us more easily verify that the test shaders are valid in the first
place.

Also:
- Add test/extract-spvasm.py to split that output to separate SPIR-V
  assembly files
- Add optional second argument test/test-all.sh to specify a directory
  look for input files.
- BUILD.gn:  Add dependency from //test:tint_unittests_main to
  //test:tint_unittests_config to pick up source dependency on
  the internal header of the SPIRV-Tools optimizer, needed by
  the indirection through src/reader/spirv/parser_impl_test_helper.h

This is useful for bulk testing

Fixed: tint:756
Change-Id: I4fe232ac736003f7d9be35544328302d652381ea
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49605
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-05-05 09:46:31 +00:00
Ben Clayton 02ebf0dcae ast: Migrate to using ast::Type
Remove all sem::Type references from the AST.
ConstructedTypes are now all AST types.

The parsers will still create semantic types, but these are now disjoint
and ignored.
The parsers will be updated with future changes to stop creating these
semantic types.

Resolver creates semantic types from the AST types. Most downstream
logic continues to use the semantic types, however transforms will now
need to rebuild AST type information instead of reassigning semantic
information, as semantic nodes are fully rebuilt by the Resolver.

Bug: tint:724
Change-Id: I4ce03a075f13c77648cda5c3691bae202752ecc5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49747
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-05-05 09:09:41 +00:00
James Price 781de097eb writer/spirv: Fix static array accessors
If the array accessor expression uses a literal index, generate an
OpCompositeExtract instruction. Dynamic indices will be handled in a
follow-up patch.

Fixed: tint:767
Change-Id: I79a980d7d558a49def30816d04dcaa566f284c8f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49701
Reviewed-by: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
2021-05-05 02:35:41 +00:00
David Neto df48b955b2 spirv-reader: update tests to wrap parser impl
This is a step to being able to dump the SPIR-V for
successfully converted modules.

Bug: tint:756
Change-Id: Ifa48c88835ff10824c542a4e13d8a2d3a7f7f484
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49604
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-05-04 20:17:41 +00:00
Ben Clayton c6ed25cd3e Prepare tests for switch to AST types
Register all aliases, and don't share type nodes

Bug: tint:724
Change-Id: I7ac20c8a75f232fa7fe1e8c1a5690f411888f6e4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49750
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-05-04 19:02:01 +00:00
Ben Clayton 02ada29af2 Add Transform::CreateASTTypeFor()
Reconstructs the AST nodes needed to build the given semantic type.

Bug: tint:724
Change-Id: Iadf97a47b68088a6a1eb1e6871fb3a7248676417
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49745
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-05-04 18:13:21 +00:00
Ben Clayton 3e5e4fd8e5 spirv: Add calls to MaybeCreateTypename()
typ::Types originating from ConvertType() will hold direct pointers to ast::Struct and ast::Aliase. These must not be used directly. Instead TypeNames should be created to refer to these.

Bug: tint:724
Change-Id: I7f511e0da56e5d3ac587cdb22b0baf38474bed1e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49746
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-05-04 18:13:11 +00:00
Ben Clayton e5b315084d CloneContext: Support inplace cloning
Add a new constructor that only takes a ProgramBuilder.
This allows cloning objects to and from the same ProgramBuilder.

Also clean up tests.

Change-Id: I7c7bbaced4956f9094d0a6231aa4d7f7b6f17d4c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49744
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-05-04 18:06:31 +00:00
Ben Clayton 49a545c919 ast::Module: Move ConstructedTypes() to typ::Type
And add a few additional helper methods.
Stepping stone to having the module only reference AST nodes.

Bug: tint:724
Change-Id: Ib321dadce5f739afe4f71cbafde9dd2d1c6431bb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49743
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-05-04 18:03:11 +00:00
Ben Clayton 0f88b31503 ProgramBuilder: Add more helpers
And use MaybeCreateTypename() in more places.

Bug: tint:724
Change-Id: I232229c76205e148a2235dc5706522adb0789bcc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49742
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-05-04 17:36:31 +00:00
Ben Clayton 89952d0412 Fix all doxygen warnings
Change-Id: Ic312bc3771a69765b43f1a7c025f1f57783823c0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49741
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-05-04 17:20:31 +00:00
Antonio Maiorano ca992196d2 spirv reader: do not add duplicate constructed types
My last CL (https://dawn-review.googlesource.com/c/tint/+/49542) made it
so that AST nodes are re-created every type we resolve a spirv type id
to a tint type. This creates duplicate nodes, most of which are cleaned
up at the end of parsing. However, duplicates added as global
constructed types are not handled, so this CL makes sure we do not add
said duplicates.

Bug: tint:769
Bug: tint:724
Change-Id: Ifab46aa3b843a841c4371659dbec64891fdabc9a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49760
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-05-04 14:51:11 +00:00
Antonio Maiorano 1b898d56b4 spirv parser: create ast types along with sem types
The spirv parser now creates ast types along with sem types via
typ::Type. All sem::Type* were replaced with typ::Type, and its `ast`
member is used over the `sem` member to make it easier to migrate to
ast-only.

The parser was written to take advantage of the fact that types were
resolved to semantic types during parsing. For instance, a mapping of
spirv typeid to sem::Type* was used throughout (`id_to_type_`) to
resolve types once, and to support type aliasing. Since the goal is to
only create AST types, and to resolve only in the Resolver, I made many
changes to remove this dependency on semantic types. For instance, we
now always call ConvertType(typeid) instead of looking up via
id_to_type. Similarly, the `signed_type_for_` and `unsigned_type_for_`
maps were replaced with `UnsignedTypeFor` and `SignedTypeFor` functions.

Bug: tint:724
Change-Id: I3aee3928834febd71b473d6a8d8cb77b1ac94e21
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49542
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-05-03 20:49:40 +00:00
Ben Clayton b6831c3395 castable.h: Fix warning
> clang --version
Apple clang version 11.0.3 (clang-1103.0.32.29)

../src/castable.h:199:11: error: definition of implicit copy assignment operator for 'CastableBase' is deprecated because it has a user-declared destructor [-Werror,-Wdeprecated]

Seems to only be raised with this particular flavor of clang?

Change-Id: I9a549c753cd28a11855138a97823e7c1c92fab25
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49532
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-04-30 21:27:02 +00:00
Ben Clayton 1a492a27db writer/hlsl: Begin migration to ast::Types
The HLSL writer doesn't really care much for ast::Types, so most of the work here is repointing the logic to fetch the resolved, semantic type.
Output for aliases has changed, as the semantic type resolves away aliases.

Bug: tint:724
Change-Id: I6eb9d5c2fbcd62eef0f9dd145360714db649e13f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49530
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-30 20:22:49 +00:00
Ben Clayton ccab6bd694 reader/spirv: Return early if MakeExpression() fails
Bug: tint:762
Change-Id: If17e666cf459117c52ece73cb20ea8f70ed1fcd5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49531
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-04-30 20:22:19 +00:00
Ben Clayton fbec46fba9 Resolver: Generate mapping for ast::Type -> sem::Type
Currently untestable as nothing currently calls Type(const ast::Type* ty).

Bug: tint:724
Change-Id: I92dd772acd758b0960a7e9a19f15c91414ab505c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49527
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-30 20:20:19 +00:00
Ben Clayton f34cb1fe70 writer/msl: Begin migration to ast::Types
The MSL writer doesn't really care much for ast::Types, so most of the work here is repointing the logic to fetch the resolved, semantic type.

Bug: tint:724
Change-Id: I017b83c9f661cc01cbde377991aab184c1733348
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49529
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-30 20:19:09 +00:00
Ben Clayton 44539d85b2 writer/spirv: Begin migration to ast::Types
The SPIR-V writer doesn't really care much for ast::Types, so most of the work here is repointing the logic to fetch the resolved, semantic type.

Bug: tint:724
Change-Id: I7647e17b015bac8394bc0fc76daceb7c0a391a47
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49528
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-30 20:13:19 +00:00
Ben Clayton 1737485a05 ast: Add ast::NamedType
Have ast::Struct and ast::Alias derive from it.
NamedType currently derives from ast::Type, but this might change in the future.

Bug: tint:724
Change-Id: I46ab7751c89176f4dec34d63247d2459d02ab6bb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49525
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-30 19:58:49 +00:00
Ben Clayton 3068dcb3d7 sem::Function: Add ReturnType()
This is the resolved, semantic, return type of the function.

Bug: tint:724
Change-Id: I4ef9f7874414a3ea48131d0102da776f6d82a729
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49526
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-30 19:24:29 +00:00
Ben Clayton fa9af4b0ef writer/spirv: Return error message in Disassemble
Instead of printf-ing and returning an empty string.
When there's a lot of other test output, it can be really hard to actually spot the error message.
With the error being returned, this will likely appear in a EXPECT_EQ() style error message.

Change-Id: I733741a68de4843e986037c5e309c5a4c3d66124
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49522
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-30 19:23:49 +00:00
James Price e87ded8567 Rename builtin constant_id to override
There are no downstream usages, so we can skip deprecation. Allowing
the ID to be omitted will be done in a separate patch.

Fixed: tint:754
Change-Id: I3bd6de4d0f426fc3c66708bfd5b411a4051b375b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49581
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-30 17:14:19 +00:00
Ben Clayton 083b591783 writer/wgsl: Emit ast::Types
This takes precedence over semantic types.

WGSL should be printed as faithfully as possible to the parsed program.
The semantic nodes are more abstract than the AST - aliases are folded
away, decorations may be absorbed into the semantic types, etc.

Bug: tint:724
Change-Id: I500af3d20e4ea3f9bfcb7664f0ad2360aeeecd68
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49350
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-30 16:01:29 +00:00
Ben Clayton 275eb7e4e4 reader/spirv: Clean up disjoint AST nodes
Perform a program clone at the end of parsing to remove any unreachable AST nodes.
Actually fixing the parser to never create these looks like a huge amount of work.

Fixed: tint:749
Change-Id: Ib956634257e0933c9702d6be22f79942f7cf4c51
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49520
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-30 10:43:19 +00:00
Ben Clayton 9481156eb9 Fix Undefined Behaviour
All caused by calling Castable::As<> on nullptr objects.

Bug: tint:760
Change-Id: I0a408b3cd58086cfeab5a1af34d643f50f304948
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49523
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-30 10:16:45 +00:00
Zhaoming Jiang 30c03a5d50 HLSL writer: Translate the built-in function "mix" into "lerp"
The built-in function "mix" in WGSL should be translated into the
intrinsic function "lerp" in HLSL according to the HLSL document.

With this patch the dawn sample CubeReflection will be able to run
correctly with tint generator on D3D12 backend.

Bug: tint:758
Change-Id: I7e84987c02fd2090d5e7af8f4aba995fc95a6fdb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49601
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-30 08:47:06 +00:00
David Neto e08cc15dd9 spirv-reader: HLSL-IO: Convert input, output vars to private
Bug: tint:508
Change-Id: I5cd7c1b476112eb489f9e6acc94f7a1cf6e43b6d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48863
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-29 22:04:55 +00:00
James Price 5f7f7c0f9e Revert "transform/EmitVertexPointSize: Handle entry point parameters"
This reverts commit e6307e5100.

Reason for revert: This change assumes that vertex shaders do not return void, but the validation for this is currently disabled since CTS still has vertex shaders that return void.

Original change's description:
> transform/EmitVertexPointSize: Handle entry point parameters
>
> Generate a new struct that contains members of the original return
> type with the point size appended to it, and replace return statements
> as necessary.
>
> The SPIR-V sanitizer then special-cases this builtin when handling
> entry point IO to always use a RHS which is a literal.
>
> Fixed: tint:732
> Change-Id: Id718632a5e671f3e7c82a304f5bc1fc223a6c8ee
> Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49440
> Kokoro: Kokoro <noreply+kokoro@google.com>
> Reviewed-by: Ben Clayton <bclayton@google.com>
> Commit-Queue: James Price <jrprice@google.com>
> Auto-Submit: James Price <jrprice@google.com>

TBR=bclayton@google.com,jrprice@google.com,noreply+kokoro@google.com

Change-Id: I6113b2d8994eb088cb890a6af52e392b2d5a45f6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49582
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: James Price <jrprice@google.com>
2021-04-29 21:29:36 +00:00
Ben Clayton f0756e347a resolver: Improve the ICE msg about nodes
Include the pointer - helps debugging

Change-Id: I50058095710eb528446bbd8d8e3069dd657c75c8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49521
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
2021-04-29 20:57:55 +00:00
David Neto 7896d85146 spirv-reader: Register a name for an entry point inner implementation
It's tricky when mulitple entry points share the same implementation
function.

Bug: tint:508
Change-Id: Ie3084d4af8d6eb3aa9f0d25babb8ebfaed7b2fae
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48902
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-29 20:28:15 +00:00
David Neto ac16789eba spirv-reader: add option to use HLSL-style pipeline IO
This is currently unused.

Bug: tint:508
Change-Id: I9027d468496014123a41b9941cf9df35868b6e1a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49000
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-29 19:47:05 +00:00
Antonio Maiorano 543d471889 TypePair: add more operators to fix ambiguous bool conversions and nullptr comparisons
Bug: tint:724
Change-Id: I6698d95aeebe067d7b370b35fca05372e120b8ef
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49321
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
2021-04-29 17:47:34 +00:00
James Price 0a45d84fd4 Add missing include to fix g3 build
This is needed for std::nullptr_t.

Change-Id: I45780e783a81b29fb173cd3fa59542b5dbda0823
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49541
Commit-Queue: James Price <jrprice@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-04-29 16:48:44 +00:00
James Price 3189bf02e6 reader/wgsl: Allow trailing commas in lists
Also allows empty constexpr type constructors.

Fixed: tint:739
Change-Id: Ic4729c13b6ac538491d5d1d3c7960e78fac80127
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49443
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-29 15:56:54 +00:00
James Price 4248a46bfb reader/wgsl: Set source locations for literals
Change-Id: I34c6fd6760fb948682d427648cae963b9c1d8a6d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49442
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-29 15:54:44 +00:00
James Price e80887d14c reader/wgsl: Handle parentheses inside expect_argument_expression_list
This simplifies the callsites, which were previously each having to
handle the "empty list" case (and soon: trailing commas). This is also
a better match for the grammar rules in the WGSL spec.

Change-Id: I88ed54f94964f7b23a0fd9b584659037abb567ff
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49465
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-29 15:49:44 +00:00
James Price 961dc6fbf5 reader/wgsl: match spec rules for function calls
Function calls should be parsed in `primary_expression`. Renames the
old `postfix_expression` to `singular_expression`, with the recursive
part now becoming `postfix_expression`.

Fixed: tint:170
Change-Id: I1afad794880916db38a25d73447cdaf84abd6584
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49464
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: James Price <jrprice@google.com>
2021-04-29 15:02:15 +00:00
James Price e6307e5100 transform/EmitVertexPointSize: Handle entry point parameters
Generate a new struct that contains members of the original return
type with the point size appended to it, and replace return statements
as necessary.

The SPIR-V sanitizer then special-cases this builtin when handling
entry point IO to always use a RHS which is a literal.

Fixed: tint:732
Change-Id: Id718632a5e671f3e7c82a304f5bc1fc223a6c8ee
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49440
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
2021-04-29 13:05:34 +00:00
James Price 65ae64d009 transforms: Add a ProgramBuilder::Sym() helper
This creates a new, unnamed symbol.

Change-Id: I0ea11e812296c3215ba624a18777d3e7233e2ae4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49441
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: James Price <jrprice@google.com>
2021-04-29 12:59:14 +00:00
David Neto 77f7f5d369 spirv-reader: register statically accessed inputs and outputs
Bug: tint:508
Change-Id: I585abb0791f5ea0bcb282f12f6940e718da4956d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48861
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: David Neto <dneto@google.com>
2021-04-29 00:09:04 +00:00
James Price 0949bdf68f Add transform to strip entry points from a module
Remove the Generator::GenerateEntryPoint() APIs as they were mostly
unimplemented and not used by anything except the Tint sample app,
which now uses the new transform.

Change-Id: I1ccb303d6c3aa15e622c193d33b753e22bf39a95
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49160
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
2021-04-28 15:33:03 +00:00
Ben Clayton f5f311e264 Global tweaks to handle having no sem::Type
Soon, we'll start migrating the AST from using sem::Types to ast::Types.
This change fixes up a bunch of places that makes the assumption that the semantic type is always expected.

Bug: tint:724
Change-Id: I96096bdf7177751ca6c6240e1739244cbeb82761
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49348
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-28 14:31:23 +00:00
Ben Clayton 2ac55febf5 sem::StructMember: Add Type()
Once the AST switches to pure ast::Type nodes, we need a way to fetch the semantic type for a structure member.

Bug: tint:724
Change-Id: I4b55c1ec0220e29ca4ff3131cf2d41409821a538
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49347
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-28 14:13:13 +00:00
Ben Clayton 109b18f504 ast: Remove types from ast::Literals
A literal has an implicit type, so there should be no type on the AST node.

This highlighted that the resolver was nto canonicalizing TypeConstructorExpression types, which has been fixed.
This required preservation of the declared type name in order for error messages to contain aliased names.

Bug: tint:724
Change-Id: I21594a3e8a0fb1b73c6c5b46a14b8664b7f28512
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49345
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2021-04-28 13:50:43 +00:00
Ben Clayton 0bf0fb9b29 ast::TypeName: Clone the name.
Caught by the new seatbelts in the CloneContext.

Bug: tint:724
Change-Id: I1877248455e7654cb9c980cacd2f73562b006233
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49349
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-28 13:39:53 +00:00
Ben Clayton e41808b6b9 Add typ::Ptr<T>
A simple raw pointer wrapper that will allow us to migrate typ aliases to ast::Types without immediately having to fix up all the `auto` declarations to `auto*`.

Bug: tint:724
Change-Id: Icff7e009b768d9e54c8c73059c700af788962e77
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49346
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-28 13:32:13 +00:00
Ben Clayton 95c2e95100 ProgramBuilder: Don't wrap nullptr types
Once we start migrating over to just creating `ast::Type`s instead of a
AST+SEM pair, we're going to start having the sem::Type of the TypePair
be nullptr. Only create composite AST / SEM types if the inner type has
a non-nullptr AST / SEM type.

Bug: tint:724
Change-Id: I9bec53d1be4e8dc43f5d6c86fc5f968bf61fb41e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49344
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-28 12:58:13 +00:00
Ben Clayton 12ed13d0d4 resolver: Be const-correct with sem::Types
Make all the sem::Type pointers const.
The later stages still have not been fixed up, so there's liberal usage of const_cast where we create semantic nodes.

Bug: tint:745
Change-Id: I160b791f2b7944f8966bc961e061d1e5996c1973
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49343
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-28 12:38:13 +00:00
Ben Clayton 761e6b139c ast: Migrate all nodes over to typ::*
(except for ast::Module)

CloneContext::Clone(typ::Type) now only clones the sem::Type. Attempting
to clone both the AST and SEM type will cause the cloned AST to be
disjoint. Another change will switch this over to cloning the AST.

Bug: tint:724
Change-Id: I2baf5491365d7dc25e6b25d02bfbb46bf90fd0d9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49341
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-28 09:29:13 +00:00
Ben Clayton 4c0b7807f8 formatter: handle tabs
Transform these into whitespace so we can sensibly align the ^^ markers
with the text.

Change-Id: I151c0e55bc0a02c1cff6e381cb9839c9f9abdaf6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48694
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-27 18:01:28 +00:00
Antonio Maiorano 4b16a160d5 wgsl parser: use new TypesBuilder factory functions, and set Source for ast::Type nodes
* ProgramBuilder: added a bunch of overloads that take Source

* Added MultiTokenSource RAII helper to build source ranges for
multi-token types

* Added comparison operators to Source::Range and Source::Location to
make it easier to write tests to compare Source ranges

* Moved CombineSourceRange from resolver.cc to a static function in
Source named Source::Combine()

* Added Source tests for all ast type nodes returned by the wgsl parser

Bug: tint:724
Change-Id: I6fb6211a3c42c14693df8746af6a30f5aa56f2af
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48963
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-27 17:32:37 +00:00
David Neto d30047fea0 spirv-reader: always reserve entry point names
We have to be careful when the same function is used for
two entry points.  The first entry point name will be registered
as the name for the function ID.  But subsequent entry points
should have their names reserved in the namer, even if they
aren't associated with an ID.

Bug: tint:508
Change-Id: I3b6e7770ce49aa1b73594e57bdda5800febd55ed
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48864
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-27 16:14:06 +00:00
David Neto f63a2948c6 Better document ast::Variable parameters
In particular, "is_const=true" is required for formal parameters.

Change-Id: I05105da901a02d9bb51c88cab7430dd211c7b0ea
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49302
Commit-Queue: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-27 15:16:06 +00:00
David Neto 2c953eca48 spirv-reader: SaveName -> Register, add RegisterWithoutId
Change-Id: Iab2eaa3b2d13a3cbb8f6bca01ed79be14dedbfd1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49141
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-27 14:39:47 +00:00
Ben Clayton 86a406b79e Revert "transforms: Use new ProgramBuilder::Sym() helper"
This reverts commit 19b4b6cc2b.

Reason for revert: https://dawn-review.googlesource.com/c/tint/+/48980 was reverted which added the Sym() helper.

Original change's description:
> transforms: Use new ProgramBuilder::Sym() helper
>
> Change-Id: I8600a1935556632c94778248f3711531a22f4701
> Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48981
> Commit-Queue: James Price <jrprice@google.com>
> Reviewed-by: Ben Clayton <bclayton@google.com>

TBR=bclayton@google.com,jrprice@google.com,noreply+kokoro@google.com

Change-Id: Ie176df6e1b7606615e2acfae99e7853e6227185a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49261
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-27 14:24:08 +00:00
Ben Clayton e008b1ffcf Revert "transform/EmitVertexPointSize: Handle entry point parameters"
This reverts commit 05e16ed1c5.

Reason for revert: Breaks Dawn autoroll.

 [ RUN      ] VertexBufferRobustnessTest.DetectInvalidValues/Metal_Intel_R_UHD_Graphics_630__e_metal_enable_vertex_pulling
 ../../src/tests/DawnTest.cpp:945: Failure
 Value of: self->mExpectError
   Actual: false
 Expected: true
 Got unexpected device error: Tint SPIRV reader failure:
 Parser: error: cannot store a value other than constant 1.0 to PointSize builtin: OpStore %8 %18


Original change's description:
> transform/EmitVertexPointSize: Handle entry point parameters
>
> Generate a new struct that contains members of the original return
> type with the point size appended to it, and replace return statements
> as necessary.
>
> Fixed: tint:732
> Change-Id: I2b5816144d5e95c65baca95dc0c50b4dfdd25ed3
> Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48980
> Auto-Submit: James Price <jrprice@google.com>
> Commit-Queue: James Price <jrprice@google.com>
> Reviewed-by: Ben Clayton <bclayton@google.com>

TBR=bclayton@google.com,jrprice@google.com,noreply+kokoro@google.com

Change-Id: Id795d5320471d09d66a964c8e469b60da8f0a672
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49260
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-27 12:58:31 +00:00
Ben Clayton 5d5ec24571 src/transform: Remove deprecated APIs
These have now been removed from Dawn.

Change-Id: I50e784141e6eb07f4f0d3f508bb8c6199429dd63
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48044
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-04-26 20:38:36 +00:00
James Price 19b4b6cc2b transforms: Use new ProgramBuilder::Sym() helper
Change-Id: I8600a1935556632c94778248f3711531a22f4701
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48981
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-26 19:49:06 +00:00
James Price 05e16ed1c5 transform/EmitVertexPointSize: Handle entry point parameters
Generate a new struct that contains members of the original return
type with the point size appended to it, and replace return statements
as necessary.

Fixed: tint:732
Change-Id: I2b5816144d5e95c65baca95dc0c50b4dfdd25ed3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48980
Auto-Submit: James Price <jrprice@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-26 19:37:46 +00:00
David Neto 9ef328f530 spirv-reader: add namer::IsRegistered
Change-Id: I014132f9a655c7f52ebce4b141f6ea5235e828f1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49140
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-26 19:25:06 +00:00
James Price 439ef278b7 transform/VertexPulling: Handle entry point parameters
Adds support for the new shader IO syntax by processing entry
parameters and pushing them to function-scope variables as necessary.

Module-scope variables are still supported for now.

Fixed: tint:731
Change-Id: I36d7ce4e3a990b6323292cb7c685af37187d6fda
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48960
Auto-Submit: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-26 17:39:46 +00:00
Antonio Maiorano 31204afeb0 Add ast::ExternalTexture
Also create it in wgsl parser. With this, we now create all the AST type
nodes in the wgsl parser.

Bug: tint:724
Change-Id: I575c9eb0ffbd60c3e7aca0b00227d9833ef65d58
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48962
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-26 14:55:25 +00:00
Antonio Maiorano 73fdc16c33 wgsl parser: replace almost all sem::Type* with typ::Type where possible
All that remains in the wgsl parser that references sem::Type* are
the register_constructed funcs/types, and adding an ast::ExternalTexture
type.

Also:

* Added specialization of OperatorArrow for type::TypePairs that returns
the value by reference so that operator-> can chain properly.

* In a few places where we expect the type to implicitly cast to a
pointer for a bool expression, e.g. `if (type)` or `TINT_ASSERT(type)`,
I added access to the `.sem` member of the TypePair. I tried adding an
implicit cast to bool, but this results in ambiguity in gtest for
equality comparisons.

* Constified more type pointers in type nodes

* Replaced header includes with forward declares in wgsl/parser_impl.h

Bug: tint:724
Change-Id: Ie0875aa4d4a5e830e3466ac40c63cd185f357200
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48881
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-26 14:19:55 +00:00
David Neto 8f9de8a509 spirv-reader: Add method to be used in tests later
Bug: tint:508
Change-Id: Ifd83bcfe168a2be0a11e8a81e392ba20101fc586
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48865
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-26 09:56:05 +00:00
James Price 12353bc5fd Remove duplicate using directive
This alias is already defined in src/ast/decoration.h and is probably
just a copy-paste error.

Change-Id: I9efc16881b551ccac287eef1f86ca7560e87131b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48982
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-23 22:11:14 +00:00
Ben Clayton 6052d41d51 sem::Alias::type_name(): Optimize complexity
Precalculate the type_name to reduce complexity from O(N²) to O(N).

Fixed: chromium:1199700
Fixed: chromium:1200936
Change-Id: Ifd16508ace42d4a686f06d58121cc106842df7d3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48691
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-23 18:21:34 +00:00
Ben Clayton b205b872ae reader/spirv: Don't create disjoint AST nodes
This is a waste of memory, and now fires a TINT_ASSERT() in the resolver.

Add some more information to the resolver assertion message so that its easier to identify the node. This is especially useful when there's no source information available.

Fixed: tint:740
Bug: tint:469
Change-Id: I0cd4529db7b3906e64da6ed7290163509eb0c3f2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48689
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-23 18:19:54 +00:00
Antonio Maiorano ab215981fe Fix linux dawn roll
As in other places, we need to #undef Bool for X11

Bug: tint:741
Change-Id: I0185ed3c252f540212504b88859c600618fbfe23
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48961
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-23 18:09:34 +00:00
Ben Clayton 3b3cf5f2d3 ProgramBuilder: Fixup last few uses of sem::Type*
With typ::Type.

Involves decoupling the use of named types as sub-types of other types,
otherwise ty.array("x", Structure(...)) produces an AST tree with
duplicated AST nodes.

Bug: tint:724
Change-Id: I2b4e904dc23bb554a75d4612f6543f1911f469bd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48693
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-23 15:41:34 +00:00
Ryan Harrison 099ceb2050 Remove use of UnwrapAll()
Change-Id: I26518ecd17cd3a69357698d1e1a2201fcbc460e0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48880
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-23 08:36:33 +00:00
Antonio Maiorano 0b9ea91fcf Make ast::StructMember accept typ::Type
A minimal change to get a feel for what updating AST types to accept
typ::Type (for now) looks like.

Bug: tint:724
Change-Id: I33b33eb6af90e3629f76716a421f952f5a4bc11d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48841
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-04-23 08:35:13 +00:00
Antonio Maiorano 05abdf5096 wgsl parser: make type_decl() return typ::Type
Many more changes to come, but this just gets things started.

Bug: tint:724
Change-Id: I6c1dab0d9b7998e273543f2a72b6f8eafeb19fda
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48840
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-23 08:19:33 +00:00
Brandon Jones 145f865fb1 Add texture_external parsing and intrinsic overloads
Adds texture_external to ParserImpl. Adds texture_external overloads to
TextureSample, TextureLoad, and TextureDimensions to the intrisic table.
Adds corresponding tests.

Bug: dawn:728
Change-Id: I5e5557a10327f8c3d3044319decd748f812ecf3e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48722
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-22 22:47:03 +00:00
Ryan Harrison add325bb61 Add check for access controls on Storage Textures
BUG=tint:736

Change-Id: I6baae6507597383dd58b0d86605cbd44d5488c8f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48842
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-04-22 19:57:33 +00:00
Antonio Maiorano 26fa9927e8 Constify Type* constructor args for ast/sem classes
To avoid breaking things, functions that return the type cast away
the constness for now. This, however, makes it easier to use typ::Type
with these classes, as typ::Type stores pointers to const types. This
also brings us one step closer to constifying types everywhere.

Bug: tint:724
Change-Id: Ia3f4b76f375184dd09b8041c1f60bf1afaefe629
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48740
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-22 15:34:13 +00:00
Ben Clayton e204f27f86 ProgramBuilder: Migrate any remaining types to typ::*
Used as a stepping stone to emitting the ast::Types instead.

Bug: tint:724
Change-Id: Ib2d6c150fe8aa7c1e2c502676922b14b1518a4be
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48686
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-22 14:40:23 +00:00
Ben Clayton 7241a504f0 ProgramBuilder: Migrate arrays to typ::TypePair
Used as a stepping stone to emitting the ast::Types instead.

Bug: tint:724
Change-Id: Idadb7d8b5d6fce1d898127675442221de07a633d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48685
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-22 14:32:53 +00:00
Ben Clayton fdb91fd85e ProgramBuilder: Migrate matrices to typ::TypePair
Used as a stepping stone to emitting the ast::Types instead.

Bug: tint:724
Change-Id: Ic81f0a00456e91ac089df32193c4323c2e779c29
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48684
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-22 14:30:53 +00:00
Ben Clayton e30ffeb02a ProgramBuilder: Migrate vectors to typ::TypePair
Used as a stepping stone to emitting the ast::Types instead.

Bug: tint:724
Change-Id: I19d7df9ab684db598783235c1720586966a232e0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48683
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-22 14:24:43 +00:00
Ben Clayton 43073d8aa3 tests: Use ProgramBuilder helpers where we can
A general code cleanup

Change-Id: Ib251ca2d4b71f75736bdba8b4255965593a76c31
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48680
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-22 13:50:53 +00:00
David Neto 261642e4e3 Update spirv-reader readme
Change-Id: I933cab554b3bbd278a23b892535cba4992649002
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48760
Auto-Submit: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
Commit-Queue: Alan Baker <alanbaker@google.com>
2021-04-22 12:54:43 +00:00
David Neto 943ded79d2 spirv-reader: support OpTranspose
Change-Id: If338b22b703257e863e511579cfd3abcaa0bdfe7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48761
Auto-Submit: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Alan Baker <alanbaker@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-04-22 12:29:45 +00:00
Ben Clayton d5ceafee16 resolver: Temporarily disable vertex position validation
CTS needs updating to fix this validation error, and this is blocking autorolls for tint and dawn.

Change-Id: Ie3aaa37f0914fdb39099e7c15e65be0bcca0677a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48682
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-04-21 22:55:42 +00:00
Ben Clayton 42708348b7 resolver: Validate uniform buffer types
Fixed: tint:210
Change-Id: I7763ca23a5dce09755a1ca71d35f24897a875ac0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48604
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-21 17:55:12 +00:00
Ben Clayton 8db818840e Resolver: Validate array el is not [[block]] struct
Fixed: tint:90
Change-Id: I9500a8c7fad9acf5f797dd2903217821c953acb6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48421
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-21 16:45:02 +00:00
James Price 2dd393729c Require vertex shaders to return builtin(position)
Fixup many tests that were just returning void.

Change-Id: Ic93db5b187c679dc1c24a356b48a64e41ba9a823
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48560
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-21 16:13:42 +00:00
Ben Clayton fec63b7aa6 Resolver: Add ast -> sem type resolving
Not currently called (nothing currently attaches ast::Type nodes to the AST), but implements some of the boilerplate that'll be shortly required.

This change also removes a bunch of duplicated enumerators from the sem namespace for their counterpart in the ast namespace.

Bug: tint:724
Change-Id: I0372a9f4eca2f9357ff161e7ec1b67eae1c4c8f6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48603
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-21 13:47:12 +00:00
Ben Clayton a922e65d72 ProgramBuilder: Generate type pairs for primitives
Emit the new typ::I32, typ::U32, typ::F32, typ::Void, typ::Bool types instead of the just the sem::Types.

Used as a stepping stone to emitting the ast::Types instead.

Bug: tint:724
Change-Id: Ic492e33bc909e0821b581af05242d956631db2e3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48602
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-21 13:37:22 +00:00
Ben Clayton 440636c15c Add typepair.h
Introduces typ::Type which wraps a templated pair of AST and SEM type pointers.
This is a temporary helper to ease migration of the thousands of tests that use the ProgramBuilder over from sem::Type to the new ast::Types.

Bug: tint:724
Change-Id: I4e2643a819cde97947d789fce7a74c251f837a58
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48601
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-21 13:32:22 +00:00
Corentin Wallez c0810e7e6e Fix gn check in Chromium
- Move headers from libtint_sem_src into libtint_core_all_src so that
there is no circular header dependency between headers of these two
targets. libtint_sem_src is now just a hack to have a different name for
a few .cc files.
 - Made libtint_core_src publicly depend on its deps so that headers of
libtint_core_all_src are made visible through it.
 - Added spvtools dependencies in a couple places that were mistakenly
removed in a previous commit.
 - Moved helpers common to multiple unittest targets out of
tint_unittests_core_src and into a tint_test_helpers target that
all tint_unittests_source_set depend on.
 - Ran GN format that reordered some lists a bit.

Bug: None
Change-Id: I544a73d73366be9dd2ac8e56c7593fd9f2b86cf8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48600
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-04-21 09:18:52 +00:00