Commit Graph

419 Commits

Author SHA1 Message Date
Ben Clayton 01208e7e42 tint: Rename Global() -> GlobalVar()
We have `GlobalLet()`, `Let()`, `Var()`, so this just
keeps things consistent

Change-Id: Ie9f79b62e737a15b995c5a2b19f84621a5ac3cc9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94604
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-06-25 08:12:59 +00:00
Ben Clayton 41486e1135 tint: Rename GlobalConst() -> GlobalLet()
GlobalConst() is going to mean a module-scope `const`, once we
support `const`. `GlobalLet()` will then be removed.

Bug: tint:1580
Change-Id: Ie00e9ccdee8c111266850bfe1e1e24f022a59a06
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94603
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
2022-06-25 07:17:29 +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 268d7b8357 tint: Add support for atomic ops to spirv reader
The following operations are supported:

OpAtomicLoad
OpAtomicStore
OpAtomicExchange
OpAtomicCompareExchange
OpAtomicCompareExchangeWeak
OpAtomicIIncrement
OpAtomicIDecrement
OpAtomicIAdd
OpAtomicISub
OpAtomicSMin
OpAtomicUMin
OpAtomicSMax
OpAtomicUMax
OpAtomicAnd
OpAtomicOr
OpAtomicXor

These are not, but may be supported in the future:

OpAtomicFlagTestAndSet
OpAtomicFlagClear
OpAtomicFMinEXT
OpAtomicFMaxEXT
OpAtomicFAddEXT

Bug: tint:1441
Change-Id: Ifd53643b38d43664905a0dddfca609add4914670
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94121
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2022-06-24 22:28:23 +00:00
Ben Clayton ebed939759 tint/resolver: Tidy up variable_test.cc
Split tests up by variable type, and group them.

Change-Id: I4a9ae620883cd2acc05745b54f85df7b3fe7ac3d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94602
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-24 22:21:39 +00:00
Ben Clayton 68ae36e43d tint/resolver: Rename var_let_*test.cc -> variable_*test.cc
Gives us a place to put `const` and `override` tests.

Bug: tint:1580
Change-Id: I0340c37e96f796d2f879d4045623b35927e45c78
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94601
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-24 21:26:39 +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 32cb9cf2f8 tint/writer: Disable constant inlining for lets
Once 'const' is introduced, let will no longer resolve to a
creation-time constant value.

Add temporary code into each of the writers to prevent constants that
originate from a 'let' from being inlined. This will reduce the amount
of noise in later CLs.

Bug: tint:1580
Change-Id: Id3493a43ac09fe9f042ff2d517d04b2ae854d43e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94541
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-06-24 18:15:39 +00:00
Zhaoming Jiang c5f7e8f0bc tint: Fix emitting identity matrix ctor in HLSL
This patch fix the issue of identity matrix constructors in HLSL. This
patch also fix dawn e2e tests for identity matrix constructors and zero
matrix constructors.

Bug: tint:1596, tint:1545
Change-Id: I6c41eb299c1d5f89cf18720611f450abae26d3f4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94042
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
2022-06-24 17:21:59 +00:00
Ben Clayton f47887d207 tint/writer/msl: Generate an array<T,N> helper
And remove the WrapArraysInStructs transform.

Wrapping arrays in structures becomes troublesome for `const` arrays, as
currently WGSL does not allow `const` structures.

MSL 2.0+ has a builtin array<> helper, but we're targetting MSL 1.2, so
we have to emit our own. Fortunately, it can be done with a few lines of
templated code.

This produces significantly cleaner output.

Change-Id: Ifc92ef21e09befa252a07c856c4b5afdc51cc2e4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94540
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2022-06-24 17:01:59 +00:00
Ben Clayton 3c054304a8 tint/sem: Support arrays for sem::Constant
https://github.com/gpuweb/gpuweb/issues/3056 proposes that creation-time
constant expressions should support arrays. We have verbal agreement to
update to spec to support const arrays.

Bug: tint:1580
Change-Id: If460f729384d700a1c2149c5b7dbe8613a960184
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94330
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2022-06-24 15:28:28 +00:00
Ben Clayton e8d47d5263 tint/sem: Add more checks to constant_test.cc
Check more stuff.

Change-Id: I99ba3200bb72975e9b0a740d632f7766d38e9a84
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94334
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2022-06-24 09:01:18 +00:00
Ben Clayton ab70ff7a2f tint/writer/spirv: Clean up accessor tests
Remove duplicate tests.
Use a common pattern of sanitizing, building and dumping the whole
module instead of calling individual methods. There's too much internal
state being tracked in the tests for my liking.

Split most tests into three:
* Const_* tests will check the emission of creation-time-constant
  expressions.
* Runtime_* tests will check the emission of runtime expressions, where
  indexing operates with a constant index.
* Dynamic_* tests will check the emission of runtime expressions, where
  indexing operates with a runtime index.

Bug: tint:1580
Change-Id: I0f92aaaa570cbd917d2b6937c6396605c6b542c9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94333
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-24 08:57:38 +00:00
Ben Clayton 3a68ab4a17 tint/writer: Minor generator cleanup.
No-op change.

Change-Id: Ic5057bbacea09c6ed57d4f735a18d6c1040f1f5f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94332
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-24 08:30:28 +00:00
Ben Clayton 5041480715 tint/writer: Clean up EmitConstant() methods
Aside from more SPIR-V using OpConstantNull, this is a no-op change.
By refactoring these methods, they're easier to read, and contain less
lambda-heavy code.

Change-Id: I89c26b2b9f1cd0785d86fb3293f7cfda550bef2e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94331
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-24 08:06:19 +00:00
Zhaoming Jiang 18b966321b tint: remove duplicated ending newline in ctor_conv_intrinsic.cc
This patch remove the duplicated ending newline in ctor_conv_intrinsic
to make cl presubmit upload check happy.

Change-Id: Iec9f415416407696ad210243d011e53dcf28b554
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94662
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2022-06-24 08:02:19 +00:00
Ben Clayton c1cb9dc1a5 tint/resolver: Evaluate constant index accessors
If the object and index are both constant expressions, resolve the
index as a constant.

Note: Expectations have been updated for indexing on 'let's. Once
'const' is introduced, 'let' will no longer be treated as a constant
expression, and these expectations will be reverted.

Bug: tint:1580
Change-Id: I42793d36c1a5f82890ccaa5dbbb71b4346493bef
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94329
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-06-23 15:46:54 +00:00
Antonio Maiorano f99671b830 tint: spir-v reader: fix atomicCompareExchangeWeak with var comparator
Also fix HLSL generator to unwrap the ref type when emitting the
comparator value.

Bug: tint:1185
Change-Id: I01d04ca6357e72fd5ead0f25012ab39794e65da5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94522
Reviewed-by: Ben Clayton <bclayton@chromium.org>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-06-23 13:14:54 +00:00
dan sinclair 77bf233cef Move tint unittest behind a build flag.
This CL moves the Tint unittest code behind a build flag in order
to hide the //testing/test.gni dependency from downstream consumers.

The unittests are enabled by default and can be disabled by setting
`tint_build_unittests` to false.

Bug: dawn:1517
Change-Id: Id560ed98416ba0725b62a93ddd27caf341699e75
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94481
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
2022-06-22 12:40:43 +00:00
Ben Clayton 1ed376be34 tint/sem: Add range overload of Constant::AllZero()
Checks whether the range of elements are all zero.

Change-Id: I22b91bff25f3fb7fd0e89abd690f139614300e81
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94328
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-22 10:03:33 +00:00
jchen10 ef62b58cf9 Skip Gamma and Gamut conversions for BT.709->SRGB
This introduces a new field 'doYuvToRgbConversionOnly' in
ExternalTextureParams to have the WGSL only do yuv->rgb conversion for
better performance. User studies shows that users don't really care
about the Gamma difference between 2.4 and 2.2.
https://source.chromium.org/chromium/chromium/src/+/main:ui/gfx/color_space.cc;l=1022;drc=a1dbb594a6741a400db35fe3678e77bad2504ea4

Bug: dawn:1082
Bug: dawn:1466
Change-Id: I61c0fe65c5969d8a61c267c202c8dd64c259ed8a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92901
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jie A Chen <jie.a.chen@intel.com>
2022-06-22 03:14:26 +00:00
Ben Clayton 797f0f82e0 tint/sem: Return vector for Type::ElementOf(matrix)
Return the column vector type, instead of the column vector element
type. This matches what you'd get if you were to index the matrix.

DeepestElementOf() can be used to easily obtain the matrix column
element type.

Change-Id: I5293f4cca205c9e378253ac67880bf9d998814aa
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94327
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-22 00:02:03 +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 e021566617 tint/reader/wgsl: Lex 'const'
The parser doesn't consume this yet.

Bug: tint:1580
Change-Id: I3e78a7fdd1bd6b2a4fb4b52379a8ccc9a05869a3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94325
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-06-21 18:38:23 +00:00
Ben Clayton 3b3ef36241 tint/sem: Add Type::DeepestElementOf()
Like `ElementOf()`, but returns the most nested element type.

Change-Id: Ieb97f830293d4714d0d5ddc0c9304e41e994f61b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94324
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-06-21 09:35:22 +00:00
Ben Clayton 7ee324551c tint/ast: Add 'const' AST node
Nothing currently generates or consumes these (yet).

Bug: tint:1580
Change-Id: I892956d33fcd587be85659781108a236b2839b3c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94323
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-06-20 20:46:22 +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
Ben Clayton ee49b1ed95 tint/resolver: Clean up 'var' resolving
Split the logic out of Resolver::Variable().

Also correctly allows type inference of module-scoped 'var's.

Fixed: tint:1584
Change-Id: I32eb11f0a847775137fef937da6f4032a3b3c2b9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93784
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-06-20 15:30:41 +00:00
James Price 80fdd624a0 tint: Process functions in dependency order
For this transform, this will help when we promote private variables
to function scope when only referenced by a single function.

Bug: tint:1509
Change-Id: I04f7b8e1a8531a13317617604a49cafe4f7d47f1
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94001
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: David Neto <dneto@google.com>
2022-06-20 14:51:13 +00:00
James Price 46583621c0 tint: Refactor ModuleScopeVarToEntryPointParam
Split the main Process() function up into smaller functions to make it
less unwieldy.

Change-Id: Ibbe3141a82221879b9d4ed232eebdd0344f1698c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94000
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-06-20 12:39:33 +00:00
Ben Clayton a05e31b5af tint/resolver: Clean up parameter resolving
Change-Id: If5069575e319a1b04682596c2ab364b414300370
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93782
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-06-18 17:26:40 +00:00
dan sinclair 0a4e2a1373 Remove NOLINT lines from c++17 headers
The depot_tools cpplint.py has been updated to accept the c++17 headers
so we no-longer need to mark with NOLINT.

Bug: dawn:1379
Change-Id: I938a4cac5ca881cd1b556f4b8d58741b6a1e6af1
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94240
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
2022-06-18 14:34:00 +00:00
James Price c7f7ca3d9e tint: Simplify ++/-- handling in transform
Now that we have untyped literals, we can just add `1` rather than
adding either `1u` or `1i`.

Bug: tint:1488
Change-Id: I59512be8fc67b1bf45088478da7c93bed37a69b8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94141
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2022-06-18 14:22:15 +00:00
Zhaoming Jiang d713669329 Tint: Fix VectorizeScalarMatrixConstructors to run for ref to scalar
This patch make VectorizeScalarMatrixConstructors transform run for
reference to scalar as well as scalar types node, i.e. run for
`mat2x2<f32>(v[2])`, where `v` is a f32 vector, as well as
`mat2x2<f32>(1.0)`.

Bug: tint:1589
Change-Id: I5d3e367ee6a9826b3e1add3495aaac0ae326be14
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94023
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2022-06-17 15:36:59 +00:00
dan sinclair 889a499ef4 Remove test/tint/BUILD.gn.
This Cl moves the contents of the test/tint/BUILD.gn file into the
src/tint/BUILD.gn file. This moves the tests into the same build file as
what is being tested. This is more in line with how the CMakeLists.txt
file is setup.

This removes the need to update 2 BUILD.gn files when adding new files
and tests to tint.

Bug: tint:1517
Change-Id: I9beb8a8bff7c10ac875647246ad4362f7e60f7da
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94040
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2022-06-17 13:01:59 +00:00
Ben Clayton ecb46b33cc tint/resolver: Move texture validation to the right place
Validating sampled and multisampled texture types does not belong in Validator::Variable().

Change-Id: Ie0f2502508c28af6fb6d3f4d7803171d946c511b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93783
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-06-17 12:52:20 +00:00
Ben Clayton dcdf66ed5b tint/ast: Derive off `ast::Variable`
Add the new classes:
* `ast::Let`
* `ast::Override`
* `ast::Parameter`
* `ast::Var`

Limit the fields to those that are only applicable for their type.

Note: The resolver and validator is a tangled mess for each of the
variable types. This CL tries to keep the functionality exactly the
same. I'll clean this up in another change.

Bug: tint:1582
Change-Id: Iee83324167ffd4d92ae3032b2134677629c90079
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93780
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-06-17 12:48:51 +00:00
Zhaoming Jiang be6fb2a8d2 tint: Fix emitting vector constant in HLSL writer
This patch fix the issue that HLSL generator emit wrong constant
element index for vectors with all elements being the same, which may
cause error when emitting a matrix constant with sub columns having
identical elements.
Corresponding unit test is implemented.

Bug: tint:1588
Change-Id: Ia40b3f1a676d84aadaa5ce900677547fb15abe7f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94041
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2022-06-17 12:48:46 +00:00
dan sinclair 4b88dbcf8e Fixup continue support in while loops.
The generators were not setting `emit_continuing_` when emitting while
loops. This caused a crash when a `continue` was encountered. This CL
adds the `emit_continuing_` setup to the while emission. It also guards
the `emit_continuing_` usage with making sure the function is setup.

Bug: tint:1490
Change-Id: Ia89c49e567acda71a1f851a582103723cff71d49
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93960
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2022-06-16 15:27:38 +00:00
dan sinclair 57dcd3601c Fixup merge test issue
The while loop and let error message landed about the same time and there were
merging issues that didn't get caught by CQ.

Change-Id: I5cd606f1809cc29fa2366d3b78883fa0cfc3b394
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93961
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-16 13:44:38 +00:00
dan sinclair 49d1a2d950 Add while statement parsing.
This CL adds parsing for the WGSL `while` statement.

Bug: tint:1425
Change-Id: Ibce5e28568935ca4f51b5ac33e7a60af7a916b4a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93540
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
2022-06-16 12:01:27 +00:00
Ben Clayton 2a8861d20e tint: Rework errors around variable declarations
Standarize the messages, using 'let', 'override' or 'var'.

Module-scope 'let' needs to be replaced with 'const', but baby steps.

Bug: tint:1582
Change-Id: I290aede118a30ab0f4294c89ec43005371c87b45
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93446
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-16 08:36:30 +00:00
Zhaoming Jiang 418e873ad2 tint: Make sure enable directives go first in ordered_globals
This patch change DependencyAnalysis::SortGlobals() to make sure that
'enable' directive nodes go before any other global declarations in the
sorted global node list, and thus ensure that all extensions will be
registered by reslover before dealing with any other global declarations.
This is necessary because some transforms will add AST nodes before any
other global nodes, and these added nodes should be handled by resolver
after 'enable' nodes are handled.

Bug: tint:1472
Change-Id: Idc2253fc055b0f121cb0cafcaca5275c23ed7b0d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93760
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-06-16 08:30:17 +00:00
James Price 33563dc7d7 tint/transform: Move State to anonymous namespace
Copy/pasting this transform as a starting point for new transforms
causes the `State` classes to clash, and weird things happen. This
prevents that from happening.

Change-Id: Ia1c6b2b96e4d6375309aed535d7a87372b839792
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93880
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-16 08:28:22 +00:00
James Price 3e38d7effe tint: Remove support for smoothStep builtin
The new spelling `smoothstep` was introduced in M102.

Fixed: tint:1483
Change-Id: Ia5e1401f8f09450a3a767b0bb975216bd85be8db
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93360
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2022-06-15 23:32:14 +00:00
Ben Clayton 446b1a7df1 tint/clone_context.h: Template the vector allocator type
Currently nothing in Tint uses a different allocator type, but this
allows the CloneContext to support different allocators, the day we do.

Change-Id: I70367bd3710128d0708b3369f66b441344b789f8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93602
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-06-15 21:36:27 +00:00
Ben Clayton 2032d03400 tint/transform: Remove use of StorageClass on parameter
Parameters don't have storage classes or access qualifiers. This was
just (ab)using the fact that a parameter uses the same AST type as a
'var'.

Also simplify the parameter disable validation logic.

Bug: tint:1582
Change-Id: Ic218078a410f991e7956e6cb23621a94a69b75a3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93603
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-06-15 19:32:37 +00:00
David Neto 7bdeb49d64 Fix comment on constructor parameter
Change-Id: I29d19188f189d2c2ff7b70058782cf7a89e1dabd
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93820
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-06-15 16:49:37 +00:00
Ben Clayton 2ae29830db tint: Add ast::ParameterList, use it
This is currently identical to ast::VariableList, but once we break
ast::Variable up, this will become a different vector type.

Bug: tint:1580
Change-Id: Ib2db5772996a63cd1989e36f1034dc1fbd3b371a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93601
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-06-15 10:14:27 +00:00
Ben Clayton 7164b97272 tint: Clean up Func() usage
Drop the vector typename from the initializer lists. These don't really
provide any significant help in understanding the arguments types, as
the list of element types can be easily inferred.

This is done to simplify the refactor ast::VariableList ->
ast::ParameterList.

Bug: tint:1580
Change-Id: Ibf8564ca9b2bafd2eaa2e4aa54c29be6bbe7a682
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93600
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-06-15 10:02:37 +00:00
David Neto 93928b0d19 spirv-reader: Don't hoist builtin vars.
Fixed: tint:1577
Change-Id: I1decc99e4a5a293b49c24aa15d1ac6dd0287462e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93680
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Auto-Submit: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
2022-06-15 08:31:09 +00:00
Zhaoming Jiang cae289da70 tint: Fix exactly representable check in lexer
This patch fix two implicit type conversion to make Kokoro green.

Bug: tint:1473, tint:1502
Change-Id: I7f4d1d71e45a3d8e834625a9f71acc72a8816685
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93343
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-06-11 16:00:44 +00:00
Zhaoming Jiang 0fb4e2c608 tint: f16 literal in WGSL lexer and check subnormal f32/f16 hex literal
This patch
1. Add F16 literal support in WGSL lexer and parser for both decimal and
hex form. Also fix the f16::Quantize method to deal with subnormal cases
correctly.
2. Fix exactly-representable check for hex f32 literal to deal with
subnormal cases.
3. Implement and fix related unitests for f16 and f32.

Bug: tint:1473, tint:1502
Change-Id: Ia4a7c9144ef9323fb23b2200a64e1ca8afb6c334
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93100
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
Commit-Queue: David Neto <dneto@google.com>
2022-06-10 18:18:35 +00:00
Antonio Maiorano 856d6af57e tint: uniformity: detect pointers assigned to in non-uniform control flow
Bug: tint:1558
Change-Id: Ia92258f1fb40b008a6052ce2ea5a20ec29351ce5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93264
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2022-06-10 17:55:23 +00:00
dan sinclair 0fa572ff05 Emit deprecation warnings for @stage.
This PR enables the deprecation warnings for the @stage builtin.

Bug: tint:1503
Change-Id: I4a560f451a9ad56bc712f6a04c18eba6ae67ab64
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93121
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
2022-06-09 15:33:42 +00:00
Antonio Maiorano bd30d9e594 tint: uniformity: control flow reconverges after short-circuiting op when behaviour is {Next}
Bug: tint:1561
Change-Id: I685fe970f2c36d4ed39ba5fbe519736c031fbeca
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93160
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2022-06-08 16:01:01 +00:00
James Price a4666888a4 tint: Fix include layering violation
Headers exposing functionality from the core Tint library should be
included via include/tint/tint.h.

This fixes the google3 build.

Change-Id: I82a9d0105b3b44fb4c4c89b59e9282290dd49c61
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93120
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: James Price <jrprice@google.com>
2022-06-08 15:04:12 +00:00
dan sinclair b29892be09 Update src/tint unittests to new @stage format.
This CL updates all of the Tint unittests to the new @stage shorter
syntax. This also updates the WGSL writer to emit the new short forms
instead of using the deprecated form.

Bug: tint:1503
Change-Id: I8c49e5319a19cccb5b4b5078f3ab39c50f31a9a8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92483
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-06-07 13:55:34 +00:00
Ben Clayton 33fe68ee0f tint/resolver: Prevent ICE with invalid input
Attempting to return an abstract-numeric when the function had no return type would trigger an ICE, as an abstract numeric cannot materialize to a void type.

Bug: chromium:1332613
Change-Id: I635ebb8dddb2e7628939607a4f964be62b616745
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92720
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-06 15:11:04 +00:00
Antonio Maiorano f25140fe6f tint: fix emitting duplicate structs for atomicCompareExchangeWeak
Bug: tint:1574
Change-Id: Id4ae2d2de9ac4678260f4ecfb3a0f779d170f9a4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92280
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2022-06-03 14:47:01 +00:00
dan sinclair f0c150b01b Add parsing of shorter stage attributes.
This CL adds the ability to parse the `@compute`, `@fragment` and
`@vertex` attrbutes. The `@stage(...)` are still accepted and are not
marked as deprecated yet.

Most tests are still using `@stage(..)` except for a testing one.

Bug: tint:1503
Change-Id: I85cad5996605035e83109b021ffb13db98b1a144
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92480
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2022-06-03 02:47:40 +00:00
Ben Clayton c0af5c5c9c tint: Add builtin tests for arguments passed by var
Change-Id: I81b69d23e40675d7f525e6369afec9aa0659d043
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92321
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-06-02 14:36:10 +00:00
Ben Clayton 451eee0fed tint: Stub intrinsic @const evaluation
Add support for @const to builtins in intrinsics.def.
Propagate this flag through to the intrinsic table.
Handle builtins that are @const annotated in the resolver.

Currently no intrinsics are decorated with @const, so there's nothing to
test (yet).

Bug: tint:1504
Change-Id: I172483688617782bd7c58b70e3f38d0222a5d1af
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92323
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2022-06-01 23:57:20 +00:00
Ben Clayton e0cd855aa2 tint/writer/spirv: Tweak builtin tests to use 'var's
If the builtin has values passed by literal, let or const, then they may
be evaluated at shader-creation time, which makes the tests almost useless.

Bug: tint:1504
Change-Id: I004f49ec4b3430c8015e65d3fde1f5fa4fdd10f9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92322
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-06-01 22:21:40 +00:00
Ben Clayton e3e91c0d75 tools: intrinsic-gen - [[decoration]] -> @attribute
More closely resembles WGSL.

Change-Id: Ia1b93bb443b4e3bf9329f8026d1924f12648cb7b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92245
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2022-06-01 20:44:50 +00:00
Ben Clayton 0d757d2fad tint/resolver: Enable abstract-numerics
Turn on resolving of abstract-integer and abstract-float types, as well
as materialization to their concrete types.

Bug: tint:1504
Bug: chromium:1330805
Fixed: tint:1572
Change-Id: I09c95406e11b64bb0267fe7b1ed08af986dbd553
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91840
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-06-01 20:34:40 +00:00
Ben Clayton e593585e21 tint/transform: Remove FoldConstants
No longer used.

Bug: tint:1504
Change-Id: I48548afc421a2658b5367125bd63c80a7f4bc87f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92084
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-01 16:04:19 +00:00
Ben Clayton a20ef0c0f1 tint/sem: Fix Constant constructor with initializer_list
This was always constructing the elements with AFloat, when it should pick between AInt / AFloat based on the type T.

Bug: tint:1504
Change-Id: I2dd4a9bcd829c47c9b0e8d730c5f58a5266d3626
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92240
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Zhaoming Jiang <zhaoming.jiang@intel.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-06-01 15:58:27 +00:00
Ben Clayton 8e3485248e tint/writer/spirv: Inline constant expressions
This is required to handle materialized values, and for constant
expressions.

Bug: tint:1504
Change-Id: If0a49e9b03566c06aa6e4e4c284fc427e1541e91
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92082
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-06-01 15:57:22 +00:00
Ben Clayton 609ce6de8d tint/sem: Consider sign bit for Constant helpers.
Constant::AnyZero(), Constant::AllZero() now consider -0.0 as non-zero,
as this is different from WGSL's zero-initializer value for floating
point numbers.

Also consider FP sign for Constant::AllEqual().

Bug: tint:1504
Change-Id: I00503880ee29bd741b94cc98909a8a823e32522a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92243
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2022-06-01 15:35:50 +00:00
Ben Clayton e9f8b09063 tint/writer/hlsl: Inline constant expressions
This is required to handle materialized values, and for constant
expressions.

Bug: tint:1504
Change-Id: I79ad567954de2d1cfea09dda255894e4e2aa678e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92081
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-06-01 13:14:39 +00:00
Zhaoming Jiang 84b48cf30c Tint: num_workgroups use free binding group if not specified
In this patch NumWorkgroupsFromUniform::Config changed to storage
std::optional<sem::BindingPoint>, and if it has no value,
NumWorkgroupsFromUniform will choose a free binding group, i.e.
binding 0 of the largest used group plus 1 is used if at least one
resource is bound, otherwise group 0 binding 0 is used. Tint CLI
is also changed to provide a --hlsl-root-constant-binding-point
option allowing user to specify the binding point for num_workgroups
uniform buffer.

Bug: tint:1566
Change-Id: I3b8c22a4276bab722d901f5b07d23a268786c417
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91980
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
2022-06-01 10:23:51 +00:00
Ben Clayton cb6ddd2aa6 tint/writer/msl: Inline constant expressions
This is required to handle materialized values, and for constant
expressions.

Bug: tint:1504
Change-Id: Ic3ac62317241fa6f7009360128f222aeb56f62e4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92083
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-06-01 10:08:29 +00:00
Ben Clayton 25b7e98d11 tint/writer/glsl: Inline constant expressions
This is required to handle materialized values, and for constant
expressions.

Bug: tint:1504
Change-Id: Ie0177f148e08a0e1a3f4d7e06e283f121655804b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92080
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2022-06-01 01:11:59 +00:00
James Price 37d92ca244 tint/spirv: Fix atomicCompareExchangeWeak
We were missing an `UnwrapRef` when generating the return type, and
were generating invalid SPIR-V when the value being stored was a
reference. The auto-generated builtin tests only test with literal
values.

Fixed: tint:1573
Change-Id: If42280b3cc8ad3fba7355d333e02400c6db843fa
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/92144
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
2022-06-01 00:03:29 +00:00
Ben Clayton 7e495d8f2e tint/resolver: Implement candidate overload resolution
Once abstract-numerics are supported, we encounter our first ambiguous
overloads which need resolving. Implement this.

Bug: tint:1504
Change-Id: I79ade04ac3c7ae754b92cb0691b46f449766824a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91964
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-05-31 21:46:19 +00:00
Ben Clayton bfb5fd794c tint/sem: Add more helpers to Constant
Many backends can produce cleaner code if all the elements are zero or
the same value.

Bug: tint:1504
Change-Id: Iff3227884473b0be42395e4a637a7fe0b7a1b238
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91966
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-05-31 21:23:29 +00:00
Ben Clayton 8bd5fec482 tint/writer/wgsl: Emit 'f' suffix on FloatLiteralExpressions
If the literal was constructed with an 'f', make sure we print it.

Bug: tint:1504
Change-Id: I6f04e31a166919c07574db56b0a2063ce5b8ca5c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91965
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-05-31 20:45:59 +00:00
Ben Clayton 22bd004409 tint/resolver: Materialize RHS of non-phony assignments
Phony assignments do not materialize the RHS.
See: https://github.com/gpuweb/gpuweb/pull/2968

Bug: tint:1504
Change-Id: I29bb15e813d2b01876b5ec670c31b7aff3230986
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91963
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-05-31 20:40:59 +00:00
Ben Clayton 649d3d9602 tint/resolver: Materialize array size expression
Bug: tint:1504
Change-Id: If67228f18b26f718689f641beae95d281baf9c0c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91962
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-05-31 18:11:34 +00:00
Ben Clayton 49a09140b9 tint/resolver: Materialize array index expression
Bug: tint:1504
Change-Id: Ib14f4aa8ed7ca9d4bc4cdf6f4acdfa7eec03b716
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91961
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-05-31 15:22:21 +00:00
Antonio Maiorano 08f4b557fc Implement atomicCompareExchangeWeak returning struct instead of vec2
Also fixed implementation of this atomic in GLSL. It was emitting code
that would not compile because, as for HLSL, we must pass in the
variable directly to atomic funcs, not via an in/out arg to a function.

Bug: tint:1185
Change-Id: Id0e9f99d6368717511ef3a94473634c512e10cb8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91881
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2022-05-31 13:20:28 +00:00
Ben Clayton 61537d3f57 tint: Add Checked[Add|Mul|Madd]()
Test-for-overflow utilities for AInt.

Bug: tint:1504
Change-Id: I974ef829c72aaa4c2012550855227f71d4a370a0
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91700
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-05-31 13:14:29 +00:00
dan sinclair 61d76ebb5c Update some forward declarations.
This CL removes some forward declarations which are no longer needed
and adds one missing declaration which was pulled in from other headers.

These were found by the clang-tidy bugprone-forward-declaration-namespace
check.

Bug: dawn:1414
Change-Id: I8906861e472f2d64a1547c8c6de348cd4151ffb5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91742
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
2022-05-30 18:00:58 +00:00
Ben Clayton 8b09bc97c0 tint: Lex abstract integers
Check that the parsed number fits in an abstract-integer.

Refactor the unit tests so that they're maintainable. Add missing tests.

Bug: tint:1504
Change-Id: I04b6604820d527da66e3f6fcb47391efc0c3330a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91701
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
2022-05-30 17:54:38 +00:00
Ben Clayton b8ac933909 tint/resolver: Materialize arguments to @workgroup_size
Bug: tint:1504
Change-Id: I69b448e62a4ebd684f6832f76fd28d8a31892a1a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91847
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-05-28 10:34:06 +00:00
Ben Clayton 8c7ffbd9d5 tint/resolver: Materialize argument to bitcast
Bug: tint:1504
Change-Id: I4eb4f041e69154dccd9719746a30dd6963dcd252
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91846
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2022-05-28 07:09:17 +00:00
Ben Clayton 3a236c6c51 tint/resolver: Add tests for implicit type materialization
These are tests for when there's no explicit target type for a
materialization. In this case we expect an abstract-int to
materialize to an i32 and an abstract-float to materialize to a
f32.

Fix a bug uncovered where we were creating a transposed matrix.

Bug: tint:1504
Change-Id: Ie69dd7ec47174d3d7bef20315fd3780dade3a325
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91845
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-05-28 05:28:11 +00:00
Ben Clayton 3aa0f8182b tint/resolver: Rename test field names, update comments
Try and make things a little clearer.

Change-Id: I66b051e71d4fc8366afe8b2b90067c7c0708d7cc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91844
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2022-05-27 22:06:26 +00:00
Ben Clayton eac0566718 tint/resolver: Make Materialize() handle nullptr expressions
Simplifies common usage

Bug: tint:1504
Change-Id: I901c512388b0793a0b27b2bb0e40169e815342f2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91843
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-05-27 21:39:56 +00:00
Ben Clayton 572eaf271e tint: Remove ConversionFailure::kTooSmall
Nothing errors on this. Simplifies code.
Also: Disable MSVC warnings about constant overflow.

Fixed: tint:1564
Change-Id: I5bb2c2ebb89966f5b3f7cbcd73672e110b1b98cd
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91622
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-05-27 20:22:26 +00:00
Ben Clayton 4b04721075 tint/resolver: Ensure that validation is done before CollectTextureSamplerPairs()
CollectTextureSamplerPairs() makes assumptions that the argument types are correct. If they're not, you can end up with NPEs.

Bug: chromium:1327698
Change-Id: Ic9b14126c4b7129bb080f01c90f692b59cd1631e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91850
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-05-27 20:16:26 +00:00
Ben Clayton aff5e9e722 tint/reader/wgsl: Error if a hex float is not exactly representable
Fixed: tint:1564

Change-Id: I3ba8d13055fd279868fcca9e7f8576a279b6902c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91429
Reviewed-by: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-05-27 18:29:26 +00:00
Ben Clayton e6c03a3799 tint/reader/wgsl: Lex abstract floats
And remove lexer errors about float magnitudes been too small.

Also add tests for non-hex float literal overflow.

Bug: tint:1504
Bug: tint:1564
Change-Id: Ia26817d4f2a99af694e9935692b98ef91f97d2b3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91428
Reviewed-by: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-05-26 19:39:05 +00:00
Ben Clayton a644c3d835 tint/reader/wgsl: Use C++17 hex floats for tests
C++17 supports hex float literals. Use these to simplifty the test expectations.

Bug: tint:1504
Change-Id: Id47b0963da93f3b5da261c72fe863e791c16af1f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91427
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-05-26 17:40:15 +00:00
Ben Clayton 30f01c1790 tint/reader/wgsl: Lex abstract hex floats
Scale up the hex float parsing to support doubles.

Also make it an error if the hex float resolves to an inf or NaN.
See: https://github.com/gpuweb/gpuweb/issues/2953

Bug: tint:1504
Change-Id: Ie923bb5f660285fb7563cfe8dafa07d87b898a7e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91426
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2022-05-26 17:01:22 +00:00
Ben Clayton 09373989ec tint: Clamp constants to type's limits when number is unrepresentable
When converting values between two concrete types, handle the case that
the value is unrepresentable by the target type.

For integers, the converted value will be either the maximum or minimum
value for the integer type.

For floats, the converted value will be positive or negative infinity.

Bug: tint:1504
Change-Id: Ia56fb8170c0ea994632194f166062823d9507249
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91621
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
2022-05-26 08:31:45 +00:00
Jiawei Shao ce6adf4c67 tint: Implement DP4a on SPIR-V writer
Bug: tint:1497
Test: tint_unittests
Change-Id: Id0aa2cedb5de1a2f3139b1f67c320ac78f93aa57
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91500
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-05-26 00:25:04 +00:00
Ben Clayton 8ae9e94344 tint/reader/wgsl: Restructure Lexer::try_hex_float() constants
No-op change. Just makes it easier to migrate to float64.

Bug: tint:1504
Change-Id: Ice5bf40514bc7f7faf30e51e4b1e22e6cf2375ad
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91424
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-05-25 23:42:04 +00:00