Commit Graph

34 Commits

Author SHA1 Message Date
Austin Eng 86a617f110 Add InsertBraces: true to .clang-format
Bug: none
Change-Id: I4b4f2a4abfea7adcea406f458bc4e4a13b0e8c43
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91000
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: dan sinclair <dsinclair@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2022-05-19 20:08:19 +00:00
Ben Clayton aaa9ba3043 tint: Simplify sem::Constant::Scalar
Migrate from a hand-rolled tagged-union of [i32, u32, f32, f16, bool]
types. Instead use a std::variant of [AInt, AFloat, bool]. The Constant
holds the actual type, so no information is lost with the reduced types.

Note: Currently integer constants are still limited to 32-bits in size.
This is enforced by the frontend.

Bug: tint:1504
Change-Id: I316957787649c454fffb532334159d726cd1fb2d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/90643
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-05-17 20:51:04 +00:00
Ben Clayton 3b5edf1435 tint: Add matrix identify and single-scalar ctors
Fixed: tint:1545
Change-Id: I86451223765f620861bf98861142e6d34c7e945b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/90502
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-05-16 21:14:11 +00:00
Jiawei Shao 1c75921db9 tint: fix translation of DP4a on HLSL
This patch adds a workaround on a DXC error in the translation of DP4a
functions that the third parameter "acc" of both dot4add_i8packed() and
dot4add_u8packed() can only be a variable, or a compile error will be
generated.

Bug: tint:1497
Test: tint_unittests
Change-Id: I263d27fb18bd354e0c9110f60cbc98860cf7afe5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/90027
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-05-15 13:53:21 +00:00
Zhaoming Jiang 62bfd318ae tint: Implement `f16` keyword in Tint frontend
This patch:
1. Add the `f16` WGSL extension.
2. Add `f16` as keyword, and remove it from reserved word list.
3. Add ast::f16 and sem::f16, and implement validation that using `f16`
   type must be with `f16` extension enabled.
4. Add `Number<NumberKindF16>` for f16 literal and constant, and add
   `ast::FloatLiteralExpression::Suffix::kH`.
5. Add placeholder in all writer which report error when try to emit f16
   type.

Bugs: tint:1473, tint:1502
Change-Id: Ifb363beeb2699ed7cac57e07227d1b2cfa8050b4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/89922
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
2022-05-13 12:01:11 +00:00
Jiawei Shao ab9757036b tint: Implement DP4a on HLSL writer
Bug: tint:1497
Test: tint_unittests
Change-Id: I29cc3e56949071230cdbd5afdc59eef076777149
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/89706
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-05-13 00:09:56 +00:00
James Price 791b4351d1 tint: Add transform to disable uniformity analysis
This is done via a new extension, which in the future could also be
used by shader authors as an escape hatch while we are still refining
the analysis.

The transform is run by the sanitizers for all of the non-WGSL
backends.

Bug: tint:880
Change-Id: Ibe90d7437d34c741a91eda65dff6d21d8469b9c7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88464
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2022-05-11 13:50:33 +00:00
Ben Clayton 41285aa578 tint: Lex different tokens for float suffixes
Generate different tokens for:
• 'f' suffixed float literals
• unsuffixed integer literals

'f' and unsuffixed are currently both treated as f32 by the resolver,
but this is the first step to supporting abstract floats.

Bug: tint:1504
Change-Id: Id3b1fe420b6eb8901f88d6a5de06ef4f54aa3edf
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/89031
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
2022-05-10 14:55:34 +00:00
Ben Clayton 0ce9ab042e tint: Change all ProgramBuilder literals to 'i' or 'u' suffix
Unsuffixed integer literals are currently treated as i32,
but will shortly become AbstractInteger. To keep tests behaving
identically to how they are currently, change all test literals
to using either 'i' or 'u' suffixes.

Bug: tint:1504
Change-Id: Ic373d18ce1c718a16b6905568aec89da3641d36b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88845
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-05-05 20:23:40 +00:00
Ben Clayton 8822e2966a tint: Merge [S|U]intLiteralExpression
Merge SintLiteralExpression and UintLiteralExpression with
IntLiteralExpression. IntLiteralExpression has a new Suffix field which
indicates whether the literal is either a:
• 'i' suffixed integer literal
• 'u' suffixed integer literal
• no-suffix integer literal

Have the SPIR-V reader produce no-suffixed literals for i32 types, to
keep this change small. In future changes the SPIR-V reader will
produce 'i' suffixed types for these.

Have all consumers of IntLiteralExpression treat unsuffixed integers the
same as 'i'-suffixed literals. Unsuffixed will be treated as abstract in
future changes.

Removed SemHelper::TypeOf(const ast::LiteralExpression* lit).

Fixed: tint:1510
Bug: tint:1504
Change-Id: I443f41984e637ddd948182ee756af1010c5f8226
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88842
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-05-04 22:18:49 +00:00
dan sinclair 41e4d9a34c Consistent formatting for Dawn/Tint.
This CL updates the clang format files to have a single shared format
between Dawn and Tint. The major changes are tabs are 4 spaces, lines
are 100 columns and namespaces are not indented.

Bug: dawn:1339
Change-Id: I4208742c95643998d9fd14e77a9cc558071ded39
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87603
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-05-01 14:40:55 +00:00
James Price 26ebe5ec36 tint: Refactor if-else statement representation
Instead of using an `if` node that has a list of `else` statements,
make each `if` statement have a single optional `else` statement,
which may itself be an `if` statement (or just a block statement).

This better matches the WGSL grammar (now that we have removed
`elseif`), and simplifies various pieces of code that handle these
statements.

Change-Id: Ie4272f1422224490ac598a03aa8b4dd00ba03010
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87940
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: James Price <jrprice@google.com>
2022-04-29 00:14:53 +00:00
Ben Clayton 01004b7732 tint: Remove '_type' suffix from file names
These suffixes existed because the GN build errored when there were two files sets with the same name (ast + sem).
This is no longer required as the GN build splits these into two separate targets.

Change-Id: Ib451da33a5f4aa5c867cb99419dd252766dc3daa
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88308
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-04-28 18:49:04 +00:00
dan sinclair f7ec85f9bd Rename UniformConstant to Handle.
The UniformConstant storage class was renamed to Handle in the WGSL
spec. This CL updates Tint internals to match.


Bug: tint:1138
Change-Id: I93ec581575955ab6830eb8aea44f74dbc28e9ef5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88280
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-04-28 09:48:26 +00:00
Zhaoming Jiang 7098d3d692 tint: Add enable directive for extensions
In this CL the enable directive is implemented.
1. Add AST node for enable directive, assign a ExtensionKind (enum) for
each supported extension.
2. Use an unorder_set in ast::Module to record all required extensions'
kind.
3. Provide inspector methods for getting names of used extension, and
getting all used enable directives' extension names and location.
4. For different writer, the extension nodes are handled in different
ways. MSL and HLSL writers will just ignore the extension nodes, while
SPIRV and GLSL writers will emit corresponding code.
5. Implement unittests and end2end test for enable directive and
inspector, using a reserved extension name `InternalExtensionForTesting`.

Bug: tint:1472
Change-Id: I40cb4061554deb477bc2005d7e38c9718385f825
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86623
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
2022-04-27 02:27:52 +00:00
Antonio Maiorano 7eaab38574 tint: Simplify backend Sanitize functions by passing in Options
Reduces the amount of variable duplication and copying we do.

Bug: tint:1495
Change-Id: I7999eadf09dc899361926e01dea715e9edc124c9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86203
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2022-04-11 16:33:30 +00:00
dan sinclair 6a5bef1912 Condense namespaces in tint/writer/hlsl.
This PR condenses the namespaces in the tint/writer/hlsl folder.

Change-Id: Iecbf1965ade236547e2f5654a66fa8367df9f092
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86024
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-04-07 14:30:24 +00:00
Antonio Maiorano a730eb738e Add option to auto generate bindings for external textures
With this change, the backend sanitizers always run the
MultiplanarExternalTexture transform. If the new option is enabled, it
auto-generates bindings for this transform.

This change also enables this auto-generation for the Tint commandline
application, as well as for the fuzzers.

Bug: chromium:1310623
Change-Id: I3c661c4753dc67c0212051d09024cbeda3939f8c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/85542
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2022-04-06 13:57:54 +00:00
James Price 508a9660a5 hlsl: Implement compound assignment
Use the ExpandCompoundAssignment transform to convert compound
assignments to regular assignments.

Bug: tint:1325
Change-Id: Ic843964ec24d8a2f00f801823f8f8bbf1c6fab5c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/85284
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-03-31 22:30:10 +00:00
Antonio Maiorano b349710476 HLSL: workaround FXC error "continue cannot be used in a switch"
Added a new transform::RemoveContinueInSwitch that replaces continue
statements in switch cases with setting a bool variable, and checking if
the variable is set after the switch to continue.

Bug: tint:1080
Change-Id: I3c0a6c790e1bb612fac3f927a4bd5beb2d0d4ed1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/84960
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2022-03-31 15:02:25 +00:00
James Price e6c76095fc builtins: Add smoothstep, deprecate smoothStep
Bug: tint:1483
Change-Id: I8702933312a7e46f82745f232214910433485fe5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/85261
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2022-03-30 17:57:39 +00:00
Antonio Maiorano 66d6668372 Implement discard semantics
Implement new transform UnwindDiscardFunctions that replaces discard
statements with setting a module-level bool, adds a check and return for
this bool after every function call that may discard, and finally
invokes a single function that executes a discard from top-level
functions.

Regenerated tests and remove HLSL ones that used to fail FXC because it
had difficulty with discard.

Bug: tint:1478
Bug: chromium:1118
Change-Id: I09d680f59e2d5d0cad907bfbbdd426aae76d4bf3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/84221
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2022-03-28 20:51:32 +00:00
James Price dfc1a2c081 Remove support for the @stride attribute
We still use the StrideAttribute AST node in the SPIR-V reader for
strided arrays and matrices, which are then removed by transforms.

The WGSL parser no longer has to handle attributes on types.

Bug: tint:1381
Change-Id: Ifa39575ce207d3fdfcbef7125fe6a3686fad5f20
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/83963
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-03-21 16:09:17 +00:00
Antonio Maiorano 93baaae60b PromoteSideEffectsToDecl: add to 4 backends and regen tests
Added to hlsl, msl, glsl, and spirv backends.

Bug: tint:1300
Change-Id: I06062bd8e4b32acbc4a8670b060a7a22bc1ae034
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/80600
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
2022-03-15 15:35:13 +00:00
Ben Clayton dc0e31cfaa sem: Remove Type::type_name.
Remove last remaining uses, and fix up a whole lot of tests.

Bug: tint:1383
Change-Id: Id2a11fc2d748b72823f4a077bcd6ba7be705a02b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/82744
Reviewed-by: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-03-07 18:34:57 +00:00
James Price bcd9ad2ebb Remove isNan, isInf, isFinite, and isNormal
These were deprecated in M98.

Fixed: tint:1312
Change-Id: Ieec17bfcc729f90d0a9aa8904a162167b9de54ed
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/82800
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
2022-03-05 00:39:14 +00:00
Brandon Jones 6661b28d1e Delete Single-Plane External Texture Transform
The multiplanar external texture transform has been integrated into
Dawn, which means we have no use for the single plane transform - so it
should be deleted.

Bug: dawn:1082
Change-Id: Id8977d03839b76c90ae6e70400d048c13fbe85f4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/80120
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Brandon1 Jones <brandon1.jones@intel.com>
2022-02-25 20:14:52 +00:00
Ben Clayton fe08ba4677 builtins: Add insertBits
CTS tests: https://github.com/gpuweb/cts/pull/1012

Bug: tint:1371
Change-Id: Idd55c0bc9dad1dffb558d0bc57d744f65e9041b5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/81701
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
2022-02-23 21:18:09 +00:00
Ben Clayton d868e860e0 builtins: Add extractBits
CTS tests: https://github.com/gpuweb/cts/pull/1005

Bug: tint:1371
Change-Id: I228c7b2a27c6fbac0653c416fac603a6fb4bff85
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/81640
Reviewed-by: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
2022-02-23 21:18:09 +00:00
Ben Clayton 8169693136 builtins: Add firstLeadingBit
Currently polyfilled for all backends.
HLSL should be able to map this to 'firstbithigh', but there might need
to be some special case handling for 0 (undocumented behavior). For now
just polyfill.

CTS tests: https://github.com/gpuweb/cts/pull/1004

Bug: tint:1367
Bug: tint:1449
Change-Id: I9c9a08ea93d1c4a602e0ab763e95e2eea336fb0d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/81503
Reviewed-by: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-02-23 18:20:30 +00:00
Ben Clayton df3630c194 builtins: Add firstTrailingBit
Currently polyfilled for all backends.
HLSL should be able to map this to 'firstbitlow', but there might need
to be some special case handling for 0 (undocumented behavior). For now
just polyfill.

CTS tests: https://github.com/gpuweb/cts/pull/1003

Bug: tint:1367
Bug: tint:1449
Change-Id: I8125b32687196678906e5a9d056b4f2efd885073
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/81502
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-02-23 14:32:14 +00:00
Ben Clayton f8672d8c35 builtins: Add countTrailingZeros
Requires polyfilling for all but the MSL backend.

CTS tests: https://github.com/gpuweb/cts/pull/1002

Bug: tint:1367
Change-Id: I0cf56b74c01f30436f9ad00595a554a4042587e4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/81501
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Ben Clayton <bclayton@google.com>
2022-02-22 23:16:39 +00:00
Ben Clayton 27aa57ccac builtins: Add countLeadingZeros
Requires polyfilling for all but the MSL backend.

CTS tests: https://github.com/gpuweb/cts/pull/1001

Bug: tint:1367
Change-Id: I75097de945909e3242ede9001124d8821bc832bc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/81380
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-02-22 23:13:39 +00:00
Ryan Harrison dbc13af287 tint->dawn: Shuffle source tree in preperation of merging repos
docs/    -> docs/tint/
fuzzers/ -> src/tint/fuzzers/
samples/ -> src/tint/cmd/
src/     -> src/tint/
test/    -> test/tint/

BUG=tint:1418,tint:1433

Change-Id: Id2aa79f989aef3245b80ef4aa37a27ff16cd700b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/80482
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2022-02-21 15:19:07 +00:00