Commit Graph

431 Commits

Author SHA1 Message Date
Ben Clayton 91785d277b resolver: Fix bug in dep graph SortGlobals()
If we encounter a global twice, the stack vector was not popped, which could trigger false cyclic-dependency errors. Because the cyclic dependency did not actually exist, later logic could break, expecting to find a global->global edge which did not exist.

Fixed: chromium:1273451
Change-Id: I9d99f1aeeaea042d9ed847a878c4717803122240
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70980
Reviewed-by: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-11-25 18:07:57 +00:00
Ben Clayton 0079a597e6 test: Add a test case for tint:1321
It's surprising that the fuzzers didn't find this, but I've confirmed that at least one of the fuzzers will fail with this case.
By adding a e2e test case, this will be used as a seed for the fuzzer corpus.

Bug: tint:1321
Change-Id: Ibf4bfa50bf376ae4cba401dfc31a2498fa3b9eec
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70982
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-11-25 18:02:36 +00:00
Ben Clayton e0a560c8da transform: Don't consider type-ctor/casts as having side-effects
RemovePhonies was transforming:

_ = f32(1)
_ = vec2<f32>(1.0, 2.0)

into:

f32(1)
vec2<f32>(1.0, 2.0)

Which the resolver gets grumpy about, as these are expressions, not statements.

Fixed: chromium:1273230
Change-Id: Ie85d3cee705fa3f792db686c021d76331e241f17
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70960
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Ben Clayton <bclayton@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
2021-11-25 16:10:28 +00:00
Ryan Harrison 1c1b9762ce Add tests for fuzzers::RandomGenerator
BUG=tint:1019

Change-Id: Ia462080877a97348c5589bfa71231a832a7ebfd3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70081
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-11-24 14:55:05 +00:00
Ben Clayton b05e185a36 resolver: Support shadowing
Add transform::Unshadow to renamed shadowed symbols. Required by a
number of other transforms.

Replace Resolver symbol resolution with dep-graph.

The dependency graph now performs full symbol resolution before the
regular resolver pass.
Make use of this instead of duplicating the effort.

Simplfies code, and actually performs variable shadowing consistently.

Fixed: tint:819
Bug: tint:1266
Change-Id: I595d1812aebe1d79d2d32e724ff90de36e74cf4b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70523
Reviewed-by: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-11-23 20:45:51 +00:00
Ben Clayton e524ee1813 transform: Combine InlinePointerLets and Simplify
They are always used together, and can actually be simplified when
combined.
This transform cannot currently deal with shadowing, and will need
need to depend on a new 'unshadow' transform.

Fixes a long-standing bug where we'd get an ICE if we attempt to inline
a pointer let declaration with side-effects in a for-loop initializer.

Fixed: tint:1321
Bug: tint:819
Change-Id: I236fed688e33a4996e47310b5ece44c991b5249f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70661
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-11-23 20:45:51 +00:00
Ben Clayton a40e45522b intrinsics: Deprecate isNan, isInf, isFinite, isNormal
These have all been removed from the spec as we cannot guarantee they will behave as expected on the various backends.

Bug: tint:1312
Change-Id: I9d7d81cfdc44489fffe08c5183ed8da84901a024
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70665
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-11-23 18:57:57 +00:00
Ben Clayton 7cff4c8745 test: Update expected output of FXC bug
Looks like this should have been part of bc5d8f6b

Bug: tint:1112
Change-Id: I62e98bbb5f8ca29a171d5d5baa65af55b3a090d4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70664
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-11-23 18:57:57 +00:00
Ben Clayton 1185d61648 utils: Add Lookup()
A find or return-default utility.
Rename `find_or_replace.h` to `map.h` which contains both these utilties that operate on maps.

Change-Id: Iaa76ea3f5c5a1210e413c131dd0556c126ee5d0a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70521
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-11-23 18:37:37 +00:00
David Neto e85efca13f storageBarrier() has workgroup memory scope
The storageBarrier() builtin causes flushes to be visible to
all invocations within a workgroup, not the whole device.
The limitation is inherited from Metal.

Fixes: tint:1310
Change-Id: I6f94faa88bd3c7b6cec0601312c6c65a907c5973
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69800
Auto-Submit: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-11-22 20:47:37 +00:00
Antonio Maiorano bc5d8f6bcf Revert "HLSL: force FXC to never unroll loops"
This reverts commit 11d09f2fe7.

Reason for revert: Failing roll of Tint to Dawn: https://dawn-review.googlesource.com/c/dawn/+/70100

Original change's description:
> HLSL: force FXC to never unroll loops
>
> Emit the "[loop]" attribute on "for" and "while" so that FXC does not
> attempt to unroll them. This is to work around an FXC bug where it fails
> to unroll loops with gradient operations.
>
> FXC ostensibly unrolls such loops because gradient operations require
> uniform control flow, and loops that have varying iterations may
> possibly not be uniform. Tint will eventually validate that control flow
> is indeed uniform, so forcing FXC to avoid unrolling in these cases
> should be fine.
>
> Bug: tint:1112
> Change-Id: I10077f8b62fbbb230a0003f3864c75a8fe0e1d18
> Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69880
> Kokoro: Kokoro <noreply+kokoro@google.com>
> Reviewed-by: Ben Clayton <bclayton@google.com>
> Commit-Queue: Antonio Maiorano <amaiorano@google.com>

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: tint:1112
Change-Id: I8e8f3c0abfa6e6bc5d0e67af9428a46ef867d5c1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70540
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-11-22 19:31:56 +00:00
Stephen White 7368e287dc GLSL: fix single-valued vector init.
No need for the HLSL-style repeated swizzle; GLSL allows construction
of a vector from a scalar value of the component type.

Bug: tint:1317

Change-Id: Ia0afe3012cbb56716a2d1c5c3849dd662a5ff89c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70342
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
2021-11-22 16:14:16 +00:00
Ben Clayton 177e7bfa5d IntrinsicTable: remove double underscores
'__' is reserved in C++, and the 'match__' and 'build__' functions are causing OSS-fuzz builds to fail.

Add the change in tint behavior to the OT notes.

Add end to end tests for underscores. While the GLSL and MSL compilers seem to accept leading and double underscores in identifiers, the tint build failure has highlighted we have more work to do here (crbug.com/tint/1319)

Fixed: oss-fuzz:41214
Bug: tint:1292
Bug: tint:1319
Change-Id: I32b7bf4e0cff26e678b788457f90452c2503da50
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70480
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-11-22 15:24:16 +00:00
Ben Clayton 4183051b54 resolver: Add dependency-graph analysis
Performs a module-scope (global) declaration dependency analysis, so
that out-of-order global declarations can be re-ordered into dependency
order for consumption by the resolver.

The WGSL working group are currently debating whether out-of-order
declarations should be included in WebGPU V1, so this implementation
currently errors if module-scope declarations are declared out-of-order,
and the resolver does not currently use this sorted global list.

The analysis does however provide significantly better error diagnostics
when cyclic dependencies are formed, and when globals are declared
out-of-order.

The DependencyGraph also correctly now detects symbol collisions between
functions and types (tint:1308).

With this change, validation is duplicated between the DependencyGraph
and the Resolver. The now-unreachable validation will be removed from
the Resolver with a followup change.

Fixed: tint:1308
Bug: tint:1266
Change-Id: I809c23a069a86cf429f5ec8ef3ad9a98246766ab
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69381
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2021-11-22 11:44:57 +00:00
James Price 1bf5af25ad reader/wgsl: Allow identifiers to start with an underscore
Try to lex identifiers before punctuation, and backtrack if we only
see a single underscore or something that starts with two underscores.

Rename the modf and frexp return types to start with two underscores.

Spec PR:
https://github.com/gpuweb/gpuweb/pull/2326

Change-Id: Id283af100babfe84faa183345cb8a60848140caa
Fixed: tint:1292
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70160
Reviewed-by: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
2021-11-19 21:52:13 +00:00
Stephen White 0ff3050c6c GLSL: a grab bag of texture fixes.
Use imageSize() on images, not textureSize().
In GLSL, the LOD parameter to textureSize() is mandatory for
sampled textures, so emit a default 0 if not supplied. (Also, don't pack
the level into the coords argument; that's an HLSLism.)
GLSL returns the array size of array textures in the final component
of textureSize(); remove it for WGSL.
Write the subtype of storage images correctly (uimage*, iimage*, etc).
This required a bit of cleanup to move "writeonly" ahead of subtype
emission.

Bug: tint:1298
Change-Id: Ica1cec0f833a9b684143c8b0cf6d090fb511a7d2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70140
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-11-19 19:06:23 +00:00
Antonio Maiorano a52059e189 Add end-to-end test for tint:1112
I meant to add this to this CL:
https://dawn-review.googlesource.com/c/tint/+/69880

Bug: tint:1112
Change-Id: I7b5a3ab068ddbce1650a9e00609fed11e32db17d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70320
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-11-19 18:33:23 +00:00
Stephen White 943c410d51 GLSL: implement atomics.
Bug: tint:1314

Change-Id: Ic7a88761752d2db3374be043c94f02fd20684c03
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69560
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
2021-11-19 17:46:13 +00:00
Austin Eng 38fa643702 Add HLSL/MSL generator options for ArrayLengthFromUniform
ArrayLengthFromUniform is needed for correct bounds checks on
dynamic storage buffers on D3D12. The intrinsic GetDimensions does
not return the actual size of the buffer binding.

ArrayLengthFromUniform is updated to output the indices of the
uniform buffer that are statically used. This allows Dawn to minimize
the amount of data needed to upload into the uniform buffer.
These output indices are returned on the HLSL/MSL generator result.

ArrayLengthFromUniform is also updated to allow only some of the
arrayLength calls to be replaced with uniform buffer loads. For HLSL
output, the remaining arrayLength computations will continue to use
GetDimensions(). For MSL, it is invalid to not specify an index into
the uniform buffer for all storage buffers.

After Dawn is updated to use the array_length_from_uniform option in the
Metal backend, the buffer_size_ubo_index member for MSL output may be
removed.

Bug: dawn:429
Change-Id: I9da4ec4a20882e9f1bfa5bb026725d72529eff26
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69301
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
2021-11-19 04:11:33 +00:00
Antonio Maiorano 11d09f2fe7 HLSL: force FXC to never unroll loops
Emit the "[loop]" attribute on "for" and "while" so that FXC does not
attempt to unroll them. This is to work around an FXC bug where it fails
to unroll loops with gradient operations.

FXC ostensibly unrolls such loops because gradient operations require
uniform control flow, and loops that have varying iterations may
possibly not be uniform. Tint will eventually validate that control flow
is indeed uniform, so forcing FXC to avoid unrolling in these cases
should be fine.

Bug: tint:1112
Change-Id: I10077f8b62fbbb230a0003f3864c75a8fe0e1d18
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69880
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-11-18 13:50:12 +00:00
Stephen White 1704fe53f5 GLSL: implement inf, nan.
Use uintBitsToFloat.

Bug: tint:1306
Change-Id: Ie9a5e14c13c0d63b57c126f16c4e2a5c7a77e3f7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69740
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
2021-11-18 13:11:43 +00:00
Ben Clayton 8085671ed2 test: Add missing cases for UBO dynamic loads
Looks like a typo in the test cases I wrote.

Change-Id: Ieb4d8ce28827e47ab0baef7b1178395d97f90ace
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69841
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-11-17 14:54:07 +00:00
Brandon Jones bf7ec8f70b Add MultiplanarExternalTextureTransform and Tests
Implements MultiplanarExternalTextureTransform to allow transforming a
texture_external binding into two texture_2d<f32> bindings and a uniform
buffer binding. Transforms textureSampleLevel and textureLoad calls with
a texture_external parameter into custom functions that can handle both
single-plane RGBA or bi-planar YUV. Includes tests.

Bug: dawn:1082
Change-Id: Icb6d8b0f3773feca01c833171f07230c3531f3aa
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68620
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-11-17 12:10:16 +00:00
Stephen White ae4487f3f9 GLSL: rename all identifiers prefixed with gl_.
In GLSL, all identifiers beginning with gl_ are reserved (not just those
explicitly named in the spec), and so any found in WGSL must be renamed.

Bug: tint:1304
Change-Id: I92ed7ec674620f67775378ecb8debcfdb4b5bbb4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69701
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
2021-11-16 19:13:36 +00:00
Stephen White b9170c65fc GLSL: fix vector relational ops.
In GLSL, relational operators are only valid for scalar operands. For
vector operands, lessThan, greaterThan, etc must be used.

Bug: tint:1303

Change-Id: Ia800f89111630c756dc1b30ef0c6858fb520fb16
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69561
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-11-16 16:16:56 +00:00
Stephen White 2fe0f4b42b GLSL: add .expected.glsl files for all tests.
Bug: tint:1301
Change-Id: Id3a591a2fa0dfdb112046d5c57defbae07483e0d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69480
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
2021-11-16 15:15:36 +00:00
Ben Clayton 8492d727a7 test: Shuffle files around.
In an attempt to better follow the guidelines in docs/end-to-end-tests.md.

Change-Id: Id012004e8a376598bb69cf364ca7ca0735632a2e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69342
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-11-15 20:45:50 +00:00
Ben Clayton 735dca8393 ast: Remove TypeConstructorExpression
Add a new 'Target' to the ast::CallExpression, which can be either an
Identifier or Type. The Identifier may resolve to a Type, if the Type is
a structure or alias.

The Resolver now resolves the CallExpression target to one of the
following sem::CallTargets:
* sem::Function
* sem::Intrinsic
* sem::TypeConstructor
* sem::TypeCast

This change will allow us to remove the type tracking logic from the WGSL
parser, which is required for out-of-order module scope declarations.

Bug: tint:888
Bug: tint:1266
Change-Id: I696f117115a50981fd5c102a0d7764641bb755dd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68525
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-11-15 20:45:50 +00:00
Ben Clayton a539d8d33c utils: Add utils::Transform
An element-wise vector transformation utility function.
Similar to JS/TS's map() method on arrays.

Change-Id: I4baf52daa918f2e7bf5f9b4af13894fe66826f7c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69103
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-11-12 13:04:06 +00:00
Ben Clayton e7a94965c1 BUILD.gn: Fix gn check error
The 'tint_unittests_src' source_set needed to depend on gmock_and_gtest,
which is normally done with the 'tint_unittests_source_set' template,
but this is the root source_set for the unit tests.
To fix, these root-level sources have been moved to
'tint_unittests_core_src' which uses the 'tint_unittests_source_set'
template.

Change-Id: I0d76c55c744646fd7deff22406a668f8c6cdf519
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69220
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
Kokoro: Ben Clayton <bclayton@google.com>
2021-11-12 11:33:17 +00:00
Ben Clayton 3fe243b282 BUILD.gn: Split up unit tests into separate source sets
Prevents errors when we have the same _test.cc file in two different
directories.

Change-Id: I62eaea9452762670b7a24cdb2d7b0bef4fe52280
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/69102
Kokoro: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-11-11 16:23:55 +00:00
Antonio Maiorano 8bc1a3045d HLSL: workaround FXC sometimes failing with 'not all control paths return a result' in functions with discard
To fix this, we trick the compiler by wrapping the function body with an
if (true) { <function body> } followed by returning an unused value of
the return type.

Bug: tint:1081
Change-Id: I763bf768f40d07a1045f0a70017bb40d488c8428
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68822
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-11-10 14:38:34 +00:00
Ben Clayton a838bb718b ast: Rename ArrayAccessorExpression to IndexAccessorExpression
The object is not always an array. The index can be applied to vectors
too.

Change-Id: Ifb63d1862090d28cb48d692870e9dd01ddbce5df
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68841
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-11-09 09:35:00 +00:00
Ben Clayton 30848b6594 ast: Add 'Expression' suffix to literals
Literals are now expressions, so in keeping with all the other
expression types, suffix the class name with Expression.

I'm not overly keen on requiring everything to have an Expression
suffix, but consistency is better than personal preference.

Bug: tint:888
Change-Id: Ida1f1b98c71d5d0fe6399bca938010cd5d3a00c3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68840
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-11-09 09:35:00 +00:00
Ben Clayton 575c4efe2f Remove ScalarConstructorExpression
Just make Literal an expression. The ScalarConstructorExpression
provides no real value, aside from having a ConstructorExpression base
class that's common between ScalarConstructorExpression and
TypeConstructorExpression. TypeConstructorExpression will be folded into
CallExpression, so this hierarchy will serve no purpose.

First step in resolving the parser ambiguity of type-constructors vs
type-casts vs function calls.

Bug: tint:888
Change-Id: I2585d5ddbf6c0619a8f24c503e61ebf27c182ebe
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68524
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-11-09 09:35:00 +00:00
Antonio Maiorano f3f8ec3845 Update test expectation files
Some pass DXC, but not FXC (e.g. continue_in_switch).
Some now pass (e.g intrinsics/gen/atan2/*.hlsl)
Some now fail gracefully instead of asserting (e.g. 807.spv)

Change-Id: I92b17fcadc7850de5bd93ff07507cea7e5487fc9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68820
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2021-11-08 20:16:48 +00:00
Antonio Maiorano 02acf59184 HLSL backend: work around FXC ignoring switch with only default case
In HLSL code, if a switch statement has only a default case, FXC will
effectively ignore the code in that case. In this change, we detect this
and work around it by emitting the code in the default block without the
switch.

Bug: tint:1188
Change-Id: I69b405cdb4c669fb093eb49aa138923419dcf8f8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68440
Kokoro: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
2021-11-05 20:39:07 +00:00
Ben Clayton 189dc7d3fd instrinsics: Implement dot() for integer vector types
Fixed: tint:1263
Change-Id: I642ea0b6c9be7f04930cf6ea1a8059825661e326
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68520
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-11-05 18:37:16 +00:00
Ben Clayton a9156ff091 Rework Resolver so that we construct semantic types in a single pass.
The semantic nodes cannot be fully immutable, as they contain cyclic
references. Remove Resolver::CreateSemanticNodes(), and instead
construct and mutate the semantic nodes in the single traversal pass.

Give up on trying to maintain the 'authored' type names (aliased names).
These are a nightmare to maintain, and provided limited use.

Significantly simplfies the Resolver, and allows us to generate more
semantic to semantic references, reducing sem -> ast -> sem hops.

Note: This change introduces constant value propagation across constant
variables. This is unlocked by the earlier construction of the
sem::Variable.

Change-Id: I592092fdc47fe24d30e512952511c9ab7c16d7a1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68406
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
2021-11-05 16:51:38 +00:00
James Price 85170d76bc Disallow taking the address of a vector component
Update or remove tests that try to do this.

Fixed: tint:491
Change-Id: I1f351a4abf68ae9bc6b100885fb1bcea08b31211
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68242
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-11-04 19:55:57 +00:00
James Price def9d97609 spirv-reader: Sink pointer-to-vector-component
WGSL does not support pointer-to-vector-component, so the SPIR-V
reader needs to sink these pointers into their use.

Bug: tint:491
Change-Id: Ib5ae87d2f6bbac13280314ba11369d7ced505b56
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/68241
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
2021-11-04 19:55:57 +00:00
James Price e548db90f6 msl: Handle buffer variables in transform
This removes a lot of awkward logic from the MSL writer, and means
that we now handle all module-scope variables with the same transform.

Change-Id: I782e36a4b88dafbc3f8364f7caa7f95c6ae3f5f1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67643
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-10-28 15:00:39 +00:00
Ben Clayton 6c4effe654 writer/spirv: Fix [[override]] for zero-init defaults
These expressions were not emitted as spec-ops, failing new CTS tests.

Change-Id: I56e8f56a22de2b8dac9a8bd7a2d694d8d81dca35
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67480
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
2021-10-26 10:05:02 +00:00
James Price 91689fb6f0 Add support for matrix construction from scalars
Use a transform to convert these to the vector form for the MSL and
SPIR-V backends.

MSL only has the scalar form from version 2.0 onwards.

Fixed: tint:1123
Change-Id: I384abd9872d9eae52a10a37cbd6aa96004692e9c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67360
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-10-25 19:20:31 +00:00
Ben Clayton c73b57f2c6 Address late review comments from 67064
Use spec-spelling of 'constructible'.
Add missing test file to 'test/BUILD.gn'

See https://dawn-review.googlesource.com/c/tint/+/67064

Change-Id: Ie39773617fd0a363d63cc6449bf3905c9eb6786d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67380
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-10-25 14:26:55 +00:00
Ben Clayton 33c13c6e28 writer/hlsl: Do not emit `(void) call_expr;`
Just emit `call_expr;` instead.

Fixed: tint:1259
Change-Id: I84a2976d82f891e9263f3e11e5774fcb01ea09bd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67381
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-10-25 11:00:44 +00:00
Ben Clayton 7b776f18b0 Deprecate Ignore()
It's been removed from the spec:
https://github.com/gpuweb/gpuweb/pull/2127

Fixed: tint:1213
Change-Id: I163fe807765bb1ac0580b398f4897daea555216a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67067
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-10-22 06:23:12 +00:00
Ben Clayton c2fa68e551 Migrate more tests from Ignore() to phony-assignment
The `Ignore()` intrinsic is about to be deprecated, so don't use it for testing.

Bug: tint:1213
Change-Id: I314ecaeb9a9c337c7b6980189054120a74807ebd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67066
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
2021-10-22 00:21:44 +00:00
James Price a41694e9a3 validation: Allow interpolate(flat) on integral IO
Produce a warning if the attribute is missing for integral vertex
outputs or fragment inputs. This will become an error in the future,
as per the WGSL spec.

Add the attribute to E2E tests.

Bug: tint:1224
Change-Id: Ia1f353f36cb7db516cf9e8b4877423dec3b3e711
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67160
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2021-10-21 23:08:44 +00:00
Ben Clayton 1aa98e62c0 Implement phony assignment
Bug: tint:1213
Change-Id: Ib1ebc4947405c4ada7a9bdbc6bd5a36447bbd234
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67064
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-10-21 23:04:44 +00:00