Commit Graph

37 Commits

Author SHA1 Message Date
Ben Clayton a34fa0ecb7 Remove sem::Alias
With the parsers now using ast::Types, nothing should be producing these any more.

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

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

Change-Id: I523f97054de2c553095056c0bafc17c48064cf53
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49966
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-05-10 17:25:21 +00:00
Ben Clayton 4cd5eea87e sem: Fold together sem::Array and sem::ArrayType
There's now no need to have both.
Removes a whole bunch of Sem().Get() smell, and simplifies the resolver.

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

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

Bug: tint:724
Fixed: tint:761
Change-Id: I756a32680ac52441fd6eebf6fc53dd507ef5e538
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49961
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-05-07 14:49:34 +00:00
Brandon Jones b432f232b5 Add Transform For External Textures
Adds a transform to reclassify single-plane texture_external types into 2d sampled textures. Adds a unit test for the transform.

Bug: dawn:728
Change-Id: Id1f88565aeacbfea47b140181c78ad122edbdae8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49641
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-05-05 16:38:12 +00:00
Ben Clayton 1737485a05 ast: Add ast::NamedType
Have ast::Struct and ast::Alias derive from it.
NamedType currently derives from ast::Type, but this might change in the future.

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

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

Change-Id: I1ccb303d6c3aa15e622c193d33b753e22bf39a95
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49160
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
2021-04-28 15:33:03 +00:00
Antonio Maiorano 31204afeb0 Add ast::ExternalTexture
Also create it in wgsl parser. With this, we now create all the AST type
nodes in the wgsl parser.

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

Also:

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

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

* Constified more type pointers in type nodes

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

Bug: tint:724
Change-Id: Ie0875aa4d4a5e830e3466ac40c63cd185f357200
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48881
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-26 14:19:55 +00:00
Ben Clayton 3b3cf5f2d3 ProgramBuilder: Fixup last few uses of sem::Type*
With typ::Type.

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

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

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

Bug: None
Change-Id: I544a73d73366be9dd2ac8e56c7593fd9f2b86cf8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48600
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-04-21 09:18:52 +00:00
Ben Clayton 8a8d26bbd9 ast: Add type nodes
Copy all of the type classes from src/type into ast.

Required the merging of:
* type::Struct into the existing ast::Struct - ast::Struct now has a name.
* type::AccessControl into the existing ast::AccessControl enumerator - The old ast::AccessControl enumerator is now ast::AccessControl::Access

Bug: tint:724
Change-Id: Ibb950036ed551ec769c6d3d2c8fb411809cf6931
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48383
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-20 15:04:21 +00:00
Antonio Maiorano aea9c68de9 Move type/* files to sem/ directory
Bug: tint:724
Change-Id: I45d83d32dbce1fbee265810615c18219ef879b20
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48363
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-04-19 22:54:43 +00:00
Brandon Jones e94237dcdd Add ExternalTexture Type
Adds ExternalTexture type and basic unit tests in accordance with the
currently proposed WGSL specification.

Bug: dawn:728
Change-Id: I7a16a351ff098ba6df5b1e6305c390e3ca1c9d46
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47180
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-19 20:35:13 +00:00
Antonio Maiorano 3244bcdb67 Rename sem_*.cc to *.cc
This makes the .cc files match the header file name, which allows for
the text editor "header flip" feature to actually work. The reason these
files were named this way was because GN doesn't allow name conflicts in
the same source set, despite the files being in different directories.
This change splits the files into different source sets. To do so, we
use GN templates, which also reduces duplication in each target
definition.

Bug: tint:724
Change-Id: I9a7ed3912e4b85b2b38d360805203f3488b86c4c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48160
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-19 15:20:03 +00:00
Antonio Maiorano 5cd71b8c0a Rename semantic to sem
* Rename namespace semantic to sem
* Rename directory src/semantic/ to src/sem/

Bug: tint:724
Change-Id: I76383b821fbca7f1037a803c497b595a706dcb06
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48120
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-16 19:07:51 +00:00
Ben Clayton e6995de232 Add ProgramID feed it into all ast::Nodes
This will be used to detect accidental leaks of program objects between programs.

Bug: tint:709
Change-Id: I20f784a2c673d19a04a880b3ec91dfe2eb743bdb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47622
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-13 23:27:27 +00:00
Ben Clayton 6a802cd3e4 writer/hlsl: Move the renamer into the sanitizer transform
The renamer logic in the HLSL writer was inconsistent, and actually
broke some valid shaders.

Change-Id: I8fbddc7e657f5509b18435fdf352a39d83c1b89c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47224
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-09 17:28:18 +00:00
Antonio Maiorano 71512e30ca Remove validator.h
With this change, the Validator is fully removed from Tint, including
from it's public API.

Fix: tint:642
Change-Id: Id4867cc3866bb2ea09eff499537d58b938d18f43
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47125
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-09 13:26:38 +00:00
Ben Clayton 015b9aa93a Add transform::CalculateArrayLength
Used to used to replace calls to arrayLength() with a value calculated from the size of the storage buffer.

Bug: tint:185
Change-Id: If7ddc8dad2ed3d20c1d76b5f48bfd2c7634f96e2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46877
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-09 10:28:48 +00:00
Ben Clayton 6d30523a11 Add transform::DecomposeStorageAccess
Used to breakdown storage buffer reads and writes into primitive loads and stores.

Bug: tint:683
Change-Id: I92983deef7485bc1a6a5d9921ec82f8e19b09744
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46876
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
2021-04-09 09:10:38 +00:00
Antonio Maiorano 8f42be3f60 Delete Validator except public API
Now that all validation has been moved to the Resolver, we can delete
the Validator. This change removes everything except validator.h with
the public no-op API. We can remove this once we remove dependencies on
this public API in Dawn.

Bug: tint:642
Change-Id: I644cd900615509c9cdd57c375c6217a50126e36c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47023
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-07 16:32:01 +00:00
Ben Clayton 1b8d9f227b CloneContext: Don't create named symbols from unnamed
Registering a new Symbol with the NameFor() of the source symbol creates
a new *named* symbol. When mixing these with unnamed symbols we can have
collisions.

Update CloneContext::Clone(Symbol) to properly clone unnamed symbols.

Update (most) the transforms to ctx.Clone() the symbols instead of
registering the names directly.

Fix up the tests where the symbol IDs have changed.

Note: We can still have symbol collisions if a program is authored with
identifiers like 'tint_symbol_3'. This will be fixed up in a later
change.

Change-Id: I0ce559644da3d60e1060f2eef185fa55ae284521
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46866
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-07 11:16:01 +00:00
Ben Clayton b502fdf82b Add ast::InternalDecoration
An tint-internal decoration used to add metadata between a sanitizer transform and a backend.

Will be used for declaring backend-specific intrinsic calls.

Change-Id: Ia05ba7dada0148de2d490605ba4d15c593075356
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46868
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-07 08:09:21 +00:00
James Price 3f985b984d Add a transform for canonicalizing entry point interfaces
After the transform, an entry point's parameters will be aggregated
into a single struct, and its return type will either be a struct or
void. All structs in the module that have entry point IO decorations
will have exactly one pipeline stage usage.

This will be used to sanitize entry points for the MSL and HLSL
generators.

Change-Id: I7d2fcfba961d2e20326086964207747d573b6e05
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46500
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-31 17:44:27 +00:00
Ben Clayton e0c1221b37 Add transform::BindingRemapper
A transform to replace binding points and access control flags.

Required by Dawn for the HLSL and MSL backends

Fixed: tint:104
Fixed: tint:621
Fixed: tint:671
Change-Id: Ic6ccc4a8a7724697cc4af0fad25394a1973eeb22
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46262
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-03-29 21:25:45 +00:00
Ben Clayton 01ac3dd917 Add utils/hash.h
Contains hash combining functions borrowed and tweaked from Dawn

Change-Id: I0bc9478bcdba0b923d0b01825c275290ffa29976
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46268
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-29 15:13:55 +00:00
Corentin Wallez f40330502d Remove the warning suppression for Skia
Skia changed to only add -Weverything for Skia files so this warning is
no longer needed.

Bug: dawn:706
Change-Id: I7ac111cfaf580ee0868fb318f953fe983ee17df2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45607
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
2021-03-23 16:32:59 +00:00
Ben Clayton 91da97d6c3 Remove ast::NullLiteral
This isn't in the WGSL spec, nor is it generated by readers.
This was only used inside the SPIR-V writer, but this remaining usage was removed in the parent change.

Change-Id: I1bbfde67dc760b761af010a7a144dccb52369148
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45343
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-03-22 16:06:35 +00:00
Ben Clayton eae161cd9f writer/spirv: Clean up constant generation
Requiring a temporary stack-allocated ast::Literal is an unpleasant requirement to generate a SPIR-V constant value.
GenerateU32Literal() was also creating an invalid AST - the type was U32, yet an an ast::SintLiteral was used.

Instead add Constant for holding a constant value, and use this as the map key.

This also removes the last remaining use of ast::NullLiteral, which will be removed in the next change.

Change-Id: Ia85732784075f153503dbef101ba95018eaa4bf5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45342
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-22 15:32:35 +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
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 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