Commit Graph

196 Commits

Author SHA1 Message Date
Antonio Maiorano fe2b417f83 Validate swizzles don't mix between rgba and xyzw
Added test.

Bug: tint:79
Change-Id: Ibb17cc2d9198403cdf6a2e456ad29d906deac9f7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/43460
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-03-01 20:01:39 +00:00
Antonio Maiorano 6ce2edfa1f Validate sign of RHS matches LHS for scalar variable declarations
Statements like `var u : u32 = 0;` should fail because '0' is a signed
integer being used to initialize an unsigned variable.

Added test.

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

Bug: tint:258
Change-Id: Ie0173207b788e87de39867a5aa41e8cc13ec33de
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42520
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-02-24 22:11:34 +00:00
Ben Clayton 6d612ad478 TypeDeterminer: Resolve swizzles
Have the TD resolve swizzles down to indices, erroring out if they're not valid.

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

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

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

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

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

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

Fixed: chromium:1180544
Fixed: chromium:1180814
Change-Id: I121dd194356419f94b09c7ee1ed544a350a114b3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42220
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-02-24 13:31:22 +00:00
Ben Clayton 7206e25798 Remove deprecated APIs
Remove the Parser classes from the wgsl and spirv namespaces.
These have been replaced with a Parse() method.

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

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

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

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

Change-Id: I064fbbe2387ebe980776ee99ed2ff48d6ea5d5b5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41621
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-02-17 13:10:49 +00:00
James Price c9af597997 [semantic] Add semantic::Variable::Users()
Returns a list of ast::IdentifierExpression* nodes that reference the
variable.

Change-Id: I36f475c6ddf5482f9ae9b432190405625f379f0d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41661
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-16 21:15:01 +00:00
Ben Clayton f97b9c9310 Add semantic::Statement
Add Stmt() accessor on all semantic::Expressions so the owning statement can be retrieved.

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

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

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

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

Fixes tint -> dawn autoroller.

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

Change-Id: I2ac19ba52fc0834e5a35b4b35a210dcc170866fc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41240
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-02-09 15:37:44 +00:00
Ben Clayton 06d8db2bcb Add texture intrinsics to the IntrinsicTable
Automatically implements verification of texture intrinsic overloads.

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

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

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

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

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

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

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

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

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

Bug: tint:361
Change-Id: I4dadc4a99293f12ede9e9cbd9132ba5f9b9830ed
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40284
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-08 19:13:19 +00:00
Alan Baker c63e1c0791 Implement data packing intrinsics
* Fix how the HLSL writer determines how to use a RWByteAddressBuffer
* Fix how the HLSL writer decides the register space for a storage
  variable
* Fix inference of hlsl format in the tint executable
* Add support for data packing intrinsics
  * type determination
  * validation
  * writers
  * spirv reader

Bug: tint:340, tint:473, tint:474
Change-Id: I45dc8fd7c6f9abc7d30f617c7e3d713d7965b76e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40342
Commit-Queue: Alan Baker <alanbaker@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-04 16:17:49 +00:00
Ben Clayton c1052a4971 Add semantic::MemberAccessorExpression, use it.
Pull the mutable 'is_swizzled' semantic field from ast::MemberAccessorExpression and into a new semantic::MemberAccessorExpression node.
Have the TypeDeterminer create these semantic::MemberAccessorExpression nodes.

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

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

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

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

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

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

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

Bug: tint:390
Change-Id: I237b1bed8709dd9a3cfa24d85d48fc77b7e532da
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39902
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-03 16:43:20 +00:00
Alan Baker 2e6a1bb396 Remove special case type determination
* Affects any, all, derivatives, dot and select
* Add validation for those builtins

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

Change-Id: Id11b739770af904a9b7afe0b1c2de50e1428a165
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39540
Commit-Queue: Alan Baker <alanbaker@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-01 15:33:13 +00:00
Ben Clayton 3335254c1c Migrate to using semantic::Expression
Remove the mutable `result_type` from the ast::Expression.
Replace this with the use of semantic::Expression.

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

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

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

Bug: tint:390
Change-Id: Iba494a9c5645ce2096da0a8cfe63a4309a9d9c3c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39003
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-29 10:55:40 +00:00
dan sinclair 3a5b15d4e5 Record when an identifier expression is a swizzle.
This CL updates the type determiner to record if an identifier
expression is a swizzle and then uses that in the MSL and HLSL generator
to output the swizzle name directly.

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

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

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

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

Mutable ProgramBuilders can be moved into immutable Programs.

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

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

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

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

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

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

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

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

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

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

Bug: tint:390
Change-Id: I98c73a6b8102eebf48a889315a376195f9379f63
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38556
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-25 22:09:18 +00:00
Ben Clayton d59cedb5a5 Add tint::Program as a wrapper of tint::ast::Module.
`tint::Program` will become the new public API object for a parsed shader program.
For now, have Program be a simple wrapper around ast::Module so we can migrate Dawn's use of the public tint API.

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

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

Change-Id: Ic5bee46ceb109ea591ba7fec33685220b244a1ae
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38540
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-25 18:14:08 +00:00
Ben Clayton 6761160dc1 ast: Move Module function methods to FunctionList
Module will be split into Module (immutable) and ModuleBuilder (mutable).
By moving these methods to the FunctionList, we can deduplicate a bunch of common logic.

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

Remove Reset(). It was not used.

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

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

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

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

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

Bug: tint:390
Change-Id: I8349bbbd1b19597b8e6d51d5cda0890de46ecaec
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38002
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-21 15:42:10 +00:00
Ben Clayton 0a68b365eb Implement textureNumSamples()
SPIR-V reader TODO

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

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

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

Bug: tint:286
Change-Id: Ia944ed8557fbf490d78db2a1b49c31d0aba08728
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37740
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-01-13 18:48:11 +00:00
dan sinclair 1c200cffd0 Remove outerProduct.
The community decided to remove outerProduct from WGSL. This Cl removes
the pieces from Tint.

Change-Id: Ib1735867e4a7ca852a72549fc8c9bd86e8de22b0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37600
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-01-12 22:00:58 +00:00
dan sinclair 987376cd21 Revert the namer changes.
This CL reverts the changes to use the top level namer in the various
backends. This is causing issues when rolling into Dawn in the case
where the tint generator is used to create SPIR-V which is sent to
SPIRV-Cross but then generator and inspector aren't used. The entry
points end up being incorrect as SPIRV-Cross gets the renamed entry
points.

Change-Id: I4749e1d773f2bd9edcce83e63555f07a443d5ca5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37342
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-01-12 04:34:53 +00:00
Ben Clayton f6866a2ffc Add std::hash<tint::Symbol> specialization
Allows symbols to be used as keys for std::unordered_map and std::unordered_set.
Replace all map / set use of uint32_t for Symbol, where applicable.

Change-Id: If142b4ad1f0ee65bc62209ae2f277e7746be19bb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37262
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-01-11 22:02:42 +00:00