Commit Graph

1725 Commits

Author SHA1 Message Date
Ben Clayton c98dedf57a Validator: Fix GCC unused variable warning / error
Change-Id: I36e1a86328249abccfde4e6b7712d6e2a9d32c7b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45286
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-18 20:05:34 +00:00
Antonio Maiorano 9970ec63ca Move struct validation from Validator to Resolver
* Moved Validator::ValidateConstructedType, which only validated
structs, to Resolver as ValidateStructure.
* Moved relevant tests to new files, and also updated all failing tests
to validate Source location.
* Fixed other tests that broke now that we're validating structs.

Bug: tint:642
Change-Id: Iefc08ef548f52d8c3798d814d2183c56d1236c2d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45160
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-18 17:59:54 +00:00
Ben Clayton e072465d83 Resolver: Handle AccessControl for storage-class propagation
Fix msl tests that were impacted by this

Change-Id: I00f4280c2f059358d9187babda9e44f2d16b096e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45244
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-03-18 16:44:24 +00:00
Ben Clayton a63145a923 Resolver::IsStorable() Handle AccessControl types
Also: Clean up tests.
Change-Id: Ib22bd742b4e3cab55ee078d634ea7aee9a5b8d58
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45243
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-03-18 16:39:54 +00:00
Arman Uguray 097c75ae3e Resolver: Enforce matrix constructor type rules
Added enforcement for matrix constructor type rules according to the
table in https://gpuweb.github.io/gpuweb/wgsl.html#type-constructor-expr.

Fixed: tint:633
Change-Id: I97fc7f558f04780ed03252d94c071af3e0e07e26
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45020
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Arman Uguray <armansito@chromium.org>
2021-03-18 15:43:14 +00:00
Ben Clayton 512bdf1612 Diagnostic: Replace 'info' with 'note'
Change-Id: Icde015422882bad9a1427d5480718c822a28fd6a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45242
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-03-18 14:14:34 +00:00
Corentin Wallez 399b88845c Quickfix for unknown warning in Chromium
Chromium uses clang 13.0 that likely removes the warning while Skia uses
clang 12.0 that still has the warning. Temporarily skip the
-Wno-return-std-move-in-c++11 in Chromium only while Skia changes to not
add warnings to it's third_party dependencies.

Bug: dawn:706
Change-Id: I625f0046204328dcf2cfb1eb9824f8a4a928b8ff
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45240
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-18 12:27:24 +00:00
Ben Clayton 4f390a196e msl tests: Verify that the structure layout is correct
The Metal programming language is a C++14-based Specification with
extensions and restrictions.

Tint is written in C++14.

Take advantage of the fact that MSL is based on the same language that
Tint is written in, and validate that the field members match what the
C++ compiler expects.

Fixed: tint:650
Change-Id: I352871d6efa3f0a5631e7b986284fb5f1a0b3e9f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45060
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-03-18 11:08:14 +00:00
Ben Clayton 5907039597 msl: Implement more types for structure layout
Implement layout logic for vectors, matrices and default-stride arrays.

Custom stride arrays are complex, and will be tackled as a followup change.

This change also emits byte offsets for all structure members as comments. This is even emitted for non-storage uses, which can be cleaned up as a followup.

Fixes a whole lot of TINT_ICE() for non-complex WGSL shaders.

Bug: tint:626
Change-Id: I92a78451d29bdb04dbf28862ad22317f27bced60
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44864
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
2021-03-18 10:03:04 +00:00
Ben Clayton a88090b04d Resolver: Track storage class usages of structures
This will be used to validate layout rules, as well as preventing
illegal types from being used in a uniform / storage buffer.

Also: Cleanup logic around VariableDeclStatement
This was spread across 3 places, entirely unnecessarily.

Bug: tint:643
Change-Id: I9d309c3a5dfb5676984f49ce51763a97bcac93bb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45125
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-03-17 22:47:33 +00:00
Ben Clayton 893afdfd2c Resolver: Defer building of semantic::Struct until end
This will allow us to collect up usage information of the structures in a single pass.

Bug: tint:320
Bug: tint:643
Change-Id: Iaa700dc1e287f6df2717c422e66ec453b23b22dc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45123
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-03-17 22:01:53 +00:00
Ben Clayton ad97343214 Add semantic::Struct::SizeNoPadding
This is the size of the structure without the trailing alignment
padding. This is what the Dawn needs from the Inspector.

Fixed: tint:653
Change-Id: Iaa01ba949e114973e4a33e084fc10ef9e111016c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45120
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-17 21:54:13 +00:00
James Price 4ffd3e2ea5 [spirv-writer] Handle non-struct entry point return values
Generate a global variable for the return value and replace return
statements with assignments to this variable.

Add a list of return statements to semantic::Function.

Bug: tint:509
Change-Id: I6bc08fcac7858b48f0eff62199d5011665284220
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44804
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-17 14:24:04 +00:00
Ben Clayton 417b82291b Fix GCC warning about an unused local variable
Change-Id: Idd064713ce8919e96f84a8a13fa04779fa889208
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44871
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-03-17 14:00:44 +00:00
Antonio Maiorano d600972e49 CMake: fix warnings on msvc builds
Remove /W3 from default flags, and disable a couple of warnings:

C4127: conditional expression is constant
C4458: declaration of 'identifier' hides class member

These match our warning settings of Clang/GCC more closely.
Also fix some valid warnings in some tests.

Change-Id: I46cb30b93ece74039db4aa0d6b52a675ee36859d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44960
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-17 13:32:54 +00:00
James Price 4f4534df3a Enable InsertBefore to work on global declarations
Use it for entry point IO sanitizing transforms to fix cases where structures were being inserted before type aliases that they reference.

Also fixes up some ordering issues with the FirstIndexOffset
transform.

Change-Id: I50d472ccb844b388f69914dcecbc0fcda1a579ed
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45000
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: James Price <jrprice@google.com>
2021-03-17 09:26:04 +00:00
Corentin Wallez 4f4a285750 Suppress -Wreturn-std-move-in-c++11 for building in Skia
Bug: dawn:706
Change-Id: I882b58cf19a678f1eaa55cacc19a1ada67b55cce
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44868
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-17 09:13:04 +00:00
Ben Clayton 50f169dcc8 debug: Add TINT_UNIMPLEMENTED()
Use this when we have code TODOs, so we can easily find them.

Change-Id: I7720d4cc3a52d51f3c240e86611b4a8eea566a6a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44863
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-03-17 04:55:33 +00:00
James Price 15dcd8fb15 [validator] Fix return statement type validation for aliases
Unwrap type aliases from the function return type before comparing to
the return value.

Add additional test coverage for aliased and non-aliased cases.

Change-Id: I4aa43f681468cd2c68e84da71222aea952117c1a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44923
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-03-16 22:08:13 +00:00
Ben Clayton 1222c15172 Fix CMake build warnings / errors
Fixed: tint:651
Change-Id: I6d4119f4acecbea1555a85c53b4f3e905be2c556
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44866
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-03-16 21:58:23 +00:00
Ryan Harrison 377acdda46 Add Storage Texture bindings to GetResourceBindings
BUG=tint:647

Change-Id: Iebf8e71366cf816d46b1acca11c1a0a7f1183530
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44900
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-03-16 20:52:33 +00:00
Antonio Maiorano cb21680714 TestHelper: rename td_ to resolver_
Change-Id: I7fb82fa6c2802747762fca3af1d5e59eb44ffb5a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44881
Auto-Submit: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-16 16:31:33 +00:00
Antonio Maiorano be0fc4e929 Validate binary operations
This change validates that the operand types and result type of every
binary operation is valid.

* Added two unit tests which test all valid and invalid param combos. I
also removed the old tests, many of which failed once I added this
validation, and the rest are obviated by the new tests.

* Fixed VertexPulling transform, as well as many tests, that were using
invalid operand types for binary operations.

Fixed: tint:354
Change-Id: Ia3f48384256993da61b341f17ba5583741011819
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44341
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-16 13:26:03 +00:00
Ben Clayton 7d80c2783a validator_decoration_test: Handle new size / align decorations
Bug: tint:626
Change-Id: Ibaaff85d4cd2e0a0bce05006d2bf74ca884a8db0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44783
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-03-15 21:59:42 +00:00
Ryan Harrison 935927d0f6 [inspector] Remove check that uniform buffers have an access wrapper
BUG=tint:641

Change-Id: I49c2e59e1555c839665cde9d30bb8181c4b28814
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44802
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>
2021-03-15 21:30:52 +00:00
David Neto 5a01b72b98 Remove unusued param
Fixes GCC build

Change-Id: I0d89d48bdaa24f4199afa03197e8bbf1a0576b28
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44803
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-03-15 21:28:22 +00:00
Arman Uguray 3549e2ea8c Resolver: Enforce vector constructor type rules
Added enforcement for vector constructor type rules according to the
table in https://gpuweb.github.io/gpuweb/wgsl.html#type-constructor-expr.

This surfaced a number of existing tests that violated some of these
rules or had a type-declaration related bug, so this CL fixes those as
well (these tests either passed the incorrect number of arguments to a
vector constructor or relied on implicit conversions between numeric
types).

Fixed: tint:632
Fixed: tint:476
Change-Id: I8279be3eeae50b64db486ee7a91a43bd94fdff62
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44480
Commit-Queue: Arman Uguray <armansito@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-15 21:21:33 +00:00
Ben Clayton 2f9ced0341 Update DEPRECATED comments about offset decorations
Let's keep these for the SPIR-V reader case. The way things currently work is actually nicer than attempting to generate size / align decorations in the SPIR-V reader.

Change-Id: I83087c153e3b3056e737dcfbfd73ae6a0986bd7c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44684
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-03-15 20:34:22 +00:00
Ben Clayton 822fa54d87 writer/wgsl: Fix size / align decoration emission
This was broken by a rebase of the Default Struct Layout change.
This went unnoticed because there was no test coverage for these. Added.

Also replace `[[offset(n)]]` decorations with padding fields.

Bug: tint:626
Change-Id: Iad6f1a239bc8d8fcb15d18a204d3f5a78a372350
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44683
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-03-15 20:25:12 +00:00
Ben Clayton fd3cf82056 Fix missing printed errors from run-parallel
These errors were captured, but not printed.

Fix the lint error that was not being displayed.

Change-Id: I56da5c3a044b8a8e41695883ce780aca6245ad04
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44780
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-15 20:18:32 +00:00
David Neto c7e4032009 Rename Transform() to Run() to fix build
Two changes merged that were not compatible (44681 and 44603).

Change-Id: Ib35c4d738e4749b904c0c83626de730de63b8417
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44800
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-15 20:10:02 +00:00
Antonio Maiorano 5106a0653c Add CastableBase::To() overload with predicate
This allows for a more optimal way to filter the result of To(). Updated
Type query functions to make use of it. Added tests.

Change-Id: If3a65259345fbe6b92c6d367ab01fa718bb7cfee
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44463
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-15 19:55:02 +00:00
Ben Clayton b903aadcd2 Fix GCC warnings / errors
Fixed: tint:636
Change-Id: Ic1bb602b07d659e553d8cb09fd5898482c40c0c1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44681
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-15 19:19:42 +00:00
James Price 6eda12a55d [wgsl-writer] Use EmitDecorations() for function parameters
Removes some duplicated code.

Change-Id: I05120e5f443810e54babb842f0f993e4e0a7da79
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44603
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-15 17:35:02 +00:00
Antonio Maiorano a089a56c73 Add Castsable::IsAnyOf<T1, T2, ...>()
This makes it a little easier to check if an object is one of any of the
types provided. Updated Type query functions to make use of IsAnyOf.
Added tests.

Change-Id: I12ea62b32042b6675d998ab85b86f2fe15861330
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44462
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-15 17:29:03 +00:00
Antonio Maiorano 81a4753c38 Castable: factor out Is and As to free standing functions
These can now also be called with nullptr and will return false or
nullptr respectively.

Change-Id: I5fcf292503dd718f8d3771c7c39c204ce03ff4f7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44461
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-15 17:20:51 +00:00
James Price cc193de025 [wgsl-writer] Generate decorations on function return types
Bug: tint:576
Change-Id: I60d046fb4db558daf52178600b962eaeb6d3f843
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44602
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-15 17:15:23 +00:00
James Price feecbe0d83 [wgsl-reader] Allow decorations on function return types
Add a return type decoration list field to ast::Function.

Bug: tint:513
Change-Id: I41c1087f21a87731eb48ec7642997da5ae7f2baa
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44601
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-15 17:01:34 +00:00
James Price 20a438a5c3 [msl-writer] Fix leak in HandleEntryPointIOTypes
Avoid cloning parameters until we know we are going to rewrite the
function.

Change-Id: I0b0e2513d8652a0f2e561419848f77875d67591b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44600
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-15 16:47:11 +00:00
James Price cf79a16fef [hlsl-writer] Handle non-struct entry point parameters
Add a sanitizing transform to collect input parameters into a
struct. HLSL does not allow non-struct entry-point parameters, so any
location- or builtin-decorated inputs have to be provided via a struct
instead.

Bug: tint:511
Change-Id: I3784bcad3bfda757ebcf0efc98c499cfce639b5e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44420
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-15 16:39:21 +00:00
Ben Clayton a75205265e Add src/utils/math.h
Move the RoundUp() and IsPowerOfTwo() methods from Resolver.cc to this file.

Add tests

Change-Id: Ib7af53dfa5e69083ec4fc2484da92a84c9468818
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44682
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-03-15 13:37:41 +00:00
Ben Clayton d614dd5d12 Implement Default Struct Layout
Implements https://github.com/gpuweb/gpuweb/pull/1447

SPIR-V Reader is still TODO, but continues to function as the offset
decoration is still supported.

Bug: tint:626
Bug: tint:629
Change-Id: Id574eb3a5c6729559382812de37b23f0c68fd406
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43640
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2021-03-15 10:43:11 +00:00
Corentin Wallez 5929a04316 Split BUILD.gn into per-subdirectory BUILD.gns
This will allow Tint's dependent to depend on libtint without GN
discovering Tint's test and try to build them. In particular it will
help use Tint in Dawn in Skia's standalone build which doesn't have
//testing.

Bug: dawn:706
Change-Id: Idd28662b89aa75df7704eaae205328dce0b96fef
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44540
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
2021-03-15 08:43:11 +00:00
James Price e2bc7aa747 Delete some obsolete sources
These were supposed to be deleted in 95d4077.

Change-Id: Ic2a08283a8f4255f107492fcfa1bb0f320969f73
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44500
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-12 16:59:26 +00:00
James Price 4c8d7259da [msl-writer] Handle non-struct entry point parameters
Add a sanitizing transform to collect location-decorated parameters
into a struct.

Bug: tint:510
Change-Id: I1e9bf829dac946e5fec0ecfe6da7e1ef9cebff8e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44322
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-11 18:27:22 +00:00
James Price d3e3681d63 [wgsl-writer] Generate builtin and location decorations on struct members
Bug: tint:576
Change-Id: Ie8ace8dd77095abedcca97caca330e2d11a7559c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44321
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
2021-03-11 17:47:52 +00:00
James Price 95d4077648 Flatten ast::Decoration class hierarchy
Remove the decoration groupings (Array, Function, Struct,
StructMember, Type, Variable), such that all *Decoration classes now
subclass ast::Decoration directly. This allows for decorations to be
used in multiple places; for example, builtin decorations are now
valid for both variables and struct members.

Checking that decoration lists only contain decorations that are valid
for the node that they are attached to is now done inside the
validator.

Change-Id: Ie8c0e53e5730a7dedea50a1dec8f26f9e7b00e8d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44320
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
2021-03-11 17:39:32 +00:00
Ryan Harrison f1773c6700 [inspector] Include component type information for stage variables
BUG=tint:630

Change-Id: Ib30221e7a2d35e77a164969428ed6bfc07bc2a8e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44340
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-11 16:37:32 +00:00
James Price a0d48382cb [spirv-writer] Handle entry point parameters
Add a sanitizing transform to hoist entry point parameters out as
global variables.

Bug: tint:509
Change-Id: Ic18f69386a58d82ee11571fa9ec0c54cb5bdf2cf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44083
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-11 15:57:21 +00:00
James Price f4ff6af0b4 [wgsl-writer] Emit decorations on function parameters
This is needed to correctly generate entry point IO parameters.

Bug: tint:576
Change-Id: I9b96886d5ea90a54a568dd36506da563227afde7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44082
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-10 23:50:49 +00:00
James Price 5c460bf2fc [wgsl-reader] Add support for entry point parameters
This just handles non-struct parameters for now. Structs will be
handled in a later patch.

Bug: tint:513
Change-Id: Idfb202a599fcd84400b89515f21bfed6fd3795b5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44081
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-10 23:18:29 +00:00
Ben Clayton f4c0d54423 Resolver: Add test for continue after var decl
Bug: tint:17
Change-Id: Ibd51269d60447fa0d6408fbaf5b6d023a95073f2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44050
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-10 23:15:09 +00:00
James Price 7e17bfbfd9 [validator] Remove obsolete rules and tests
Entry points are now allowed to have parameters and return types as
part of the changes made in:
https://github.com/gpuweb/gpuweb/pull/1426

Bug: tint:512
Change-Id: I20caa940f6d194f62ce1dfa5d247927c5b5a9628
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44080
Auto-Submit: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-10 22:36:59 +00:00
Ben Clayton 8454d824d4 ast: Replace IsValid() with TINT_ASSERT()
The readers must not produce invalid ASTs.
If readers cannot produce a valid AST, then they should error instead.
If a reader does produce an invalid AST, this change catches this bad behavior early, significantly helping identify the root of the broken logic.

IsValid() made a bit more sense in the days where the AST was mutable, and was constructed by calling setters on the nodes to build up the tree.
In order to detect bad ASTs, IsValid() would have to perform an entire AST traversal and give a yes / no answer for the entire tree. Not only was this slow, an answer of 'no' didn't tell you *where* the AST was invalid, resulting in a lot of manual debugging.
Now that the AST is fully immutable, all child nodes need to be built before their parents. The AST node constructors now become a perfect place to perform pointer sanity checking.

The argument for attempting to catch and handle invalid ASTs is not a compelling one.
Invalid ASTs are invalid compiler behavior, not something that should ever happen with a correctly functioning compiler.
If this were to happen in production, the user would be utterly clueless to _why_ the program is invalid, or _how_ to fix it.
Attempting to handle invalid ASTs is just masking a much larger problem.

Let's just let the fuzzers do their job to catch any of these cases early.

Fixed: chromium:1185569
Change-Id: I6496426a3a9da9d42627d2c1ca23917bfd04cc5c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44048
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2021-03-10 11:41:49 +00:00
Antonio Maiorano 6ce58becd2 Fix VS clang-cl build
* Disable "undefined-var-template" in code, rather than in build files
* Add back some missing headers required when building in this context
* Make sure gtest/gmock do not override the default runtime library

Change-Id: I12c05943fc1d2dee4733ae70db7da026f67e0dad
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44180
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-09 21:51:50 +00:00
Ben Clayton 5fb87dd915 Resolver: Validate if() conditions are bools
Fixed: tint:317
Change-Id: Ica56dfb12d6b1a45e61d0d791f723414b464da5f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44163
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-09 15:17:28 +00:00
Ben Clayton 2c41f4fbdf Resolver: Split tests into multiple files
Try and make sense of the huge number of tests we have.

Rename tests so they have a consistent naming style.

Change-Id: I0c089d5945778a8718480a1a2f854435e7b0e79a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44162
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-09 15:12:57 +00:00
Ben Clayton 786cea419d Add resolver::TestHelper
First step in splitting out resolver tests into multiple files

Change-Id: I58c66ad5e348a50b3e028dff5749cfacb273ea62
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44161
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-09 15:10:27 +00:00
Ben Clayton c7dcbae41c Resolver: Place into a resolver namespace
I'm going to start pulling apart the resolver tests into separate files, and the test helper shouldn't go into the root tint namespace.

Change-Id: Ie7d131c5b92837c6c9df05b2938cf014a0402ce2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44160
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-09 15:08:48 +00:00
Ben Clayton 9430cb4775 Resolver: Validate usage of break
Also remove unused fields of Resolver (block_to_info_, block_infos_). We can put them back when they're actually needed.

Fixed: tint:190
Change-Id: I1a02a24eca7fba32b8e1120abb88040138a39c6a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44051
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-09 15:06:37 +00:00
Antonio Maiorano 5e9eb2037d spir-v builder: fix loop-scoped variable not found in continuing block
Make sure variables from the loop block remain in scope for
continuing block. Note that we need to do this because the continuing
block is a sibling of the loop body block in the AST, rather than a
child.

Added test.

Fixed: tint:526
Change-Id: If622995e3aac4cd3c06c2dbd87ffcaa36b0f09c5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43680
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-03-09 14:41:17 +00:00
Ben Clayton 01df2a7cee Add TINT_ASSERT()
Replacement for the places where we currently use assert(), and there is no sensible place to put the error into a diag::List.

Change-Id: Id154340b0353f8a3e8962771263f1cc87dce2aa4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44047
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-09 13:52:18 +00:00
Ben Clayton 5b36d2c612 Remove all unnecessary includes
All includes from .cc to .h are preserved, even when transitively included.

It's clear that there are far too many includes in header files, and we should be more aggressive with forward declarations. tint:532 will continue to track this work.

There are, however, plenty of includes that have accumulated over time which are no longer required directly or transitively, so this change starts with a clean slate of *required* includes.

Bug: tint:532
Change-Id: Ie1718dad565f8309fa180ef91bcf3920e76dba18
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44042
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-03-09 11:11:17 +00:00
Ben Clayton 5f0ea11365 Rename TypeDeterminer to Resolver
Move out of the src root and into its own subdirectory
Rename methods to remove the 'Determine' prefix.

Fixed: tint:529
Change-Id: Idf89d647780f8a2e7495c1c9e6c402e00ad45b7c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44041
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-03-09 10:54:37 +00:00
Antonio Maiorano fd31bbd3f1 TD: validate continue statements bypassing body variables
We now keep track of scopes as a tree of BlockInfos that track variables
declared in each scope. For loop scopes, we store the index of the first
variable (if any) that follows the first continue statement. Using this
data structure, when parsing expressions, we validate that used
variables in continuing blocks are not bypassed by a continue statement
in the parent loop block.

Also:
* Validate that continue statements are in a loop in TD. This error is
already caught by the spir-v writer, but better to catch it here.
* Add more utility functions to ProgramBuilder to make it easier to
write tests

Fixed: tint:17
Change-Id: I967bf2cfb63062bac8dcca113d074ba0fe2152e2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44120
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-09 10:26:57 +00:00
Ben Clayton fe2ceb9b5d reader/wgsl: Remove ParserImpl::diagnostics()
Put all errors straight into the ProgramBuilder::Diagnostics()

Fixes a TODO. Kills an assert().

Bug: chromium:1185569
Change-Id: I4e6f3b06106c3cfe75cf2bcdfc56b14ad73e81d9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44046
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-03-08 16:17:55 +00:00
Ben Clayton f9f48c60f7 transform/Renamer: Pass through swizzles and intrinsics
These must not be mangled.

Bug: tint:273
Change-Id: I05b02bf785c9d6ab587996bfed284e89912cd0cb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43941
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-04 23:37:25 +00:00
Ben Clayton 97b92178c5 writer/msl: Remove the renaming logic
This is now entirely handled as transforms.

Bug: tint:273
Change-Id: Ib3c0db7b5ecf024b6ae2aed7788e4b582d07c4ce
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43983
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-03-04 23:24:05 +00:00
Ben Clayton 37d2b35d59 transform::Msl: Rename reserved keywords
This change begins the work to move the reserved keyword remapping out of the writer and into the sanitizer transform.

If the transform::Renamer is in use, then these symbols should never have to be remapped - however for debugging purposes it is often nice to be able to emit code that isn't entirely mangled.

The logic in the msl writer will be removed as a followup change

Bug: tint:273
Change-Id: I76af03ff80388a48d9dd80a5b5fdfe21f3c8e7a0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43982
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-04 23:03:25 +00:00
Ben Clayton f25d51977a Move IntrinsicType parsing to semantic/intrinsic.h
Keeps the enum / parse / print code all together.

Change-Id: I78e5e15b6a97d3aec619a94e4390ecc4a77ab478
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43980
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-04 23:00:46 +00:00
Ben Clayton dee7d36f8a reader/wgsl: Tail-call optimize expression methods
Fixes stack overflows in complex arithmetic expressions

Fixed: chromium:1182709
Change-Id: I5f5470cf59525725a437f26672904e9653b447a7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43940
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-04 22:52:05 +00:00
Ben Clayton d1781fd0af Remove tint::Namer
Replaced with tint::transform::Rename and was never used.

Bug: tint:273
Change-Id: Icf0b19b389377f3c9a6efcf3ca232ba294775f9b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43981
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-03-04 21:00:15 +00:00
Ben Clayton 798876e7eb Optimize demangling
Don't continually replace the string in-place.
Makes pathological fuzzer tests ~140x faster to run.

Fixed: chromium:1182606
Change-Id: I48bd39ecb8488e34c9e75da52b5e9f355ca896ee
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43920
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-03-04 16:29:05 +00:00
Ben Clayton e18a18bc1c Add transform::Renamer
Renames symbols.
Currently only supports renaming to a symbol with a monotonic increasing suffix.

Change-Id: I7ae67a7b1740ac0e83c1821643cf7b8b1959f84d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42842
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-03-04 11:12:45 +00:00
Ben Clayton 5ca9741b69 CloneContext: Add support for transforming symbols
Will be used by a Renamer transform

Change-Id: Ic0e9b69874f51103f0beec7745d32a9f8419e93a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42841
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-03-04 10:42:55 +00:00
David Neto ec44eef965 spirv-reader: handle OpUndef at module scope
Fixed: tint:523
Change-Id: I47639c8f701ca049c7215874cdea27f86d8a415b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43760
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-03-03 19:58:04 +00:00
Ben Clayton 5a13258981 TD: Fix O(2^n) of reachable-by-entry-point
Re-jig the code so that this can be performed in O(n).

Fixed: tint:245
Change-Id: I6dc341c0313e3a1c808f15c66e0c70a7339640e5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43641
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
2021-03-03 19:54:44 +00:00
Ryan Harrison 04d93c88a0 Add inspector support for DepthTexture reflection
BUG=tint:527

Change-Id: I4f017993ffa85515b5b646bd9cf15c4b6d50c441
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43700
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-03 13:46:43 +00:00
Ben Clayton 7732ca51c4 Rename TINT_INSTANTIATE_CLASS_ID()
to TINT_INSTANTIATE_TYPEINFO()

ClassID isn't a thing any more.

Change-Id: Ie1c0d4a95e58ef7166d3cab5ef733a2dfc702345
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42921
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-03-02 20:51:18 +00:00
Ryan Harrison 2f8df72930 Reland "Remove deprecated textureLoad overloads with no level param"
This is a reland of cc4c22ebaa

Original change's description:
> Remove deprecated textureLoad overloads with no level param
>
> BUG=tint:516
>
> Change-Id: I7004e0dbd44d703c684118136b05b84cf609c6ba
> Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42703
> Reviewed-by: Ben Clayton <bclayton@google.com>
> Commit-Queue: Ryan Harrison <rharrison@chromium.org>

Bug: tint:516
Change-Id: Ic52893c78046cd54575cea51c244f6df5a4f843c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43620
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-02 20:31:58 +00:00
Ben Clayton e879143801 Pull Is() out of castable and into a new TypeInfo
Allows you to query type inheritance without having an instance of the type.

Also add TypeInfo::name. Helpful for decent error messages. Strings can be removed from NDEBUG builds if we consider them too large.

Change-Id: Ie501b37f46e63d956cc020f8c9b68e91737472f0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42920
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-02 20:30:08 +00:00
Ryan Harrison 5cfd4f5a07 Revert "Remove deprecated textureLoad overloads with no level param"
This reverts commit cc4c22ebaa.

Reason for revert: Broke Dawn e2e tests w/ SwiftShader

Original change's description:
> Remove deprecated textureLoad overloads with no level param
>
> BUG=tint:516
>
> Change-Id: I7004e0dbd44d703c684118136b05b84cf609c6ba
> Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42703
> Reviewed-by: Ben Clayton <bclayton@google.com>
> Commit-Queue: Ryan Harrison <rharrison@chromium.org>

Bug: tint:516
Change-Id: I6b7857304872fd0048c23999ac223ce9dcaf7fe1
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43540
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
2021-03-02 12:39:34 +00:00
Ben Clayton 1653668355 Remove deprecated transform APIs
Change-Id: I330b52ed6b485690a64c74fe34bebfe02fb52598
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42265
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-03-02 11:53:42 +00:00
James Price a349e54149 Remove unused testing files
Change-Id: I0af37c775a818a5a76baa48fb8e55b38c6b40eee
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43480
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-01 23:22:19 +00:00
James Price 9062f13202 Rename test file for consistency
We use _test.cc for everything else, so this makes globbing for test
sources simpler.

Change-Id: I6d1a3ad0f3bbeaabe981fbce66967de7e2f9e4d5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43481
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-01 22:51:39 +00:00
Antonio Maiorano 364b30f7de spirv builder: allow unsigned int cases for switch statements
Change-Id: If7a8955961b56925cae538249d4e17495d3f8e1b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42901
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
2021-03-01 22:44:19 +00:00
Ryan Harrison cc4c22ebaa Remove deprecated textureLoad overloads with no level param
BUG=tint:516

Change-Id: I7004e0dbd44d703c684118136b05b84cf609c6ba
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42703
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2021-03-01 21:54:49 +00:00
Antonio Maiorano fe2b417f83 Validate swizzles don't mix between rgba and xyzw
Added test.

Bug: tint:79
Change-Id: Ibb17cc2d9198403cdf6a2e456ad29d906deac9f7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43460
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-01 20:01:39 +00:00
Antonio Maiorano 05d9bffdbd Make IntLiteral store and return a u32 value
With this change, the base IntLiteral class now stores a u32, and
derived UintLiteral and SintLiteral are implemented in terms of it. This
will allow us to improve the current pattern of casting down to each
derived type to retrieve the value.

Change-Id: I0c1e56c5e04333a0d3d5f30a3fb28e784f785843
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42900
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-02-26 22:56:16 +00:00
Ben Clayton a8b20bec7b CloneContext: Drop the first CloneContext* parameter from the ReplaceAll() callback
You have to have the CloneContext in order to call ReplaceAll() in the first place. The overhead of capturing the pointer in the closure is negligible.

Cleans up the callsites.

Change-Id: I3a0fd808517d69f19756f590f3426e5ba226c57e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42840
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-26 19:33:56 +00:00
Ben Clayton d5638c93c5 BoundArrayAccessors: Add more tests
Bug: tint:521
Change-Id: I0a9ea7f487b052d1ee6ffa5be079d18633acc72c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42844
Commit-Queue: Austin Eng <enga@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
2021-02-26 18:53:36 +00:00
Antonio Maiorano 6ce2edfa1f Validate sign of RHS matches LHS for scalar variable declarations
Statements like `var u : u32 = 0;` should fail because '0' is a signed
integer being used to initialize an unsigned variable.

Added test.

Bug: tint:79
Change-Id: I34f6d21b4355167f49f9a8b5d4ed34a808823185
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42702
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-02-26 18:25:56 +00:00
Ryan Harrison e5c105d40a Add testing for 1D w/ level textureLoad overload
BUG=tint:516

Change-Id: Ic075dc52618bc6d2492e82538f0f02d45f925ddf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42700
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2021-02-25 23:57:28 +00:00
dan sinclair 2aaf7b5c76 [MslWriter] Emit using statement for metal
This CL updates the MSL backend to emit a using namespace for metal
instead of using the `metal::` prefix.

Bug: tint:463
Change-Id: I63d3ea5b5a56e61d71cd6d17a51a5120363ea007
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42741
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-02-25 21:17:47 +00:00
Ben Clayton c1f7e90417 Fix typo in FirstIndexOffset::Data
s/first_index_offset/first_instance_offset

Change-Id: I7f77490cf5e75002baaedcb319140dd329a087ac
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42461
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-25 14:11:50 +00:00
Ben Clayton 2432e3429d Rework TINT_INSTANTIATE_CLASS_ID() to avoid complex static initializers
The chromium tests for static initializers get upset about the call to
ClassId::New() in a global variable initializer.

Instead, take the address of a unique 'token' variable to generate the
unique identifier.

This is similar to how things were before
https://dawn-review.googlesource.com/c/tint/+/42460
but of taking the address-of the token in the header, we're instead
taking the address-of inside the cpp file, avoiding the DLL issues
that 42460 addressed.

Change-Id: Id18c5b90b365b0960fac347729a4927528d34c07
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42462
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-25 13:41:30 +00:00
dan sinclair f8fa6cf43c Register function symbol in TypeDeterminer after processing body.
This CL removes the registration of functions to after the function body
has been processed. This allows us to catch recursive calls where the
function calls itself. Prior to this we'd find the called function and,
if the function was an entry point, end up in a loop trying to walk all
the callers. With this change, the function is not found when we do
the lookup and we exit as expected.

Bug: tint:258
Change-Id: Ie0173207b788e87de39867a5aa41e8cc13ec33de
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42520
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-02-24 22:11:34 +00:00
Ben Clayton 80cb20de7c Fix ClassIDs for DLL usage
If ClassID::Of<T>() is used inside tint and used outside tint for the same type, and tint is built as a DLL, then the address of the Unique<T>::token can resolve to different addresses, entirely breaking Castable.

Replace address-of for a unique symbol with a single static counter that's incremented for each use of TINT_INSTANTIATE_CLASS_ID().

Change-Id: I40dc81b1273110291d90a1d5ec05428f7e703c6a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42460
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-24 21:03:34 +00:00
dan sinclair 72260e44ae Remove parsing of StringLiteral.
The StringLiteral token was removed from the spec when all usage was
removed. This CL removes the remaining parsing bits from Tint.

Change-Id: I02f5dbdbad649c62c22c69a55616e0087a0f56d4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42440
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-02-24 18:56:34 +00:00
dan sinclair 8feb9b847f Update the rounding modes to match the spec.
The spec was clarified that a value of .5 rounds towards the even value.
This matches the HLSL `round` method. This CL updates SPIR-V to use the
`RoundEven` GLSL450 call and the `rint` MSL call so they match the spec
requirements.

Change-Id: I97ce2e29b9639ad72b6846b32dbe3abb8d9f6cff
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42421
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-02-24 18:01:54 +00:00
Ben Clayton eb496d0a4d transform: API cleanup
Transforms are meant to be reusable. Those that hold state cannot be used concurrently.
State leakage between runs is dangerous.
To fix this:
* Add transform::Data - A new base class for extra information emitted by transforms.
* Add transform::DataMap - A container of Data, keyed by type.
* Add a transform::DataMap field to Transform::Output.
* Have FirstIndexOffset emit a FirstIndexOffset::Data.
* Deprecate the getters on the transform.

Mutability of the transform config is also dangerous as setters can be called while a transform is actively running on another thread.
To fix:
* Expose a VertexPulling::Config structure and add a constructor that accepts this.
* Deprecate the setters on VertexPulling.

Also deprecate Transform::Output::diagnostics.
Put all the transform diagnostics into the returned Program. Reduces error handling of the client.

Change-Id: Ibd228dc2fbf004ede4720e2d6019c024bc5934d1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42264
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-24 15:55:24 +00:00
Ben Clayton 94b36c3e86 src/transform: Remove @notes that are no longer true
The transform::Manager no longer does anything special. It is now a container of transforms that acts like a single transform.

Change-Id: I5e51e250cfa610b651445b7cd5efd29811c56d2e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42261
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-02-24 15:08:54 +00:00
Ben Clayton 03eaff3b0a wgsl::ParserImpl: Use sync() for postfix_expr()
postfix_expr() handles `[]` array accessors and call expressions `()`.

Have postfix_expr() use sync to parse these:
* It will use the end bracket token to attempt to resynchronize the parser on error
* It also considers maximum parser recursion depth, avoiding stack overflows

Fixed: chromium:1180573
Change-Id: I8c1c62c68e24a564e0e4e7d0de9f5a3fa7032369
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42222
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-24 14:21:52 +00:00
Ben Clayton 6d612ad478 TypeDeterminer: Resolve swizzles
Have the TD resolve swizzles down to indices, erroring out if they're not valid.

Resolving these at TD time removes swizzle parsing in the HLSL writer, and is generally useful information.

If we don't sanitize in the TD, we can end up trying to construct a resulting vector of an invalid size (> 4) triggering an assert in the type::Vector constructor.

Fixed: chromium:1180634
Bug: tint:79
Change-Id: If1282c933d65eb02d26a8dc7e190f27801ef9dc5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42221
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-24 14:15:02 +00:00
Ben Clayton 8b1851dbdc ClassID: Support use as unordered map / set keys
Change-Id: Ia6c21dfc33445ba828b2f244d8a3479fb3328805
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42263
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-02-24 13:51:32 +00:00
Ben Clayton ce9229cd2e Program: Fix move of diagnostics.
Add test.

Change-Id: Ide47df8b3a946818ed9a8ffd62411284f568609b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42262
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-02-24 13:51:13 +00:00
Ben Clayton 33a8cddb2d TypeDeterminer: Error if an IdentifierExpression to a callable is not called
IdentifierExpressions that resolve to functions and intrinsics were not being assigned a semantic::Expression as there is no function / intrinsic type to give them. This lead to NPEs in the writers when these identifiers were reached and TypeOf() is called.

Adding a new tint::type::Callable is an option, but until functions become a type in the language, this seems like a very large and debatable change.

Attempting to detect IdentifierExpressions with no semantic node in the validator is another option, but this is clunky as it has to detect incomplete semantic info from the TD, and cannot identify whether this actually resolved to a function or an intrinsic.

Instead we now error in the TD if encounter an IdentifierExpression that resolves to a function or intrinsic which is not called (ident is not followed with parenthesis).

Fixed: chromium:1180544
Fixed: chromium:1180814
Change-Id: I121dd194356419f94b09c7ee1ed544a350a114b3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42220
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-02-24 13:31:22 +00:00
Ryan Harrison 13dbbc6797 Remove references 1D Array texture dimension
WGSL recently removed this concept, since it didn't exist in WebGPU,
so excising it from the code.

BUG=tint:515

Change-Id: Ibbca6bd643fd96c2fb10bd33f471c9e9e58de535
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42320
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2021-02-24 05:05:21 +00:00
Ben Clayton 767df5f03b Fix infinite spin in wgsl parser
If the parser hits a `maximum parser recursive depth reached` situation, then we need to try and resynchronize the parser.

If we fail to do this, then the synchronized_ flag may remain true, and the parser will believe progress is still being made.
In this situation the parser may try to reparse the same token, forever.

By calling sync_to() we either find the end of the block, and forward progress can be made, or synchronized_ is set to false, and the parser can error out cleanly.

Add test case from fuzzer report.

Fixed: chromium:1180128
Change-Id: I893077677fd3dfbd4b9b400cd32db842b06db500
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42029
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-19 20:01:43 +00:00
Ben Clayton 527a0bbf25 Have Program::IsValid() return false unless built
An unbuilt program doesn't have an ast::Module, so Program::AST() will just explode.

* Have a Program default to false for IsValid()
* Initialize the ast_ field to nullptr. This was previously floating.
* Return from CommonFuzzer::Run() earlier if the InputFormat is not recognised.

Fixed: chromium:1180130
Fixed: chromium:1180157
Change-Id: I9b67daa10746f386f44919a7b9ac5c171092d6e5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42028
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
2021-02-19 19:04:18 +00:00
Ben Clayton 3bb3116bdf hlsl/writer: Validate texture intrinsics with DXC
Change-Id: I4cb8f9a700842e43facbd83cd9af24a00a74658f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42023
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-19 12:45:45 +00:00
Ben Clayton 53d057c572 Add tint_unittest flags for enabling DXC validation
HLSL validation will be disabled by default, and is now opt-in with
--validate-hlsl and/or with a --dxc-path

Change-Id: Ia98d7b1fbba50168bbe85c7982b73598100016d7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42024
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-19 12:39:25 +00:00
Ben Clayton 4c4ceeea9d Fix missing doxygen on enum warning
Change-Id: I4e3b22e64554427f341a1bb260d72aa202c6b53c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42027
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-02-18 21:40:39 +00:00
Ben Clayton 1d98236770 Source: Restructure Source::File
Add Source::FileContent to hold the file source content and per-line data.

Have Source hold an optional pointer to a FileContent, and add a file_path field.

This allows us to kill the `FreeInternalCompilerErrors()` filth as we're now able to construct Sources that hold a file path without file content.

Change-Id: I03556795d7d4161c3d34cef32cb685c45ad04a3d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42026
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-18 21:40:19 +00:00
Ryan Harrison 41e58d89ea Clean up unresolved comments from review
Some comments from https://dawn-review.googlesource.com/c/tint/+/42060
were not addressed before it landed, this is a follow-up to address
them.

BUG=tint:489

Change-Id: Ieafe143e867ce0f5edf6cf2258db3ed12ffc13fb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42080
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-02-18 21:04:29 +00:00
Ben Clayton 89036852cc Don't build test_main.cc in chromium builds
Chromium has its own test main() entrypoint.

To ensure that Chromium doesn't panic about memory leaks with the tests that exercise the ICE cases, we have to explicitly call the FreeInternalCompilerErrors() functions in these tests (at least until I can add this to end of Chromium's test main() function)

Change-Id: I2ea5109fcdb5f68f56a19709a1ec35ed72c0f760
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42025
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-18 20:23:09 +00:00
Ryan Harrison 94cfbbeb5f Extract more StorageTexture information
BUG=tint:489

Change-Id: I03a15fdd156bf0c85b1afebb6e0e26fd44dff51f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42060
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-18 20:11:49 +00:00
Ben Clayton 15daded41b hlsl/writer: Fix output for texture intrinsics and types
Fixed: tint:146
Change-Id: Icf356faf7bee364a0783c717ee76ea98056b4401
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42022
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-18 16:49:48 +00:00
Ben Clayton 1d5a7eb82f semantic::Function: Clean up ReferencedXXX() return types
Use a type alias for the most common and lengthy return type.

Drop the `const` from the return type - it is (or at least should be) meaningless.

Fix `auto& referenced_variables =` local variable declaration in inspector.cc.
You cannot take a reference to a non-ref return value of a function.
I have no idea why the compiler wasn't erroring about this.

Change-Id: Icc0b4a9bf4b4c9d03b44670eda27214ef04ad41c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42021
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-02-18 16:36:18 +00:00
Ben Clayton 3a9a55eec6 ICE macros: Use '<<' for error message
Lessens the friction of using these macros.
Also allows you to add a message to TINT_UNREACHABLE(), which you couldn't do before.

Change-Id: Ida4d63ec96e1d99af71503e8b80d7a5a712e6a47
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42020
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-18 16:33:38 +00:00
Ben Clayton 41085503e1 Add hlsl::TestHelperBase::Validate()
Looks for DXC on PATH.
If found, it will invoke DXC with the shader program generated by the writer to verify the shader can compile.

Change-Id: Iad8b4021bac16d01214b500ddb89b5f743927ce9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41943
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-18 16:19:09 +00:00
Ben Clayton ce7e18e87c Add tint::Command
Command is a helper used by tests for executing a process with a number of arguments and an optional stdin string, and then collecting and returning the process's stdout and stderr output as strings.

Will be used to invoke HLSL and MSL shader compilers to verify our test generated code actually compiles.

Change-Id: I5cd4ca63af9aaa29be7448bb4fa8422e6d42a8ce
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41942
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-18 15:49:08 +00:00
Ben Clayton a87fda9225 Add tint::TmpFile
TmpFile constructs a temporary file that can be written to, and is automatically deleted on destruction.

Will be used to create a temporary source file for verifying generated HLSL and MSL against their shader compilers.

Change-Id: Ieaa6f257b93f4f2193dafe6297603816f6964928
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41941
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-18 15:39:00 +00:00
Ben Clayton 7206e25798 Remove deprecated APIs
Remove the Parser classes from the wgsl and spirv namespaces.
These have been replaced with a Parse() method.

Remove the TypeDeterminer::Run() method, this was not called by tint and
the TypeDeterminer is now non-public API.

Change-Id: I5ddb82768da04398ab3958d1647be44f9fe30c21
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41840
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-17 20:15:25 +00:00
Ben Clayton 6b4924fb0e Add TINT_UNREACHABLE() and TINT_ICE() helper macros
Appends an error message with the tint compiler source location to the
provided diagnositic list, and then calls the global error handler if
one is set.
Tests and the sample app now register an error handler to print the
diagnostic list to stderr and abort when NDEBUG is not defined.

All uses of assert(false) have been fixed up to use these macros.

Change-Id: I2f63e51ed86ac23883301d280070bd1a357c6cb2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41620
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-17 20:13:34 +00:00
Ben Clayton c7ca7668cc Fix TypesBuilder::builder pointer initialization
When copying or moving a ProgramBuilder, we always want the ProgramBuilder::ty to point back to the owner.
We were previously std::move()'ing the ty field, which is not correct - this will result in the TypesBuilder pointing to the wrong ProgramBuilder.

I'm not sure why we've not seen any issues with this using clang, but running under MSVC immediately highlighted this brokenness.

Change-Id: I4293bb00ac4fbdfa66d12b1504a7bd060e014cd6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41861
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-17 16:23:52 +00:00
Ben Clayton 34ae7d2ce7 wgsl/parser: Avoid stack overflows
Most recursive control flow passes through Sync().
Error out if the Sync() function is recursively called too many times.

This replaces the more specific kMaxConstExprDepth, which also passes
through Sync().

Fixed: chromium:1178436
Change-Id: I64a05f9f6a4fe6d2b53a3ca75642b30e98c7a35f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41724
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-17 16:16:02 +00:00
Ben Clayton 52296de528 Add tint::Cloneable base class
The CloneContext was previously dealing with pointers to CastableBase, which has no guarantees that the object was actually cloneable.
Add a Cloneable base class that CloneContext can use instead.

Improves readability and produces cleaner compiler errors if you try to clone a non-cloneable object.

Change-Id: I4352fc5dab3da434e4ab160a54c4c82d50e427b4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41722
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-17 13:17:39 +00:00
Ben Clayton f81df124f6 Add utils/unique_vector.h from TypeDeterminer
Add tests.

Change-Id: I064fbbe2387ebe980776ee99ed2ff48d6ea5d5b5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41621
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-02-17 13:10:49 +00:00
Ben Clayton 43a160dcbb Validator: Strip out unreachable code
A large chunk of validation is now handled by the IntrinsicTable. Remove this.

Also fail validation and propagate diagnostics from the Program to the validator if attempting to validate a broken program. This should prevent undefined behaviour if the user forgets to check the program.IsValid() after parsing.

Change-Id: I2972e8ce296d6d6fca318cee48bc6929e5ed52db
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41549
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2021-02-17 01:08:41 +00:00
Ben Clayton 4602ce7195 ast: Remove @notes about semantic info not being cloned
Semantic info is no longer part of the ast, so it is now odd to mention semantic info on a clone method for the AST.

Improve the documentation around cloning on the Program methods and the CloneContext.

Change-Id: Ib1cf255acfd994521aaa5add2789e5117db6b072
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41548
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2021-02-17 01:01:03 +00:00
Ben Clayton 81a29fe555 ProgramBuilder: Remove storage parameter from [Global]Const()
Storage classes are unused for constants.

Also trim extra arguments to these variable constructor functions that are already defaulted to the same value.

Change-Id: Ia0b44364de000bfb8799de15827ce08fcce5f5be
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41541
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2021-02-17 00:26:52 +00:00
Ben Clayton 37571bc32d ProgramBuilder: Swap parameter order for Var and Const
Move the storage parameter after type.
Const() has no use for storage classes, so this parameter will be removed in the next change.
This reordering keeps Var() and Const() parameter types identical for the first two non-optional fields

Change-Id: I66669d19fa2175c4f10f615941e69efcab4c23e1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41540
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-16 23:57:01 +00:00
Ben Clayton 4b9e7f92b9 transform::Hlsl: Hoist array initializers out of expressions
Move these into a separate const variable declaration statement just above the before the use of the array initializer.
HLSL does not allow array initializers as part of a sub-expression

Fixed: tint:406
Change-Id: I98f93f2eca172865691831011c852de5e57c5ad6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41484
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
2021-02-16 23:21:51 +00:00
Ben Clayton f77771e21b CloneContext: Add InsertBefore()
Inserts objects before others when cloning

Change-Id: Ibf247abae3aeb3d351048f1182db2a2b42b2c677
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41547
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-16 23:09:31 +00:00
Ben Clayton e909744640 CloneContext: Use As<T>() instead of static_cast<T>
And assert that the cast succeeded.

There is a danger with Replace() or ReplaceAll(), where you can end up replacing a node with another node of an incompatible type for some reference of that object. Previously this would silently cast to the incorrect type, and Bad Things would happen. Now we will assert in this situation.

I have not observed this issue happening (all current uses of Replace() and ReplaceAll() are believed to be safe). This is just an edge case I've spotted and wanted to add some safety belts for.

Change-Id: Icf4a4fe76f7bc14bcc6b274de68f7d0b3d85d71f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41546
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2021-02-16 22:27:11 +00:00
James Price ea9e471e30 [spirv-writer] Add support for sample index/mask builtins
Use a sanitizing transform to convert scalar `sample_mask_{in,out}`
variables to single element arrays.

Add the `SampleRateShading` capability if the `sample_index` builtin
is used.

Bug: tint:372
Change-Id: Id7280e3ddb21e0a098d83587d123c97e3c34fa1b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41662
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
2021-02-16 21:44:13 +00:00
James Price 1413733be8 [wgsl-reader] Add support for sample index/mask builtins
Bug: tint:372
Change-Id: I2cbadf31f350c49ae0689d8b05f3f7a92d074efd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40560
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2021-02-16 21:37:01 +00:00
James Price c9af597997 [semantic] Add semantic::Variable::Users()
Returns a list of ast::IdentifierExpression* nodes that reference the
variable.

Change-Id: I36f475c6ddf5482f9ae9b432190405625f379f0d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41661
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-16 21:15:01 +00:00
Ben Clayton 45b18ce064 Fix CMake build, fix doxygen warning
inspector_test.cc: Remove unused method
test_helper.h: Fix comment type on member

Change-Id: I53b1392fa1fa8154efdcd471d1df1bbf27e04dc9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41728
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-16 20:56:21 +00:00
Ben Clayton f97b9c9310 Add semantic::Statement
Add Stmt() accessor on all semantic::Expressions so the owning statement can be retrieved.

Change-Id: I5d584335a6d137fdeab0b8d74a161fcae9b46080
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41545
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
2021-02-16 18:45:45 +00:00
James Price e7dab3c9ea [ast] Rename Builtin::kSampleId to Builtin::kSampleIndex
Other builtins use WGSL terms instead of SPIR-V terms too, and the
WGSL writer is relying on the output of `operator<<(Builtin)`, which
just stringifies the name of the enum. This also matches the
equivalent `semantic::Usage::kSampleIndex` enum.

Added test coverage for WGSL builtin generation.

Bug: tint:372
Change-Id: I8077d22c4a5ddf67b1ad07e7365453db74db8e7d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41660
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
2021-02-16 18:21:41 +00:00
Ryan Harrison d086c147d0 Add support fo extracting information about Storage Textures
BUG=tint:489

Change-Id: I28e4b0e568aea463971e9d2f5a04f04e942e2564
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41600
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-16 15:10:23 +00:00
Vasyl Teliman 652d40a3d1 wgsl-reader: Add support for nested array accessors
Bug: tint:501
Change-Id: I23f4e73696f48d29b3f9d63997fa1c5004cf4d34
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41622
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-02-16 14:53:49 +00:00
David Neto 909c166034 spirv-reader: ignore NonSemantic. extended instructions
This is the first step in being able to read code generated
by Clspv.

Actively ignore the instructions instead of applying stripping
transform before hand. That way we have a chance at properly counting
instructions, which helps produce better diagnostics.

Bug: tint:3
Change-Id: I82bde88897485380d70dc8b287c3843eae5489b6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41641
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-16 14:51:48 +00:00
Ben Clayton 545c9742d5 Cloning: move arguments to create() into temporary locals
In C++ argument evaluation order is undefined. MSVC and Clang evaluate these in different orders, leading to hilarity when writing tests that expect a deterministic ordering.

Pull out all the argument expressions to create() in the clone functions so a cloned program is deterministic in its ordering between compilers.

Change-Id: I8e2de31398960c480ce7ee1dfaac4f67652d2dbc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41544
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
2021-02-11 20:27:14 +00:00
Ben Clayton 7b6bcb6e0b Fix AST declaration order when cloning Programs
Change 41302 correctly fixed up Module::Clone(), but this wasn't actually called by the CloneContext, as Module::Clone() returns a new Module, where as the CloneContext needs to clone into an existing Module.

Refactor the code so that this duplicated logic is moved into a single Module::Copy() method.

Fixed: 1177275
Change-Id: Ia8c45ef05e03b2891b5785ee6f425dd01cb989c6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41542
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-02-11 20:23:03 +00:00
Ben Clayton 5585f0789c Add SymbolTable::New()
Generates a new unnamed symbol.
Useful for creating temporaries in transforms.

Change-Id: I3aa037e4a6b2d400f24e01bbb3555af68da26748
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41480
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-11 14:54:41 +00:00
Ryan Harrison 5d64f60a60 Add ability to get all bound resources in a single call
Also adds to the binding struct what type of resource it is.

BUG=tint:489

Change-Id: I8ce56a1a613b330150545781cb42d2afeaa69375
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41460
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2021-02-10 22:16:05 +00:00
Ben Clayton 8b1906d996 Validation tests: Check the Program is valid
If the program is invalid, then the content of the program is undefined.
Don't attempt to test undefined behavior.

Remove the one remaining test that was using an invalid program.

Change-Id: I4bb77b8048768717a312ed94b96efb3416274b63
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41384
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-10 21:47:04 +00:00
Ben Clayton 47c4d18375 Move intrinsic overload tests from Validator -> TypeDeterminer
TypeDeterminer now does overload resolution. Move these tests to the right place.

Change-Id: I27a4fccac34ded00f9828a77cc25ccfe1cb5c0ea
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41383
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
2021-02-10 21:42:35 +00:00
Ben Clayton 2522b29f7d type_determiner_test.cc: Rename ImportData to Intrinsic
Change-Id: I3ecf7e1480ee3b50815b9cb1d37ac397eada348f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41382
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
2021-02-10 21:40:36 +00:00
Ben Clayton 81da283b2c Add type::Type::UnwrapAliasIfNeeded()
Unwraps aliased types until reaching a non-alias.

Change-Id: I6546d60b7cbe07d4c8cc5a0b439329af8b468ca9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41500
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-10 21:40:15 +00:00
Ben Clayton 46d78d731b ProgramBuilder: Add Symbol overloads of Var(), Const(), Global(), GlobalConst()
Useful if you have a symbol already

Change-Id: Ib9e15ea761f58ee67dc3cc722d9129cd5369d92b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41481
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-10 21:34:26 +00:00
Ben Clayton faca02d438 IntrinsicTable: Fix a number of TODOs
And add tests for IntrinsicTable.

Drop all the type unwrapping - be precise:
* Display the actual argument types in the signature mismatch message
* Only dereference pointer arguments if the parameter does not expect a pointer

Correctly match access control on storage types

Note that I was mistaken in tint:486 - the TypeDeterminer is resolving identifiers to variables correctly as pointer types. The confustion here was probably due to all the UnwrapAll() calls, which have now all gone.

Fixed: tint:486
Change-Id: I239eabd1fedfc082566c4af616ccfc58786cae25
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41280
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-10 21:34:25 +00:00
Ben Clayton 2101c35f3b Stub sanitizer transforms for the hlsl, msl & spirv writers
These transforms will perform work to massage the Program into something consumable by the given writer.

Change-Id: I8989e8d4bc1a9cae7ce1f8764c8f3811db3bd04d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41483
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-10 21:22:03 +00:00
dan sinclair c2118b0dcb Fixup build issues.
This CL adds some override decorations for various destructors and turns
of Werror for the spirv-tools build.

Change-Id: I10ac72cfaee247334f6db2918230283b1f975955
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41420
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-02-10 16:57:24 +00:00
Ben Clayton 22a9f175e0 Add missing #include to fix CMake build
Change-Id: I3ff04a2e9f4b04ffad924b15c4c5049360651705
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41381
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-02-10 16:41:23 +00:00
James Price dfd1714174 [wgsl-writer] Emit globals in declared order
Instead of emitting all global variables and then functions, emit
global declarations in the order they were added to the AST.

This fixes issues where the reording might generate an invalid WGSL
program from a valid input (e.g. when declaring a global variable with
the same name as a variable inside a function that precedes it).

This also unifies the implementation of Generate() and
GenerateEntryPoint(), to avoid implementing the same logic twice.

Change-Id: I60a4e5ed4a054562cdcc3d028f8d577434a6d713
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41303
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-02-10 15:34:37 +00:00
David Neto 0c7f97626f spirv-reader: support OpCompositeInsert
This generates intermediate variable to stuff the component into,
then a constant definition to evaluate the result for later use.

Bug: tint:3
Change-Id: If2e6bb24e2b1e621c3602509eb3237c40f53897b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41360
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-10 15:05:56 +00:00
James Price c0f30195a0 [validation] Validate globals in declared order
Instead of validating all global variables and then functions,
validate global declarations in the order they were added to the AST.

This fixes false-positive "redeclared identifier" errors when a global
variable is declared after a function that declares a variable of the
same name, and false-negative "identifier not declared" errors when a
global variable is declared after a function that tries to use it.

Change-Id: Ibf5e5265bc2f8ca892096f0420757b70e1984525
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41302
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-09 23:22:32 +00:00
James Price 558385357f [ast] Capture global declaration order
Adds a vector<CastableBase*> to ast::Module which stores the list of
global variables, functions, and types, in the order that they were
declared.

This will be used to fix validation and backend issues around name
uniqueness.

Change-Id: I14491f6ebc0fc7341bd3fb3b3f408faa234a91f7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41301
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-09 21:39:10 +00:00
James Price 3eaa450984 [ast] Add ast::Module::AddFunction()
Remove the non-const ast::Module::Functions() getter.

Change-Id: I365eece04837ee6bd51147d226c73e04ce5d9bd4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41300
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: James Price <jrprice@google.com>
2021-02-09 21:26:21 +00:00
Alan Baker cd17ea88e3 Implement data unpacking intrinsics
* Add support for data unpacking intrinsics
  * spir-v reader
  * type determiner
  * intrinsic table
  * spir-v, hlsl and msl writers

Bug: tint:341
Change-Id: I8f40d19d59a4699af75cd579fe8398c735a77a59
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41320
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Alan Baker <alanbaker@google.com>
2021-02-09 21:23:00 +00:00
James Price 2a284b2a13 [hlsl-writer] Add support for sample_mask builtins
Bug: tint:372
Change-Id: Ie3fe7f6853396ff6a4ff47045b98b3b561bf1340
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40561
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-02-09 19:22:45 +00:00
James Price 2b5acacbd4 [msl-writer] Add support for sample_mask builtins
Bug: tint:372
Change-Id: Ib1d9dc525fbc180b603241c4746cbbd54077a489
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40640
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-02-09 19:13:25 +00:00
Ben Clayton 3e8060b4e3 Add type::Type::FriendlyName()
Gives a WGSL-like string for the given type.

Also cleans up some code in IntrinsicTable.

Change-Id: I89a2fadb5291b49dcbf43371bb970eef74670e2c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40605
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-09 18:52:34 +00:00
Ben Clayton 6f48851f27 writer/spirv: Validate arrayLength()
This was tested but the output was not run through the validator.
Once the AST is actually correct, the output is validated correctly.

Fixed: tint:266
Change-Id: I83bb53323c124c8fbaa3cd9b80524f89c2e30557
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40601
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-09 18:45:14 +00:00
Ben Clayton 7b7d69854d TypeResolver: Fix TypeOf() for CallExpression
While traversing and resolving the AST, TypeOf() was called to look up
the semantic node for the given AST expression in order to fetch the
resolved type. However, for CallExpression semantic nodes are
constructed at the end of the AST traversal, and GetType() for these
would unexpectedly return nullptr, causing a crash.

To fix, have TypeDeterminer maintain an internal map of ast::Expression
to resolved type. Always populate this internal map whenever SetType() is
called. At the end of the AST traversal, have CreateSemanticNodes()
construct the semantic nodes for any ast::Expression nodes that do not
already have a semantic node assigned.

With this, GetType() will always return the type set with SetType().

Fixes tint -> dawn autoroller.

Fixed: tint:488
Change-Id: I2830c496d9b2e4807ec01ed69aeafb3912f4a890
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40606
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
2021-02-09 17:38:05 +00:00
dan sinclair 81302443f7 Fix building with gcc.
This CL renames the Parameters using statement to ParametersList so it
doesn't conflict with the Parameters method which is used later to
return the ParametersList.

Change-Id: I2ac19ba52fc0834e5a35b4b35a210dcc170866fc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41240
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-02-09 15:37:44 +00:00
Ben Clayton ab10db454b writer/spirv: Fix intrinsic calls with ptr 'out' parameters
Use the new semantic::Intrinsic::Parameters() information to determine whether a parameter is a pointer.
Don't generate a load if the parameter expects a pointer.

Fixed: tint:361
Change-Id: I1420a6b0e22d52f67a5e52151fb073ac33df5bd5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40508
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-08 23:07:45 +00:00
Ben Clayton 06d8db2bcb Add texture intrinsics to the IntrinsicTable
Automatically implements verification of texture intrinsic overloads.

Bug: tint:449
Change-Id: I74858902ddcc02337641dd422b800378215b0c7a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40507
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-08 22:59:44 +00:00
Ben Clayton 59d24735d0 Add IntrinsicTable
Provides a centeralized table for all intrinsic overloads.

IntrinsicTable::Lookup() takes the intrinsic type and list of arguments, returning either the matched overload, or a sensible error message.

The validator has expectations that the TypeDeterminer resolves the return type of an intrinsic call, even when the signature doesn't match. To handle this, create semantic::Intrinsic nodes even when the overload fails to match. A significant portion of the Validator's logic for handling intrinsics can be removed (future change).

There are a number of benefits to migrating the TypeDeterminer and Validator over to the IntrinsicTable:
* There's far less intrininsic-bespoke code to maintain (no more duplicate `kIntrinsicData` tables in TypeDeterminer and Validator).
* Adding or adjusting an intrinsic overload involves adding or adjusting a single Register() line.
* Error messages give helpful suggestions for related overloads when given incorrect arguments.
* Error messages are consistent for all intrinsics.
* Error messages are far more understandable than those produced by the TypeDeterminer.
* Further improvements on the error messages produced by the IntrinsicTable will benefit _all_ the intrinsics and their overloads.
* The IntrinsicTable generates correct parameter information, including whether parameters are pointers or not.
* The IntrinsicTable will help with implementing autocomplete for a language server

Change-Id: I4bfa88533396b0b372aef41a62fe47b738531aed
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40504
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-08 22:42:54 +00:00
Ben Clayton 316f9f6b6d Add semantic::Intrinsic
semantic::Intrinsic derives from semantic::CallTarget, which can be obtained from the Target() accessor on the CallExpression.

Flesh out semantic::Parameter to contain a `Usage` - extra metadata for the parameter.

The information in `Intrinsic` is enough to remove the `semantic::IntrinsicCall` and `semantic::TextureIntrinsicCall` types.

Change-Id: Ida9c193674ad8605d8f12f6a1d27f38c7d008434
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40503
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-08 22:31:44 +00:00
Ben Clayton bab3197fda ProgramBuilder: Add more helpers for Members / Arrays
Add overloads of TypesBuilder::array() that take a stride parameter.
Add overload of ProgramBuilder:Member() that has an offset

Change-Id: If8337e410e73eade504432599a9798bbc511382e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40600
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-08 21:16:21 +00:00
Ben Clayton 4c51d97a5c Validator: Change the error message for v-0031
It previously said:

"a struct containing a runtime-sized array must be in the 'storage' storage class"

This had be looking at the variable's storage class, when the error was actually trying to tell me I needed `[[block]]` on the struct declaration.

Change-Id: I7a23a0c0c35508bdac20c808d2635592638dfa77
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40602
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
2021-02-08 21:14:52 +00:00
Ben Clayton a51aa1f805 Fix intrinsic tests so arguments match an overload
Change-Id: I8c5464e3198c6a3b154f5f3433466955e203efee
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40502
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-08 21:10:11 +00:00
Ben Clayton b57c19d450 Change StorageTexture::SubTypeFor() signature
So that it takes a type::Manager instead of a ProgramBuilder.
Makes this callable from places that has the former and not the latter.

Change-Id: Ie968617ae944cc6621c17467a4f7caadacba548f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40505
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-08 20:35:01 +00:00
Ben Clayton 3b4f3d2860 Fix tests so they only exercise legal texture overloads
textureLoad():
* Does not operate on cube textures
* Does not have a `level` parameter for storage textures
* Requires an `array_index` argument for arrayed texture types

textureSample():
* Only supports f32 data types for sampled textures

Bug: tint:449
Change-Id: I30b3a0c32245d5e6c4b1f3aeef112a67ffb1d055
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40506
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-08 20:24:52 +00:00
Ben Clayton 599d8f8c0d Rename intrinsic.cc to sem_intrinsic.
For consistency with the other .cc file names in this directory.
The reason we need the sem_ prefix is because all the tint lib code is compiled as a single target, and .GN cannot cope with .cc files with the same file name, even if they're in different directories.
This could be fixed by building each directory as a separate target, but we have circular dependencies that currently make this impossible.

Change-Id: I2f1379ff11dd863f81662449f73d67832f0a8a4e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40501
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-08 20:11:22 +00:00
Ben Clayton 052ab89a1e Rename semantic::Intrinsic to semantic::IntrinsicType
This allows us to create a semantic::Intrinsic class that holds more information about the particular intrinsic overload.

Change-Id: I180ddb507ebc92172badfdd3a59af346f96e1f02
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40500
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-08 19:53:42 +00:00
Ben Clayton 2ddb1783c5 Add semantic::CallTarget, have Function derive from it
CallTarget holds parameter information. This is simple to extract from an ast::Function.
CallTarget will also be used for intrinsics, which can be overloaded. CallTarget will hold the resolved overload parameter signature.

Bug: tint:361
Change-Id: I4dadc4a99293f12ede9e9cbd9132ba5f9b9830ed
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40284
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-08 19:13:19 +00:00
David Neto 7efea888fa spirv-reader: instance_index must have u32 store type
Fixed: tint:485
Change-Id: I73613ae916b2d86b25470f292e5bf5cd5c7f288b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40582
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-08 16:12:09 +00:00
James Price 61306b882d [wgsl-reader][wgsl-writer] Fix implicit handle storage class for textures
Unwrap the type before checking if it is a handle type, to account for
access decorations.

Bug: tint:332
Change-Id: I8af9749fec1e2f5dbd7c3bec0b73e506ae111a28
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40540
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-08 15:08:49 +00:00
David Neto 6d1687fb01 spirv-reader: vertex_index always has u32 store-type
Fixed: tint:483
Change-Id: Ie26941ab751425dfbc0924ea21bee32dc0f92527
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40623
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-08 15:02:49 +00:00
Corentin Wallez 3c568f188d Revert "spirv-reader: add disabled test for compare sampling with explicit Lod"
This reverts commit 4a7981e300.

Reason for revert: Empty GTest Values() causes compilation error in Chromium.

Original change's description:
> spirv-reader: add disabled test for compare sampling with explicit Lod
>
> This is blocked by discussion at W3C
> https://github.com/gpuweb/gpuweb/issues/1319
>
> Bug: tint:482
> Change-Id: Ic3a2b32fb09a431edbd7716a394a9eb3f163fb85
> Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40621
> Commit-Queue: Ben Clayton <bclayton@google.com>
> Reviewed-by: Ben Clayton <bclayton@google.com>
> Auto-Submit: David Neto <dneto@google.com>

TBR=dneto@google.com,bclayton@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: tint:482
Change-Id: I637c40950cd343196c2703c9854f584bf8f1c084
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40603
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
2021-02-08 09:49:09 +00:00
David Neto 4a7981e300 spirv-reader: add disabled test for compare sampling with explicit Lod
This is blocked by discussion at W3C
https://github.com/gpuweb/gpuweb/issues/1319

Bug: tint:482
Change-Id: Ic3a2b32fb09a431edbd7716a394a9eb3f163fb85
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40621
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: David Neto <dneto@google.com>
2021-02-05 22:06:03 +00:00
David Neto a2fa690cda spirv-reader: sample_mask_in, sample_mask_out
TODO: passing pointer to them as a function parameter

Bug: tint:471
Change-Id: Ibd55bdc77a2bfb0f5712dd9bf332910999b8d0d1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40123
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-04 22:12:30 +00:00
James Price 1f2d38c826 [wgsl-writer] Omit the storage class for handle types
These types have an implicit storage class of UniformConstant.

Bug: tint:332
Change-Id: I78c5b2a085e543ebba7d5e92b8f11550d0cd4d49
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40400
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: James Price <jrprice@google.com>
2021-02-04 18:35:40 +00:00
James Price 0ff5e0bfb8 [wgsl-reader] Remove explicit storage class from samplers/textures
Automatically set the storage class to UniformConstant.

Producing an error if an explicit storage class is given is deferred
until downstream users have caught up.

Bug: tint:332
Change-Id: I70e7390dc95d6f578a0fdeb675ca63a8b5b4fa26
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40160
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
2021-02-04 18:26:00 +00:00
David Neto ef6eefdc8f spirv-reader: builtin conversions for sample_mask_in, sample_mask_out
Enum conversion of builtins depends on storage class.

Bug: tint:471
Change-Id: I0b93c26139f72c70786b9b70f1016e62e1df62f4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40122
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-04 17:34:00 +00:00
James Price 77f4f0280d [type-determiner] Add test coverage for scoping rules
Change-Id: I56430365585678812d6a91e26e0faee1409e53b3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40200
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-04 16:33:20 +00:00
David Neto f4329f57e5 spirv-reader: GLSLStd450RoundEven maps to round
This is from the resolution to https://github.com/gpuweb/gpuweb/issues/1381

Bug: tint:3
Change-Id: If4158d8ff3bffce0e82d2230e5df5650193e7541
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40180
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-04 16:22:50 +00:00
Alan Baker c63e1c0791 Implement data packing intrinsics
* Fix how the HLSL writer determines how to use a RWByteAddressBuffer
* Fix how the HLSL writer decides the register space for a storage
  variable
* Fix inference of hlsl format in the tint executable
* Add support for data packing intrinsics
  * type determination
  * validation
  * writers
  * spirv reader

Bug: tint:340, tint:473, tint:474
Change-Id: I45dc8fd7c6f9abc7d30f617c7e3d713d7965b76e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40342
Commit-Queue: Alan Baker <alanbaker@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-04 16:17:49 +00:00
Ben Clayton fbd47c752e writer/spriv: Promote the SPIR-V validation to the test helper
This is useful for checking that generated SPIR-V is actually valid.

Change-Id: I851748f96b00e57d5915b32e4afec2b1c933b691
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40283
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-02-04 15:34:39 +00:00
Ben Clayton c1052a4971 Add semantic::MemberAccessorExpression, use it.
Pull the mutable 'is_swizzled' semantic field from ast::MemberAccessorExpression and into a new semantic::MemberAccessorExpression node.
Have the TypeDeterminer create these semantic::MemberAccessorExpression nodes.

Bug: tint:390
Change-Id: I8fc6e36dabb417190528536a94d027af54059222
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40142
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-02-03 23:55:56 +00:00
Ben Clayton df629c5404 Fix all tests so TypeDetermination runs without errors
If TypeDetermination fails, then semantic info may be missing.
We don't want to have to guard against missing semantic nodes in each writer.

Bug: tint:390
Change-Id: I3124b514ce88f83bd3f75747c4ec6c960282f3c6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40141
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-02-03 23:42:26 +00:00
Ben Clayton ea9c86c296 ast: Move [Set]IsSwizzle() from IdentifierExpression to MemberAccessorExpression
This is more a property of a MemberAccessorExpression than the identifier itself.

Change-Id: Icb17df1fe43a959332d73df026e77ca4e07d23ed
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40140
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-02-03 22:26:36 +00:00
David Neto a568701d61 spirv-reader: support sample_id builtin variable
TODO: support sample_id declared with signed integer store
type, and then having the pointer passed to a helper function.

Bug: tint:471
Change-Id: Iac303ff6118b2d2d518e5070a8d589dcd3616f39
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40020
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: David Neto <dneto@google.com>
2021-02-03 22:01:46 +00:00
Ben Clayton 1618f4be4e Add semantic::Call, IntrinsicCall, TextureIntrinsicCall, use them.
semantic::Call derives from semantic::Expression, and Type() is the return type of the function
Pull the mutable semantic field from ast::Identifier and into a new semantic nodes.
Have the TypeDeterminer create these new semantic nodes.

Note: This change also fixes the node that holds the semantic information for a call.
Previously this was on the identifier, and this is now correctly on the CallExpression.
The identifier of the CallExpression should resolve to the target function, not the return type.
Functions can currently be represented as a type, and the identifier of a CallExpression now has no semantic information.

Bug: tint:390
Change-Id: I03521da5634815d35022f45ba521372cbbdb6bc7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40065
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-02-03 21:02:25 +00:00
Ben Clayton 48b384168c type::StorageTexture: Remove set_type()
The subtype of a storage texture is statically determinisic from the ImageFormat, and does not need to be late-set by the TypeDeterminer.

Add StorageTexture::SubtypeFor() helper for returning the subtype for a given ImageFormat, and add the subtype as another immutable constructor parameter.

Bug: tint:390
Change-Id: Ibe732293e3142064b60f4e666a7eb39ae8db50e7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40064
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-02-03 20:28:26 +00:00
Ben Clayton b17aea159c Add semantic::Variable, use it.
Pull the mutable semantic field from ast::Variable and into a new semantic::Variable node.
Have the TypeDeterminer create these semantic::Variable nodes.

Bug: tint:390
Change-Id: Ia13f5e7b065941ed66ea5a86c6ccb288071feff3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40063
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-02-03 17:51:09 +00:00
Ben Clayton 401b96b9bb Simplify usage of the TypeDeterminer in tests
Make private all TypeDeterminer::DetermineXXX() methods, forcing all tests to use the root-level TypeDeterminer::Determine() method.
Remove TypeDeterminer::RegisterVariableForTesting().

The main use for calling the TypeDeterminer::DetermineXXX() methods was to perform type determination on a partial AST.
This was messy and often resulting in multiple calls into TypeDeterminer. Most tests already perform a full TypeDeterminer::Determine() call when the program is built, so many of these were redundant.
The exposure of these internal methods for testing also makes refactoring the TypeDeterminer extremely difficult.

Add a number of ProgramBuilder helper methods for attaching the partial AST in these tests to the root of the AST, greatly simplifying the use of the TypeDeterminer:
* ProgramBuilder::Global() and ProgramBuilder::GlobalConst() are helpers that register the variable returned by ProgramBuilder::Var() and ProgramBuilder::Const(), respectively.
* ProgramBuilder::WrapInFunction() is a variadic function that accepts variables, expressions and statements, attaching these to the root of the AST via a dummy function.

Most test classes now no longer use their own TypeDeterminer, and instead properly depend on the automatic type determination performed at Program build time.

Bug: tint:390
Change-Id: Ie901890420c5de170cdf2a7aaef9b96fc3bebd60
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40062
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-02-03 17:19:59 +00:00
Ben Clayton 87c78ddabc Add semantic::Function, use it.
Pull the mutable semantic fields from ast::Function and into a new semantic::Function node.
Have the TypeDeterminer create these semantic::Function nodes.

Bug: tint:390
Change-Id: I237b1bed8709dd9a3cfa24d85d48fc77b7e532da
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39902
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-03 16:43:20 +00:00
David Neto c694d43c75 ast: add sample_mask_in, ample_mask_out, sample_id
Fixed: tint:472
Change-Id: Id7ac14f4ec34fce8172747bfc24b1693addbe738
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39842
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: David Neto <dneto@google.com>
2021-02-02 15:27:15 +00:00
David Neto f2d687137c spirv-reader: support OpImageQuerySamples
Bug: tint:109
Change-Id: I1a7677c9322f5f2f01d6bf436222b58ab9bdbf95
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39721
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-02 15:07:25 +00:00
Ben Clayton 90da745fbd Program: Fix IsValid() state on TypeDeterminer error
The error was added to diagnostics_, and then this list was replaced with diagnostics from the builder.
This resulted in the error silently being dropped.

Change-Id: Ifdda99bfb1582fa5d0fa691f7d39cfe3f17e60e5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39901
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-02 15:06:05 +00:00
Ben Clayton 42d1e097e6 Have ProgramBuilder::Func() register the function
With the ast::Module::Functions().

Also remove pointless calls to td.Determine() that will automatically be
done when the program is built.

Change-Id: Ia7506e430b04d91d4f6b02fb6b678d0ea9912bcd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39900
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-02 14:29:15 +00:00
James Price 611f727a09 [validation] Handle variable scoping for nested blocks
* Push/pop the variable scope stack when validating blocks
* Handle nested blocks in ValidateStatement()
* Add test coverage

This also fixes issues with other types of validation errors not being
caught when inside nested blocks.

Change-Id: Ia8d0138b346a8a7aa607497d51fd6aaf675dc8be
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39980
Auto-Submit: James Price <jrprice@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-02 14:28:15 +00:00
David Neto d277f3a85a spirv-reader: support OpImageQueryLevels
Bug: tint:109
Change-Id: I1bb7bbdca2322df28e7b22225e4b1bfdb74dbf73
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39720
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-01 23:43:44 +00:00
David Neto 1d2bcb99d6 spirv-reader: support OpImageQuerySizeLod
It queries the dimensions and array levels of a sampled image.

Bug: tint:109
Fixed: tint:423
Change-Id: Ia9ac0ee84b0282dbde8729a1698c9b21943723d2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39682
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: David Neto <dneto@google.com>
2021-02-01 22:47:54 +00:00
David Neto 4d098a7b75 spirv-reader: WGSL does not support OpImageQueryLod
Bug: tint:109
Change-Id: Ife61dca63c605a456407140d5c4fdb6b4bfa97a0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39681
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: David Neto <dneto@google.com>
2021-02-01 21:47:04 +00:00
Alan Baker db67a287b8 Handle MSL and HLSL builtins more consistently
* Fixes missing namespace for metal builtins
    * Consolidates handling of most builtins
    * Implements ldexp for msl and hlsl
    * Many more tests

Change-Id: I43a4876785d488921421ab64c2999aa036d831a8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39940
Commit-Queue: Alan Baker <alanbaker@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-01 21:30:54 +00:00
David Neto 7ecf92a53c spirv-reader: support OpImageQuerySize
Change-Id: I27ad580ae84f18a69b31700f56bbbcf59d3818e6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39680
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
2021-02-01 19:44:24 +00:00
James Price 4cec1429d7 Add tokens for left and right shift
Manually split `>>` and `>=` tokens when looking for a `>` to
correctly parse ptr/array/vec declarations and initializations.

Bug: tint:171, tint:355
Change-Id: Iee89a844fd999e337ae44ef9b192cc122fbf9e54
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39362
Auto-Submit: James Price <jrprice@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-01 18:23:23 +00:00
Ben Clayton 222e09735e EmitVertexPointSize: Don't share expressions between functions
AST nodes are syntax tree nodes, not semantic tree nodes.

The pointsize IdentifierExpression was being created once and used in multiple functions.
The type determiner assumes that expressions are not shared between functions (otherwise the same IdentifierExpression may end up resolving to two different types / semantic nodes based on scope).

Bug: tint:469
Fixed: tint:468
Change-Id: I4c85d25ee3fd333d14739b519d5ee6cda767d52e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39880
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-01 16:54:44 +00:00
Alan Baker 2e6a1bb396 Remove special case type determination
* Affects any, all, derivatives, dot and select
* Add validation for those builtins

Change-Id: I029b5acf92ddb2239c4f50d2e179bdb63d09aafd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39801
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Alan Baker <alanbaker@google.com>
2021-02-01 16:03:03 +00:00
Alan Baker e809fb3ae5 Refactor unnecessary builtin checks
* Move unnecessary builtin checks out of type determination and into
  validation
  * Type determination now uses a bare minimum of information for most
    builtins
  * Validation now does majority of checking of builtins
* Added const qualifier to type accessors

Change-Id: Id11b739770af904a9b7afe0b1c2de50e1428a165
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39540
Commit-Queue: Alan Baker <alanbaker@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-01 15:33:13 +00:00
James Price a6ced4d0b4 [wgsl-reader] Add support for constant_id decoration
Bug: tint:155
Change-Id: I207fd87d0708c66ea0fe7de81b156db98eea8e60
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39560
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-01 14:59:13 +00:00
Ben Clayton 3d20d49211 src/types/bool_type.h: Undefine Bool if defined
X11's use of #defines strike again.

Fixes tint -> dawn autoroller

Change-Id: Iccac4f2ac3a548b490dafc54e024a858419080e6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39760
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-02-01 14:55:13 +00:00
David Neto 45f1832f11 spirv-reader: support OpVectorInsertDynamic
Change-Id: I30b9ad14faf921c3ec0bf47729480d4f7d37f561
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39161
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-29 21:32:11 +00:00
Ben Clayton 3335254c1c Migrate to using semantic::Expression
Remove the mutable `result_type` from the ast::Expression.
Replace this with the use of semantic::Expression.

Bug: tint:390
Change-Id: I1f0eaf0dce8fde46fefe50bf2c5fe5b2e4d2d2df
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39007
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-29 16:43:41 +00:00
Ben Clayton 5c186625b6 Add semantic::Expression, implement semantic::Info
semantic::Expression will hold the resolved expression type.
Migration to this will happen in the next change.

Bug: tint:390
Change-Id: I637eb6777d603ab0828c0e5e7126bd2ac1b0c4bc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39006
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-29 15:46:42 +00:00
Ben Clayton 7fdfff1de4 Add semantic::Node
Rename Program(Builder)::Nodes to ASTNodes, and add SemNodes.

Bug: tint:390
Change-Id: If501ea5f5d1cbb4bc2673b303aa8ebce7195e2c3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39005
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-29 15:17:30 +00:00
Ben Clayton e43c830b14 Add ProgramBuilder::Wrap()
Follows the basic shallow-clone pattern of type::Manager::Wrap(),
which this new method uses.

Use ProgramBuilder::Wrap() in the writers, where we were previously
using type::Manager::Wrap(). This simplifies some of the logic
(especially around AppendVector()).

This is now required as semantic information is generated inside the
writers for newly constructed AST nodes, and we need to register
this semantic info so it can be fetched later.

Change-Id: Ia362204a1f13054e50545baeb7d269f210a36826
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39004
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-29 11:59:32 +00:00
Ben Clayton 708dc2d040 Simplify calls to ast::Node::[to_]str()
Add helpers on Program and ProgramBuilder that significantly simplify
usage.
Also demangle - this also reduces a bunch of copy-pasta code.

Change-Id: I6215c346e7f6e49c20aced058a6150603253ed93
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39342
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-29 11:22:40 +00:00
Ben Clayton dd1b6fca9f Introduce semantic::Info
Will hold the mutable fields that currently reside in the otherwise immutable-AST.

Change the AST string methods to accept a `const semantic::Info&`. This is required as some nodes include type-resolved information in their output strings.

Bug: tint:390
Change-Id: Iba494a9c5645ce2096da0a8cfe63a4309a9d9c3c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39003
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-29 10:55:40 +00:00
David Neto 63049a420e spirv-reader: support OpVectorExtractDynamic
Use array-access syntax

Fixed: tint:450
Change-Id: Ida90180015cace8cfa94c0116c3e37c3c6d59212
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39222
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: David Neto <dneto@google.com>
2021-01-28 22:21:29 +00:00
David Neto ad27ee8c10 spirv-reader: Handle OpInBoundsAccessChain for storage class translation
Fixed: tint:457
Change-Id: I25410a1e59cbc78f76da65c28312a8ddd6b3319b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39220
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-28 21:22:39 +00:00
dan sinclair 875e966a66 Revert "Remove support for the set decoration."
This reverts commit 67beed1b94.

Reason for revert: CTS Roll happened just before this fix landed in CTS.

Original change's description:
> Remove support for the set decoration.
>
> This CL removes the set decoration support, it has been replaced by the
> group decoration.
>
> Change-Id: Ib9ca94872d39e5da9dbe18bba3cae6d64320e55d
> Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38824
> Auto-Submit: dan sinclair <dsinclair@chromium.org>
> Reviewed-by: Ben Clayton <bclayton@google.com>
> Commit-Queue: dan sinclair <dsinclair@chromium.org>

TBR=dneto@google.com,dsinclair@chromium.org,bclayton@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: I89dec6d2663e18ac8e15ae3c7a5ffb443591f6b9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39360
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-01-28 20:27:39 +00:00
dan sinclair 5ad2d0087b Revert "Remove support for the old _idx builtins."
This reverts commit c2972cfa60.

Reason for revert: Looks like CTS in Chrome doesn't have this change yet.

Original change's description:
> Remove support for the old _idx builtins.
>
> This CL removes the old _idx variants of builtins in favour of the
> _index versions.
>
> Change-Id: I1678b5fae63c9d4f7f63feabf7410a58505d397a
> Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38825
> Auto-Submit: dan sinclair <dsinclair@chromium.org>
> Reviewed-by: Ben Clayton <bclayton@google.com>
> Commit-Queue: dan sinclair <dsinclair@chromium.org>

TBR=dneto@google.com,dsinclair@chromium.org,bclayton@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: I29b6016f2e9e0b6245e22e2e18ff2f8c9a17dc74
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39280
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-01-28 16:49:11 +00:00
dan sinclair 30c1f25a7a Reland "Remove support for # comments."
This reverts commit 21b52b60b6.

Reason for revert: Dawn fixes landed, trying again.

Original change's description:
> Revert "Remove support for # comments."
>
> This reverts commit 6e570a9360.
>
> Reason for revert: Missed Dawn tests
>
> Original change's description:
> > Remove support for # comments.
> >
> > This CL removes support for parsing # style comments. Only the //
> > comments are accepted now.
> >
> > Change-Id: I062c2a86149ecf828723c74f7168243678ee5870
> > Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38823
> > Commit-Queue: dan sinclair <dsinclair@chromium.org>
> > Commit-Queue: Ben Clayton <bclayton@google.com>
> > Auto-Submit: dan sinclair <dsinclair@chromium.org>
> > Reviewed-by: Ben Clayton <bclayton@google.com>
>
> TBR=dneto@google.com,dsinclair@chromium.org,bclayton@google.com
>
> Change-Id: Iaf19ab9def92ad10c27d70480d259e25f3da719d
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39061
> Reviewed-by: dan sinclair <dsinclair@chromium.org>
> Commit-Queue: dan sinclair <dsinclair@chromium.org>

TBR=dneto@google.com,dsinclair@chromium.org,bclayton@google.com

# Not skipping CQ checks because this is a reland.

Change-Id: I91a478237bc9853108e1ce97b9fdc2ce01841998
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39221
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-01-27 22:30:55 +00:00
James Price 186af2f6ad [wgsl-reader] Fix struct constructor expressions
The parser was matching struct constructors as function calls.

Bug: tint:458
Change-Id: Ia98489e3a6d62eea2e423c6344b6e35b8f9649f0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39101
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-27 21:49:06 +00:00
Ben Clayton dd69ac3505 Automatically run the TypeDeterminer when building programs
Removes the need for Dawn to use the TypeDeterminer directly.
TypeDeterminer errors will be added to the Program diagnostics list.

Change-Id: I4cfb405e7e6b0e94727296eea872a3ddc4412b66
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38921
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-27 19:23:55 +00:00
Ben Clayton 844217fa34 Add Diagnostics to Program, reader::[wgsl,spirv]::Parse()
By putting diagnostics into the program, we can hold all the diagnostic messages for parsing and type determination in one place.
This also means that we can simplify the public WGSL and SPIR-V Parser interfaces to a single function.

Change-Id: Ib6ab5fa180addd45c4aaf0c6b192d47182ffb50a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38920
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-27 18:49:05 +00:00
dan sinclair 21b52b60b6 Revert "Remove support for # comments."
This reverts commit 6e570a9360.

Reason for revert: Missed Dawn tests

Original change's description:
> Remove support for # comments.
>
> This CL removes support for parsing # style comments. Only the //
> comments are accepted now.
>
> Change-Id: I062c2a86149ecf828723c74f7168243678ee5870
> Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38823
> Commit-Queue: dan sinclair <dsinclair@chromium.org>
> Commit-Queue: Ben Clayton <bclayton@google.com>
> Auto-Submit: dan sinclair <dsinclair@chromium.org>
> Reviewed-by: Ben Clayton <bclayton@google.com>

TBR=dneto@google.com,dsinclair@chromium.org,bclayton@google.com

Change-Id: Iaf19ab9def92ad10c27d70480d259e25f3da719d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39061
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-01-27 18:32:16 +00:00
dan sinclair 3a5b15d4e5 Record when an identifier expression is a swizzle.
This CL updates the type determiner to record if an identifier
expression is a swizzle and then uses that in the MSL and HLSL generator
to output the swizzle name directly.

Change-Id: I77c0e1e80dce9e2f09cbbd37476a146b06555ee2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38960
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-01-27 17:39:35 +00:00
David Neto 36194197ac spirv-reader: textureLoad explicit Lod sometimes
WGSL requires an explicit level-of-detail for textureLoad
for sampled textures and depth textures

Fixed: tint:462
Change-Id: I43758b002da91af9901d12664861ace971833020
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38828
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: David Neto <dneto@google.com>
2021-01-26 21:58:34 +00:00
dan sinclair 34ac1afd99 Remove old texture type support.
This CL removes all of the old texture type names in favour of the new
variants.

Change-Id: Icb3c9ed8e39c8d7320fd6a6706b8029fcb3e5947
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38826
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-01-26 21:44:54 +00:00
dan sinclair c2972cfa60 Remove support for the old _idx builtins.
This CL removes the old _idx variants of builtins in favour of the
_index versions.

Change-Id: I1678b5fae63c9d4f7f63feabf7410a58505d397a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38825
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-01-26 20:21:31 +00:00
dan sinclair 67beed1b94 Remove support for the set decoration.
This CL removes the set decoration support, it has been replaced by the
group decoration.

Change-Id: Ib9ca94872d39e5da9dbe18bba3cae6d64320e55d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38824
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-01-26 20:18:51 +00:00
dan sinclair 6e570a9360 Remove support for # comments.
This CL removes support for parsing # style comments. Only the //
comments are accepted now.

Change-Id: I062c2a86149ecf828723c74f7168243678ee5870
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38823
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-01-26 19:28:51 +00:00
Ben Clayton 1461cd96d6 Add diag::List::add_error() helper
Refactors a common pattern in the tint codebase.

Change-Id: Ia8a70d952fd8c204facd0120f24e43ccc9305622
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38840
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 18:52:11 +00:00
Ben Clayton a6b9a8eb2f Split Program into Program and ProgramBuilder
Program is now immutable*, and remains part of the public Tint
interface.

ProgramBuilder is the mutable builder for Programs, and is not part of
the public Tint interface. ast::Builder has been folded into
ProgramBuilder.

Immutable Programs can be cloned into a mutable ProgramBuilder with
Program::CloneAsBuilder().

Mutable ProgramBuilders can be moved into immutable Programs.

* - mostly immutable. It still has a move constructor and move
  assignment operator - required for practical usage - and the
  semantic information on AST nodes is still mutable.

Bug: tint:390
Change-Id: Ia856c50b1880c2f95c91467a9eef5024cbc380c6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38240
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton 1f7e18bbc0 ast::Builder: Add shortcuts to the Program methods
This builder will be merged into ProgramBuilder, where these will become methods.
To breakup this change, perform the refactoring as a separate change.

Bug: tint:390
Change-Id: I2c9151cd9f198e99d88eaf296dd994293df6c425
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38720
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton 8d391f7a10 ast::TypesBuilder: Change const fields to getters
This is required in order to support move operators for TypesBuilder.

Bug: tint:390
Change-Id: I9667bda5f5be267df092f5cd94dc40db053ae6e2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38555
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton deb02019d5 transform: Fix multiple mutability issues with VertexPulling
ConvertVertexInputVariablesToPrivate() mutated the source program global variables, and copied them into the destination program.

Symbols and types were assigned across the program boundary without cloning.

Bug: tint:390
Change-Id: I03c8924e6ba94b745e74de0ab57f8a489e85cc50
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38554
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton 5d9b1c38c2 Add CloneContext::Replace()
Instructs the clone context to replace a single object instance with a given replacement.
Will be used to fix brokenness in transforms.

Bug: tint:390
Change-Id: I17bf1cdf7549f697281ca7c286bdb5771e5a6f1a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38553
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton 3bd1f81889 hlsl & spriv writers: Remove const_cast hacks
Use the new type::Manager::Wrap() function to build a new temporary type manager that wraps the program's type manager.

This allows the writer to construct temporary new types (if they weren't already in the program) without actually mutating the program.

Bug: tint:390
Change-Id: Icadab42d66e0a88c494bd21b3a4f7bae2ed13832
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38552
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton a458c57662 type::Manager: Add Wrap()
Wrap returns a new Manager created with the types of `inner`.

The Manager returned by Wrap is intended to temporarily extend the types of an existing immutable Manager.

Bug: tint:390
Change-Id: I46bebf8b83cf7987ddcf2513c54f9f885a028c60
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38551
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton 44bec80e5f Demangler: Change signature of primary Demangle() function
Have this take a SymbolTable instead of a Program.
Program will be split into Program (immutable) and ProgramBuilder (mutable). We'll need Demangler to support both.

Bug: tint:390
Change-Id: I6447dd9674919d4867ed8ba126880cdfd9bf7128
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38550
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton d7137d7233 Program: Remove deprecated symbol methods
Fixup all usages

Bug: tint:390
Change-Id: If861b044eae006af2fd86d348de6ba62f448bc6a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38549
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton cf757e3a89 Program: Remove deprecated types and nodes methods
Fixup all usages

Bug: tint:390
Change-Id: I14c9a0420be7da2d26bf21bce96ca0ded0978711
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38548
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton 83158f214f Program: Remove deprecated function methods
Fixup all usages

Bug: tint:390
Change-Id: I949235908e50702d6c8b2e7e2299594879653e01
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38547
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton 1b3d6e460c Program: Remove deprecated constructed-type methods
Fixup all usages

Bug: tint:390
Change-Id: I739a7625cd385cb889369ab7c766462fbcd7cf12
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38546
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton a86f4effe4 Program: Remove deprecated global variable methods
Fixup all usages

Bug: tint:390
Change-Id: I2e239dfc77872acb9f0b2ee5494350605dd780a1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38545
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton a07396a13c Reintroduce ast::Module as the root AST structure
Holds the global variables, constructed types and functions.

Deprecate the functions on program that forward on to the module.
These will be fixed up in another change.

Bug: tint:390
Change-Id: I47b6921a7d84be18113dec830c8435d4e0d4182d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38544
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton 9f7a414505 Namer: Take a SymbolTable instead of a Program
Program is going to undergo some heavy refactoring.
Reduce unnecessary dependencies to what Namer actually wants.

Change-Id: Ie411da113a2728321c52ba0a72ae7c2139469886
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38543
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton d542a2875f SymbolTable: Rename GetSymbol() to Get()
The Symbol suffix is unnecessary, given the class name

Change-Id: Ibf222555a8bf5c3e4b6cf27e8006573570b1bd48
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38542
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton c40f627bea Migrate from using ast::Module to Program
Enforce all places where Dawn passes in or returns a ast::Module, now takes a `const Program* ` or returns a `Program`.

As the end goal of all this is to have immutable Programs, all Program inputs take a pointer instead of moving the actual object.

As consumers of a Program are now all const, we have to const_cast to work around all the places we've been incorrectly mutating a ast::Module.
These const_casts are temporary, and will be fixed in the next set of changes.

Depends on https://dawn-review.googlesource.com/c/dawn/+/38522

Bug: tint:390
Change-Id: Ie05b112b16134937d1b601e9b713ea4ec4e1c677
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38541
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton be610ba987 Add TypeDeterminer::Run()
This is a temporary function to help with Dawn migration.
It will be removed after the migration to using Program and ProgramBuilder is complete.

Bug: tint:390
Change-Id: I98c73a6b8102eebf48a889315a376195f9379f63
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38556
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-25 22:09:18 +00:00
Ryan Harrison b16a5d6e9b Exclude builtins from reflected stage variables
BUG=tint:456

Change-Id: I941b25dd5bf5e758d5fdecf379137d92d5db8556
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38460
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
2021-01-25 21:15:08 +00:00
Ben Clayton d59cedb5a5 Add tint::Program as a wrapper of tint::ast::Module.
`tint::Program` will become the new public API object for a parsed shader program.
For now, have Program be a simple wrapper around ast::Module so we can migrate Dawn's use of the public tint API.

Add new Program variants of public APIs for places that returned or took a Module.

Remove Reset() methods from Generators, they aren't used, and make the migration harder.

Change-Id: Ic5bee46ceb109ea591ba7fec33685220b244a1ae
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38540
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-25 18:14:08 +00:00
David Neto aee7acaaea spirv-reader: refactor getting image, sampler
Change-Id: I6620781f620067e4df8f7e39f2bb2a80b32f9ecf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38180
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: David Neto <dneto@google.com>
2021-01-25 15:16:58 +00:00
Ben Clayton 5c243f824c Rename CloneContext::mod to CloneContext::dst
In the future, CloneContext will be operating on `Program`s so a field called `mod` is poorly named.
CloneContext has a `src` member, so rename to `dst` to keep symmetry.

Bug: tint:390
Change-Id: Ic724f8a18b46ef719790394cdc810f7eb3681234
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38364
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-01-22 13:41:06 +00:00
Ben Clayton 6761160dc1 ast: Move Module function methods to FunctionList
Module will be split into Module (immutable) and ModuleBuilder (mutable).
By moving these methods to the FunctionList, we can deduplicate a bunch of common logic.

Bug: tint:390
Change-Id: I3fd85200aae4e8dc3d5afce8c9aaa6512809a3a0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38363
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-21 18:45:50 +00:00
Ben Clayton 281b602f59 type::Manager: Simplify interface and use BlockAllocator
Internally use BlockAllocator to allocate the types.
When we optimize the allocation patterns of BlockAllocator, this will now benefit both AST nodes and types.

Remove Reset(). It was not used.

Remove type::Manager::Get(std::unique_ptr<type::Type>) - this was used (via Module::unique_type) in one place, which has easily been migrated to using the standard Module::create<>.

Replace all remaining uses of std::unique_ptr<> of types in tests with the standard create<> so we can guarantee uniqueness of the types.

Change-Id: Ib0e1fe94e492b31816450df5de0c839a0aefcb9e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38362
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-21 16:35:10 +00:00
Ben Clayton 1e29f4beb0 Move CloneContext and Traits from src/ast to src/
CloneContext clones the AST, types, symbols and in the future semantic info.
3/4 of these are non-ast, so promote these up to the root.

Bug: tint:390
Change-Id: I49619796e6f81f9ab64f79413a12c87312cb1901
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38361
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-21 16:20:40 +00:00
Ben Clayton f12054ea2a test: Add Build() method for tests using ast::Builder
This separates out the usage of the built module from the construction of the module.

Previously, we'd happily interleave generator testing with module construction statements. Once the AST / Program is made immutable, this will no longer be possible.

Bug: tint:390
Change-Id: Ib4538228e93ca816f5bb796d024f021116609213
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38360
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-21 16:15:00 +00:00
Ben Clayton 207b5e2de1 Move tint::ast::type to tint::type
Despite `tint::ast::type::Type` being in the AST namespace, these classes are clearly not AST nodes:
* They don't derive from ast::Node
* They're deduplicated by the type manager
* None of the types have an Source - they have no lexical declaration point
* The fact we have `ast::Struct` and `ast::type::Struct` clearly demonstrates what is an AST node, and what is a type.
* We have code scattered in the codebase (TypeDeterminer, writers, etc) that create new types after parsing - so clearly not part of the original syntax tree.

Types in tint are closer to being semantic info, but due to the parse-time generation of types, and tight dependency of ast::Nodes to types, I'd be reluctant to class these as semantic info. Instead, put these into a separate root level `tint::type` namespace and `src/tint` directory.

The fact that types exist in the ast::Module has already caused bugs (https://dawn-review.googlesource.com/c/tint/+/37261). This is a first step in separating out types from the ast::Module.

Bug: tint:390
Change-Id: I8349bbbd1b19597b8e6d51d5cda0890de46ecaec
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38002
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-21 15:42:10 +00:00
Ben Clayton 587f387fd9 Add tint::BlockAllocator<T>
A container and allocator of objects of (or deriving from) the template type `T`.

Objects are allocated by calling Create(), and are owned by the BlockAllocator.
When the BlockAllocator is destructed, all constructed objects are automatically destructed and freed.

Objects held by the BlockAllocator can be iterated over using a View or ConstView.

Use this to hold the ast::Nodes in the ast::Module

This is called BlockAllocator as it can be optimized to hold objects in contiguous memory blocks, which will improve cache coherencey. Currently BlockAllocator is a straight port of the vector-of-unique-ptr, taken from ast::Module.

Change-Id: I4bf4d298aec3c70d2ddf833e2f168416cbb024c0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38001
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-21 15:30:10 +00:00
Vasyl Teliman e1abcb4564 wgsl-reader: support multiple case selectors
Bug: tint:454
Change-Id: I5a046e19f66b5807723e96593ea6ba107ef69e6c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38261
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-01-20 21:53:13 +00:00
Ryan Harrison afb8cfb254 Add location data to input/output variable reflection
Adds this data to the Inspector API, as well as needed internal
utility methods.
Updates and expands tests to cover changes.

BUG=tint:452

Change-Id: I598f8149cb6abd13abf606416ae61e615b99e1e1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38200
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2021-01-20 18:58:17 +00:00
David Neto ed14524b1e Refactor getting number of coordinate dimensions
Change-Id: Ibafffb29bc33c722b8a4da25ed7a9c1986d13a24
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38162
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: David Neto <dneto@google.com>
2021-01-19 03:29:35 +00:00
David Neto 71012dcc2f validator: Support assignment through pointer
Also enable a test to check assigning to scalar literal.

Fixed: tint:419
Change-Id: Ic565af22c4ef6b60c41faaf9fabe3bd55fe48d2d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37961
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
2021-01-18 22:17:25 +00:00
dan sinclair 336bb0b4dd Update storage_buffer storage class.
This Cl updates the `storage_buffer` storage class to just be `storage`.

Change-Id: Ibfaecbb0862bd60d39665eb937c0b6300899e177
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38161
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-01-18 21:06:34 +00:00
David Neto 20f4d1daca validator: add IsStorable helper function
Bug: tint:419
Change-Id: Ib15aa819a032d8412fb3bc162b29a02c331f56b8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37960
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
2021-01-18 19:45:24 +00:00
dan sinclair d7335fa974 Update builtin idx names.
This CL upldates the vertex_idx, instance_idx and global_invocation_idx
builtins to use the full _index names. The original values still exist
until we can update downstream users.

Change-Id: Icd02601eeb15704d5463158541c07816d98e5383
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37940
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-01-18 15:51:13 +00:00
dan sinclair c068cfc139 Support the group decoration.
This CL changes the set decoration to a group decoration. We still parse
`set` until downstream users can be updated.

Bug: tint:338
Change-Id: I610d1ed769b3a26c117ad6d875f8a99a3d5b7754
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37920
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-01-15 12:22:16 +00:00
David Neto 0e17caa361 spirv-reader: expand OuterProduct to primitive ops
Bug: tint:3
Change-Id: Id6de3554d945bc743a484e80b494690c26552079
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37660
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
2021-01-14 19:01:27 +00:00
Ben Clayton 0a68b365eb Implement textureNumSamples()
SPIR-V reader TODO

Bug: tint:140
Bug: tint:437
Change-Id: Id95855660680b12e3ff49b6340ef966dfa49f8e4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37848
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-14 18:11:17 +00:00
Ben Clayton 6e5b5ecc52 Remove underscores from ValidTextureOverload enum names
For consistency's sake.

Change-Id: I08d0b7a5377fed0075feb7c3a0332cda43fb73bd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37847
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-14 18:09:07 +00:00
Ben Clayton d97132028a Implement textureNumLevels()
SPIR-V reader TODO

Bug: tint:140
Bug: tint:437
Change-Id: Icd41b2ef84e62b304e446589eb2e37c38279af35
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37846
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-14 18:06:57 +00:00
Ben Clayton c21f1f92a2 Implement textureNumLayers()
SPIR-V reader TODO

Bug: tint:140
Bug: tint:437
Change-Id: Id397f5f07a2f18f365dc9c2d588e619cea8f89dc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37844
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-14 16:50:07 +00:00
Ben Clayton 8121fe3367 Add missing doxygen comments
Change-Id: Ia4b1a5bc1d046633a7f1f91e23659d237d35e640
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37842
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-14 15:52:52 +00:00
Ben Clayton 1f14595723 reader/wgsl: Remove duplicate lexer logic
See:
https://dawn-review.googlesource.com/c/tint/+/37780/1/src/reader/wgsl/lexer.cc#750

Bug: tint:286
Change-Id: I6d39fdfefad619beb65ad1d496b27925da3db8ed
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37840
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-14 14:15:02 +00:00
dan sinclair 904c5b9621 Add texture_storage_yy parsing.
This CL adds support for the decorated texture storage tokens. The old
_ro_ and _wo_ tokens still exist until downstream users are updated.

Bug: tint:286
Change-Id: I4ddc50be3b22bd3feeab41b3b4fe4ded63e6e59a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37780
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-01-14 08:34:46 +00:00
Ben Clayton 395ec2c4ae writer/spirv: Add TextureStorageWithDifferentAccess test
Checks that multiple texture_storage types with different access modifiers only produces a single OpTypeImage.

This was broken before Ia944ed8

Bug: tint:286
Change-Id: Idbcd0189d46b78b31d5ec38f355d2369cb86327a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37707
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-13 19:28:12 +00:00
dan sinclair d50a3041fa Remove access control from StorageTexture.
This CL removes the access control value from the storage textures and,
instead, wraps in an type::AccessControl. This matches the current spec
where the access is an annotation on the type as opposed to part of the
type.

Bug: tint:286
Change-Id: Ia944ed8557fbf490d78db2a1b49c31d0aba08728
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37740
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-01-13 18:48:11 +00:00
Ben Clayton 57166264e0 Fix ValidTextureOverload enum names for kSampleCompare
For some stupid reason, these were all incorrectly prefixed with kSampleGrad, despite the test data all being correct.

Bug: tint:140
Change-Id: If556194d06c7596419a9e7b83165361bb19c7f44
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37705
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-13 16:36:51 +00:00
Ben Clayton 7c5980991a writer/[hlsl,msl]: Emit a implicit return for entrypoints
WGSL no longer requires a return statement at the end of each function, and the generated entrypoint functions are not valid without a return.

Fixed: tint:446
Change-Id: I702e4217f4ac41013e30927d532895c6835f6ca9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37704
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-13 16:34:51 +00:00
dan sinclair 1c200cffd0 Remove outerProduct.
The community decided to remove outerProduct from WGSL. This Cl removes
the pieces from Tint.

Change-Id: Ib1735867e4a7ca852a72549fc8c9bd86e8de22b0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37600
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-01-12 22:00:58 +00:00
Ben Clayton 8f4784006e writer/spirv: Validate SPIRV for all texture intrinsic functions
Finds brokenness.

Change-Id: I1280d456dfe0e4296100e40eef4fb0a17d3d047a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37450
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-01-12 21:52:50 +00:00
Ben Clayton 72114bd61b writer/spriv: Cast level parameter to f32 for depth texture sampling
SPIR-V expects a f32, while WGSL has an i32 type for these.

Bug: tint:143
Change-Id: I8e724f24f12154f57cddfd01dfd727e440ca8450
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37449
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-01-12 21:42:28 +00:00
Ben Clayton 9a9aa58ddd writer/spriv: Extract first element from depth texture reads
These operations return a vec4, when WGSL expects a single float scalar.

Fixed: tint:438
Change-Id: I4e16190155f80481897ad7db8b96ed3e58a7bfe3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37448
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-01-12 21:39:19 +00:00
Ben Clayton ecad052dac writer/spirv: Use ConstOffset instead of Offsets
Offset requires the ImageGatherExtended capability, where as ConstOffset does not. WGSL enforces the offset range required by SPIRV.

Bug: tint:143
Change-Id: Ia098010ecdb8a4a01999b4e9a6faabf3f4d1251f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37447
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-01-12 21:37:28 +00:00
Ben Clayton 2dbd556a18 writers: Duplicate cube height for textureDimensions()
All shader backend languages describe cubes as width / height, but give no way to query depth. WGSL however returns a vec3<i32> for cube textures when calling textureDimensions().
As cube textures must be square (width == height == depth), just replicate the height for the depth.

See https://github.com/gpuweb/gpuweb/issues/1345

Bug: tint:140
Bug: tint:437
Change-Id: I76ef18ee4bd8b53d5f9d9d3f1c10c3f7cb23e137
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37446
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-01-12 21:20:48 +00:00
Ben Clayton ecc2cdfb61 writer/spirv: Use OpImageQuerySizeLod for non-MS images
Fixes validation error:
`Image must have either 'MS'=1 or 'Sampled'=0 or 'Sampled'=2`

Bug: tint:140
Bug: tint:437
Change-Id: If6d7e86aeb7767b212debf94bcae9ee2ce8ad209
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37445
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-12 21:18:58 +00:00
Ben Clayton d1aef67011 writer/spirv: Fix storage class and add decorations for texture test cases
These are required for correct SPIR-V emission.

Bug: tint:444
Change-Id: I6d25dcc6e06af7f9ca9f250758b7901171923773
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37444
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-01-12 20:14:18 +00:00
Ben Clayton 50c5fa1100 writer/spirv: Refactor IntrinsicTextureTest.OutsideFunction_IsError
Use the same builder helpers as IntrinsicTextureTest.Call, significantly reducing boilerplate

Change-Id: Idb37a1704b9ed76c3872d14003ff279b2955d18b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37443
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-01-12 20:09:42 +00:00