Commit Graph

524 Commits

Author SHA1 Message Date
dan sinclair dee9136c20 [hlsl-writer] Add binary operator emission.
Emits the binary operators.

Bug: tint:7
Change-Id: I6f4fce3b6fb646b8340e39538b041715a676ac28
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25164
Reviewed-by: David Neto <dneto@google.com>
2020-07-21 15:58:20 +00:00
dan sinclair fbbc617888 Parse void function call.
This CL updates the WGSL parser to handle a void function call.

Fixes: tint:45
Change-Id: If5b2a4b9e62f0b10e0f2e2e10c0ca2586c5268e8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25322
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-07-21 15:13:36 +00:00
dan sinclair e5228407f4 [hlsl-writer] Add emission of identifiers
This CL adds identifier emission and an HLSL namer to guard against
names using reserved words.

Bug: tint:7
Change-Id: Id3d73ff683048c26ac99451d21c3dd7ef3c620a3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25001
Reviewed-by: David Neto <dneto@google.com>
2020-07-21 14:51:33 +00:00
dan sinclair b44fe3c034 Emit call statements from the various backends.
This CL adds emission of CallStatement to the various backends.

Bug: tint:45
Change-Id: Ia2bdf0433f136c516ecccdcbc64a5365094220af
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25281
Reviewed-by: David Neto <dneto@google.com>
2020-07-21 13:44:27 +00:00
dan sinclair 50080b74e1 Type determine the call statement.
This CL adds type determination for the call statement.

Bug: tint:45
Change-Id: I2460fe6c6103bdf7e5d0367cded1d78ca5d671d6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25321
Reviewed-by: David Neto <dneto@google.com>
2020-07-21 13:42:13 +00:00
dan sinclair 2e40491467 Add a call ast statement.
This CL adds CallStatement to the AST to allow wrapping a CallExpression
into a statement.

Bug: tint:45
Change-Id: I5a9525514344fcc2cf9900eb2cd78c1fb94ca2ef
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25320
Reviewed-by: David Neto <dneto@google.com>
2020-07-21 13:42:05 +00:00
David Neto 0a56a103be [spirv-reader] Support select over scalars and vectors
Still TODO: OpSelect over arrays and structures, as permitted in SPIR-V 1.4

Bug: tint:3, tint:99
Change-Id: I70f6c8a43ea3339cd715813c6eb0128d66ff0df8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25301
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-07-21 13:36:25 +00:00
David Neto d6b024b66d Add missing Doxygen comments on two methods.
Bug: tint:3
Change-Id: I5cb5c3ce078951363279ccc999074c0c46dfad6e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25300
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-07-20 23:31:56 +00:00
David Neto c29bad28ad [spirv-reader] Support function calls, except returning void
Functions returning void are blocked on https://crbug.com/tint/45

Change-Id: I15ec9cf0e267571bbfab921c678a59e25d0e3619
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25280
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-07-20 22:19:01 +00:00
dan sinclair feffa9d887 [hlsl-writer] Scaffold the HLSL backend.
This CL adds the scaffolding for the HLSL backend.

Bug: tint:7
Change-Id: Iaf9f5159bc409f3ac71fcec281229258bdfa021b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25000
Reviewed-by: David Neto <dneto@google.com>
2020-07-20 22:13:37 +00:00
dan sinclair 5dee499c57 [msl-writer] Emit storage buffers.
This Cl adds the emission of storage buffers to the MSL backend.

Bug: tint:8
Change-Id: I6923926b36e73f2e351443cf1d2bf6d70873bc9a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25264
Reviewed-by: David Neto <dneto@google.com>
2020-07-20 22:13:20 +00:00
dan sinclair 26c8a216e8 [msl-writer] Add import emission.
This CL adds emission of import function calls to the MSL backend.

Bug: tint:8
Change-Id: Ib8b8638b11caee2ff3557d551447b215ef2a4c69
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25262
Reviewed-by: David Neto <dneto@google.com>
2020-07-20 22:13:00 +00:00
David Neto 747e80a9b3 [spirv-reader] Drop NonWritable NonReadable for now
Pending WGSL issue https://github.com/gpuweb/gpuweb/issues/935

Bug: tint:3, tint:99
Change-Id: I90771e6e0c6a2f109fd6e361d79adea273ca7bc6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25261
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-07-20 20:00:10 +00:00
Ryan Harrison c8af502c01 Fix issues with BUILD.gn
Couple of little style issues, and a path to a file that was incorrect.

Change-Id: I21d1a4ca41bc36163602378086989ac712f54469
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25265
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-07-20 19:54:23 +00:00
dan sinclair 18c85f52e4 [msl-writer] Cleanups and refactors.
This CL cleans up some interfaces and methods in the MSL generator and
generator impl classes.

Bug: tint:8
Change-Id: I9aabeb1ecb69baeaa9cb6bbc15e313806923dddc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25163
Reviewed-by: David Neto <dneto@google.com>
2020-07-20 17:27:58 +00:00
dan sinclair f1c3fb7670 [msl-writer] Handle uniform buffers.
This CL adds support for handling uniform data. Currently the uniform is
added to a buffer where the number is the binding value. This will need
to be updated to accept the correct mapping from the embedder.

Bug: tint:8
Change-Id: Icccccbe599a9555defa6136e384745f4093df020
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25104
Reviewed-by: David Neto <dneto@google.com>
2020-07-20 13:46:32 +00:00
David Neto e6c575538a [spirv-reader] Support DescriptorSet and Binding
Bug: tint:3
Change-Id: I92d44cc59883d3834aedd2529ab5e20b49d6eb31
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25200
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-07-20 13:24:58 +00:00
David Neto 6982c22eee [spirv-reader] Handle old-style storage buffers
Old way:
  - struct decorated with BufferBlock
  - Uniform storage class

New way
  - struct decorated with Block
  - StorageBuffer storage class

Also fixes the result type for an access chain.

Bug: tint:99
Change-Id: I2324ba94bb19b369d206313de798bdfec6099fe0
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24605
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-07-20 13:24:26 +00:00
David Neto 3c3d2275fe [spirv-reader] Support Location on module vars
Bug: tint:3
Change-Id: If7fc85251cbffab477b0b4f86c204de6c6a853f6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25103
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-07-16 21:13:58 +00:00
David Neto d8a4d4b06f [spirv-reader] Ignore empty string user names
Bug: tint:3
Change-Id: Ibef645b123706cf9fa7d5b98413a709d4624244d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25102
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-07-16 20:58:09 +00:00
David Neto 5f43fedcdd [spirv-reader] Handle gl_Position
Emits it as a module-level variable.  Deconstruct and throw away
the gl_PerVertex struct.

Not handled: unusual patterns that are technically valid but
which don't occur in practice:
- loading, storing, or producing intermediate values of the whole structure.
- multiple definitions of the per-vertex structure (e.g. if someone had
  put both a vertex shader and a tessellation shader in the same
  module.)

Bug: tint:3, tint:99
Change-Id: I3ad9ff6ab780a002367f01f385bfa7d6ddba6db9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24880
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-07-16 20:15:22 +00:00
dan sinclair 4264af9d3d [msl-writer] Emitting of program constants.
This CL adds code to emit program constants in the MSL backend.

Bug: tint:8
Change-Id: I63e40983253349d2e293904fbe9b6f543b885b34
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24940
Reviewed-by: David Neto <dneto@google.com>
2020-07-16 17:54:26 +00:00
dan sinclair 3f10421cee [msl-writer] Fixup matrix and array constructors.
This CL fixes up the array constructors to emit `{}` instead of
`<type>[<size>]()`. The matrix example is also updated to have the
correct data format for WGSL matrices which fixes the MSL output.

Bug: tint:8
Change-Id: I3a08a8814d4b8b38a57b6324e2182a271c958ef3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25060
Reviewed-by: David Neto <dneto@google.com>
2020-07-16 14:35:44 +00:00
dan sinclair 4556cbe24f Differentiate size and stride in array type name.
This CL adds a `_stride_` into the array type name to differentiate an
array of 8 elements and a runtime array of stride 8.

Bug: tint:102
Change-Id: Iaf10fe5957acde16a9ccdf2a0fd8a83e47bb57bc
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24962
Reviewed-by: David Neto <dneto@google.com>
2020-07-16 14:02:40 +00:00
David Neto aa601387a2 [spirv-reader] Support duplicate type definitions
Affects structs, runtime arrays

Bug: tint:3, tint:99
Change-Id: I9ca73f8f3f6395c829d134460ad4b1a9e50c3ec9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24720
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-07-16 13:00:37 +00:00
dan sinclair b0391c6fa4 [msl-writer] Add struct offset support.
This CL adds support for injecting padding into structs in the MSL
backend.

Bug: tint:8
Change-Id: I83631a71ce4a2f00b61974ee2c0c7ca1b97f3028
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24601
Reviewed-by: David Neto <dneto@google.com>
2020-07-15 20:54:48 +00:00
dan sinclair 7caf6e5959 [msl-writer] Add builtin support
This CL extends module scoped variables to include support for builtins.

Bug: tint:8
Change-Id: I9e4363be32401bfdd45ad5d1727d9432aca206fe
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24786
Reviewed-by: David Neto <dneto@google.com>
2020-07-15 20:51:16 +00:00
dan sinclair 5423d91d87 Add helpers for referenced variables.
This CL adds a helper to get referenced builtins and referenced
locations from the ast::Function.

Change-Id: I95cf7efd6b0fe9569c5e514d3245112e78147ffe
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24783
Reviewed-by: David Neto <dneto@google.com>
2020-07-15 18:26:25 +00:00
dan sinclair d1684ed287 [msl-writer] Refactor some entry point variable code.
This CL cleans up some of the entry point variable code.

Bug: tint:8
Change-Id: Ic89ff3608d34af26eeb9fe9408cdbd5c7de22dda
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24782
Reviewed-by: David Neto <dneto@google.com>
2020-07-15 18:26:17 +00:00
dan sinclair df415a8919 [msl-writer] Generate entry point functions.
This CL generates entry point functions and duplicate functions as
needed to call from the entry points.

Bug: tint:8
Change-Id: I8092ce463248e7a887c26ae05b0774e8fa21ab94
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24764
Reviewed-by: David Neto <dneto@google.com>
2020-07-15 18:04:11 +00:00
dan sinclair c5a5f9666f [msl-writer] Handle emitting user function calls.
This CL adds support for calling user defined functions from the MSL
backend. Intrinsics and imports are not handled yet.

Bug: tint:8
Change-Id: I45c3078d014ab89cc0eec76dd626759077e1a890
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24763
Reviewed-by: David Neto <dneto@google.com>
2020-07-14 20:37:38 +00:00
dan sinclair de2dd68f2b Inherit refererenced globals up the call stack.
A given caller should inherit the globals referenced from a callee. This
way, a given entry point will have a list of all the variables used up
the stack which it needs to reference.

Change-Id: Ib6efcdd5c3347749ad2d54aecfa425bd966a62fd
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24762
Reviewed-by: David Neto <dneto@google.com>
2020-07-14 20:37:28 +00:00
dan sinclair a2eb8c52b2 [msl-writer] Generate input/output structs
This CL adds generation of the input/output structures for entry points.

Bug: tint:8
Change-Id: I93942496bcea0a2eea944e5e1cd0baf383530f5e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24721
Reviewed-by: David Neto <dneto@google.com>
2020-07-14 20:37:20 +00:00
dan sinclair 16890b9ce8 Add determination of entrypoint callees.
This Cl updates the type determiner to annotate each function with the
name of any entry points which call into the given function. This will
allow determining in the backends if we need to duplicate the function
due to differing entry point parameter requirements.

Bug: tint:8
Change-Id: Icd7c4ccab72dd6eabcf0abaf1159319949c4ecf5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24760
Reviewed-by: David Neto <dneto@google.com>
2020-07-14 19:45:47 +00:00
David Neto 919011af0a [spirv-reader] Refactor how we emit const definitions
Take the type of a const-definition (or a write to a hoisted variable)
from the generated expression rather than the directly-converted type
from the SPIR-V ID.

This prepares the way for remapping storage buffers from
Uniform/BufferBlock to StorageBuffer/Block representation.

Bug: tint:99
Change-Id: I6104d8ad96312053562468a3cdb247932c1cb6cb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24604
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-07-13 14:16:12 +00:00
David Neto 018428dcd0 [spirv-reader] avoid using WGSL reserved words
Bug: tint:3
Change-Id: I8ab9ee4604f725cefcfab854e953caba7051b1ee
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24524
Reviewed-by: dan sinclair <dsinclair@chromium.org>
2020-07-13 14:15:52 +00:00
dan sinclair 25058a9213 [msl-writer] Fix output of array-of-array.
This CL fixes the output of multi-dimentional arrays in the MSL backend.

Bug: tint:7, tint:100
Change-Id: I8fe925145973555f77673e9db97f150077e2471f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24560
Reviewed-by: David Neto <dneto@google.com>
2020-07-10 00:03:19 +00:00
dan sinclair 45101598a1 [msl-writer] Add variable declarations.
This CL adds variable declarations to the MSL backend.

Bug: tint:7
Change-Id: Icf63ad44a217213e5036eb76429e25a3031822eb
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24540
Reviewed-by: David Neto <dneto@google.com>
2020-07-08 20:52:46 +00:00
dan sinclair d0f7381090 [msl-writer] Better error message for missing statement and expression.
If the statement or expression being emitted is not implemented this
will now output the failed statement.

Bug: tint:7
Change-Id: I8a359abd369067540d503a1facbee018e91e8666
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24523
Reviewed-by: David Neto <dneto@google.com>
2020-07-08 18:29:21 +00:00
dan sinclair 723c5b4889 [msl-writer] Add missing include.
Need the algorithm include to build on Windows.

Bug: tint:7
Change-Id: I5691c9e30c762271c767934921fe925120a67e01
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24522
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-07-08 17:17:46 +00:00
dan sinclair 928f59ca46 [msl-writer] Handle remapping remap collisions.
If the remapper give an ident a new name which collides with a future
ident name we need to rename the future name to not collide.

Bug: tint:7
Change-Id: I162a3071f75ed714cee730b78aebefa8c75c77de
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24521
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
2020-07-08 17:17:35 +00:00
Ryan Harrison 7b819aa162 Multiple fixes to get BUILD.gn builds working again
Change-Id: I00c8050d85e25c4e926c06b4df1381434de92f34
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24460
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-07-07 19:11:07 +00:00
David Neto 6453bee795 [spirv-reader] Even better hoisted variables
Use the fact that in WGSL the scope corresponding to the loop construct
encloses the scope for its associated continue construct.
In our construct data structure, the two are adjacent but not
overlapping.

This improvement means that when a definition is in a loop construct,
but used only in the loop or associated continue construct, then no
hoisting is required.

Bug: tint:3
Change-Id: I8d33b8f76303ab2868306847e846b4c26899e746
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24420
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-07-07 17:25:48 +00:00
dan sinclair 6249e38189 Use Tint Generator Number.
This Cl updates the code to use the new Tint generator ID.

Bug: tint:5

11d7637e7a..308bd07424

$ git log 11d7637e7..308bd0742 --date=short --no-merges --format='%ad %ae %s'
2020-06-26 dj2 Register the Tint compiler

Created with:
  roll-dep build buildtools testing third_party/binutils third_party/googletest third_party/spirv-headers third_party/spirv-tools tools/clang

Change-Id: I703d7bf7ad81bc6190e45a5271a30bc7110f4cb7
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24401
Reviewed-by: David Neto <dneto@google.com>
2020-07-06 19:50:42 +00:00
David Neto 91cb60f2ec [spirv-reader] Improve placement of hoisted vars
When we hoist a variable out of a continue construct, put it
in associated loop construct, if it exists.  This reduces its
lifetime in WGSL, and easier to understand as a code reader.

Change-Id: I8f0cc37640bfe67874cbc27b55029e79e9a8992c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24321
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-07-06 18:10:52 +00:00
David Neto 4c48622aa1 [spirv-reader] Allow multi-block continue construct being the entire loop
The special case is not "single-block-loop" but rather the
case where a continue target is also its own loop header.
This can occur for single-block loops and multi-block loops.

Bug: tint:3
Change-Id: I4af1410793caf8b26a1f781e221fc0b395f07aa3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24320
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-07-06 16:13:54 +00:00
David Neto 9b9a0b07da [spirv-reader] Support OpPhi
For each OpPhi, make a variable to carry values from predecessor blocks
to the OpPhi.  Declare the variable at the smallest scope enclosing all
the predecessor blocks (where we write to it), and the OpPhi (where we
read from it).

Bug: tint:3
Change-Id: I7898b4b903d9ee1a25a7466e3c5aaf6840550e2d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24181
Reviewed-by: dan sinclair <dsinclair@google.com>
2020-07-06 16:08:17 +00:00
dan sinclair f2aaa0e985 [msl-writer] Always add the metal_stdlib include.
This CL adds the metal_stdlib include to the MSL generator.

Bug: tint:8
Change-Id: Ie80a7aa3921e2c4594cb7dc5a69d1b04a253c752
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24185
Reviewed-by: David Neto <dneto@google.com>
2020-07-02 20:53:54 +00:00
dan sinclair 6002a3345f [msl-writer] Add namer class.
This CL adds a namer class to prevent collisions with builtin names in
MSL. The MSL generator has been updated to use the namer anywhere that
names are emitted.

Bug: tint:8
Change-Id: I820f226a7286be1d5b0d613bd0fa41b68cb9f8ba
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24184
Reviewed-by: David Neto <dneto@google.com>
2020-07-02 20:53:45 +00:00
dan sinclair 53b3283c6a [msl-writer] Emit switch statements.
This CL adds support for switch and case statements into the MSL writer.

Bug: tint:8
Change-Id: Ib51f943e8476c0ecfd45e9131404f96934c6e21f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/24180
Reviewed-by: David Neto <dneto@google.com>
2020-06-30 21:33:20 +00:00