Commit Graph

1904 Commits

Author SHA1 Message Date
James Price 0949bdf68f Add transform to strip entry points from a module
Remove the Generator::GenerateEntryPoint() APIs as they were mostly
unimplemented and not used by anything except the Tint sample app,
which now uses the new transform.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reason for revert: Breaks Dawn autoroll.

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


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

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

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

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

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

Module-scope variables are still supported for now.

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

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

Also:

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

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

* Constified more type pointers in type nodes

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Bug: None
Change-Id: I544a73d73366be9dd2ac8e56c7593fd9f2b86cf8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48600
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-04-21 09:18:52 +00:00
Ryan Harrison de8f1332f6 Validate Storage Textures and update existing tests
Adds rejecting unsupported image formats and texture dimensions.

BUG=tint:718

Change-Id: Ic6375d1e75524336462ea59b159cb4c8601f55fd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48500
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2021-04-20 20:47:51 +00:00
Ben Clayton 5b3d88b748 resolver: Fix for ICE: node not reached by the resolver
More of a workaround. Will be properly fixed by tint:724 .

Fixed: tint:728
Change-Id: If4887a781106010d12209365f36f27b493a9f173
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48422
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
2021-04-20 18:11:51 +00:00
Ryan Harrison 83116d298c Add validation rules for multisampled textures
Fixes:tint:717
Change-Id: I7f23086ec516c1196a9cdc741bbaa150754a533a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47940
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-20 16:09:21 +00:00
Ryan Harrison a32e4f66e5 Remove 2d Array Multisampled Textures
These do not exist in the WGSL spec, so removing them.

BUG=tint:717

Change-Id: I5eb2280fa2f0c923b67070a9ce4a7d2fc10d365d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48460
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-20 16:00:21 +00:00
Ben Clayton 913a2f4b2a sem::StructType remove symbol()
The name now lives on the ast::Struct. Use that instead.

Bug: tint:724
Change-Id: I4ee5e9b29973e468edd8df8c5448816b36f0fca6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48384
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-20 15:21:21 +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
David Neto ba6f260629 spirv-reader: Remove stale TODO
Change-Id: Icd9bf067160c7b79b3c5d8c3123ac94a8f29376c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48400
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
Auto-Submit: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Alan Baker <alanbaker@google.com>
2021-04-19 23:16:23 +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
Antonio Maiorano 3751fd2290 Move all classes from namespace `type` to namespace `sem`
Bug: tint:724
Change-Id: I4eeabab9b00b6b28f61645bd95d326fb48609bf0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48362
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-19 22:51:23 +00:00
Antonio Maiorano 3aa226138e Rename type::Struct to type::StructType
This is to avoid name conflicts once we move all classes from namespace
`type` to `sem`.

Bug: tint:724
Change-Id: I23cdec636cb5bcf0bbba03ee7bb7c44252ddade7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48361
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-19 21:31:43 +00:00
Antonio Maiorano cf4057be01 Rename type::Array to type::ArrayType
This is to avoid name conflicts once we move all classes from namespace
`type` to `sem`.

Bug: tint:724
Change-Id: Icc3d81ae62eb3b329ce28e78a23ea27f29c9263b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48360
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-19 21:13:12 +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
Ben Clayton cf28b5aafe resolver: Call ValidateVariable() for globals
This was only called for function-scope variable declarations.
In calling this, there were inevitable tests failing, which have now been fixed.
Added a test for the single runtime-array-length validation rule that this function was checking.

Fixed: tint:345
Change-Id: Ic453c38158c1290a5e1ef6de56af0c621d97982a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48381
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2021-04-19 20:23:12 +00:00
Ben Clayton 85bfea6edd resolver: Validate storage buffers have the [[block]] decoration
Fixed: tint:94
Change-Id: I1d3e512c030ec16031b8c8fcfbde0cd1db5d1ea4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48380
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-19 20:20:33 +00:00
David Neto 8b50537767 spriv-reader: handle loop-header with internal divergence
Handle the case where the OpBranchConditional in a loop header
branches to two distinct blocks inside the loop construct.
This is an if-selection in disguise.

Create an kIfSelection with the same set of blocks as the kLoop,
and with the continue target as the merge.

Fixed: tint:524
Change-Id: I5150d19a2b4388da409e2da6e68ffafdc5d21a9a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47560
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-04-19 19:54:32 +00:00
Antonio Maiorano ff7c293141 Fix clang-cl build
Fixes "error : use of identifier 'Node' found via unqualified lookup
into dependent bases of class templates is a Microsoft extension
[-Werror,-Wmicrosoft-template]"

Change-Id: Id54cdff24189b73c625f951ae369ec292be4c81b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48340
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-19 19:41:02 +00:00
Ben Clayton 6fcefe4c25 Resolver: Check that every AST node is reached once
AST nodes must not be shared. Diamonds in the AST will cause all sorts
of exciting, non trivial bugs.

All AST nodes must be reached by the Resolver. There are two common
reasons why they may not be:
(a) They were constructed and not attached to the AST. Several
    transforms scan the full list of constructed AST nodes to find nodes
    of a given type. Having detached nodes will likely cause bugs in
    these transforms. Detached nodes is also just a waste of memory.
(b) They are attached to the AST, but the resolver did not traverse
    them. Having the resolver skip over parts of the AST will fail to
    catch validation issues, and will leave semantic gaps, likely
    breaking downstream logic.

Bug: tint:469
Change-Id: I143b84fd830699f874d2936146f0e93197db610c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47778
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-19 19:16:12 +00:00
Ben Clayton b8ea59149e writer/msl: Fix all tests that had unreachable AST nodes
By making nodes reachable, the resolver has now caught a whole lot of additional problems, which have been fixed in this CL.

Some of these broken tests were attempting to use private and workgroup variables as function-scope declarations.
This is not legal, and these have been moved to module-scope variables.

Bug: tint:469
Change-Id: I1fc3a10fa0e39e1c290a13323277d6e9257778c4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48048
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-19 16:52:42 +00:00
Ben Clayton 917b14b626 CloneContext: Assert objects are owned by the program
Check that pre-clone objects are owned by the source program.
Check that post-clone object are owned by the target builder.

Fixed: tint:469
Change-Id: Idd0eeb8dfb386e295b66b4b6621cc13dc1a30786
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48260
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-19 16:50:23 +00:00
Ben Clayton b895ba1cea writer/hlsl: Fix all tests that had unreachable AST nodes
By making nodes reachable, the resolver has now caught a whole lot of additional problems, which have been fixed in this CL.

Some of these broken tests were attempting to use private and workgroup variables as function-scope declarations.
This is not legal, and these have been moved to module-scope variables.

Bug: tint:469
Change-Id: I8c91ace57701e9bec1f706eed0d9de7507c4b65a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48223
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-19 16:06:42 +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
Ben Clayton 08031f326c writer/hlsl: Implement generation of module-scope vars
Implement emission of module scope variables of the private and workgroup storage classes.
Fix tests that were incorrectly emitting these as function-scope variables.

Change-Id: I509a7388794f4a57b06a3859d10afa2611d84991
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48222
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-19 15:11:22 +00:00
Ben Clayton f4d3949c78 writer/wgsl: Fix all tests that had unreachable AST nodes
By making nodes reachable, the resolver has now caught a whole lot of additional problems, which have been fixed in this CL.

Some of these broken tests were attempting to use private and workgroup variables as function-scope declarations.
This is not legal, and these have been moved to module-scope variables.

Bug: tint:469
Change-Id: If5e812da3f62f096e344c50782ab0f465ae74ea3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48224
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-19 14:40:49 +00:00
Ben Clayton 8198d57ff2 writer/wgsl: Handle inferred-type variable declarations
Fixes a null-pointer deference crash.

Bug: tint:672
Change-Id: Icfcb1c8754950ea0e074a0b392d0b34748a13827
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48225
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
2021-04-19 14:37:49 +00:00
Ben Clayton 238de88266 writer/spirv: Fix all tests that had unreachable AST nodes
By making nodes reachable, the resolver has now caught a whole lot of additional problems, which have been fixed in this CL.

Some of these broken tests were attempting to use private and workgroup variables as function-scope declarations.
This is not legal, and these have been moved to module-scope variables.

Bug: tint:469
Change-Id: I09c1a8e72a33d3e4df13554e8b07d0a169fcf575
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48226
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-19 14:26:00 +00:00
Ben Clayton b696607338 writer/msl: Add TINT_UNIMPLEMENTED() for module-scope vars
Module scope variables of the private and workgroup storage class are
not currently implemeted.

Change-Id: Ibb73faec5b5bcb11199e07ba4d7aa4df9c875450
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48221
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-19 14:12:29 +00:00
Ben Clayton 4649377d05 transform: Don't create detached AST nodes
Detached AST nodes will become an ICE, so only create nodes if they are going to be used.

Bug: tint:469
Change-Id: I29b3275a355e30c934e6e508185a19981dcc8a42
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48050
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-17 06:02:21 +00:00
Ben Clayton f32719ff85 reader/spirv: Don't create detatched AST nodes
EmitControlBarrier() was calling MakeOperand() to create ast::Expressions that held a ScalarConstructorExpression, which held a IntLiteral.
The literal value was then taken, and the rest was discarded.

Detached AST nodes will become an ICE, so do the work to find the literal value.

Bug: tint:469
Change-Id: I522bfe8db84e853e189c714b18598feb0d49e58b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48049
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-17 06:01:41 +00:00
Ben Clayton 169512e499 ProgramBuilder: Add a WrapInStatement() overload for literals
Lets you pass AST literals to WrapInStatement() / WrapInFunction()

Change-Id: I69d8918a61f0ea25193b64df38ed6cd606c7f044
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48047
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-17 05:52:11 +00:00
Ben Clayton 49668bbe17 ProgramBuilder: Tweak Return() signature
Instead of directly fowarding to ReturnStatement, pass the parameter through `Expr()`.
Also add a no-arg overload.

This means we can write `Return(1);`, `Return("a")`, `Return()`

Change-Id: I8f5df630f540f9cecdf82d24e2810a0844e025e8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48046
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-17 05:32:01 +00:00
Ben Clayton a0cf62f415 Fix all tests that shared AST nodes
This is not valid. Will become an ICE.

Bug: tint:469
Change-Id: I02c0eea16daf7d83f4d6c251e06d9cac0dfd7ce4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47777
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-17 00:42:41 +00:00
Ben Clayton 0ecea57a8a Add ShareableCloneable, dervies from Cloneable
The CloneContext will currently de-duplicate any pointers that are cloned multiple times, however this isn't ideal behavior for AST nodes.

AST nodes must be unique in the tree, so a non-transform clone of the AST from one program to another should only ever Clone() called once per node. Hitting the map for these is inefficent, worse still, there are cases in the transforms where we actually *want* to create N copies of the same source node. The current implementation makes this impossible.

This change introduces ShareableCloneable, a new base class that derives from Cloneable.
Repeated calls to CloneContext::Clone() for Cloneable pointer types will now produce a new, unique instance per call.

Repeated calls to CloneContext::Clone() for ShareableCloneable pointer types will de-duplicate as before.

type::Type objects are shared, want deduplication while cloning, so now derive from ShareableCloneable.
ast::Node continues to derive from Cloneable.

Bug tint:469

Change-Id: I5ca906d507de6271d5d715cfdc962a55b721e821
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47776
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-16 20:30:21 +00:00
James Price 395b48825a Add support for [[builtin(workgroup_id)]]
This is a trivial mapping to/from WGSL in all cases.

Bug: tint:478
Change-Id: I7f21a2392543a880906b54fddbdb8bbd149a526e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48140
Commit-Queue: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-04-16 19:57:34 +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 26cd48603d Castable: Add FLAGS template argument for Is,As
[Is,As] contain a static_assert() that checks a cast is actually possible (TO -> FROM share a common base class).
This has been extremely valuable - it's caught numerious impossible casts due to stupid mistakes - however it makes certain generic templates impossible to write.

Add a compile-time FLAGS argument to Is() and As(), which accepts a new kDontErrorOnImpossibleCast flag.
When specified, this static_assert will always pass, allowing impossible casts to be attempted.

Change-Id: I5ff434b329c04d007f4e6976301bf30c73ab3f8d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47775
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-16 15:05:44 +00:00
Ben Clayton 7687ec1fa3 Kokoro: Test that the _other.cc files also build
Change-Id: I908b9250de839435c3b355fb89b0bb72ab821a54
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48043
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-16 14:43:34 +00:00
Ben Clayton fe70c75bc5 *_other.cc: Remove unused parameters
Change-Id: I966461fdf70a8d23c05f4e5daa5795b7c54e186b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48042
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
2021-04-16 11:40:14 +00:00
Ben Clayton a2596bb696 Fix tmpfile_other.cc
Error: explicitly-defaulted constructor cannot have default arguments

This broke chromium, and needs fixing before we can restart the autorollers.

Change-Id: I4b04dd127b5fb7cf84e5782e07bcf68b2befc904
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48041
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
2021-04-16 11:27:44 +00:00
Ben Clayton 316dcd4166 UintLiteral::to_str() suffix with 'u'
Fixed: tint:673
Change-Id: I5a58d9e504446ccff724e368b5ea2cf835d2271b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47768
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-04-16 10:44:54 +00:00
Ben Clayton 98b084e4a4 spirv/reader: Implement derivative intrinsics
Fixed: tint:719
Change-Id: Iaa5e44a574b2843f4f6f9264b8baa8d199acd70f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47770
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-04-16 10:43:34 +00:00
Ben Clayton 648b05e4e2 Fix AttemptTintPadSymbolCollision test
This test landed simultaneously with a change that checks that storage buffers have an access qualifier, leading to broken tests.

Also fix lint issues that have crept in.

Change-Id: I4a7f0bc67d8d3e7170ddea117342a510741a495c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48040
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
2021-04-16 10:37:34 +00:00
James Price 8cb5a23afb Automatically clone all symbols in CloneContext()
Almost all transforms should clone all symbols before doing any work,
to avoid any newly created symbols clashing with existing symbols the
source program and causing them to be renamed.

The Renamer is the exception to this, and so an optional flag is used
to prevent automatic cloning of symbols for this transform.

Bug: dawn:758
Change-Id: I84527a352825b2eaa43eabe225beb9e0999bf048
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48000
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
2021-04-16 10:29:54 +00:00
Ben Clayton ed8332a0d1 writer/wgsl: Omit the newline after [[access()]] decorations
Produces ugly code for the common case.

Change-Id: I8e5b1215e19fc6461dc40b8a91922db25f9cbd76
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47764
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
2021-04-16 10:09:44 +00:00
Ben Clayton bfae10525f writer/msl: Drop leading _ for _tint_pad_N fields
Bug: tint:640
Change-Id: I4415dcd2c46bff07bef302620321acc3847a6399
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47771
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-16 10:03:04 +00:00
Ben Clayton 1773535e1c Resolver: Validate <storage> var types
https://gpuweb.github.io/gpuweb/wgsl/#variable-declaration
Variables in the storage storage class and variables with a storage
texture type must have an access attribute applied to the store type.

https://gpuweb.github.io/gpuweb/wgsl/#module-scope-variables
A variable in the storage storage class is a storage buffer variable. Its
store type must be a host-shareable structure type with block attribute,
satisfying the storage class constraints.

Fixup tests, including those that were producing warnings about `var <in>`

The WGSL writer seems to want to put a newline after every decoration block, leading to some ugly output. I'll fix this as a separate change.

Fixes: tint:531
Fixes: tint:692
Change-Id: If09d987477247ab4a7c635f6ee6e616a06061515
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47763
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-04-16 09:26:14 +00:00
Ben Clayton 4db10dd496 Resolver: Handle AccessControl in Canonical()
The canonical type was stopping at the first encountered type::AccessControl, which meant the alias in access<alias<i32>> was not being unwrapped.

Bug: tint:705
Change-Id: Idcbd824808d8ee3098fb1861add5014d7d46b0ad
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47762
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-16 08:47:14 +00:00
Ben Clayton 856a3688f7 transform: Minor changes to cleanup Dawn usage.
Move transform::Transform::Output to transform::Output.
There's no need for this to be an nested class, it stutters, and it also
prevents Dawn from forward declaring it.

Add move assignment operator to DataMap.

Change-Id: Ibe1af03abc1a872790d20ee6ec8cf18a511ea0b4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47772
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2021-04-16 08:35:24 +00:00
James Price fd7251bb02 Merge RenameReservedKeywords into the Renamer
Adds additional modes to the Renamer for renaming just HLSL or MSL
keywords. The sanitizers no longer rename reserved keywords
automatically, which isn't usually necessary anyway since Dawn renames
all symbols.

The tint executable automatically renames reserved keywords when
targeting HLSL and MSL. It now also has an option to rename
everything, which is useful for testing the renamer.

Change-Id: Idbfd53226805e851050024402be8d8f251b88707
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47960
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
2021-04-16 08:28:54 +00:00
Antonio Maiorano fc03a46516 Validate array stride
Fix: tint:707
Change-Id: I4439b10f173d8753bd1d407629954a7dad61a679
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47826
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-16 02:36:44 +00:00
Antonio Maiorano 2e0bd4acb0 Resolver: improve array handling
type::Array was the only type with special handling in that we'd resolve
all array types first in ResolverInternal, then proceed with resolving
the AST in order of declaration. This CL removes this special handling,
and instead, we now process Arrays as we process ast::Variables of
array type. This change also allows us to pass down a Source location
for validation messages when processing Arrays.

Updated some Builder tests that weren't creating a variable of the array
type they declared.

Bug: tint:707
Change-Id: I8483b3a979bc1e5e04feb1ca4d281e96e9e654be
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47825
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
2021-04-16 01:15:43 +00:00
Ben Clayton 13ef87caab Validate that Symbols are all part of the same program
Assert in each AST constructor that symbols belong to the program of the parent.

Bug: tint:709
Change-Id: I82ae9b23c88e89714a44e057a0272f0293385aaf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47624
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-15 18:20:03 +00:00
Ben Clayton f0c816a757 ast: Validate that ASTs are all part of the same program
Assert in each AST constructor that child nodes belong to the program of the parent.

Bug: tint:709
Change-Id: Icc89b69691d099e358ff632a0ca6fd7943cb0193
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47623
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-15 17:47:23 +00:00
Ben Clayton 31804e09ed reader/spirv: Fix ExpectEq() tests
Don't end the EXPECT_THAT() with `<< ToString(p->builder(), fe.ast_body());`
This string is already emitted in the error, and calling ast_body() a second time triggers an assert as the builder is already finalized.

Change-Id: Ied6aca73937e86aa6ce2d8cff8a09f67b5082349
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47767
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-15 15:28:13 +00:00
Ben Clayton cc46e393e4 Add NOLINT to the new long test names
Suppresses cpplint warnings.

Change-Id: I2c8865709037b67f7af96e737dad8b6c179c5110
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47760
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-15 00:07:38 +00:00
James Price 0d96c1d644 transform/CanonicalizeEntryPointIO: Sort struct members
HLSL interface matching rules impose additional requirements on the
order of structure members. We now sort members such that all members
with location attributes appear first (ordered by location slot),
followed by those with builtin attributes.

Fixed: tint:710
Change-Id: I90940bcb7a5b9eeb1f50f132d406d4cf74e47ea2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47822
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
2021-04-14 22:51:18 +00:00
James Price 172215e118 writer/hlsl: Fix mapping for [[builtin(front_facing)]]
Change-Id: I9493b8599e306113d4ede7b109adf5d119fbe4d6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47821
Reviewed-by: Ben Clayton <bclayton@chromium.org>
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
2021-04-14 22:15:58 +00:00
James Price 0ba48eeb52 writer/msl: Enable validation for entry point tests
Fix a test that did not have the position builtin as a vertex shader
output.

Change-Id: I8dceba59d8327938e725e7d5e62b4b9c43695710
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47820
Reviewed-by: Ben Clayton <bclayton@chromium.org>
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
2021-04-14 22:14:08 +00:00
James Price 43b84d69dd transform/CanonicalizeEntryPointIO: Fix symbol renaming
Pre-clone the program's symbols at the start of the transform,
otherwise the original program's symbols may get mangled. This causes
problems for Dawn when the entry point name is changed.

Change-Id: I414c798fb5f51afe44e8b97619f77452f97f0782
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47824
Commit-Queue: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
2021-04-14 22:08:48 +00:00
James Price edd4d3cc3b Rename builtin(sample_mask_{in,out}) to builtin(sample_mask)
Removes the need to pass the storage class to the SPIR-V reader
builtin mapping function.

Added a deprecation warning for sample_mask_{in,out}.

Bug: tint:715
Change-Id: I948ff2de2d5de7bd05e1c6ff45bd721c856900e3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47743
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-14 16:44:38 +00:00
James Price 88d7edcf7a Rename builtin(frag_coord) to builtin(position)
Use the variable storage class to determine the correct builtin to use
in the SPIR-V generator.

Added a deprecation warning for frag_coord.

Bug: tint:714
Change-Id: I5ad4956f9345e2f39f4af16e84668dec345ac82e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47742
Auto-Submit: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-14 16:37:18 +00:00
Arman Uguray d13982ff2e [msl-writer] Support MSL compiler validation in unit tests
The MSL writer GTest harness (TestHelper) now provides a function to
invoke the XCode SDK Metal compiler for the MSL output of a given
tint::Program.

The tint_unittests binary now provides the `--validate-msl` and
`--xcrun-path` command-line flags to optionally enable MSL validation
and to configure its path.

The MSL validation logic itself is conditionally compiled based on the
TINT_BUILD_MSL_WRITER define. The TINT_BUILD_* flags were previously
not propagated to the GTest binary which this CL addresses by linking
the common/public tint configs when building the tint_unittests_main
target.

Bug: tint:535
Fixed: tint:696
Change-Id: I08b1c36ba59c606ef6cffa5fa5454fd8cf8b035d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45800
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Arman Uguray <armansito@chromium.org>
2021-04-14 15:36:58 +00:00
Ben Clayton f8313e5a6e transform/BoundArrayAccessors: Fix symbol renaming
We need to pre-clone the source program's symbols before creating the symbols `min` and `arrayLength`, otherwise the original program's symbols will be suffixed with a number to make them unique.

Fixes Dawn tests that triggered this issue.

Bug: tint:712
Change-Id: Ie1cf6cbcf2050a2ce1a94acf0ae131a06f635820
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47761
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-14 14:29:28 +00:00
Ben Clayton 3dd4fae775 writer/hlsl: Use Symbols().New()
Instead of rolling another implementation inside GeneratorImpl.

Bug: tint:712
Change-Id: I26af0d68f6529c0c6dc45f51233f4618389edb55
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47638
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-13 23:48:07 +00:00
Ben Clayton 5c34060a4e transform/hlsl: Use Symbols().New() for empty entry point
And drop the leading understore, it's no longer needed.

Bug tint:712

Change-Id: Ic0ad304119ceb148984d2fa0a5e9e61f2c3a89fd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47637
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-13 23:46:17 +00:00
Ben Clayton 4d349b5391 transform: s/_tint_/tint_ for reserved keywords
Bug: tint:640
Change-Id: I7525ac97d8942fffa651847d703bf37a10cbc71d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47636
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-13 23:44:57 +00:00
Ben Clayton a5a31d35f6 transform/EmitVertexPointSize: Use SymbolTable::New()
And clean up some code in the process.

Avoids potential symbol collisions. Simplifies the logic.

Bug: tint:711
Bug: tint:712
Change-Id: I7c41dff81e1fb2abfd3f5d3fecf625a27c42f14d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47635
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-13 23:30:57 +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 f01ed13a25 transform/VertexPulling: s/_tint/tint
Don't use a leading underscore in identifiers. Tint cannot parse these, they're illegal in MSL.

Bug: tint:640
Change-Id: I6e923cf3317a646cc5f4f2a10a7a522036000c70
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47634
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-13 23:08:37 +00:00
Ben Clayton 93cd23c01b transform/VertexPulling: Use SymbolTable::New()
And clean up some code in the process.

Avoids potential symbol collisions. Simplifies the logic.

Bug: tint:712
Change-Id: Ibce5ccbd4c7fd45d5bf29906b5a83b3637b6cdcc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47633
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-13 23:04:07 +00:00
Ben Clayton bd1597a545 transform/Renamer: Use SymbolTable::New()
Avoids potential symbol collisions. Simplifies the logic.

Bug: tint:712
Change-Id: I4416307b10f2dbe38964b6fd9342042c7e5505ec
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47632
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-13 22:58:07 +00:00
Ben Clayton 363a2e26e3 SymbolTable: Change behavior of anonymous symbols
SymbolTable::New() used to build and return a symbol without a registered name. When you asked for the name of the symbol it would return tint_symbol_N, where N is the numerical identifier for the symbol.

This approach was a major tripping hazzard for  transforms that liked to fetch the source program name, and register it in the new program (in this situation, you should always use `CloneContext::Clone(Symbol)`).
Without special casing for unnamed symbols, you could end up promoting the unnamed symbol to a named symbol, and then colliding against a new unnamed symbol.
This is exactly what happened in tint:711.

Instead, with this change:

* The concept of unnamed symbols has been removed. All symbols  now have a name.
* The signature of `SymbolTable::New()` has been changed to take a name parameter (which defaults to 'tint_symbol'). This can be used to create a new, unique named symbol (possibly with a suffix), which will not collide with any existing symbols. Note these symbols may still collide if `SymbolTable::Register()` is called with the same name. All Transforms that currently use `SymbolTable::Register()` will be fixed in another change.
* The CloneContext has been updated to use `SymbolTable::New()` instead of `Register()`. This means that any symbols defined before a clone will not collide.
* `CloneContext::CloneSymbols()` has been added which allows a transform to pre-clone all the symbols from the source program. This can be used to avoid the authored identifiers being suffixed with a number, in the case a transform calls New() before the symbol is cloned.
* `Symbol::to_str()` has been changed to return `$<id>` instead of `tint_symbol_N`. This is to avoid any confusion between the actual name and the symbol ID.

Bug: tint:711
Bug: tint:712
Change-Id: I526e4b49b7027545613859de487e6a275686107a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47631
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-13 20:07:57 +00:00
David Neto 46bb2bc935 spirv-reader: handle break and continue from if-selection header
Fixed: tint:243, tint:494
Change-Id: I6baf3360b44042b52f510b8f761376e1daab878f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47540
Auto-Submit: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Alan Baker <alanbaker@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-04-13 19:52:08 +00:00
Arman Uguray 66a8efc6ae Support optional file extension in TmpFile
TmpFile can now be supplied an optional file extension. This change
was motivated by validation work using the XCode SDK Metal compiler,
which expects a source file to end with the ".metal" extension.

See
https://developer.apple.com/documentation/metal/libraries/understanding_the_metal_shading_language_filename_extension

Bug: tint:535
Change-Id: I5d44baa20ba350530ace46569e238c4627135e51
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45720
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Arman Uguray <armansito@chromium.org>
2021-04-13 19:07:47 +00:00
Ben Clayton 12ac6e5d80 transform::VertexPulling - use DataMap for inputs
Migrate this transform to using the transform::DataMap pattern for configuration.

Allows users to fully construct their transforms ahead of time, and pass in the configuration options for each run.

Bug: tint:389
Change-Id: Ie4a8bf80d7b09cfe7bdd4ef01287d994b6b9eb4f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47626
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
2021-04-13 18:46:47 +00:00
David Neto 0386472762 spirv-reader: fix overly aggressive dominance check
When finding the true-head, false-head, and potentially the
premerge-head blocks of an if-selection, there was an overly
aggressive check for the true-branch or false-branch landing
on a merge block interior to the if-selection. The check was
determining if the merge block actually corresponded to the selection
header in question.  If not, then it was throwing an error.

The bug was that this check must be performed only if the
target in question is actually inside the selection body.
There are cases where the target could represent a structured
exit, e.g. to an enclosing loop's merge or continue, or
an enclosing switch construct's merge.

There is still a latent bug: if either the true branch
or false branch represent such a kLoopBreak, kLoopContinue, or
kSwitchBreak edge, then those are not properly generated.
That will be fixed in a followup CL.

Bug: tint:243, tint:494
Change-Id: I141cce07fa0a1dfe5fad20dd2989315e4cd7b688
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47482
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: Alan Baker <alanbaker@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-04-13 18:35:37 +00:00
Ben Clayton 095cd1c255 Fix symbol collision in RenameReservedKeywords()
Fixed: tint:711
Bug: tint:712
Change-Id: I8d0b5c926772c4265d273f6420f101f48ac29b9c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47628
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
2021-04-13 17:53:09 +00:00
Ben Clayton ebc5bd4e28 Remove debug spew from test
Bug: tint:265
Change-Id: I9495c47fc1a4e70c6f6486c6357a41ddccd886c4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47625
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: James Price <jrprice@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-13 14:20:13 +00:00
Antonio Maiorano 2543686412 Resolver: compute canonical types and store them as semantic::Variable::Type
We define the canonical type as a type stripped of all aliases. For
example, Canonical(alias<alias<vec3<alias<f32>>>>) is vec3<f32>. This
change adds Resolver::Canonical(Type*) which caches and returns the
resulting canonical type. We use this throughout the Resolver instead of
UnwrapAliasIfNeeded(), and we store the result in semantic::Variable,
returned from it's Type() member function.

Also:

* Wrote unit tests for Resolver::Canonical()

* Added semantic::Variable::DeclaredType() as a convenience to
retrieve the AST variable's type.

* Updated post-resolve code (transforms) to make use of Type and
DeclaredType appropriately, removing unnecessary calls to
UnwrapAliasIfNeeded.

* Added IntrinsicTableTest.MatchWithNestedAliasUnwrapping to ensure we
don't need to pass canonical parameter types for instrinsic table
lookups.

* ProgramBuilder: added vecN and matMxN overloads that take a Type* arg
to create them with alias types.

Bug: tint:705
Change-Id: I58a3b62538356b8dad2b1161a19b38bcefdd5d62
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47360
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-13 13:32:33 +00:00
David Neto 2f25ecf8ba spirv-reader: prove no const decls are created for handles
Fixed: tint:265
Change-Id: If175357d8c49707fd0cb69a811e972d9f808afe4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47561
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-12 21:01:22 +00:00
James Price 3ee8c37cb6 [wgsl-reader] Deprecate old syntax for entry point IO
Bug: tint:697
Change-Id: Ia6e066678753ef12dc41a753ba33c924bb662148
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47480
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
2021-04-09 19:58:58 +00:00
Ben Clayton 6f7986d9b5 writer/hlsl: Use SampleCmpLevelZero instead of SampleCmp
Currently WGSL does not allow a mip-level to be specified for `sampleCompare`, and cs_5_1 does not allow SampleCmp to be used.

Bug: tint:684
Change-Id: I53f35205185a0a1ee0dd5224fa1d8cd0ffedbea1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47429
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-09 18:20:18 +00:00
Ben Clayton 804a699ea5 writer/hlsl: Include format type for sampled textures
Required for correct output of .Load() functions

Bug: tint:689
Change-Id: I5e5ea068700bbe2239f04dc81da9acb7abce0210
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47225
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-09 17:50:08 +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
Ben Clayton 003fa8ffd6 Remove LocalReferencedBuiltinVariables()
It ignored entry point builtin parameters, meaning it was mostly useless.
Was only used by the FirstIndexOffset, which has been re-written.

Change-Id: I26abd69201576cf33b1a71e8e6a1b914871a2a74
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47223
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-09 16:54:48 +00:00
Ben Clayton 962d46ec56 Fixup all doxygen warnings
No idea why the operator<<() functions have started moaning now.

Change-Id: I338b96c53888f4ddb8e42283a6dcda7708e567f0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47431
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-09 16:51:38 +00:00
Ben Clayton 1d618b1664 transform: Reimplement FirstIndexOffset
* It didn't always produce valid WGSL (crbug.com/tint/687)
* It didn't handle builtins as entry point parameters
* It used hard-coded symbols that could collide
* It didn't use DataMap for input.

The new implementation addresses all of this.

Bug: tint:687
Change-Id: I447bec530b45414ebb8baeb4ee18261d73d1c0d2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47222
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-09 16:19:48 +00:00
Ben Clayton e9c4984489 semantic: Add Function::Parameters(), MemberAccessorExpression subtypes
Add semantic::Swizzle and semantic::StructMemberAccess, both deriving from MemberAccessorExpression

Add semantic::Function::Parameters() to list the semantic::Variable parameters for the function.

Change-Id: I8cc69f3738380c14f61d051ee2989be6194d148d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47220
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-09 13:56:08 +00:00
James Price f8f31a458f Automatically run entry point IO canonicalization
Avoids the need for downstream users to manually run this transform.

Change-Id: I0c63e2fd8b6ad49b752ed1757370e386171481cb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47440
Commit-Queue: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-09 13:50:38 +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 e2c775f4bb writer/hlsl: Fix storage buffers
Use the new CalculateArrayLength and DecomposeStorageAccess transforms to simplify storage buffer patterns before running the HLSL writer.

The HLSL writer now handles the InternalDecorations for the internal load, store, and buffer-length intrinsics.

GeneratorImpl::EmitStorageBufferAccessor() has now been entirely removed, as all this primitive load / store decomposition performed by DecomposeStorageAccess.

TODOs around runtime arrays have been removed, as this is now handled by CalculateArrayLength.

Bug: tint:185
Bug: tint:683
Change-Id: Ie25a527e7a22da52778c4477cfc22501de558a41
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46878
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-09 13:20:28 +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
James Price 3c1d4870e3 [inspector] Add support for new entry point IO syntax
Fixed: tint:706
Change-Id: Ia5625a67aaf68665cd003503b6da1bb37c0ff4b1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47282
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-08 22:41:08 +00:00
James Price daf1f1c0a8 Add ProgramBuilder::Param() helpers and use them
Fix some SPIR-V tests that were wrongly expecting parameters to be
loaded from memory as a result of them not being const.

Change-Id: Ieab6f1edd4a4ba6efd226fe190e7a49b309048c5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47281
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-08 22:15:48 +00:00
James Price a12ccb20a0 [ast] Add helpers for searching a decoration list
This is a commonly used pattern.

Change-Id: I698397c93c33db64c53cbe8662186e1976075b80
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47280
Auto-Submit: James Price <jrprice@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-08 21:53:27 +00:00
Ben Clayton c76ec15b45 reader/wgsl: Add deprecation warning for [[offset]]
Bug: tint:626
Change-Id: I3e1074bbf104d73c3a2f71234ff7821d0481ad1a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47142
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-04-08 18:11:27 +00:00
Ben Clayton 571f2b7363 wgsl: Deprecate 'const' for 'let'
Renamed with:
https://github.com/gpuweb/gpuweb/pull/1574

Bug: tint:699
Change-Id: I4dda868abe4c5bc0cba46bc81d9eb297a0663717
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47141
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-04-08 15:46:17 +00:00
David Neto 80767413b8 spirv-reader: fix position calculation of for phi var decl
Fixed: tint:495
Change-Id: I93f1b289eb33c2bda8b661f591a1c8dde775b1ab
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46220
Commit-Queue: David Neto <dneto@google.com>
Commit-Queue: Alan Baker <alanbaker@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-04-08 14:51:57 +00:00
Ben Clayton 586fca472d CloneContext: Fix CloneWithoutTransform()
Add tests

Change-Id: I39630336fc3e12ee9484783b5b374b9c3f5587ab
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47221
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-04-08 14:47:37 +00:00
Ben Clayton 9328d94572 wgsl: Deprecate '-> void' on functions
Was removed with:
https://github.com/gpuweb/gpuweb/pull/1460

Bug: tint:677
Change-Id: If08cb450189c6158561051ef6e8f2439c60bc010
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47140
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-04-08 14:39:47 +00:00
Antonio Maiorano d15391e802 Remove tint's usage of Validator
Also update comments and arch design to remove references to the
Validator.

Bug: tint:642
Change-Id: Ic0b4779ae4712a393ff209014daf25e23f32be6d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47061
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-08 14:08:47 +00:00
Antonio Maiorano 101f463992 Speed up intrinsic table registration
Reserve enough memory for overloads, and avoid copies. Opportunistically
avoid copying Source instances in ProgramBuilder API.

Speeds up runs of test_unittests.exe by about 20% (33s to 26s on my
Windows desktop).

Change-Id: I6ba26043d7750eb1f123e29c53d253614974f960
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47060
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-07 20:35:11 +00:00
Ben Clayton 933d44a2c8 transform/hlsl: Hoist structure constructors to new var
HLSL has some pecular rules around structure constructors.
`S s = S(1,2,3)` is not valid, but `S s = {1,2,3}` is.

This matches the quirkiness with array initializers, so adjust the array
hoisting logic to also support structures.

Fixed: tint:702
Change-Id: Ifdcafd98292715ae2482f72ec06c87842176d270
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46875
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
2021-04-07 17:29:31 +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 bebb1cb8f1 writer/hlsl: Fix zero-init of vectors
float3(0.0f) is not legal HLSL

Change-Id: I2fd20e9718f394c896c9515c4c9b88e490b2b758
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46874
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-07 16:30:41 +00:00
Ben Clayton ab26a8fd34 hlsl/writer: Transpose matrices
HLSL's matrices are declared as <type>NxM, where N is the number of
rows and M is the number of columns. Despite HLSL's matrices being
column-major by default, the index operator and constructors actually
operate on row-vectors, where as WGSL operates on column vectors.
To simplify everything we use the transpose of the matrices.

This is the same approach taken by SPIRV-Cross.

Change-Id: I98860e11ff1a68132736980f694b2f68b633ef83
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46873
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-07 15:54:11 +00:00
Ben Clayton 8bd7cc7e88 ast::Variable: Fix nullptr access in info_to_str
With type inference, declared_type_ may be null.
Check it is not null before calling type_name().

Change-Id: I3b7630286b75aa9d021d9cf54eecedc3287a62f2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46872
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
2021-04-07 15:32:31 +00:00
Ben Clayton dac5418819 type::Type: fix weird formatting
Change-Id: I12c6836316f30b0924c2bb5a62ee6c168749fa30
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46871
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
2021-04-07 12:48: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 3bfb6817df semantic::Struct: Add FindMember
Change-Id: Ie7b76ad8b7dbac1303ed73ba6962e584fed76238
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46628
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-07 08:35:31 +00:00
Ben Clayton f23696ddda BoundArrayAccessors: Don't share AST nodes
Each AST node must be unique.
Having diamonds in the AST causes all sorts of exciting bugs in the resolver and later transforms.

Bug: tint:469
Change-Id: I5dc43fef71a200632b3e8e8add77ec0537b01cd2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46870
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-07 08:09:41 +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
Ben Clayton 86c2cbfb7e Add semantic::VariableUser
Derives from semantic::Expression.
Maps to ast::IdentifierExpressions that resolve to a variable.

Breaks pure-immutability of semantic::Variable, as we have discussed in the past.

Change-Id: I362d4d1ed61291282a60626b84fb15566655fb14
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46627
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-07 08:09:01 +00:00
Antonio Maiorano e93d46fcbc Move remaining Validator tests to Resolver
Bug: tint:642
Change-Id: I0f983d8c0391f4e500562faadf0a621c4edb46ab
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46942
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-06 20:43:47 +00:00
Antonio Maiorano bfc97945f3 Move entry point validation from Validator to Resolver
Move logic and relevant tests.
Remove validator/validator_decoration_test.cc.

Bug: tint:642
Change-Id: Ie89118a11233931605f18e762274bb2afcaaa460
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46941
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-06 20:41:07 +00:00
Antonio Maiorano bbbb0edec2 Move global var validation from Validator to Resolver
* Moved global variable resolving logic to new function Resolver::GlobalVariable, and moved validation logic there.
* Moved global variable-related tests to resolver tests.
* Fixed many tests that started failing after this change, mainly because many globals were declared with no storage class. I set most of these to "Input".

Bug: tint:642
Change-Id: I0f8ea2091ed2bb3faa358f9497cd884b2994a40f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46940
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-06 20:18:57 +00:00
Ben Clayton 4f154a839d writer/hlsl: Fix validation errors
Several tests fail DXC validation.
Many are fixed by specifying the entry point name.

Change-Id: I1c5c0f1f9c057156106334c2e9c0f15906a06813
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46867
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-04-06 18:15:17 +00:00
James Price ca0f51fe45 [spirv-writer] Fix missing symbol clone in entry point IO transform
Fixed: tint:701
Change-Id: Id85e1170c85eedb9f04e5759aff84edc0d1c1453
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46900
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-04-06 17:31:27 +00:00
James Price 68f558f29c [resolver] Add entry point IO validation
Checks the following things:
- Non-struct entry point parameters must have pipeline IO attributes
- Non-struct entry point return type must have a pipeline IO attribute
- Structs used as entry point parameters and return values much have
  pipeline IO attributes on every member
- Structs used as entry point parameters and return values cannot have
  runtime array or nested struct members
- Multiple pipeline IO attributes on a parameter, return type, or
  struct member is not allowed
- Any given builtin and location attribute can only appear once for
  the return type, and across all parameters

Removed tests for nested structs from the SPIR-V transform/backend.

Fixed a couple of other tests with missing pipeline IO attributes.

Fixed: tint:512
Change-Id: I4c48fe24099333c8c7fcd45934c09baa6830883c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46701
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-04-06 15:51:47 +00:00
Antonio Maiorano 09356cc3dc Move VariableDecl validation from Validator to Resolver
Moved tests and fixed now broken tests.

Bug: tint:642
Change-Id: Iaa4483abde101f3963ca20e51c1069b2d64bbb5c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46661
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-06 14:07:07 +00:00
James Price 2f04dc94ce [validator] Remove requirement to have an entry point
The SPIR-V and HLSL sanitizing transforms add an empty one if
necessary.

Fixed: tint:679
Change-Id: Ic98ff3109d7381b1fbc2de68d95d57e15c7a67c0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46700
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-04-01 22:07:37 +00:00
Antonio Maiorano 1fe1a5e641 Validator: remove IsStorable and tests
This function, along with unit tests, already exist on Resolver.

Bug: tint:642
Change-Id: I35fe7ee6dc52a6f58ad6145bd15b071795ac069d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46680
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-01 20:05:07 +00:00
Antonio Maiorano 61dabab673 Validate multiply of invalid vector/matrix sizes
Added tests that test all combos of vec*mat, mat*vec, and mat*mat for 2,
3, and 4 dimensions.

Bug: tint:698
Change-Id: I4a407228261cf8ea2a93bc7077544e5a9244d854
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46660
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-01 19:58:37 +00:00
Antonio Maiorano f1b643ee70 Improve binary expression validation error message
Example:
```
  var a : i32;
  var b : f32;
  if (a == b) {
    return vec4<f32>(0.4, 0.4, 0.8, 1.0);
  }
```

Outputs:
```
error: test7.wgsl:6:9 error: Binary expression operand types are invalid for this operation: i32 equal f32
  if (a == b) {
        ^^
```

Bug: tint:663
Change-Id: Idd2bb5a248b3c7d652483931d7dd58d5123e9ee8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46640
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-01 19:40:37 +00:00
Antonio Maiorano 15c6ed048c Fix binary expression resolving and validation with type aliases
* Fixed resolving logical compares with lhs alias
* Fixed resolving multiply with lhs or rhs alias
* Fixed resolving ops with vecN<alias>and matNxM<alias>
* Fixed validation with lhs or rhs alias
* Fixed spir-v generation with lhs/rhs alias and added missing error
message
* Added tests for all valid binary expressions with lhs, rhs, or both as
alias

Bug: tint:680
Change-Id: I095255a3c63ec20b2e974c6866be9470e7e6ec6a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46560
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-04-01 14:59:27 +00:00
Ben Clayton b4275c870e CloneContext: Pass the vector to InsertBefore()
There's usually only ever one vector we want to insert into.
Inserting into *all* vectors that happen to contain the reference object is likely unintended, and is a foot-gun waiting to go off.

Change-Id: I533084ccad102fc998b851fd238fd6bea9299450
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46445
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-03-31 21:00:26 +00:00
Ben Clayton 90f43cf87f Replace all uses of assert() with TINT_ICE macros
Use TINT_ICE() where we have diagnostics, TINT_ASSERT() where we do not.

Change-Id: Ic6e842a7afdd957654c3461e5d03ecec7332e6f9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46444
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-03-31 20:43:26 +00:00
Ben Clayton dba65b7a34 Add semantic::Statement::Block() for getting the owning BlockStatement
Required special casing the ElseStatement, as this isn't actually owned by a BlockStatement.

Change-Id: Ic33c207598b838a12b865a7694e596b2629c9208
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46443
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-31 20:35:46 +00:00
James Price 285b8b6e75 [hlsl-writer] Use entry point interface canonicalization transform
This replaces the entry point IO component of the HLSL sanitizing
transform, and completes support for the new entry point IO syntax.

Struct emission in the HLSL writer is updated to use the correct
attributes depending on the pipeline stage usage.

Fixed: tint:511
Change-Id: I6a30ed2182ee19b2f25262a30a83685ffcb5ef25
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46521
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
2021-03-31 19:15:06 +00:00
James Price dc8f08a782 [msl-writer] Use entry point interface canonicalization transform
This replaces the entry point IO component of the MSL sanitizing
transform, and completes support for the new entry point IO syntax.

Struct emission in the MSL writer is updated to use the correct
attributes depending on the pipeline stage usage.

Fixed: tint:510
Change-Id: I7ace33568c5a6e1bbf5c90f67b920579ba14be78
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46520
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
2021-03-31 18:42:12 +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 c87ff9c238 Resolver: Move logic ValidateFunction() -> Function()
I inserted this non-validation code in the wrong method.

Change-Id: I43f6d8a0cbf6f0b5f20e453785b141b50d159044
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46442
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-31 17:23:07 +00:00
James Price 5c523f331d [resolver] Apply type storage class uses via return types
Change-Id: I16cf23af7f6a792d22268e6af45c77d4faeb6918
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46460
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-31 15:44:07 +00:00
James Price 494e82dc8a [resolver] Track pipeline stage usages for structs
This will be used by the generators to determine how to handle
location decorations.

Change-Id: Ib0e0ce852a5da3819781b402c5625a440c4c9544
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46400
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-31 15:42:17 +00:00
Antonio Maiorano e09989ae34 Move assignment validation from Validator to Resolver
* With this change, ProgramBuilder::WrapInStatement(expr), which
produced an "expr = expr" assignment expression, would fail validation
in some cases like for call expressions. Replaced this with a
declaration of a variable with type inferred from expr.

* Moved existing validation tests to resolver\assignment_validation.cc,
and added missing tests: AssignFromPointer_Fail.

* Fixed broken tests as a result of this change.

Bug: tint:642
Change-Id: I6a738b67edb0e116a46e936d652c2dcb4389281e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46161
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-31 13:26:43 +00:00
Antonio Maiorano 39a65a1d1e Add type inference support to Resolver
There is still no way to spell this out in WGSL, but this adds support
for VariableDecls with an ast::Variable that has nullptr type. In this
case, the Resolver uses the type of the rhs (constructor expression),
which is stored in semantic::Variable.

Added tests for resolving inferred types from constructor, arithmetic,
and call expressions.

Bug: tint:672
Change-Id: I3dcfd18adecebc8b969373d2ac72c21891c21a87
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46160
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-31 12:46:52 +00:00
Ben Clayton 55bc5409c2 writer/hlsl: Emit workgroup variables
Fixed: tint:688
Change-Id: I3f0f3fd24734421f8d36a94c501aed9881ec10b0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46379
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-03-30 20:55:08 +00:00
Ben Clayton 971774945a writer/hlsl: Fixes for textures
Don't use RWTextureXD types for read-only textures.

Emit registers for texture variables.

Change-Id: I904c38df74bd57baf462a36dad72a5d37622d3e9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46264
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-30 20:33:28 +00:00
Ben Clayton 3ac4a0e013 writer/hlsl: Fix emission of EmitStorageBufferAccessor()
Fix number of parentheses emitted for all control flows.

Add a TINT_UNIMPLEMENTED() for types that are not currently handled.

Change-Id: I987776e4d3b6d7c4d237f44db8b0eebb1a9a7fbd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46266
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-03-30 20:20:28 +00:00
Ben Clayton 0f02a6de00 writer/hlsl: Don't emit structs for storage buffer usage
Use the semantic StorageClassUsage() to determine whether the structure is used only for storage buffer usage. If it is, don't emit a struct definition for it.
This fixes issues with attempting to generate runtime arrays - they're only legal for storage buffer usage. Storage buffers use ByteAddressBuffer instead of structured loads / stores.

Bug: tint:185
Fixed: tint:682
Change-Id: I5b58a133eee2fe036a84e028fa85b611e4895b1a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46382
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-03-30 20:18:28 +00:00
Ben Clayton 59b28c4cbc Resolver: apply type storage class uses via parameters
Bug: tint:185
Bug: tint:682
Change-Id: I0a35d9419af3a74376ef96197bbe99630d54632e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46381
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-03-30 20:06:48 +00:00
Ben Clayton ced00a2380 writer/hlsl: Don't explode on unhandled member decorations
[[align(n)]], [[size(n)]] are valid decorations that should not cause the writer to fail.
Instead of allow-listing these, just handle the cases it actually cares about.

Fixed: tint:686
Change-Id: I7c60d251fcaee424fe1c1a1f1f58123eea8c99aa
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46380
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-03-30 19:54:08 +00:00
Ben Clayton 02571d15e8 writer/hlsl: Initialize output local variable
Failing to initialize this can lead to uninitialized variable errors in the FXC compiler.

Change-Id: Ic4e7ee0aab889241923382f83058e3a9a567be5b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46265
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-03-29 21:27:05 +00:00
Ben Clayton 92b5be0047 writer/hlsl: Emit binding group as spaceN
When combined with the new transform::BindingRemapper, Dawn can now correctly emit resource bindings.

Change-Id: I3e7fd7b2fc5368c5da112ec8835f5c70d45ce6c8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46263
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
2021-03-29 21:26:35 +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 a864f24c6f Add ast::Variable::BindingPoint
Use this to simplify a bunch of code in semantic::Function.

Change-Id: Ia3f8a270ec576660eab00bcfa4df9a96138bd31e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46261
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-03-29 21:21:35 +00:00
Ben Clayton af8a8ac3d6 transform: Add Data as an input
Like 42264, this is an attempt to keep transforms immutable, and to keep mutable I/O information in Data objects.

Bug: tint:389
Change-Id: Ie417872d3e97f3db3904245a30aa74fdcce76610
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46260
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-03-29 21:03:59 +00:00
Ben Clayton de1e3c02e3 Fix linter errors
Change-Id: I7b8b5c00503564d220e50eb245e812b4a5a109cd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46267
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-03-29 20:16:36 +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
Antonio Maiorano 9ef17472e8 Add semantic::Variable::Type() and use it instead of ast::Variable::type()
In anticipation of adding support for type inference, no longer use
ast::Variable::type() everywhere, as it will eventually return nullptr
for type-inferred variables. Instead, the Resolver now stores the final
resolved type into the semantic::Variable, and nearly all code now makes
use of that.

ast::Variable::type() has been renamed to ast::Variable::declared_type()
to help make its usage clear, and to distinguish it from
semantic::Variable::Type().

Fixed tests that failed after this change because variables were missing
VariableDeclStatements, so there was no path to the variables during
resolving, and thus no semantic info generated for them.

Bug: tint:672
Change-Id: I0125e2f555839a4892248dc6739a72e9c7f51b1e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46100
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-26 12:47:58 +00:00
David Neto d7f23f5c75 spirv-reader: Fix mixed-signedness binary ops
Fixed: tint:666
Change-Id: I77331081fc5acc128be81e7b85a253bf6ebab608
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46140
Auto-Submit: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-26 12:13:18 +00:00
James Price c63a64b795 [msl-writer] Fix struct constructor emission
Zero value struct expressions may still be broken (tint:477).

Change-Id: I5cf2f13ed891a50e4b8f55ce4b80d2768aa358d9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46101
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-25 21:32:27 +00:00
James Price a696b027b3 [spirv-writer] Use const for function parameters
The backend was wrongly generating OpLoad instructions for function parameter
accesses since it thought they were pointers.

Run SPIR-V validation for the entry point IO tests.

Bug: tint:509
Change-Id: Ic816a22973fb87c7ede26bad8fb595764a333250
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45941
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: James Price <jrprice@google.com>
2021-03-25 20:49:37 +00:00
James Price ea855a9144 [spirv-writer] Handle non-pointer struct member accessors
These map to OpCompositeExtract instructions.

Fixed: tint:662
Change-Id: Ibd865bdb16326de7932157cbdfe543394415b3ff
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45940
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: James Price <jrprice@google.com>
2021-03-25 20:16:48 +00:00
Antonio Maiorano cea744d558 Move Switch validation from Validator to Resolver
* Formerly, we reported the same error message if we detected no default
clause or more than one. I made it so that we output a different error
message for each. This makes it more clear, and in the case of more than
one, the error source location points at the second default clause,
rather than at the switch statement.

* Add functions to ProgramBuilder to more easily define switch and case
statements.

* Fix broken tests as a result of this change.

Bug: tint:642
Change-Id: Iab4e610a563165862d9bc190772d32a4dd24ac45
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45880
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-25 12:55:27 +00:00
James Price 5c9906e307 [spirv-writer] Handle entry point IO struct types
Recursively hoist struct members out to module-scope variables, and
redeclare the structs without entry point IO decorations. Generate a
function for storing entry point outputs to the corresponding
module-scope variables and replace return statements with calls to
this function.

Fixed: tint:509
Change-Id: I8977f384b3c7425f844e9346dbbde33b750ea920
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45821
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-03-24 17:08:06 +00:00
David Neto 84ef13c84f spirv-reader: disallow OpSwitch without preceding OpSelectionMerge
This was updated/clarified by the SPIR WG.

Bug: tint:3
Change-Id: Ie4c503f0e5f80ffeabada9c526375588e81a5ceb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45740
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: Alan Baker <alanbaker@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
2021-03-23 17:06:29 +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
Antonio Maiorano 2e97435ba6 Move return validation from Validator to Resolver
Improved error message to use friendly names. Fixed tests that broke as
a result of this change.

Bug: tint:642
Change-Id: I9a1e819e1a6110a89c826936b96ab84f7f79a084
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45582
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-22 23:20:17 +00:00
Ryan Harrison 8ac7f8ae9e Fix typo in enum
This enum isn't being used in Dawn yet, so it is safe to change without
deprecating it first.

BUG=dawn:700

Change-Id: I0f3cc788f26a8001f82aba4f9b3920e84204e4e4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45620
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-03-22 21:26:17 +00:00
Ben Clayton 5622b6bbd1 AppendVector() - support pointer args
Add tests.

Fixed: tint:639
Change-Id: I6718a1fcf5a46aca36209bec037633a862d8e568
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45600
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-22 21:05:47 +00:00
Ben Clayton f55091a9ec Implement barrier intrinsics
Fixed: tint:658
Change-Id: I28d5225f42dacb2b6b0cb51ce9f15951b31f0fc9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45284
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: Alan Baker <alanbaker@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-22 19:27:06 +00:00
James Price 570b3d6509 Add missing include for ::testing::Test
Fixes google3 build.

Change-Id: I2ff266754f65c7c4cfd00fa4a85e86712266758e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45581
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
2021-03-22 19:20:56 +00:00
Antonio Maiorano 06feb3f287 Finish moving call validation from Validator to Resolver
Call validation was already implemented in Resolver. This change
completes it by deleting the relevant code in Validator, and moving and
updating the builtins validation test to use the Resolver.

Also added the "v-0004" error code for when detecting recursion, as was
done for the similar error in the Validator.

Bug: tint:642
Bug: tint:487

Change-Id: If7973bfd2d19681a0cbf48c6d427e17a3b927cde
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45463
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-22 17:42:06 +00:00
Antonio Maiorano 4682e3fc31 Move identifier validation from Validator to Resolver
This was mostly already implemented in the Resolver, except for adding a
variable scope for blocks.

Moved tests and improved them to only add Source on the error node.

Bug: tint:642
Change-Id: I175dd22c873df5933133bc92276101aeab3021ed
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45460
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-22 17:38:45 +00:00
James Price a07d21acc5 [resolver] Fix nullptr dereference when validating continuing block
ast::IdentifierExpression nodes can appear outside of functions
(e.g. as initializers for module-scope variables), so we cannot assume
that current_block_ is not nullptr.

We already have several tests that do this, but for some reason the
nullptr dereference does not cause problems on our presubmits.

Change-Id: I612f3eb0d5711a0b1d0bb71663be7cca388b2b3c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45580
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-03-22 17:25:56 +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
James Price b225851eef [wgsl-reader] Disallow explicit storage classes on handle types
Downstream users have all caught up to the change.

Remove the "uniform_constant" token from the WGSL parser.

Fixed: tint:332
Change-Id: I046f93d5e6c26b89d419763e73b1ca583250570f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45462
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-22 15:49:16 +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
Antonio Maiorano d6fe74b01f Validator: add const init with param test
Also test initializing a const from a function parameter.

Bug: tint:642
Change-Id: Ic10a4e8b5a2f67f56bc3720cb59f8d306e175d66
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45520
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-22 14:55:55 +00:00
Antonio Maiorano 4daddd1759 Fix Validator regression reporting param not declared
This regression was accidentally introduced by my CL:
https://dawn-review.googlesource.com/c/tint/+/45382

I had removed too much of ValidatorImpl::ValidateFunction, including
its pushing of function parameters to the variable stack. As a result,,
any function parameters referenced by a function would fail the
Validator. This CL restores this bit, and adds a test for this case.

Bug: tint:642
Change-Id: I839057e73cabfb11631571ce806dec09f5d9f966
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45500
Auto-Submit: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-22 09:18:13 +00:00
Antonio Maiorano bb5617f21a Resolver: process nodes in order of declaration
Formerly, the resolver would process arrays and structs first, then
global variables, and finally functions. As we move validation from
Validator to Resolver, we need to process these nodes in declaration
order instead so that we can validate use-before-declaration. This
matches how the Validator processed nodes.

Fixed all tests that failed after this change mainly because of
variables declared after usage.

Bug: tint:642
Change-Id: I01a9575dcfff545b0a056195ec5266283552da38
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45383
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-19 18:45:30 +00:00
Ben Clayton 1b51be56f0 semantic: Clean up intrinsics
Declare enum <-> string mapping once.
Don't use `default:` so the compiler moans when the enum is not catching cases.

Change-Id: I4c8903ef75c76b1881971b66ec3b49667dcc2218
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45340
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-19 16:45:10 +00:00
Antonio Maiorano 03c01b5266 Move function validation from Validator to Resolver
* Fixed many tests that now failed validation. Most of the time,
functions declared that they returned a type, but with no return
statement.
* ProgramBuilder::WrapInFunction now returns the function is creates,
and std::moves its StatementList.
* ProgramBuilder: Added Return function to create ast::ReturnStatements
more easily.

Bug: tint:642
Change-Id: I3011314e66e264ebd7b89bf9271392391be6a0e5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45382
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-19 14:04:51 +00:00
James Price b4f11f3ff3 Add missing includes to fix build
Change-Id: Ifee7a5b4591e640fb99642ff3ddb0e7dd23425ae
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45381
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-03-19 11:37:30 +00:00
James Price 5bae31dda6 Delete unused files
A couple more headers that should have been deleted in 95d4077.

Change-Id: Icd051842d0ff143ea74eb62c636506dc2a955681
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45380
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-03-19 10:03:50 +00:00
Ben Clayton 6b2fc057c5 Resolver: Check that initializers and assignments are valid
This performs very basic type verification for assignments and variable initializers.

Pulls part of the validation logic out of the Validator into the Resolver.
Involves fixing up a bunch of broken tests.

Bug: tint:642
Fixed: tint:631
Change-Id: Ifbdc139ff7eeab810856e0ba9e3c380c6555ec20
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45281
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-03-18 21:14:44 +00:00
Ben Clayton 25eef8d2cf s/sharable/shareable
Fixed: tint:660
Change-Id: I5b98597acb771f6b07a16a85d85d8ae5249e495d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45283
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-03-18 21:03:24 +00:00
Ben Clayton 722b5a2d18 Resolver: Add validation for host-sharable / storage
Fixes a TODO

Bug: tint:60
Change-Id: Ica44d6dbff682374473cacec9d0515e6d3b02f4c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45245
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-03-18 20:46:24 +00:00
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