Commit Graph

109 Commits

Author SHA1 Message Date
dan sinclair 7517e213cf Update `workgroup_size` to use `expression`.
This CL updates the `workgroup_size` attribute to use `expression`
values instead of `primary_expression`.

Bug: tint:1633
Change-Id: I0afbabd8ee61943469f04a55d56f85920563e2da
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99960
Reviewed-by: Ben Clayton <bclayton@chromium.org>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-08-24 21:31:45 +00:00
dan sinclair acdf6e1a53 Remove `ast::VariableBindingPoint` in favour of `sem::BindingPoint`.
This CL removes `VariableBindingPoint`. The `Variable` object has a
`has_binding_point` method added which returns true if there is
_both_ a `Group` and `Binding` attribute. Code has all been updated
to use the `sem::BindingPoint` which is populated during the resolve.

Bug: tint:1633
Change-Id: I79a0da662be61d5fb1c1b61342ab239cc4c66809
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/100240
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
2022-08-24 15:47:25 +00:00
Ben Clayton b90b6bff1d tint: Minor no-op cleanup changes
Change-Id: I91ad6044e7809ed2deab0fbd4417da90c7870d81
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99705
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-08-23 16:23:05 +00:00
dan sinclair 4964d9bc20 Convert `@align` to hold an expression.
With the updated WGSL grammar the `@align` attribute takes an
expression instead of a value. This CL updates the internal data
structures to store an expression instead of an integer value.

The parser still only parses integers, they're just turned into
`IntLiteralExpressions` at the moment.

Bug: tint:1633
Change-Id: If34901798ed6ceaced354bc06ae9b6df875b700e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99980
Reviewed-by: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
2022-08-23 13:28:44 +00:00
Ben Clayton dce63f5717 tint/utils/UniqueVector: Use utils::Vector and utils::Hashset
For fewer heap allocations, faster lookups.

Change-Id: I02da7c1a63608096ec898b0d89f9f97c6db8733f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98141
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-08-17 18:07:20 +00:00
Antonio Maiorano 2de4deea1f tint: Fix implicit conversion of vector-scalar of abstract types in binary operations
Example: const v2 = vec3(1) + 2.2;

Bug: chromium:1350147
Change-Id: Ie75d76bf00a6b2f6abd49293290f6e5065c31dfb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99301
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2022-08-16 16:00:02 +00:00
Antonio Maiorano a58d8c9fac tint: fix builtin calls and binary ops with abstract args of different type
If a call to atan2 with args of type AFloat and AInt is made, Resolver
would correctly select the atan2(AFloat, AFloat) overload, but if the
input args were of type (AFloat, AInt), it would attempt to constant
evaluate without first converting the AInt arg to AFloat. The same would
occur for a binary operation, say AFloat + AInt. Before constant
evaluating, the Resolver now converts AInt to AFloat if necessary.

Bug: chromium:1350147
Change-Id: I85390c5d7af7e706115278ece34b2b18b8574f9f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98543
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2022-08-10 20:01:17 +00:00
Antonio Maiorano 7058a17bda tint: refactor ConstEval API to accept vector of constants rather than of expressions
This is needed for a follow-up change to apply implicit conversions for
AFloat to AInt.

Bug: chromium:1350147
Change-Id: Id903322d01b7aa420452c3e0fc1fa4e1c480c794
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98683
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-08-10 18:06:43 +00:00
Antonio Maiorano a8e9a6ef2b tint: Fix Resolver erroneously materializing matrices of abstract numeric type
ShouldMaterializeArgument must check that the deepest element is not
abstract numeric to support matrices.

This CL also enables the "no materialize" tests for binary ops, as
constant evaluation of binary addition was recently landed, and that's
what the test uses. The fix in this CL is also necessary for this test
to pass the matrix addition case (it would fail because it erroneously
materialized).

Bug: tint:1581
Change-Id: Id55341c05604c1ac560127826fc415eb38792503
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98682
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2022-08-10 14:32:19 +00:00
Antonio Maiorano c2a052eaa4 tint: Allow ConstEval functions to fail
They now return a utils::Result so they can add an error to diagnostics
and return Failure. Returning nullptr still means cannot evaluate at
compile time, but not a failure.

Bug: tint:1581
Change-Id: Ic30d782fb9fa725ec2faf89a87f74de6282d0304
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98107
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-08-04 13:59:36 +00:00
Ben Clayton 6d66921053 tint/resolver: Reduce small-vector sizes
The vector sizes for expression traversal were excessive.
Reduce.

Change-Id: I3a2b7e7ba4cd82310565b883f85322834275ea8a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98082
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-08-03 08:00:15 +00:00
Ben Clayton 02791e95f3 tint/resolver: Resolve static_assert
No readers produce this, yet.

Bug: tint:1625
Change-Id: I94ce3e5afd7bd81b0a5059451136aa0eed7e9283
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97961
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-08-02 23:28:28 +00:00
Ben Clayton 783b169bf4 tint/ast: Migrate to utils::Vector
Change-Id: I10dd2feeaeb86a1ee7769d2bfd172e49c2805cb3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97843
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-08-02 17:03:35 +00:00
Ben Clayton 34d46731bb tint: Replace VectorRef with ConstVectorRef.
The elements of the VectorRef is now immutable, but can be
moved, if the caller relinquishes ownership by explicitly using
std::move() at the callsite.

Also add utils::Empty as a way of signalling that a vector should be
constructed with no elements. This is helpful in templated code where
{} cannot be used due to overload ambiguity.

Change-Id: I24a50a13956b0692771a8bc9046336ad46261562
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97842
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-08-02 16:52:25 +00:00
dan sinclair 4abf28e29b tint: Add basic support for chromium_experimental_push_constant.
This extension adds support for the push_constant storage class such
that it can be tested with WGSL test files. The real goal is to allow
future transforms that will add push constants that the SPIRV writer
will output.

The extension:

 - Adds the `chromium_experimental_push_constant` enable.
 - Allows the push_constant storage class for global variables.
 - Adds validation that the types are host-shareable for push_constant
   variables, and that they don't contain f16 (must be 32bit types
   only).
 - Validates that at most one push_constant variable is statically used
   per entry-point.
 - Skips validation that the extension has been enabled if
   kIgnoreStorageClass is used.

Tests are added:

 - For parsing of var<push_constant>
   - Caught a missing conversion.
 - For each of the validation rules.
 - For the wrapping of push constants in structs if needed by
   AddSpirvBlockAttribute.
 - For the layout and type rules of the storage class.
 - For a shader with multiple entry-points using various push constants.
    - Caught a missing reset of the previous push constant variable in
      the validation check that at most one is used.
    - Caught the missing wrapping in structs that had to be added to
      AddSpirvBlockAttribute.
    - Caught incorrect logic when adding diagnostics about the call
      graph leading to the reference to push constants.

Bug: tint:1620
Change-Id: I04a5d8e5188c0dcef077f2233ba1359d1575bf51
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96682
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
2022-08-02 15:55:35 +00:00
Ben Clayton 4aa360db5d tint/resolver: Fix null-deref.
Check the result of Materialize() for an index accessor.

Bug: chromium:1347541
Change-Id: Iac1b030a1923c96d65d531a0ca5fd1f4bd4271b9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97851
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2022-08-01 18:46:54 +00:00
Ben Clayton 4a65620716 tint/resolver: Handle array() constructors
If the array constructor has no explicit type and count, infer from the
arguments.
Implement and test array materialization.

Also:
* Change sem::AbstractNumeric::IsConstructable() to return true. This
  has changed in the WGSL spec.
* Fix the test-helper builder for DataType<array<N, T>> - it was
  incorrectly calculating the array size.

Bug: tint:1628
Change-Id: I0ec4e55b469ca6423b4d1848f27bb11df4fa683b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97663
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2022-08-01 17:36:54 +00:00
Ben Clayton 8c9cc86076 tint/resolver: Simplify / optimize Validator::Call()
The resolver has sensible places to dispatch to ArrayConstructor() and
StructureConstructor(), so don't do additional, unnecessary type
dispatches.

Change-Id: Id4edb1fc0dedf431d94507b1c3378bca164746a4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97588
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-08-01 15:19:54 +00:00
Ben Clayton 9c4d0c9410 tint/resolver: Split up the Array resolving logic
In preparation for array constructors that can infer type and count
based on constructor arguments.

Bug: tint:1628
Change-Id: I9f12d7a30de232cf0d34ed7e1a356dd5b92d26d7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97587
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-07-31 19:33:04 +00:00
Ben Clayton 6fb5d379c2 tint/sem: Add const to StructMember 'type'.
This should be immutable once the sem tree is built.
Add a hacky const_cast in Resolver for now, as this is preferable to
having some things non-const in sem.

Bug: tint:745
Change-Id: I67ebce76730347c9543875ab8e1c21a47d71fd56
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97584
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-07-29 14:32:51 +00:00
Ben Clayton 8e0368e554 tint: Use utils::Vector for sem::Type::Common()
Instead of a C-style array.

Change-Id: Ieb3e9811cddf505bfd3b484b7f265459f7b0e66b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97583
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-07-29 14:15:01 +00:00
Ben Clayton 05a76183e0 tint: Split Resolver::Materialize()
Add Resolver::ConcreteType() to determine the concrete type for an
abstract-numeric (or composite of abstract).

Will be used to recursively infer the concrete types of abstract arrays.

Bug: tint:1628
Change-Id: Ia26b778abc827b531848b346f3e36938ad1a0470
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97582
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-07-29 13:19:12 +00:00
Ben Clayton 9a6acc419e tint: Add tint::OverrideId
This is a public API definition of a program-unique override identifier.

Bug: tint:1155
Change-Id: I6e55d43208e72a7a316557a89e2169d1b952f9bf
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97006
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-07-27 20:50:40 +00:00
Ben Clayton 958a4642f1 tint/resolver: Use utils::Vector in a few places
Use the new vector type in some of the hot code paths of the resolver.

Bug: tint:1613
Change-Id: Ie56d8c96f73c9112f37934ad67e588513aafb982
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96282
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-07-26 07:55:24 +00:00
Ben Clayton af47388345 tint/resolver: Optimize node marking
Use the new utils::Bitset to replace the much slower unordered_map.

Bug: tint:1613
Change-Id: I80503d2b897f754408c4ce14a221210d6abc18f7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96403
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: dan sinclair <dsinclair@google.com>
2022-07-21 23:46:15 +00:00
Ben Clayton 5716611bf0 tint/resolver: Materialize objects when indexed with non-const index
If an abstract-vector or abstract-matrix is indexed with a non-constant index expression, then the resulting value is non-constant, and so cannot be abstract.

In this situation the materialization cannot be done post-index, so materialization must happen on the object before indexing.

Bug: chromium:1345468
Change-Id: I9f29dc40301779a7ff8f173724374bd845a3a5b9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96684
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-07-21 15:25:35 +00:00
Ben Clayton 4a92a3c904 tint: Optimize sem node lookup
Add a 'NodeID' to each ast::Node which is the sequentially allocated
index of the node. Use this in sem::Info to map the AST node to the
semantic node, instead of using a std::unordered_map.

Optimised very hot code by entirely eliminating map lookups, and
dramatically reducing cache misses (lookups are usually sequentually
ordered).

Timings running
'webgpu:shader,execution,expression,call,builtin,atan2:f32:inputSource="const";vectorize="_undef_"'
with dawn/node, using SwiftShader:

    Without change: 3.22647107s
    With change:    3.10578879s

Bug: tint:1613
Change-Id: I22ec48d933b2e5f9da04494bff4e979e6f7b1982
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96140
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-07-18 20:50:02 +00:00
Ben Clayton b71bcdd45e tint: Optimization: Pre-allocate the ast -> sem map.
Change-Id: I674fe31786b08153509b470d14844d50cb7c3d9c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96143
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-07-18 16:47:32 +00:00
Ben Clayton ac660c2794 tint: Implement const eval of unary complement
Bug: tint:1581
Bug: chromium:1343242
Change-Id: I76b4f041494ceb2afcf5a604fcda32e046ffca35
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96100
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-07-15 23:54:10 +00:00
Ben Clayton 83bd738ab4 tint/resolver: Track evaluation stage
Keep track of the earliest evaluation point for an expression.
Required to properly track what can be assigned to a `const`, `override`, `let`, `var`.

Bug: tint:1601
Bug: chromium:1343242
Change-Id: I301eec21b71e9036dc1bf6c9af8079317d724762
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/95949
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-07-15 23:46:31 +00:00
Ben Clayton 6a80ce6c66 tint/resolver: Use the intrinsic table for type const dispatch
Use the @const annotations to more efficently dispatch to the right
method of the ConstEval class.

Reduces a whole lot of dynamic casting logic.

Change-Id: I6791aac51b935b46d63af29abd1e577b3306a0ff
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/95950
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2022-07-15 22:27:50 +00:00
Ben Clayton 65c5c9d92b tint/resolver: Add ConstEval class
Extract out the methods of Resolver::EvaluateXXXValue() to a new
tint::resolver::ConstEval class.

Removes more bloat from Resolver, and creates a centralized class for
constant evaluation, which can be referred to by the IntrinsicTable.

Change-Id: I3b58882ef293fe07f019ad2138a7e9dbbac8de53
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/95951
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-07-15 14:14:09 +00:00
Ben Clayton cfe07a1b33 tint/resolver: Shuffle validation code
Restructure the logic so there's less, pointless dynamic casting, and the complexity is reduced.

This alters the order in which variables are validated, hence the change of test.

Change-Id: I9a3120c0278faa5ac9f1db65eeb71a8e4a705596
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/95948
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-07-15 13:01:49 +00:00
Ben Clayton 6c098baedf tint: Implement constant expression structures
Bug: tint:1611
Change-Id: Id04c31ade297a68e7e2941efafbd812ba631fc41
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/95946
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-07-14 20:46:39 +00:00
Ben Clayton 63e6f820d8 tint/resolver: Evaluate const-expr swizzles
Bug: chromium:1341475
Change-Id: I2ac44824b08c460df759a96d0ba96f6045b60f74
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/95765
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-07-07 17:49:02 +00:00
Ben Clayton d5f53ab580 tint/resolver: Optimize constant evaluation methods
Materialize() was re-evaluating the constant values for the incoming
semantic expression, despite this already being evaluated. Just use the
sem::Expression::ConstantValue().

resolver.cc already has all the semantic pointers, so pass them in
instead of pointlessly hitting the ast -> sem map.

Change-Id: If2bc7cd10f79079fb811e9d83c5150dd3c0c244c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/95764
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-07-07 17:30:11 +00:00
Ben Clayton b6c8ea9624 tint/resolver: Fix calling of builtins at module-scope
No builtins are implemented as `@const` yet, but validation handles this already.

Bug: chromium:1341472
Change-Id: Id85893345299ba3414e2d15b85dd071c326f481d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/95762
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-07-07 17:04:21 +00:00
Ben Clayton 89bdea0f77 tint/resolver: Fix null-deref
Materialize() can return nullptr, if there's an error.
Check the returned pointer for nullptr, before continuing on to using the pointer.

Bug: chromium:1341313
Change-Id: Ib7c9e593fbf2bb4374305c341c2b04e34e7487e9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/95761
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-07-07 16:56:21 +00:00
Ben Clayton aa037ac489 tint: Refactor sem::Constant to be less memory-hungry
Change sem::Constant to be an interface to the constant data. Implement
this so that zero-initialized data doesn't need to allocate the full
size of the type.

This also makes usage a lot cleaner (no more flattened-list of
elements!), and gives us a clear path for supporting constant
structures if/when we want to support them.

Bug: chromium:1339558
Bug: chromium:1339561
Bug: chromium:1339580
Bug: chromium:1339597
Change-Id: Ifcd456f69aee18d5b84befa896d7b0189d68c2dd
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94942
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-06-29 19:07:30 +00:00
dan sinclair 3a2a279714 Fixup various warnings in Tint which were accidentally suppressed.
When enabling the SPIR-V reader or SPIR-V writer we were suppressing
-Wnewline-eof, -Wold-style-cast, -Wsign-conversion, and -Wweak-vtables
for the `libtint` cmake target and anything that depended on that
target. Because we'd build all readers/ writers by default this caused
us to never hit those warnings.

A recent change to the cmake build sets the Tint backend based on
the Dawn backend. So, there is a much higher chance of not building
the SPIR-V support if you're on a Mac or Windows machine.

This CL removes the suppression of the warnings, adds specific pragmas
into the SPIR-V reader code which imports the SPIRV-Tools headers
and fixes up the warnings which were then firing due to checking
for the new warnings.

Change-Id: I0d0be6aa3d0b692e939ce8ff924dfb82c82792fc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94901
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-29 14:38:15 +00:00
Ben Clayton c64ca23d94 tint: Deprecated module-scope 'let' for 'const'
Enable the parsing of 'const'.
Warn on use of module-scope 'let', and automatically replace with 'const'.

Fixed: tint:1580
Change-Id: I214aabca80686dc6b60ae21a7a57fbfb4898ea83
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93786
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-06-29 00:55:36 +00:00
Zhaoming Jiang 6058882d4b tint/resolver: Add f16 types, constructor, and conversions
This patch add f16 types and their constructors and conversions in
resolver and intrinsic table. Also implement relating unit tests.

Bug: tint:1473, tint:1502
Change-Id: Ida1336193a72a73959e50e6a3eb12be44c0396b5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94642
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-06-28 14:03:36 +00:00
Ben Clayton f90313396b tint/reader/wgsl: Drop const_expr parsing
The WGSL specification changed so that the enforcing of
initializers being only const-expr is no longer done by the
grammar. This is change is required to allow for 'const' expressions to
reference each other.

Bug: tint:1580
Change-Id: Ia95b6a0bc86ce391a38f4248f20898dd9a6cf27f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94683
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
2022-06-26 11:36:10 +00:00
Ben Clayton 511529f082 tint/resolver: Clean up workgroup-size error diagnostic
Change-Id: I09cc3e15c1f62d7a104e9727a104f3b2bfc9c973
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94607
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-26 09:05:00 +00:00
Ben Clayton e3834c4760 tint/resolver: Resolve 'const' variables
The frontends do not currently emit these, nor do the backends currently
handle them.

Bug: tint:1580
Change-Id: I469a5379663c2802145b28a94f5c1e348cc14ff3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94605
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2022-06-25 23:21:39 +00:00
Ben Clayton b4ff8c859a tint/resolver: Simplify array size evaluation
Use the constant evaluated value instead of manually traversing
variables to find the literal value. This is a small step towards
supporting 'const' values for array sizes.

Also make our OOB-byte related error diagnostics consistent.

Bug: tint:1580
Change-Id: Idf9eb22cdbf69d750218c554e9f826c30458c6b9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94600
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-06-24 23:30:59 +00:00
Antonio Maiorano dfeaf29055 tint: Add sem::IndexAccessorExpression
Also store expression object in MemberAccessorExpression, as well as the
struct on sem::StructMember.

These are used to implement spir-v reader atomics in a follow-up CL.

Bug: tint:1441
Change-Id: Iea49cfb7f9d2e7898d89d2dac6a16a14022c546f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94523
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2022-06-24 20:34:00 +00:00
Ben Clayton 44eb10814e tint/resolver: Change return type of EvaluateConstantValue()
These functions do not return an error - however they might return an
invalid Constant value (if a constant cannot be evaluated), which is
correctly handled by the resolver. So, drop the Result, just emit a
sem::Constant.

Change-Id: I0dd37125c0dba4ba6dcace5ee5f8b1c53cb34d33
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94326
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-21 22:56:33 +00:00
Ben Clayton 22d8dea091 tint/resolver: Fix ICE when failing to materialize
If the abstract numeric cannot materialize to the target type, we could
ICE before the validation handles this bad case. To fix, simply hoist
the validation earlier.

Bug: chromium:1337524
Change-Id: Icc603b056900131cfdb029b517f1c3d030b2ecb4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94322
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-06-20 19:23:02 +00:00
Ben Clayton e4e4854b77 tint/resolver: Clean up 'let' / 'override' resolving
Split the logic out of Resolver::Variable().

Primes the resolver for the introduction of 'const'

Bug: tint:1580
Change-Id: Id67280ed5c8c73a69c62728fb5a81a08f13628a8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93785
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-06-20 19:17:52 +00:00