Lessens the friction of using these macros.
Also allows you to add a message to TINT_UNREACHABLE(), which you couldn't do before.
Change-Id: Ida4d63ec96e1d99af71503e8b80d7a5a712e6a47
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42020
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Looks for DXC on PATH.
If found, it will invoke DXC with the shader program generated by the writer to verify the shader can compile.
Change-Id: Iad8b4021bac16d01214b500ddb89b5f743927ce9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41943
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Command is a helper used by tests for executing a process with a number of arguments and an optional stdin string, and then collecting and returning the process's stdout and stderr output as strings.
Will be used to invoke HLSL and MSL shader compilers to verify our test generated code actually compiles.
Change-Id: I5cd4ca63af9aaa29be7448bb4fa8422e6d42a8ce
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41942
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
TmpFile constructs a temporary file that can be written to, and is automatically deleted on destruction.
Will be used to create a temporary source file for verifying generated HLSL and MSL against their shader compilers.
Change-Id: Ieaa6f257b93f4f2193dafe6297603816f6964928
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41941
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
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>
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>
When copying or moving a ProgramBuilder, we always want the ProgramBuilder::ty to point back to the owner.
We were previously std::move()'ing the ty field, which is not correct - this will result in the TypesBuilder pointing to the wrong ProgramBuilder.
I'm not sure why we've not seen any issues with this using clang, but running under MSVC immediately highlighted this brokenness.
Change-Id: I4293bb00ac4fbdfa66d12b1504a7bd060e014cd6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41861
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Most recursive control flow passes through Sync().
Error out if the Sync() function is recursively called too many times.
This replaces the more specific kMaxConstExprDepth, which also passes
through Sync().
Fixed: chromium:1178436
Change-Id: I64a05f9f6a4fe6d2b53a3ca75642b30e98c7a35f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41724
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
The CloneContext was previously dealing with pointers to CastableBase, which has no guarantees that the object was actually cloneable.
Add a Cloneable base class that CloneContext can use instead.
Improves readability and produces cleaner compiler errors if you try to clone a non-cloneable object.
Change-Id: I4352fc5dab3da434e4ab160a54c4c82d50e427b4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41722
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
A large chunk of validation is now handled by the IntrinsicTable. Remove this.
Also fail validation and propagate diagnostics from the Program to the validator if attempting to validate a broken program. This should prevent undefined behaviour if the user forgets to check the program.IsValid() after parsing.
Change-Id: I2972e8ce296d6d6fca318cee48bc6929e5ed52db
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41549
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Semantic info is no longer part of the ast, so it is now odd to mention semantic info on a clone method for the AST.
Improve the documentation around cloning on the Program methods and the CloneContext.
Change-Id: Ib1cf255acfd994521aaa5add2789e5117db6b072
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41548
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Storage classes are unused for constants.
Also trim extra arguments to these variable constructor functions that are already defaulted to the same value.
Change-Id: Ia0b44364de000bfb8799de15827ce08fcce5f5be
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41541
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Move the storage parameter after type.
Const() has no use for storage classes, so this parameter will be removed in the next change.
This reordering keeps Var() and Const() parameter types identical for the first two non-optional fields
Change-Id: I66669d19fa2175c4f10f615941e69efcab4c23e1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41540
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Move these into a separate const variable declaration statement just above the before the use of the array initializer.
HLSL does not allow array initializers as part of a sub-expression
Fixed: tint:406
Change-Id: I98f93f2eca172865691831011c852de5e57c5ad6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41484
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Inserts objects before others when cloning
Change-Id: Ibf247abae3aeb3d351048f1182db2a2b42b2c677
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41547
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
And assert that the cast succeeded.
There is a danger with Replace() or ReplaceAll(), where you can end up replacing a node with another node of an incompatible type for some reference of that object. Previously this would silently cast to the incorrect type, and Bad Things would happen. Now we will assert in this situation.
I have not observed this issue happening (all current uses of Replace() and ReplaceAll() are believed to be safe). This is just an edge case I've spotted and wanted to add some safety belts for.
Change-Id: Icf4a4fe76f7bc14bcc6b274de68f7d0b3d85d71f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41546
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Use a sanitizing transform to convert scalar `sample_mask_{in,out}`
variables to single element arrays.
Add the `SampleRateShading` capability if the `sample_index` builtin
is used.
Bug: tint:372
Change-Id: Id7280e3ddb21e0a098d83587d123c97e3c34fa1b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41662
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
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>
inspector_test.cc: Remove unused method
test_helper.h: Fix comment type on member
Change-Id: I53b1392fa1fa8154efdcd471d1df1bbf27e04dc9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41728
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
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>
Other builtins use WGSL terms instead of SPIR-V terms too, and the
WGSL writer is relying on the output of `operator<<(Builtin)`, which
just stringifies the name of the enum. This also matches the
equivalent `semantic::Usage::kSampleIndex` enum.
Added test coverage for WGSL builtin generation.
Bug: tint:372
Change-Id: I8077d22c4a5ddf67b1ad07e7365453db74db8e7d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41660
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
BUG=tint:489
Change-Id: I28e4b0e568aea463971e9d2f5a04f04e942e2564
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41600
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This is the first step in being able to read code generated
by Clspv.
Actively ignore the instructions instead of applying stripping
transform before hand. That way we have a chance at properly counting
instructions, which helps produce better diagnostics.
Bug: tint:3
Change-Id: I82bde88897485380d70dc8b287c3843eae5489b6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41641
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
These files were added in dfd1714, but only added to CMakeLists.txt.
Change-Id: I775e8fef68b2f4900a6c562533512f0eda01b795
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41700
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
In C++ argument evaluation order is undefined. MSVC and Clang evaluate these in different orders, leading to hilarity when writing tests that expect a deterministic ordering.
Pull out all the argument expressions to create() in the clone functions so a cloned program is deterministic in its ordering between compilers.
Change-Id: I8e2de31398960c480ce7ee1dfaac4f67652d2dbc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41544
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
Change 41302 correctly fixed up Module::Clone(), but this wasn't actually called by the CloneContext, as Module::Clone() returns a new Module, where as the CloneContext needs to clone into an existing Module.
Refactor the code so that this duplicated logic is moved into a single Module::Copy() method.
Fixed: 1177275
Change-Id: Ia8c45ef05e03b2891b5785ee6f425dd01cb989c6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41542
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Generates a new unnamed symbol.
Useful for creating temporaries in transforms.
Change-Id: I3aa037e4a6b2d400f24e01bbb3555af68da26748
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41480
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Also adds to the binding struct what type of resource it is.
BUG=tint:489
Change-Id: I8ce56a1a613b330150545781cb42d2afeaa69375
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41460
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
This is no longer public-api
Change-Id: I030d37b0d1dbd38ea3ec6d19c47b15d7ce9d0667
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41482
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
If the program is invalid, then the content of the program is undefined.
Don't attempt to test undefined behavior.
Remove the one remaining test that was using an invalid program.
Change-Id: I4bb77b8048768717a312ed94b96efb3416274b63
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41384
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
TypeDeterminer now does overload resolution. Move these tests to the right place.
Change-Id: I27a4fccac34ded00f9828a77cc25ccfe1cb5c0ea
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41383
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
Unwraps aliased types until reaching a non-alias.
Change-Id: I6546d60b7cbe07d4c8cc5a0b439329af8b468ca9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41500
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Useful if you have a symbol already
Change-Id: Ib9e15ea761f58ee67dc3cc722d9129cd5369d92b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41481
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
And add tests for IntrinsicTable.
Drop all the type unwrapping - be precise:
* Display the actual argument types in the signature mismatch message
* Only dereference pointer arguments if the parameter does not expect a pointer
Correctly match access control on storage types
Note that I was mistaken in tint:486 - the TypeDeterminer is resolving identifiers to variables correctly as pointer types. The confustion here was probably due to all the UnwrapAll() calls, which have now all gone.
Fixed: tint:486
Change-Id: I239eabd1fedfc082566c4af616ccfc58786cae25
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41280
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
These transforms will perform work to massage the Program into something consumable by the given writer.
Change-Id: I8989e8d4bc1a9cae7ce1f8764c8f3811db3bd04d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41483
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This CL adds some override decorations for various destructors and turns
of Werror for the spirv-tools build.
Change-Id: I10ac72cfaee247334f6db2918230283b1f975955
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41420
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Change-Id: I3ff04a2e9f4b04ffad924b15c4c5049360651705
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41381
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Instead of emitting all global variables and then functions, emit
global declarations in the order they were added to the AST.
This fixes issues where the reording might generate an invalid WGSL
program from a valid input (e.g. when declaring a global variable with
the same name as a variable inside a function that precedes it).
This also unifies the implementation of Generate() and
GenerateEntryPoint(), to avoid implementing the same logic twice.
Change-Id: I60a4e5ed4a054562cdcc3d028f8d577434a6d713
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41303
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This generates intermediate variable to stuff the component into,
then a constant definition to evaluate the result for later use.
Bug: tint:3
Change-Id: If2e6bb24e2b1e621c3602509eb3237c40f53897b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41360
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Instead of validating all global variables and then functions,
validate global declarations in the order they were added to the AST.
This fixes false-positive "redeclared identifier" errors when a global
variable is declared after a function that declares a variable of the
same name, and false-negative "identifier not declared" errors when a
global variable is declared after a function that tries to use it.
Change-Id: Ibf5e5265bc2f8ca892096f0420757b70e1984525
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41302
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Adds a vector<CastableBase*> to ast::Module which stores the list of
global variables, functions, and types, in the order that they were
declared.
This will be used to fix validation and backend issues around name
uniqueness.
Change-Id: I14491f6ebc0fc7341bd3fb3b3f408faa234a91f7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41301
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
* 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>