Commit Graph

1562 Commits

Author SHA1 Message Date
Ben Clayton 4b9e7f92b9 transform::Hlsl: Hoist array initializers out of expressions
Move these into a separate const variable declaration statement just above the before the use of the array initializer.
HLSL does not allow array initializers as part of a sub-expression

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

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

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

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

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

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

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

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

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

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

Added test coverage for WGSL builtin generation.

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

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

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

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

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

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

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

Fixed: 1177275
Change-Id: Ia8c45ef05e03b2891b5785ee6f425dd01cb989c6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41542
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-02-11 20:23:03 +00:00
dan sinclair dc9d3e0cd5 Roll dependencies
Roll third_party/googletest/ 389cb68b8..f3ef7e173 (40 commits)

389cb68b87..f3ef7e173f

$ git log 389cb68b8..f3ef7e173 --date=short --no-merges --format='%ad %ae %s'
2021-02-04 absl-team Googletest export
2021-02-03 dmauro Googletest export
2021-02-03 absl-team Googletest export
2021-02-02 absl-team Googletest export
2021-02-02 absl-team Googletest export
2021-02-02 absl-team Googletest export
2021-02-02 dmcardle Googletest export
2021-02-02 absl-team Googletest export
2021-02-01 absl-team Googletest export
2021-01-27 absl-team Googletest export
2021-01-27 absl-team Googletest export
2021-01-26 absl-team Googletest export
2021-01-26 absl-team Googletest export
2021-01-25 absl-team Googletest export
2021-01-25 absl-team Googletest export
2021-01-22 absl-team Googletest export
2021-01-20 absl-team Googletest export
2021-01-20 ofats Googletest export
2021-01-19 absl-team Googletest export
2021-01-19 absl-team Googletest export
2021-01-19 krzysio Googletest export
2021-01-19 absl-team Googletest export
2021-01-16 dreamer.tan Fix link to Google Test Primer
2021-01-15 absl-team Googletest export
2021-01-15 absl-team Googletest export
2021-01-14 absl-team Googletest export
2021-01-14 absl-team Googletest export
2021-01-10 krystian.kuzniarek fix a broken link
2021-01-13 dmauro Googletest export
2021-01-13 dmauro Googletest export
2021-01-13 absl-team Googletest export
2021-01-08 absl-team Googletest export
2021-01-07 absl-team Googletest export
2021-01-05 absl-team Googletest export
2021-01-05 absl-team Googletest export
2021-01-05 absl-team Googletest export
2020-12-29 absl-team Googletest export
2021-01-06 davidben Restore GTEST_ATTRIBUTE_PRINTF_ on ColoredPrintf
2021-01-03 krystian.kuzniarek remove explicit function overloads of CmpHelper?? for BiggestInt arguments
2020-12-25 mattias.ellert Fix gtest-help-test failure on GNU/kFreeBSD

Created with:
  roll-dep third_party/googletest

Roll third_party/spirv-headers/ faa570afb..75b30a659 (4 commits)

faa570afbc..75b30a659c

$ git log faa570afb..75b30a659 --date=short --no-merges --format='%ad %ae %s'
2020-08-19 jason Add header changes for SPV_EXT_shader_atomic_float_min_max
2021-01-27 jason.ekstrand Re-run buildSpvHeaders to fix indentation
2021-01-19 dneto Header generator: Check enumerant ordering
2021-01-05 ben.ashbaugh add function control bitfield reservation section reserve bit 16 for an upcoming Intel extension

Created with:
  roll-dep third_party/spirv-headers

Roll third_party/gpuweb-cts/ 89ba81c39..d836e71f2 (20 commits)

89ba81c395..d836e71f29

$ git log 89ba81c39..d836e71f2 --date=short --no-merges --format='%ad %ae %s'
2021-02-11 corentin Implement some of api:validation:vertex_state (#461)
2021-02-10 kainino standardizeExtent3D
2021-02-10 kainino factor out makeBufferWithContents
2021-02-10 kainino add more texture format subtypes
2021-02-09 kainino roll types
2021-02-10 kainino renames in operation test helpers
2021-02-03 kainino use new helpers, subcases, selectDevice in operation tests
2021-02-03 kainino [trivial] Move helpers to util/texture/image_copy.ts
2021-02-10 jamesprice.dev Remove explicit storage class from samplers/textures (#464)
2021-02-08 enrico.galli Add button to print creation stack to console in /standalone/ (#457)
2021-02-08 corentin Update the test plan for validation/vertex_state (#458)
2021-02-05 shrekshao Update wgsl comments from # to // (#456)
2021-02-04 kainino Use subcases in copyImageBitmapToTexture tests (#453)
2021-02-04 kainino Update copyBetweenLinearDataAndTexture tests for new bytesPerRow/rowsPerImage rules (#452)
2021-02-03 kainino fix "INFO: subcase:" prints (#454)
2021-02-01 9856269+sarahM0 [wgsl] validation v-0040: uniform and storage buffer are declared with group and binding decorations. (#428)
2021-02-01 kainino Loosen precision in multisample resolve operation test (#446)
2021-02-01 shrekshao Add sampler anisotropy tests (#437)
2021-02-01 tojiro Update defaultQueue->queue, OUTPUT_ATTACHMENT->RENDER_ATTACHMENT to match latest spec (#449)
2021-02-01 kainino add todos in createView tests (#450)

Created with:
  roll-dep third_party/gpuweb-cts

Roll third_party/spirv-tools/ 297723d75..cfa1dadb1 (6 commits)

297723d75a..cfa1dadb1e

$ git log 297723d75..cfa1dadb1 --date=short --no-merges --format='%ad %ae %s'
2021-02-10 dj2 Update a few virtuals to overrides. (#4143)
2021-02-05 46493288+sfricke-samsung spriv-val: Vulkan image gather constant component (#4133)
2021-02-05 46493288+sfricke-samsung spirv-val: Fix/Label UniformConstant VUID (#4134)
2021-02-05 46493288+sfricke-samsung spirv-val: Add Vulkan Invariant Decoration VUID (#4132)
2021-02-02 46493288+sfricke-samsung spirv-val: label tests for VUID 04657 (#4119)
2021-02-01 46493288+sfricke-samsung spirv-val: Add Vulkan PSB64 convert VUID (#4122)

Created with:
  roll-dep third_party/spirv-tools

Change-Id: I5632e3eed6d8e8731faeb4800e903a8893a60f9f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41560
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2021-02-11 15:04:03 +00:00
Ben Clayton 5585f0789c Add SymbolTable::New()
Generates a new unnamed symbol.
Useful for creating temporaries in transforms.

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

BUG=tint:489

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

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

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

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

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

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

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

Correctly match access control on storage types

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Also cleans up some code in IntrinsicTable.

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

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

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

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

Fixes tint -> dawn autoroller.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Change-Id: I7a23a0c0c35508bdac20c808d2635592638dfa77
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40602
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
2021-02-08 21:14:52 +00:00
Ben Clayton a51aa1f805 Fix intrinsic tests so arguments match an overload
Change-Id: I8c5464e3198c6a3b154f5f3433466955e203efee
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40502
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-02-08 21:10:11 +00:00
James Price 21692def05 Skip SPIR-V validation when not generating SPIR-V
Otherwise the sample app crashes when using --dawn-validation with a
non-SPIR-V output format.

Change-Id: Ic6e03e758747602d15f3a1d5b9d9cefee1aad527
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41120
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-08 20:45:11 +00:00
Ben Clayton b57c19d450 Change StorageTexture::SubTypeFor() signature
So that it takes a type::Manager instead of a ProgramBuilder.
Makes this callable from places that has the former and not the latter.

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

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

Bug: tint:449
Change-Id: I30b3a0c32245d5e6c4b1f3aeef112a67ffb1d055
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/40506
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-02-08 20:24:52 +00:00