Commit Graph

503 Commits

Author SHA1 Message Date
Ben Clayton 7fdfff1de4 Add semantic::Node
Rename Program(Builder)::Nodes to ASTNodes, and add SemNodes.

Bug: tint:390
Change-Id: If501ea5f5d1cbb4bc2673b303aa8ebce7195e2c3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39005
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-29 15:17:30 +00:00
Ben Clayton e43c830b14 Add ProgramBuilder::Wrap()
Follows the basic shallow-clone pattern of type::Manager::Wrap(),
which this new method uses.

Use ProgramBuilder::Wrap() in the writers, where we were previously
using type::Manager::Wrap(). This simplifies some of the logic
(especially around AppendVector()).

This is now required as semantic information is generated inside the
writers for newly constructed AST nodes, and we need to register
this semantic info so it can be fetched later.

Change-Id: Ia362204a1f13054e50545baeb7d269f210a36826
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39004
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-29 11:59:32 +00:00
Ben Clayton dd1b6fca9f Introduce semantic::Info
Will hold the mutable fields that currently reside in the otherwise immutable-AST.

Change the AST string methods to accept a `const semantic::Info&`. This is required as some nodes include type-resolved information in their output strings.

Bug: tint:390
Change-Id: Iba494a9c5645ce2096da0a8cfe63a4309a9d9c3c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/39003
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-29 10:55:40 +00:00
Ben Clayton a6b9a8eb2f Split Program into Program and ProgramBuilder
Program is now immutable*, and remains part of the public Tint
interface.

ProgramBuilder is the mutable builder for Programs, and is not part of
the public Tint interface. ast::Builder has been folded into
ProgramBuilder.

Immutable Programs can be cloned into a mutable ProgramBuilder with
Program::CloneAsBuilder().

Mutable ProgramBuilders can be moved into immutable Programs.

* - mostly immutable. It still has a move constructor and move
  assignment operator - required for practical usage - and the
  semantic information on AST nodes is still mutable.

Bug: tint:390
Change-Id: Ia856c50b1880c2f95c91467a9eef5024cbc380c6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38240
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton c40f627bea Migrate from using ast::Module to Program
Enforce all places where Dawn passes in or returns a ast::Module, now takes a `const Program* ` or returns a `Program`.

As the end goal of all this is to have immutable Programs, all Program inputs take a pointer instead of moving the actual object.

As consumers of a Program are now all const, we have to const_cast to work around all the places we've been incorrectly mutating a ast::Module.
These const_casts are temporary, and will be fixed in the next set of changes.

Depends on https://dawn-review.googlesource.com/c/dawn/+/38522

Bug: tint:390
Change-Id: Ie05b112b16134937d1b601e9b713ea4ec4e1c677
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38541
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-26 16:57:10 +00:00
Ben Clayton d59cedb5a5 Add tint::Program as a wrapper of tint::ast::Module.
`tint::Program` will become the new public API object for a parsed shader program.
For now, have Program be a simple wrapper around ast::Module so we can migrate Dawn's use of the public tint API.

Add new Program variants of public APIs for places that returned or took a Module.

Remove Reset() methods from Generators, they aren't used, and make the migration harder.

Change-Id: Ic5bee46ceb109ea591ba7fec33685220b244a1ae
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38540
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-25 18:14:08 +00:00
Ben Clayton 1e29f4beb0 Move CloneContext and Traits from src/ast to src/
CloneContext clones the AST, types, symbols and in the future semantic info.
3/4 of these are non-ast, so promote these up to the root.

Bug: tint:390
Change-Id: I49619796e6f81f9ab64f79413a12c87312cb1901
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38361
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-21 16:20:40 +00:00
Ben Clayton 207b5e2de1 Move tint::ast::type to tint::type
Despite `tint::ast::type::Type` being in the AST namespace, these classes are clearly not AST nodes:
* They don't derive from ast::Node
* They're deduplicated by the type manager
* None of the types have an Source - they have no lexical declaration point
* The fact we have `ast::Struct` and `ast::type::Struct` clearly demonstrates what is an AST node, and what is a type.
* We have code scattered in the codebase (TypeDeterminer, writers, etc) that create new types after parsing - so clearly not part of the original syntax tree.

Types in tint are closer to being semantic info, but due to the parse-time generation of types, and tight dependency of ast::Nodes to types, I'd be reluctant to class these as semantic info. Instead, put these into a separate root level `tint::type` namespace and `src/tint` directory.

The fact that types exist in the ast::Module has already caused bugs (https://dawn-review.googlesource.com/c/tint/+/37261). This is a first step in separating out types from the ast::Module.

Bug: tint:390
Change-Id: I8349bbbd1b19597b8e6d51d5cda0890de46ecaec
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38002
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-21 15:42:10 +00:00
Ben Clayton 587f387fd9 Add tint::BlockAllocator<T>
A container and allocator of objects of (or deriving from) the template type `T`.

Objects are allocated by calling Create(), and are owned by the BlockAllocator.
When the BlockAllocator is destructed, all constructed objects are automatically destructed and freed.

Objects held by the BlockAllocator can be iterated over using a View or ConstView.

Use this to hold the ast::Nodes in the ast::Module

This is called BlockAllocator as it can be optimized to hold objects in contiguous memory blocks, which will improve cache coherencey. Currently BlockAllocator is a straight port of the vector-of-unique-ptr, taken from ast::Module.

Change-Id: I4bf4d298aec3c70d2ddf833e2f168416cbb024c0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38001
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-21 15:30:10 +00:00
David Neto ed14524b1e Refactor getting number of coordinate dimensions
Change-Id: Ibafffb29bc33c722b8a4da25ed7a9c1986d13a24
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38162
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: David Neto <dneto@google.com>
2021-01-19 03:29:35 +00:00
dan sinclair c068cfc139 Support the group decoration.
This CL changes the set decoration to a group decoration. We still parse
`set` until downstream users can be updated.

Bug: tint:338
Change-Id: I610d1ed769b3a26c117ad6d875f8a99a3d5b7754
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37920
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-01-15 12:22:16 +00:00
Ben Clayton 0f4638b9e4 Revert "Extract demangler out to separate source set"
This reverts commit 2f7fea1f19.

Reason for revert: breaks autorollers

Original change's description:
> Extract demangler out to separate source set
>
> And add this as a dep to libtint_core_src and tint_ast_clone_fuzzer.
>
> Should fix chromium autoroller
>
> Change-Id: Ic5f43bae85e010839a1940c1ae2d570a9613d269
> Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37708
> Commit-Queue: dan sinclair <dsinclair@chromium.org>
> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
> Reviewed-by: dan sinclair <dsinclair@chromium.org>

TBR=rharrison@chromium.org,dsinclair@chromium.org,bclayton@google.com

Change-Id: If872d1655e13dd5d67f898a3d9a43c76b2866973
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37845
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-14 16:31:05 +00:00
Ben Clayton 2f7fea1f19 Extract demangler out to separate source set
And add this as a dep to libtint_core_src and tint_ast_clone_fuzzer.

Should fix chromium autoroller

Change-Id: Ic5f43bae85e010839a1940c1ae2d570a9613d269
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37708
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-14 14:15:22 +00:00
Ryan Harrison 1870a48d5f Add fuzzer for Inspector
BUG=tint:445

Change-Id: Ic342c7e83827bcc57bfd134dec92b03cb9708a70
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37540
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
2021-01-13 15:50:11 +00:00
Ryan Harrison f813959302 Convert libtint deps to be public
This removes the requirement of targets that depend on libtint needing
to include the transitive deps to access somethings like headers.

BUG=tint:447

Change-Id: I52a86b93e517f2745f04711f508a838f8f6850b6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37720
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-13 15:42:51 +00:00
Ryan Harrison 0b5d1dd5d8 Re-land fuzzing work with fix
Revert "Revert 3 fuzzing CLs, since they are preventing rolling into Chromium."

This reverts commit 1d9935cf37.

Also adjusts BUILD.gn file, so that Chromium build can find all the
needed symbols.

BUG=tint:58,tint:59,tint:193,tint:194,tint:199,tint:436

Change-Id: I3fe71ff52c8156f30fccfaab0bf7f647f158aea4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37460
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2021-01-12 16:23:48 +00:00
dan sinclair 987376cd21 Revert the namer changes.
This CL reverts the changes to use the top level namer in the various
backends. This is causing issues when rolling into Dawn in the case
where the tint generator is used to create SPIR-V which is sent to
SPIRV-Cross but then generator and inspector aren't used. The entry
points end up being incorrect as SPIRV-Cross gets the renamed entry
points.

Change-Id: I4749e1d773f2bd9edcce83e63555f07a443d5ca5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37342
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2021-01-12 04:34:53 +00:00
dan sinclair f74b90b3dd Use a test namer in the MSL generator.
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>
2021-01-11 16:24:32 +00:00
dan sinclair 8d6e625ef4 Convert HLSL to higher level namer.
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>
2021-01-11 16:24:32 +00:00
dan sinclair 05b64849b2 Convert MSL generator to unsafe namer.
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>
2021-01-11 16:24:32 +00:00
Ryan Harrison 1d9935cf37 Revert 3 fuzzing CLs, since they are preventing rolling into Chromium.
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>
2021-01-11 15:22:19 +00:00
Ryan Harrison 4a29008c7e Adding fuzzing for Transforms
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>
2021-01-08 02:42:43 +00:00
Ryan Harrison 39545b7e7c Add fuzzers for various emission paths
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>
2021-01-07 20:33:22 +00:00
Ryan Harrison 766e31d507 Create common utility class for fuzzing
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>
2021-01-07 16:20:32 +00:00
Ben Clayton e9d7f7e640 src/transform: Reimplement tests in WGSL
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>
2021-01-06 12:57:41 +00:00
Ben Clayton 1523f5c276 Start cleaning up tests (3/N)
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>
2020-12-14 22:30:57 +00:00
dan sinclair 2d0282b308 Add a demangler
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>
2020-12-11 18:29:03 +00:00
Ben Clayton a80511e021 ast: Merge DecoratedVariable into Variable
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>
2020-12-11 13:07:02 +00:00
dan sinclair 89caee197c Add a symbol table.
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>
2020-12-10 16:56:02 +00:00
Ben Clayton 7f04e5c1e2 Implement textureLoad()
Bug: tint:140
Bug: tint:143
Bug: tint:144
Bug: tint:145
Bug: tint:146
Bug: tint:147
Change-Id: I8f41abac2e355c121e8868aa708ae51d0db87665
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34960
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-12-09 15:57:00 +00:00
Enrico Galli 3d449d2be5 [transform] Add first index offset transform
Adding new transform to workaround D3D's vertex/instance_index always
starting from 0

Bug: dawn:548
Change-Id: I048f39e76e236570f3ce337a77d804384ee659a4
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34600
Commit-Queue: Enrico Galli <enrico.galli@intel.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-12-08 21:07:24 +00:00
dan sinclair c35176eadf Remove the context object.
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>
2020-12-07 16:03:54 +00:00
Ben Clayton 00b77a80ab Rework all transforms to transform-on-copy
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>
2020-12-04 09:06:09 +00:00
Ben Clayton 2bc6840d3c Add ast::CloneContext::ReplaceAll()
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>
2020-12-03 18:10:39 +00:00
Ben Clayton f1f10e6571 Add src/traits.h
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>
2020-12-03 17:14:29 +00:00
Ben Clayton 76d12f0f5a Add EmitVertexPointSizeTransform
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>
2020-12-03 14:54:09 +00:00
dan sinclair b3becb2f25 Fixup gn check.
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>
2020-12-02 16:11:59 +00:00
dan sinclair f7e3bfc1a5 Fixup fuzzer name.
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>
2020-12-02 15:23:28 +00:00
Ben Clayton ed2b97811e ast: Add Module.Clone()
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>
2020-12-01 18:04:17 +00:00
Ben Clayton 95feb99a9d Add Castable template class
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>
2020-11-30 22:50:25 +00:00
Ben Clayton 83b32455c2 writer/msl: Emit texture builtin functions
Bug: tint:145
Change-Id: I8a2d10c2e7239c81a11933c009d9175d4f4d8577
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33782
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
2020-11-26 15:07:52 +00:00
Ben Clayton 41c8cd3e68 writer/hlsl: Move the coord/arrayidx packing to utility function
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>
2020-11-26 13:57:32 +00:00
Ben Clayton 3e67c5dba6 Move type_manager to the ast dir/namespace
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>
2020-11-23 19:30:55 +00:00
Kai Ninomiya 4c13659a2a Fix includes and BUILD.gn deps for gn check
Bug: tint:331
Change-Id: If1c1fa7495cf50f2456eb0b150c8b9a692dee12f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33620
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
2020-11-20 20:17:24 +00:00
Ben Clayton 0f4632d0ae writer/hlsl: Emit texture builtin functions
Fixes: tint:146
Change-Id: I2a59fd369c767163ac1b72976883a577fd51a632
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33422
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-11-20 10:28:24 +00:00
Ben Clayton 2da833d815 writer: Simplify floats when printed
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>
2020-11-20 10:04:44 +00:00
dan sinclair 7214f407dc [wgsl-reader] Add support for read only storage buffers.
This Cl adds the necessary infrastructure to parse the access decoration
for storage buffers.

This CL incorporates changes from bclayton@ from
https://dawn-review.googlesource.com/c/tint/+/33202 and
https://dawn-review.googlesource.com/c/tint/+/33201

Bug: tint:287
Change-Id: I7479f2cf7ab794b24c682b9927c4c68f6d325839
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33161
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Auto-Submit: dan sinclair <dsinclair@chromium.org>
2020-11-19 18:55:01 +00:00
Ben Clayton f2bfeda1c4 writer/spriv: Move IntrinsicTextureTest to its own file
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>
2020-11-19 14:08:51 +00:00
Ben Clayton 3ea3c997b5 Implement textureSample builtins
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>
2020-11-18 21:19:22 +00:00
David Neto bd7ab2cd5f spirv-reader: Add (handle) Usage abstraction
Bug: tint:109
Change-Id: I5cb8f35636c61cf2f837271a51c4753117b288be
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32387
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: David Neto <dneto@google.com>
2020-11-17 18:32:18 +00:00
David Neto cebde298f9 spirv-reader: add GetMemoryObjectDeclarationForHandle
Bug: tint:109
Change-Id: Ifb437ce9a39db7f92ca081e7ea551a576b0ecb2b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32740
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
2020-11-17 17:59:38 +00:00
Ben Clayton 10d5c6a6b6 ast: Have all tests derive from new TestHelper
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>
2020-11-13 21:58:28 +00:00
dan sinclair 196e097730 Place the namer into the context object.
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>
2020-11-13 18:13:24 +00:00
dan sinclair 20a8d31849 Create an AST builder class.
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>
2020-11-12 19:49:10 +00:00
Ben Clayton af8091e353 wsgl parser: support multiple error messages
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>
2020-11-11 18:44:36 +00:00
dan sinclair 84f827506a [spirv-writer] Hash names
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>
2020-11-10 21:49:56 +00:00
Ben Clayton 0573714bfd wsgl parser: Have Expect & Maybe operator-> deref
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>
2020-11-09 20:44:34 +00:00
Sarah Mashayekhi 34f90a0097 [validation] make validator directory
Change-Id: Ia5caea84b48b37f0bee9582ee4c8514da4ee3978
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/31981
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
2020-11-06 17:31:15 +00:00
Ben Clayton 35298800a6 ast: Have all decorations derive from base class
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>
2020-11-03 21:40:20 +00:00
Ben Clayton 2e6cc992c8 Implement diagnostic color printing
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>
2020-11-02 19:26:28 +00:00
Ben Clayton f0740ae0f2 Add tint::diag namespace for diagnostics
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>
2020-11-02 15:41:08 +00:00
Ben Clayton 5bee67fced Add File & Range information to tint::Source
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>
2020-10-30 20:44:53 +00:00
dan sinclair c55fc39acb [ast] Unify the access control types.
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>
2020-10-29 13:36:32 +00:00
Ben Clayton 4dd5665502 Add tests for all reachable parser errors
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>
2020-10-29 13:05:52 +00:00
dan sinclair bfd81096a5 [ast] Add AccessControlType.
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>
2020-10-27 18:50:59 +00:00
Ryan Harrison 8904253837 Add getting constant ID information from Inspector
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>
2020-10-16 02:26:54 +00:00
dan sinclair eb5d3e147d [wgsl-reader] Allow array decorations to have multiple blocks.
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>
2020-10-08 19:34:25 +00:00
Ryan Harrison 1a9a2dd07d Add Inspector class
This class is used to examine a module and get information about its
contents. This is the getting side of shader of reflection. Future
work will add transforms that perform the setting side of reflection.

In addition to the basic class and infrastructure, this CL adds a
GetEntryPoints() function demonstrate it works. More functionality
will be added in later CLs.

BUG=tint:257

Change-Id: If41dbb6c93302e0332754c086c75729d6ffe04d0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/29320
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2020-10-05 14:52:36 +00:00
dan sinclair 5bb9b75684 [transform] Add a simple transform manager.
This CL holds a simpler manager to hold and execute multiple transforms.

Bug: tint:206
Change-Id: I45f6b55134f871167704f3549c4e4c72ef806c3a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/29121
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2020-09-29 23:54:03 +00:00
dan sinclair 97b729de10 [transform] Add Transformer base class
This CL adds a Transformer base class from which the transformers will
inherit.

Bug: tint:206
Change-Id: I542eacb05d9a92af46d172a5803c245472c0e22c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/29120
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-09-29 20:28:21 +00:00
dan sinclair b403cb50ab [transform] Add BufferArrayAccessors transform
This CL adds a buffer array accessor clamping transform to
the available transforms in Tint.

Bug: tint:101
Change-Id: If9d5b0fb2c3adba723ce2185870b0e10981103a6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28980
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-09-29 18:40:40 +00:00
dan sinclair 9e7f9dc96c [ast] Add constant_id decoration
This CL adds AST support for the constant_id decoration.

Bug: tint:150
Change-Id: Ifde5a5325f770567ea24129e786953d89f3f514b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/29100
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-09-29 18:07:50 +00:00
dan sinclair 3c02592718 Remove cast operator.
This CL removes the cast operator and converts the tests over to using
type constructors.

Bug: tint:241
Change-Id: I2526acb61f5624b2e1c068612a2ddcc748c92aed
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28860
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-09-24 14:38:44 +00:00
dan sinclair 5c948e4f8f [transform] Move the transform folder
This CL moves the transform folder from src/ast to src/. The transforms
operate on the AST, but they aren't part of the AST so I think the top
level folder makes more sense.

This will possibly cause issues when rolling if the transform is being
used.

Change-Id: Ibd7c94474168a7a4bdf38321f4e12ad111c80323
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28941
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-09-24 14:30:34 +00:00
dan sinclair a7d498e060 Rename 'as' to 'bitcast'
This CL updates Tint to use 'bitcast' instead of 'as' for the OpBitcast
conversions.

Bug: tint:241
Change-Id: I53a80de10421b2d9cc009527eebe5ff07e1285c2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28801
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
2020-09-22 22:07:13 +00:00
dan sinclair b4fee2f824 Update builtin methods.
This CL removes the import mechanism, the identifier paths and updates
all of the standard library methods to be builtins.

Bug: tint:242
Change-Id: If09b98a155ae49ced3986ba2c9b517a060693006
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28720
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-09-22 19:42:13 +00:00
dan sinclair 5f8126271d Remove EntryPoint.
This CL removes the EntryPoint node and transitions everything to the
stage decoration.

Change-Id: Ib2840155905c8fa60ff35870f0c4b6705efb73ff
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28705
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
2020-09-22 14:53:03 +00:00
dan sinclair de2a019a7f [spirv-reader] Emit StageDecoration when building the functions
This CL adds the emission of StageDecoration to entry point functions.
EntryPoint nodes are still emitted. We duplicate the function emission
if there are multiple entry points pointing to the same function.

Change-Id: Icb48a063f5c6a30948bbe2c37c7fce7431af5864
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28665
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2020-09-22 14:22:12 +00:00
dan sinclair f91b9664e7 [hlsl-writer] Emit function decoration stage
This CL updates the hlsl writer to emit stage decorations.

Change-Id: Ic9ae9fbd47537f141949e27c876d37e6d4dcd97d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28704
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2020-09-22 13:47:32 +00:00
dan sinclair b5bb2d91af [msl-writer] Update to emit based on pipeline stage.
This CL updates the MSL writer to emit data base on the pipeline stage.

Change-Id: I9fb2e146f0c898d9703d69a6a92f535757106bba
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28703
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2020-09-21 18:58:01 +00:00
dan sinclair a8274b2fef [spirv-writer] Emit entrypoint from function decoration.
This CL updates the SPIRV-Writer to emit entry point information based
on the function stage as well as EntryPoint nodes.

Change-Id: I1fa937cbb2159b31516b0189216d679e03f0384d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28702
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2020-09-21 18:49:01 +00:00
dan sinclair 767ea855ab [wgsl-reader] Parse stage decoration
This CL adds parsing of the stage decoration to the WGSL parser. The
decoration is not hooked up yet so it's effectively ignored.

Change-Id: I8d86c55cee189f993c10b6da31a9c388ba452021
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28664
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2020-09-21 17:42:10 +00:00
dan sinclair d05f93fd8e [wgsl-reader] Add workgroup_size parsing
This CL adds parsing of the `workgroup_size` function decoration.

Change-Id: Ia90efc2c014ac0e1614429280cc903d30cf8171d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28663
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
2020-09-21 00:37:08 +00:00
dan sinclair 643827967e [ast][spirv-writer][hlsl-writer][wgsl-writer] Add workgroup_size decoration
This CL adds the workgroup_size decoration to functions and emits as
needed from the various backends.

Change-Id: Ifffde239e68047f6419c6980eca70c4efa9822c0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28662
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
2020-09-21 00:28:58 +00:00
dan sinclair 636d588f6e [ast] Add decorations to functions.
This CL extends the function AST object to allow function decorations to
be attached.

Change-Id: I5b16aa2e6927792368b7f88047c0229e258b5bd3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28661
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
Commit-Queue: Sarah Mashayekhi <sarahmashay@google.com>
2020-09-20 19:18:58 +00:00
dan sinclair d3f75ca0e8 Add support for multisampled textures.
This Cl adds the AST, WGSL-Reader and SPIRV-Writer support for the
`texture_multisampled_2d` type.

Bug: tint:237
Change-Id: Ib3eb831227b49f32162801f1e1b4e474774c78b3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28480
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2020-09-17 03:53:04 +00:00
Tomek Ponitka bcb6eb0830 [wgsl-reader] Parsing storage texture type
Bug: tint:147
Change-Id: I446786b529e777d709213e100e57cbae78ded75f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28122
Commit-Queue: Tomek Ponitka <tommek@google.com>
Reviewed-by: David Neto <dneto@google.com>
2020-09-08 16:48:09 +00:00
Tomek Ponitka 03f5e2fc9d [wgsl-reader] Parsing image storage type
Bug: tint:147
Change-Id: I79713b5dfa0a4b219cff7a6bb3c514557cf4f261
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28121
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: David Neto <dneto@google.com>
2020-09-08 16:38:39 +00:00
Sarah Mashayekhi bab2a4dd96 [validation] Add disabled tests for validating switch statements
This CL adds 6 unit tests for validating switch statements.
v-switch01: switch statement selector expression must be of a scalar integer type
v-switch02: switch statement must have exactly one default clause
v-switch03: the case selector values must have the same type as the selector expression
v-switch04: a literal value must not appear more than once in the case selectors for a switch statement
v-switch05: a fallthrough statement must not appear as the last statement in last clause of a switch

Bug: tint: 6
Change-Id: I0283afec22e56097b6f63c8455da23b87dfe26dc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27740
Commit-Queue: Sarah Mashayekhi <sarahmashay@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-09-02 19:58:06 +00:00
Tomek Ponitka fd3ca9ee47 [wgsl-reader] Parsing sampled texture type
Bug: tint:147
Change-Id: I21c864dd63c2003797c78758358ab4134cd8ff31
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28002
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-09-02 15:52:15 +00:00
Tomek Ponitka 4beff41b7d [wgsl-reader] Parsing texture sampler types
Change-Id: I6a29d81deca40e89cf5b8ca95cf0373af3dd16b7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28005
Commit-Queue: Tomek Ponitka <tommek@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-09-02 14:16:35 +00:00
Tomek Ponitka cbd1ef8523 [wgsl-reader] Parsing depth texture type
Change-Id: Ie886c85db52b934331abe2d5675d9d0e6cdd7210
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28001
Commit-Queue: Tomek Ponitka <tommek@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-09-02 14:06:45 +00:00
Tomek Ponitka c354200889 [wgsl-reader] Parsing sampler type
Change-Id: I58a3218a5d0b7ccbe6422340c94cdf3dc1bdf17a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28000
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-09-02 13:26:15 +00:00
Ryan Harrison 464928ed91 Add missing include patch
This missing in Dawn was being shadowed by spvc also including it.

BUG=dawn:521

Change-Id: I609cfcca74821ad07c0fd9e6fadf2c22fba40df0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27901
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-09-01 21:29:06 +00:00
Tomek Ponitka 6803529d58 [spirv-writer] Convert ast image format types to spv
Change-Id: I987e729a607e69294c472b7667eae82c7339a0df
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27640
Commit-Queue: Tomek Ponitka <tommek@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-08-31 15:49:43 +00:00
dan sinclair 63b007d34f [hlsl-writer] Move test helper to a template.
This CL updates TestHelper to be a templated class and converts the test
suites into using statements based off that template.

Bug: tint:7
Change-Id: I747434e7c6a8ecae353df448f06153e982dcec44
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27500
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2020-08-26 20:02:26 +00:00
dan sinclair df503f0e85 [hlsl-writer] Refactor output emission.
This CL updates the HLSL backend to take the output stream as a
parameter. This is needed because there are cases where we have to
generate the resulting stream out of order. This will allow that to
happen.

Bug: tint:7
Change-Id: Id1877a07e536a84da0555f207d1030588d44c034
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27440
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2020-08-26 19:05:46 +00:00
Sarah Mashayekhi 3fad211a8f [validation] Add a validator test helper class
Change-Id: I12d225dbbda3ceffda6f0f0dbf264a6a6b249fb2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27284
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-08-25 14:06:05 +00:00
Tomek Ponitka 63a5aa7d58 [wgsl-reader] Adding for loops
Implementing ParserImpl::for_stmt(). Also adding
for_stmt and body_stmt to ParserImpl::statement().

Bug: tint:138
Change-Id: Idc3f901648ca115f4d94b3614a940263ef841282
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27261
Commit-Queue: Tomek Ponitka <tommek@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-08-24 18:22:22 +00:00
dan sinclair d38df397e3 [hlsl-writer] Add support for import statements.
This Cl adds support for imported methods to the HLSL backend.

Bug: tint:7
Change-Id: Ib906542915670dcc916d48d9e5d64d7032ba829a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/26928
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
2020-08-19 19:19:04 +00:00