When an initializer is present, use type inference instead of
explicitly typing `var` and `let` declarations. This reduces the size
of the generated WGSL and improves readability.
Change-Id: I241ee2108279b550735945940f2b62bbbd493708
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132142
Commit-Queue: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: David Neto <dneto@google.com>
Change-Id: I4f8ff98b980d9dd9a89e7e4407f6e1cbd1eaaf0a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132320
Kokoro: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: James Price <jrprice@google.com>
An OpName decoration for a result ID may end up unintentionally
shadowing a WGSL builtin function.
Fixed: tint:1932
Change-Id: I1b1302629c69b7bdf7a0a0c97d3ad6ce3d0d587b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132080
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Unwrap sem::Materialize as well as sem::Load when looking for users of
a renamed declaration.
Fixed: tint:1934
Change-Id: I7d5ade1f902dbdb4cf3b4f7552b78359f5b3ea9a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132060
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
When traverseing an accessor expression, stop as soon as we hit a
source object that has a constant value. This prevents us from trying
to emit expressions that have abstract types and no materialization
nodes.
Bug: chromium:1442551
Change-Id: I8296ae58e63624e647052cdf966dbff15630a4d8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132040
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This makes the generated WGSL more concise and readable.
Change-Id: I78a722b9a86264d3bbf219445628dc5597cbfd62
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132141
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: David Neto <dneto@google.com>
This makes the generated WGSL more concise and readable.
Change-Id: Ia486a74796a4029aaac1c4d051d304d05f1d5ea2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132140
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: James Price <jrprice@google.com>
The BuiltinPolyfill transform expects the DirectVariableAccess transform
to run after it, but this regressed as part of
https://dawn-review.googlesource.com/c/dawn/+/122203
Add unit test along with e2e 1926.wgsl test.
Bug: tint:1926
Change-Id: I5107453ce152b12e6f2f36930846e1fffa775708
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/131020
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Allow the resolver to understand builtin structures, like
__frexp_result_f16. This allows backend transforms to declare the types,
even if they're "untypable" by the user.
Bug: chromium:1430309
Change-Id: I392709118182a058f737ccf1b7b46fc6b0b7264d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/129482
Kokoro: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
When an OpConstantComposite result is used by multiple instructions,
declare it as a module-scope `const` instead of inlining the constant
at each use site. This fixes an issue whereby the spirv-reader was
massively inflating the size of the WGSL it produces, which was caught
via an OOM fuzzer bug.
Bug: oss-fuzz:57795
Change-Id: Iac8c6a2147a7e2ebfddbaacae9fcb1dbe0b59e9d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/128881
Auto-Submit: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
When referencing a pointer parameter with a 'let', but not using that
let.
Also fix a bunch of places where we used the old names for the pointer
transforms.
Bug: chromium:1433499
Change-Id: I8decefeacd6150bd6f7637f80e62b9cb62936235
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/127540
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
D3D11 only supports HLSL SM5.0 which doesn't support `space`
(binding group in WGSL). So for D3D11, only one binding group will be
used, and tint will not emit `space` for HLSL, so shaders can be used
with D3D11.
Bug: dawn:1705
Change-Id: Ie0e9868137f10762c5243e188d76f5e41879c2bc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/125080
Commit-Queue: Peng Huang <penghuang@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Ben Clayton <bclayton@google.com>
In order to avoid declaring too many function parameters, we
previously modified this transform to redeclare private variables that
are only used inside a single function as function-scope
variables. This was broken as it meant that their values did not
persist across multiple calls to the same function.
Instead, wrap all private variables in a structure and pass it around
as a pointer.
Fixed: tint:1875
Change-Id: I83f5eb1071d57b9c6af56d6cf21b3a32c6e94260
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/124800
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
This CL updates the generators to receive the exteral texture options
instead of generating them.
Bug: tint:1855 chromium:1421379
Change-Id: Ib38b902aa441e33d394f947d753075ca6a8fe73b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/123260
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Conversion can happen for structure materialization (modf, frexp).
If both structure members are the same type and value, then a constant::Splat will be constructed, which needs to handle conversion.
Bug: chromium:1417515
Change-Id: Iadd14ce00b8d5c22226c601ec5af9a84e6c0c5cf
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122900
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
And vectors of those types.
Fixed: tint:1866
Change-Id: Ic0b5061232c5eb5a67d43dde1cd9599c580f4388
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/123201
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Ben Clayton <bclayton@chromium.org>
WGSL states that `f32` is a IEEE-754 binary32. mediump precision guarantees are much smaller than highp, and using mediump can break code generated by tint.
Change-Id: I8a129c4c8ac078c785e0d5d7d21f19ed6b3620b5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/123400
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Stephen White <senorblanco@chromium.org>
mix of ivec is not core until later GLSL versions.
Just polyfill in the writer with ternary ops.
Change-Id: Ia0c35bf95842e03ef8447019f3264d01c11fd384
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/123240
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Kokoro: Ben Clayton <bclayton@google.com>
Evaluate the LHS before the RHS.
Fixed: tint:1867
Change-Id: Ib63903ed4b1425007197a6da37f3bf54a495d88a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/123120
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
GLSL has the same behavior as MSL, in that -2147483648 is parsed as
a unary minus on '2147483648'. 2147483648 overflows an i32, so this
actually gets treated as -0.
Change-Id: Ibebd8b78a8840f18c438ed1d3d24dee486a65816
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/123202
Reviewed-by: Stephen White <senorblanco@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
... overloads for texture cube arrays
FXC is telling porkies, when it says "The array element count
of GetDimensions on TextureCubeArray objects is unavailable
on ps_5_1".
The actual issue, as identified by Teodor Tanasoaia at Mozilla,
is that the argument needs to be unsigned.
In fact, *all* the texture queries should have used an unsigned
scalar or vector for the output value. This has been broken
forever!
This reverts commit bd9f6e6684.
Change-Id: I3e217bec17c6fd203cff618b143ebef3d8a61927
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122980
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This change overhauls the Robustness transform to support three modes,
per address space:
* ignore - Disable robustness checks for the address space
* clamp - Clamp indices / texture args to ensure they're in
bounds. This was the old behavior, and continues to
be the default.
* predicate - Condition all indexing / textureLoad / textureStore /
atomic* operations on the bounds check. If any
dependent value is out of bounds, then the operation
is skipped.
This change also fixes multiple expression evaluation of the texture
builtin 'level' argument.
Change-Id: I2e300ddff2c8d3183a9701f06985ce1b262baf2c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122343
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Ben Clayton <bclayton@chromium.org>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Recent changes to DecomposeMemoryAccess meant we lost the dependency information between the user of a module-scope variable of the storage / uniform address space and the variable.
Add dependency information to ast::InternalAttribute so this can be tracked.
This change also means that symbol renaming after the DecomposeMemoryAccess should work.
Fixed: tint:1860
Change-Id: Icfa2925f95c2ac50702522df514cd11bde727546
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122660
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This CL updates the templates in the StringStream to match more types.
All of the internal `operator<<` methods have been converted over to
StringStream. The precision was increased in order to better match the
precision needed to read back as a double.
Bug: tint:1686
Change-Id: Iaa15cf247f174967dd1014647ba5a74804997c22
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122080
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
There's no good reason for this to be public.
Move it into the writers, and expose a 'disable_robustness' option to
turn it off. This can be expanded to hold more fine-grain control in the
future.
Change-Id: I6ea6e54a27b2ae0fbcba5fdf45539063045cc15a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122203
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
When using HoistToDeclBefore on a for-loop initializer, the inserted
statement would be scoped outside the for-loop. This was incorrect.
Change-Id: I764d07068e907cc203145ac8d6f0110b1b73e667
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122301
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Hoisting them would cause premature materialization. This will only
happen in cases where we do not actually need to hoist (e.g. assigning
to a phony), so we can safely skip these.
Fixed: tint:1852
Change-Id: Ifcbe3e13496daa0a6aaceb58540e60cb037885ea
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122104
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
In order to preserve padding properly for MSL, we need to use its
packed_vec type for all vec3 types in storage buffers, not just struct
members. This commit includes a complete rewrite of the PackedVec3
transform to achieve this. The key details are:
* An internal `__packed_vec3<>` type was added, which corresponds to a
`type::Vector` with an additional flag to indicate that it will be
emitted as packed vector.
* The `PackedVec3` transform replaces all vec3 types used in
host-shareable address spaces with the internal `__packed_vec3`
type. This includes vec3 types that appear as the store type of a
pointer.
* When used as an array element, these `__packed_vec3` types are
wrapped in a struct that contains a single `__packed_vec3`
member. This allows us to add an `@align()` attribute that ensures
that `array<vec3<T>>` still has the correct array element stride.
* When the `vec3<T>` appears as a struct member in the input program,
we apply the `@align()` to that member to ensure that we do not
change its offset.
* Matrix types with three rows that are used in memory are replaced
with an array of columns, where each column uses a `__packed_vec3`
inside an aligned wrapper structure as above.
* Accesses to host-shareable memory that involve any of these types
invoke a "pack" or "unpack" helper function to convert them to the
equivalent type that uses `__packed_vec3` or a regular `vec3` as
required.
* The `chromium_internal_relaxed_uniform_layout` extension is used to
avoid issues where modifying a type in the uniform address space
triggers stricter layout validation rules.
Bug: tint:1571
Fixed: tint:1837
Change-Id: Idaf2da2f5bcb2be00c85ec657edfb614186476bb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/121200
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Change the DecomposeMemoryAccess to behave more like the DirectVariableAccess transform, in that it'll inline the access of buffer variable into the load / store helper functions, instead of passing the array down.
This avoids large array copies observed with FXC, which can have *severe* performance costs.
Fixed: tint:1819
Change-Id: I52eb3f908813f72ab9da446743e24a2637158309
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/121460
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: James Price <jrprice@google.com>
UV plane's coord should be half of that of Y plane for NV12.
Bug: chromium:1415832
Change-Id: Icee851e61eca1f7da291285100f8edcce482b511
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/119860
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Jie A Chen <jie.a.chen@intel.com>
Commit-Queue: Jie A Chen <jie.a.chen@intel.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This CL makes the builtin argument resolve as a shadowable enumerator
expression.
Bug: tint:1841
Bug: tint:1845
Change-Id: I2aaa2c63025752f25c113cf2fb38f4d91c2c16c2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/120680
Kokoro: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Take advantage of the fact that all AST nodes now use an
`ast::Identifier` instead of directly using Symbols.
This will be important for ensuring that un-keyworded identifiers will
be preserved.
Bug: tint:1810
Change-Id: If5c3e9f00b4c1c14a6f11bd617bd8b895250fb7e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/119285
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
When calling the generated helper, the column and row arguments were
swapped.
Improved the unit tests to actually show this, rather than passing in a
single value for both column and row.
Bug: tint:1824
Bug: tint:1333
Change-Id: I32a92dec5e594dabd9d8d2b08474c0d6f3645520
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118420
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This fixes edge-cases, like the condition expression being a type-cast,
which DXC apparently sees as a variable re-declaration. Example:
fn foo(x : f32) {
switch (i32(x)) {
default {
}
}
}
was emitted as HLSL:
void foo(float x) {
int(x);
do {
} while (false);
}
The `int(x)` is seen as a re-declaration of `x` by DXC.
We fix this by only emitted the condition expression if it has
side-effects (which currently means it contains a call expression).
Bug: tint:1820
Change-Id: I7e4320fa09ea2d634c9e324cb0b752b0ee7dcde9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118161
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This CL removes support for the `sig` member in `frexp`. It is now an
error if `sig` is used, the deprecation is removed.
`fract` should be used instead.
Bug: tint:1766
Change-Id: I991544b675caf31f22c8c9472a60c77811ff4efd
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117920
Kokoro: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
We weren't actually enabling WGSL validating in Tint in the E2E test
runner.
Mark a few tests as SKIP for cases that do not actually validate.
Change-Id: I62a55ce701f704d744c32f2cd5cb97683e270e96
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117960
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: James Price <jrprice@google.com>
Kokoro: Ben Clayton <bclayton@google.com>
The HLSL `sign` method returns an `int` result (scalar or vector). The
WGSL `sign` expects the result to be the same type as the argument. This
CL injects a cast to the correct type after the `sign` call in the HLSL
generated source.
Bug: tint:1795
Change-Id: I51fed24b5b8b752b6b27fdfb5dd47eb803902793
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/116692
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
For logical binary expressions that can be short-circuited, if the rhs
tree contained a mix of constant and runtime expressions, we would
erroneously mark the node as runtime, although some of its children were
resolved as kNotEvaluated. This would then fail during backend
generation.
This is a fork of 115820, addressing review comments, as amaiorano is OOO this week.
Bug: chromium:1403752
Bug: tint:1581
Change-Id: I18682c7fe1db092d280390881ff86b3c0db23e9b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/116020
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Do more math on the CPU to avoid per-fragment ALU operations.
Use a mat3x2 instead of mat2x3 to avoid padding.
Fixed: dawn:1614
Change-Id: Ib0e0f7d44ed9aa16eaca712f6553214fad141feb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/116060
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Brandon1 Jones <brandon1.jones@intel.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Change-Id: I3e2d0f4e00e10ea221c1a760775550f4a0374b3b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/114420
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>