This CL updates the MSL generator to use a test namer, the various
places where the incorrect name was emitted have been fixed.
Change-Id: I20c990bdddc4f0580b09269920abe8376fa3ca07
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36900
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
This CL switches the HLSL generator to use the top level UnsafeNamer
instead of a custom namer.
Change-Id: I7643ee6586955ed2bc493104004fb9f9c524e951
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36660
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
This Cl updates the MSL generator to use the unsafe namer internally.
Change-Id: Ibeea747da1d7675c05a0dcb2416fbd491bb5d64b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36581
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Revert "Adding fuzzing for Transforms"
This reverts commit 4a29008c7e.
Revert "Add fuzzers for various emission paths"
This reverts commit 39545b7e7c.
Revert "Create common utility class for fuzzing"
This reverts commit 766e31d507.
Change-Id: Ia4e4ea2a4a5f423ea5bfa8ca9659c4028b558b45
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37180
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Fuzz all transforms being applied together, and fuzz each transform
separately.
BUG=tint:436
Change-Id: I53cf2e05c69f495f27bfa428f55ec033a85a612a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36945
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
BUG=tint:58,tint:59,tint:194,tint:195
Change-Id: Ibca5efbcd608489dcb7c6c45a5fcf596b97165dc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36901
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
This moves the usage of Tint in the fuzzers into a single class. This
will be expanded in the future to support emitting shaders, so fuzzing
tests, just need to indicate which reader & writer they want to use,
instead of having each test implement all of the API usage logic
directly.
BUG=tint:199
Change-Id: Id081a374014b7640a07b267e544ddeba3e6329dd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36760
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Easier to read and write, and ensures that the tests exercise valid AST instead of synthetic structures that can never exist.
Change-Id: I5d361ef96383c71943a424f5765952f21d740042
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/36422
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Remove Source{} with ast::Builder::create<>
Use Builder helpers where possible
Change-Id: I7b3188fa8239bf11e88ff6b396a57c23d76a3152
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35660
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
This CL adds a simple demangler to convert the `tint_symbol_YYY` back to
the original symbol name.
Change-Id: I532ed13dc4c52e0f0e3568b8b7d8d0a5c67d8472
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35440
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Remove all Variable setters (with exception to set_storage_class() which is called by the TypeDeterminer)
Bug: tint:390
Change-Id: I172667e21e2b02e85dcea6703aa1e608ec718250
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35015
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This CL adds a table which maps symbols to strings. This will allow us
to remove the use of std::string in the various AST nodes and refer to
the symbols instead.
Change-Id: I902641b3e546a2a44b3b2a39ce4f019cdcbeacc7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35100
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
This CL strips the context object out of Tint.
Change-Id: Id0dcb9c557b217c03a8d9ac08fc9fe1c799f3fdc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34742
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
instead of transform-in-place.
This is a public API breaking change, so I've added the `DAWN_USE_NEW_TINT_TRANSFORM_API` define which is used by Dawn to know which API to use.
As we're going to have to go through the effort of an API breaking change, use this as an opportunity to rename Transformer to Transform, and remove 'Transform' from each of the transforms themselves (they're already in the transform namespace).
Bug: tint:390
Bug: tint:389
Change-Id: I1017507524b76bb4ffd26b95e550ef53ddc891c9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34800
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
ReplaceAll() registers `replacer` to be called whenever the Clone() method is called with a type that matches (or derives from) the type of the first parameter of `replacer`.
`replacer` must be function-like with the signature: `T* (T*)`, where `T` is a type deriving from CastableBase.
If `replacer` returns a nullptr then Clone() will attempt the next registered replacer function that matches the object type. If no replacers match the object type, or all returned nullptr then Clone() will call `T::Clone()` to clone the object.
Example:
```
// Replace all ast::UintLiterals with the number 42
CloneCtx ctx(mod);
ctx.ReplaceAll([&] (ast::UintLiteral* in) {
return ctx.mod->create<ast::UintLiteral>(ctx.Clone(in->type()), 42);
});
auto* out = ctx.Clone(tree);
```
This is to be used by Transforms that want to replace parts of the AST on clone.
Bug: tint:390
Change-Id: I80a0e58aa3711f309f58a504f6b6a06f6c546ea1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34568
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Contains some intimidating template magic for inferring the first parameter type of a function or function-like.
Will be used by the CloneContext for transforming the AST while cloning.
Bug: tint:390
Change-Id: I432059d13e65fa0f0f3e52588eb43abe9a4efadd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34566
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
EmitVertexPointSizeTransform is a Transformer that adds a PointSize builtin global output variable to the module which is assigned 1.0 as the new first statement for all vertex stage entry points.
If the module does not contain a vertex pipeline stage entry point then then this transformer is a no-op.
Bug: tint:321
Change-Id: I0e01236339d9fa1ceab3622af0931a1199c33b99
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34561
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
The new module clone tests require the WGSL reader and writer in order
to function. This Cl adds those dependencies to the BUILD.gn file.
Change-Id: I34cd9a7de13a99145bad1f559c23d181f4fb7739
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34683
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
The AST clone fuzzer was accidentally named the same as the
SPIRV-Reader fuzzer. This Cl renames to fixup the conflict.
Change-Id: I757163718dc4e2097564427f4ac9f97a6cba9d55
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34680
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Deep-clones all `Node`s and `Type`s into a new module.
Instead of writing a million standalone tests that'll only ever test the
existing fields of each type, I've opted to write the tests using
wgsl<->ast<->wgsl conversion. This means the tests require the enabling
of TINT_BUILD_WGSL_READER and TINT_BUILD_WGSL_WRITER, but I believe this
is much easier to maintain.
I'm aware there are probably gaps in the tests, and that even full
coverage is likely to rapidly rot, so I've also added
fuzzers/tint_ast_clone_fuzzer.cc - a fuzzer based test that ensures that
all AST modules can be cloned with identical reproduction.
I've run this across 100 cores of a 3990x for 4 hours, fixing the
single issue it detected.
Note: Expressions do not currently clone their `TypeManager` determined
types. This is for two reasons:
(a) This initial CL is mahoosive enough.
(b) I'm uncertain whether we actually want to clone this info, or to
re-run the `TypeDeterminer` after each AST transform. Maybe it should
be optional. Time will tell.
Fixed: tint:307
Change-Id: Id90fab06aaa740c805d12b66f3f11d1f452c6805
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33300
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Implements `As<Blah>()` and `Is<Blah>()` automatically.
There are several benefits to using this over the pattern of hand-rolled `IsBlah()`, `AsBlah()` methods:
(1) We don't have to maintain a whole lot of hand written code.
(2) These allow us to cast from the base type to _any_ derived type in a single cast. The existing hand-rolled methods usually require a couple of intermediary casts to go from the base type to the leaf type.
(3) The use of a template parameter means these casts can be called from other template logic.
Note: Unlike the hand-rolled `AsBlah()` methods, it is safe to call `As<T>()` even if the type does not derive from `T`. If the object does not derive from `T` then `As` will simply return `nullptr`. This allows the calling logic to replace the common pattern of:
```
if (obj.IsBlah()) {
auto* b = obj.AsBlah();
...
}
```
with:
```
if (auto* b = obj.As<Blah>()) {
...
}
```
This halves the number of virtual method calls, and is one line shorter.
Change-Id: I4312e9831d7de6703a97184640864b8050a34177
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34260
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
So we can also use this for the `spirv` backend
Bug: tint:146
Change-Id: I26f70125a5015946d2428a6e669da32bdea23bcd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33780
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
First step to moving this to the `ast::Module`.
Also remove a bunch of redundant includes to `type_manager.h` as this is already included in `context.h`
Bug: tint:307
Bug: tint:337
Change-Id: Ic4baffa7b76ddefa29f56f758c25b1003ef40888
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33665
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Add `tint::writer::FloatToString()`:
Converts the float `f` to a string using fixed-point notation (not scientific).
The float will be printed with the full precision required to describe the float.
All trailing `0`s will be omitted after the last non-zero fractional number,
unless the fractional is zero, in which case the number will end with `.0`.
Use this for the wgsl, msl and hlsl backends.
Change-Id: If5701136579e4398c31c673942f30e8877e9f813
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33421
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
It's mahoosive, and will only get bigger.
Change-Id: I4593bd5ded9d67a8457676245189638874a8d5b3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33420
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Handle wsgl parsing and spirv writing of:
textureSample(), textureSampleBias(), textureSampleLevel(),
textureSampleGrad(), textureSampleCompare()
Handle the different signature for array texture types.
Includes offset overloads.
Change-Id: I6802d97cd9a7083f12439b32725b9a4b666b8c63
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32985
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
It doesn't actually do anything (yet), but will hold the context and
a helper for constructing AST nodes.
Bug: tint:322
Change-Id: Ic7ba92bf39abf64ff2ac51d81c8a6338f5eff608
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32663
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
This CL moves the namer into the context object and makes it a parameter
to the various generators. The old constructor is maintained until we've
updated downstream repos.
Bug: tint:273
Change-Id: I49b2519c4250be21fb73374b16e7c702b727078f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32580
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
This Cl adds an ast::Builder class which provides a series of helper
methods to make creating AST nodes simpler.
Change-Id: Ife57f27e598d575681f7192d65fab968191699b1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32560
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Use synchronization tokens to ensure the parser can resynchronize on error.
Bug: tint:282
Change-Id: I8bb033f8a723eb8f2bc029e1ffc8350174c964e2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32284
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This Cl hashes the OpName, OpEntryPoint and OpMemberName strings so we
are no longer passing user provided strings through into the resulting
SPIR-V binary.
Bug: tint:273
Change-Id: I0ca2c65d0cd2800c54d867ab698c7751c341778c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32061
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
For values of type T* and std::unique_ptr<T>.
This allows us to replace all occurances of `res.value->member` with: `res->member`, which also asserts that `res` is not in an error state.
Brings the verbosity back down to pre-expect and pre-maybe levels.
Bug: tint:282
Change-Id: Ib00018affca53ac5e71ee2140e7e0cd607b83715
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32141
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This is the first step in unifying the way decorations are parsed - i.e. instead of parsing decorations in different ways based on the predicted grammar that follows, we can parse decorations blocks in a unified way, then later verify what we have is as expected.
`StructDecoration` has been transformed from an `enum class` to a proper class so it can derive from `Decoration`.
Bug: tint:282
Bug: tint:291
Change-Id: Iaf12d266068d03edf695acdf2cd21e6cc3ea8eb3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31663
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
For linux and windows consoles.
Still needs hooking up to `samples/main.cc`
Bug: tint:282
Change-Id: If8430572708ea7d8788ef05d5379886be89fcb17
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31564
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Diagnostics will be used for printing parser / validator error mesasges.
Diagnostics are collected into a `diag::List`, and can then be formatted into a human readable message with `diag::Formatter`.
Bug: tint:282
Change-Id: I8bbef3db22b72d62cb9467c878d9a346890589ad
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31480
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This is the first step in improving the error messages produced while parsing.
The `line` and `column` information of `Source` has been moved to `Source::Location`.
`Source::Range` has been added that contains a `Location` interval - allowing error messages to highlight the full region of the error.
The `File` information provides an optional file path, and pre-splits the content into lines. These lines can be used to print the full line containing an error.
This CL contains a few temporary changes that help split up this work, and to ease integration with Tint.
Bug: tint:282
Change-Id: I7aa501b0a9631f286e8e93fd7396bdbe38175727
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31420
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
This CL merges the StorageAccess enum with the AccessControl enum. The
enum is moved up to src/ast and placed in its own file for clarity.
Change-Id: I95a905a399b5d2e046ea1ea429b35f2064510c2d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31242
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
These are _mostly_ covered in the over various test files, but unlike those, these new tests always parse from the root translation unit.
These new tests also use a new testing class which may be extended to verify error output for different error styles (verbosity, colors, etc).
Change-Id: I105488f9b16d90279af4cc418a1c845b6e239e9e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31263
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This CL adds the AST for an AccessControlType. This type contains an
access control (ReadOnly, WriteOnly, or ReadWrite) along with another
type pointer.
Bug: tint:208 tint:108
Change-Id: I2eed03f8760239f7e71dc2edd4a19a7c1661746e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31060
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: David Neto <dneto@google.com>
This also involves a reorganization of the code into its own
subdirectory.
BUG=tint:253
Change-Id: If05018da2662e923e659b485576704f3a6bcd062
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/30340
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This CL updates the WGSL parser to allow array decorations to accept
multiple blocks. The stride decoration on arrays was turned into a
proper decoration object instead of just storing the stride directly.
Bug: tint:240
Change-Id: I6cdc7400d8847e3e043b846ea5c9f86cb795cf86
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/29780
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
Reviewed-by: David Neto <dneto@google.com>