Commit Graph

1044 Commits

Author SHA1 Message Date
Lei Zhang
75d4316280 Fix build error about passing initializer-list to constructor.
VS2013 is not happy with using initializer-list to initialize
vector parameters to explicit constructors taking one vector.
2016-08-10 16:10:14 -04:00
Lei Zhang
dda9de965d Make type manager RAII-like w.r.t. the module to be analyzed. 2016-08-10 12:53:17 -04:00
Lei Zhang
c562e231e3 Optimization: Add type manager.
Type manager will construct a map of types gradually from
instructions.
2016-08-10 12:53:17 -04:00
Lei Zhang
6d4d15b9d0 Optimization: Add type class hierarchy. 2016-08-10 12:53:17 -04:00
Lei Zhang
80c94a4fa8 Change the interfaces of in-memory representation to use pointers.
Previously we use vectors of objects and move semantics to handle
ownership. That approach has the flaw that inserting an object into
the middle of a vector, which may trigger a vector reallocation,
can invalidate some addresses taken from instructions.

Now the in-memory representation internally uses vector of unique
pointers to handle ownership. Since objects are explicitly heap-
allocated now, pointers to them won't be invalidated by vector
resizing anymore.
2016-08-10 12:11:33 -04:00
Andrew Woloszyn
38c9471a0e Fixed the build for MSVC.
assembly_builder was missing an include for cstdint.
2016-08-10 09:45:15 -04:00
Umar Arshad
489204cf03 Check dominance of OpPhi parent and variable pairs 2016-08-09 18:19:47 -04:00
Lei Zhang
190b0d3162 Use NEW behavior for policy CMP0054.
The NEW behavior is to not dereference variables or interpret keywords
that have been quoted or bracketed.

For more information, see
https://cmake.org/cmake/help/v3.1/policy/CMP0054.html.

This is to suppress a warning when using CMake 3.1.3+.
2016-08-09 16:09:59 -04:00
Umar Arshad
816f29805b Refactor Id -> Instruction 2016-08-09 15:50:03 -04:00
qining
d49928f0cc Fix minor mistakes in the tests of dead-const-elim 2016-08-09 14:37:58 -04:00
qining
a90fc84779 Print the shader when module building failed 2016-08-08 17:19:47 -04:00
qining
51a2484b36 Dead constant elimination
A pass to remove dead constants, including both front-end constants and spec
constants.

This pass does not handle dead variables and types.
2016-08-08 17:17:15 -04:00
David Neto
c296701964 Add target envs for OpenCL, OpenGL
Covers: OpenCL 2.1, OpenCL 2.2
Covers: OpenGL 4.0, OpenGL 4.1, OpenGL 4.2, OpenGL 4.3, OpenGL 4.5.
The OpenGL environments assume the use of GL_ARB_gl_spirv, of course.
2016-08-05 18:19:30 -04:00
David Neto
b51b80980c Validator cfg fixes
- Find unreachable continue targets.  Look for back edges
  with a DFS traversal separate from the dominance traversals,
  where we count the OpLoopMerge from the header to the continue
  target as an edge in the graph.

- It's ok for a loop to have multiple back edges, provided
  they are all from the same block, and we call that the latch block.
  This may require a clarification/fix in the SPIR-V spec.

- Compute postdominance correctly for infinite loop:
  Bias *predecessor* traversal root finding so that you use
  a later block in the original list.  This ensures that
  for certain simple infinite loops in the CFG where neither
  block branches to a node without successors, that we'll
  compute the loop header as dominating the latch block, and the
  latch block as postdominating the loop header.
2016-08-05 15:15:37 -04:00
Lei Zhang
71fac5a29c Check configuration and gmock existence when adding unit tests. 2016-08-05 14:38:18 -04:00
David Neto
3184687714 Fix dominance calculation
Fixes dominance calculation when there is a forward arc from an
unreachable block A to a reachable block B.  Before this fix, we would
say that B is not dominated by the graph entry node, and instead say
that the immediate dominator of B is the psuedo-entry node of the
augmented CFG.

The fix:

- Dominance is defined in terms of a traversal from the entry block
  of the CFG.  So the forward DFS should start from the function
  entry block, not the pseudo-entry-block.

- When following edges backward during dominance calculations, only go to
  nodes that are actually reachable in the forward traversal.
  Important: the sense of reachability flips around when computing
  post-dominance.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/297
2016-08-05 11:09:29 -04:00
qining
d37ecb924a Simple Assembly code builder for test uses
AssemblyBuilder contains boilplates.
Adds OpName instructions for all added defining instructions.
Adds OpDecorate SpecId for all spec constants added with OpSpecConstant,
OpSpecConstantTrue and OpSpecConstantFalse instructions.
2016-08-04 16:45:59 -04:00
David Neto
621fa3961f Only check def dominance of reachable uses
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/295
2016-08-04 14:58:27 -04:00
David Neto
9acc0f1401 Never generate % for a friendly disassembled Id
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/290
2016-08-02 11:59:10 -04:00
David Neto
e7a9e00738 Add disabled test for phi variable def-use check
Disabled because doing a proper check requires much more
code, and it can wait.
2016-07-29 20:00:38 -04:00
David Neto
1408aea260 Avoid checking def-use dominance for OpPhi value operands
The def-use dominance checker doesn't have enough info to know
that a particular use is in an OpPhi, so skip tracking those uses
for now.  Add a TODO to do a proper OpPhi variable-argument check
in the future.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/286
2016-07-29 20:00:38 -04:00
Lei Zhang
64ff3c6dc1 Optimization: Add def use analysis. 2016-07-29 15:45:14 -04:00
David Neto
c978b72477 Fix infinite loop in dominance calculation.
Ensure the dominance calculation visits all nodes in the CFG.
The successor list of the pseudo-entry node is augmented with
a single node in each cycle that otherwise would not be visited.
Similarly, the predecssors list of the pseduo-exit node is augmented
with the a single node in each cycle that otherwise would not
be visited.

Pulls DepthFirstSearch out so it's accessible outside of the dominator
calculation.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/279
2016-07-28 16:40:55 -04:00
qining
4750895943 Fix a test failure in pass manager test
Change "Null" to "null" in pass manager test
2016-07-28 15:30:37 -04:00
qining
a24506266b Freeze spec constants to their default values
Add a pass to freeze spec constants to their default values. This pass does
not fold the frozen spec constants and does not handle SpecConstantOp
instructions and SpecConstantComposite instructions.
2016-07-28 15:23:30 -04:00
qining
ac46512b05 Add an utility: in-place string replacement 2016-07-28 12:11:34 -04:00
qining
d503d75cc3 Use friendly disassembly output 2016-07-28 09:39:42 -04:00
Umar Arshad
efc782d743 Check definitions appear in dominator of use
Also address use and def of ID in same instruction
2016-07-26 16:09:16 -04:00
Umar Arshad
66c94928a3 Refactor IDs definition and use tracking
* Creates an ID class which manages definition and use of IDs
* Moved tracking code from validate.cpp to validate_id.cpp
* Rename and combine SsaPass and ProcessIds into IdPass
* Remove module dependency in Function
2016-07-26 13:36:41 -04:00
Umar Arshad
6c61bf2dfa Fixes segfault for loops without back-edges
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/270
2016-07-25 13:21:44 -04:00
David Neto
0bdcc23f7e Disassembling: map IDs to friendly names.
Add a FriendlyNameMapper to deduce friendly names for IDs based on
OpName, type structure, etc.
2016-07-19 16:28:17 -04:00
Lei Zhang
1a9385bbd0 Track changes in SPIRV-Headers for SPIR-V 1.1 rev 2.
* The `Input` StorageClass doesn't require the `Shader` capability
  anymore.
* The `Sampled1D` and `SampledBuffer` capabilities don't require
  the `Shader` capability anymore. So they do not indirectly
  depend on the `Matrix` capability. So are the `Image1D` and
  `ImageBuffer` capabilities, which depend on `Sampled1D` and
  `SampledBuffer`.

A new GLSL grammar file is uploaded for SPIR-V 1.1, but it's the
same as the existing one for SPIR-V 1.0.

Now tracking commit 3814effb879ab5a98a7b9288a4b4c7849d2bc8ac in
SPIRV-Headers.
2016-07-18 11:55:16 -04:00
David Neto
06581f5ce6 Turn off ClipDistance CullDistance cap checks for Vulkan
Turn them off until resolution of the debate over how they should be checked.
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/261
2016-07-08 11:47:40 -04:00
David Neto
e59007320e Test v1.1 loop dependency support
For DependencyInfinite and DependencyLength, test
that they don't require a capability to be turned on.
Also, that they are assembled, binary parsed, and disassembled
correctly.
2016-07-05 12:05:00 -04:00
Lei Zhang
2c4c73cf37 Add Pass, PassManager, and StripDebugInfoPass. 2016-06-29 17:32:00 -04:00
David Neto
e461cbe268 Avoid capability checks on ID values. They are not literals
Works around issue 248 by weakening the test:
https://github.com/KhronosGroup/SPIRV-Tools/issues/248

The validator should try to track (32-bit) constant values, and then
for capability checks on IDs, check the referenced value, not the
raw ID number.
2016-06-29 10:39:21 -04:00
Lei Zhang
f760d115b9 Add tests for the cpp interface. 2016-06-28 14:52:35 -04:00
Lei Zhang
abf8f6413c Promote ir namespace and create draft libspirv.{h|c}pp. 2016-06-28 14:52:34 -04:00
Lei Zhang
8590f9cc81 Add IrBuilder for constructing SPIR-V in-memory representation. 2016-06-27 16:57:42 -04:00
Lei Zhang
200e897887 Add an option to spvBinaryToText() to ignore header output. 2016-06-27 15:25:24 -04:00
David Neto
5065227748 Use pseudo entry and pseudo exit blocks for dominance.
For dominance calculations we use an "augmented" CFG
where we always add a pseudo-entry node that is the predecessor
in the augmented CFG to any nodes that have no predecessors in the
regular CFG.  Similarly, we add a pseudo-exit node that is the
predecessor in the augmented CFG that is a successor to any
node that has no successors in the regular CFG.

Pseudo entry and exit blocks live in the Function object.

Fixes a subtle problem where we were implicitly creating
the block_details for the pseudo-exit node since it didn't
appear in the idoms map, and yet we referenced it.  In such a case the
contents of the block details could be garbage, or zero-initialized.
That sometimes caused incorrect calculation of immediate dominators
and post-dominators.  For example, on a debug build where the details
could be zero-initialized, the dominator of an unreachable block would
be given as the pseudo-exit node.  Bizarre.

Also, enforce the rule that you must have an OpFunctionEnd to close off
the last function.
2016-06-24 17:08:20 -04:00
Lei Zhang
1a050b1069 Use arguments for add_spvtools_unittest. 2016-06-22 12:13:59 -04:00
Umar Arshad
f61db0bcc6 Validator structured flow checks: back-edge, constructs
Skip structured control flow chekcs for non-shader capability.

Fix infinite loop in dominator algorithm when there's an
unreachable block.
2016-06-22 11:51:19 -04:00
David Neto
1a18739650 Fix ExtInst parsing: no IdRef* at end
The operands following the extended instruction literal
number are determined by the extended instruction itself.
So drop the zero-or-more IdRef pattern at the end of OpExtInst.

It's arguable whether this should actually be a grammar fix.  I've
chosen to patch this in SPIRV-Tools instead of in the grammar file.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/233

Also fix two test cases for OpenCL extended instructions.  These
errors of supplying too many operands are now detected.
2016-06-15 10:00:06 -04:00
David Neto
37e4600c3e Fix OpenCL pow and pown arguments
Spec fix appeared in SPIR-V 1.0 Rev 2:
https://www.khronos.org/registry/spir-v/specs/1.0/OpenCL.ExtendedInstructionSet.100.html#_changes_from_version_1_0_revision_1

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/143
2016-06-14 12:14:38 -04:00
David Neto
3ed641df39 In physical addressing, functions can return pointers
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/229
2016-06-14 11:00:39 -04:00
Lei Zhang
10dba91781 Use SPIR-V headers from the KhronosGroup/SPIRV-Headers repo. 2016-06-10 08:48:37 -04:00
Umar Arshad
11437165d6 Fix diagnostic message for layout errors 2016-06-09 15:51:39 -04:00
Umar Arshad
90a4252aae Split validate_types file into multiple classes
Creates separate files for the ValidationState, Function and
BasicBlock classes.
2016-06-08 14:40:33 -04:00
Umar Arshad
f9903c8d36 Additional CFG tests
* Empty function
* Single block loops
* Nested loops
* Nested selection
2016-06-03 15:29:44 -04:00
Dejan Mircevski
812fb7d798 Make googletest regexes portable.
On Windows, test::MatchesRegex() doesn't support brackets.  On Linux, \d
doesn't work. :(
2016-06-02 13:13:04 -04:00
Umar Arshad
0b9fd50d31 Control Flow Graph Validation 2016-06-02 12:11:52 -04:00
Lei Zhang
2ea7449c9c Create a function for adding unittests in CMake.
Also remove unnecessary main() function for unittests.
2016-05-30 10:28:56 -04:00
Dejan Mircevski
0d512bbef5 Test ABGR in both 1.0 and 1.1. 2016-05-12 22:06:28 -04:00
Dejan Mircevski
faad7fea3d Test ABGR image channel order.
Update include/spirv/spirv.h from SPIRV-Headers.
2016-05-11 15:14:21 -04:00
Dejan Mircevski
6520ba93ac Test OpModuleProcessed. 2016-05-11 12:40:59 -04:00
Dejan Mircevski
10f1020560 Remove done TODOs in OpNameTest.
Simplify the instantiation by using Values() instead of ValuesIn().

Run clang-format.
2016-05-11 10:34:27 -04:00
Dejan Mircevski
a7c1265c38 Test SpecId validation. 2016-05-11 10:01:06 -04:00
Dejan Mircevski
4376856b1a Add tests for MaxByteOffset. 2016-05-10 22:46:27 -04:00
Jamie Madill
dc4c2ba7dc Add PipeStorage tests. 2016-05-09 13:54:05 -04:00
Florian Ziesche
66fcb456c1 bitcast fixes
* ValidationState_t and idUsage now store the addressing model and memory model of the SPIR-V module (this is necessary for certain instructions that need different checks depending on if the logical or physical addressing model is used)
 * removed SpvOpPtrAccessChain and SpvOpInBoundsPtrAccessChain from spvOpcodeIsPointer again as these are disallowed in logical addressing mode and only allowed in physical addressing mode (which doesn't use/need spvOpcodeIsPointer in the first place)
 * added SpvOpImageTexelPointer and SpvOpCopyObject to spvOpcodeIsPointer
 * OpLoad/OpStore now only check if the used pointer operand originated from a valid pointer producing opcode in logical addressing mode (as per 2.16.1)
 * moved bitcast pointer tests to the kernel / physical addressing model part (+cleanup)
 * renamed spvOpcodeIsPointer to spvOpcodeReturnsLogicalPointer to clarify this function is only meant to be used with the logical addressing model
2016-04-29 14:55:05 -04:00
Dejan Mircevski
13877a3b0e Add v1.1 tests for OpLoopMerge. 2016-04-29 14:09:52 -04:00
Dejan Mircevski
3732d6cc21 Add v1.1 capabilities validation.
Refactor the ValidateCapability test fixture.

Explain the meaning of test parameters.  Factor out methods for
convenience and readability.  DRY v1.0 and v1.1 tests.
2016-04-29 13:40:01 -04:00
Dejan Mircevski
af701f8f6a Add basic Initializer/Finalizer tests. 2016-04-27 22:02:39 -04:00
Dejan Mircevski
45d391b7b1 Add OpSizeOf tests. 2016-04-27 15:41:58 -04:00
Dejan Mircevski
da8222ee4e Refactor OpExecutionModeTest and apply it on v1.1.
Previously v1.1 testing was dead.
2016-04-26 13:03:28 -04:00
Dejan Mircevski
27d6008889 Refactor v1.1 tests and turn them on.
Previously, the "V11" text fixture was empty.
2016-04-26 12:16:00 -04:00
David Neto
9166854ac9 Add CHANGES file with high level software history
Add a high level version number for SPIRV-Tools, beginning
with v2016.0-dev.  The README describes the format of the
version number.

The high level version number is extracted from the CHANGES
file.  That works around:
 - stale-bait for when we don't add tags to the repository
 - our inability to add tags to the repository

Option --version causes spirv-as, spirv-dis, and spirv-val to
show the high level version number.

Add spvSoftwareVersionString to return the C-string for
the high level version number.

Add spvSoftwareVersionDetailsString() so that clients can get
more information if they want to.
Also allows us to clean up the uses in the tool executables files,
so now only one file includes build-version.inc.

Move the update-build-version logic to the only
CMakeLists file that needs it.

The update build version script takes a new argument
to name the output file.
2016-04-22 15:19:45 -04:00
Dejan Mircevski
d3da705a22 Fix Windows build.
Replace `#ifdef 0` with comment inside a macro call.
2016-04-21 17:12:47 -04:00
Lei Zhang
f2cf719f50 Avoid going out of bound in advanceLine() and refine comments. 2016-04-21 16:08:51 -04:00
Dejan Mircevski
2ea54f5d1b Add tests for SubgroupDispatch.
Introduced in v1.1, SubgroupDispatch adds the following:
- two new execution modes
- one new capability
- two new opcodes

Extend ValidateBase methods to take a spv_target_env.  Replace the
context_ member with ScopedContext inside the said methods.  Give
ScopedContext wider visibility by moving it outside
TextToBinaryTestBase.
2016-04-21 15:46:08 -04:00
Dejan Mircevski
7b33485f6e First tests for SPIR-V v1.1.
Add test for named-barrier instructions and capability.

Add spv_target_env as an optional argument to CompileSuccessfully() and
CompileFailure().  Currently defaults to UNIVERSAL_1_0, though that
could change in the future.

Make spv_context a local variable in test methods instead of a
TextToBinaryTestBase member.  Introduce ScopedContext to make temp
contexts easier.
2016-04-19 16:34:12 -04:00
Dejan Mircevski
cb3c49ef82 Add SPIR-V 1.1 grammar.
Switch to SPIR-V 1.1 as default.
Introduce SPV_ENV_UNIVERSAL_1_1.
Add "1_0" to the internal variable names.
Add spv_target_env to spv*GetTable().
2016-04-18 10:45:57 -04:00
Dejan Mircevski
7649c7362d Fix MSVC error C2797. 2016-04-04 20:16:15 -04:00
Dejan Mircevski
3fb2676d23 Fix validation of array length. 2016-04-04 15:55:05 -04:00
Lei Zhang
6fa3f8aad9 Remove dependency on SPIR-V headers in libspirv.h.
For fulfilling this purpose, the |opcode| field in the
|spv_parsed_instruction_t| struct is changed to of type uint16_t.

Also add functions to query the information of a given SPIR-V
target environment.
2016-04-04 10:34:28 -04:00
Eric Engestrom
c9b2285bfc Fix spelling mistakes 2016-04-02 22:54:59 +01:00
Lei Zhang
4f293b7139 Use the JSON grammar file to generate various info tables.
This patch uses a Python script to parse the JSON grammar file to
generate the opcode table and operand kind tables.

Now we don't need to do the post-processing (from OperandClass
to spv_operand_type_t) and copying of the opcode info table is
not required anymore!
2016-04-01 13:18:42 -04:00
Dejan Mircevski
a1de2b37c7 Handle CRLF in assembly text. 2016-04-01 00:47:02 -04:00
Dejan Mircevski
3d27da4bc7 Add a target environment to spvContextCreate().
Run clang-format.
2016-03-31 12:16:51 -04:00
David Neto
6836e17f24 OpExecutionMode only takes a single ExecutionMode
Previously, the grammar allowed many execution modes for a single
OpExecutionMode instruction.

Removes the variable- and optional- execution mode operand type
enum values.

Issue found by antiagainst@
2016-03-29 14:51:02 -04:00
Lei Zhang
452914634e Capability fix: ImageReadWrite & ImageMipmap require ImageBasic. 2016-03-29 09:47:23 -04:00
Andrew Woloszyn
4c657bfa8f Make everything compile cleanly with -Wpedantic.
This makes SPIRV_WARN_EVERYTHING compile cleanly.
2016-03-21 10:01:13 -04:00
Lei Zhang
eb6fc51d35 Split CMakeLists.txt into smaller ones. 2016-03-17 14:43:02 -04:00
Lei Zhang
6032b98c53 Change the interface for getWord().
* It's redundant to provide two mutable spv_position to getWord().
* getWord() should take string pointer by the style guide.
2016-03-16 15:46:15 -04:00
Dejan Mircevski
755eb6dcfc Remove AssemblyContext::getWord().
Fixes #152.
2016-03-15 15:16:40 -04:00
Andrew Woloszyn
9dd1cd7f31 Fixed float->int16 conversion warnings in VS2013. 2016-03-07 15:55:44 -05:00
Florian Ziesche
680f9b7ef1 Don't check kernel entry-point signatures.
Recognize SpvOpInBoundsPtrAccessChain and SpvOpPtrAccessChain as opcodes
returning a pointer.

 * spvOpcodeIsPointer: recognize SpvOpInBoundsPtrAccessChain and SpvOpPtrAccessChain as opcodes returning a pointer

 * isValid<SpvOpEntryPoint>: don't check kernel function signatures (these don't have to be 'void main(void)')

 * added tests for kernel OpEntryPoint, OpInBoundsPtrAccessChain and OpPtrAccessChain, as well as facilities to actually test kernel/OpenCL SPIR-V

 * fixed pow and pown specification (both should take 2 parameters), spec bug reported at https://www.khronos.org/bugzilla/show_bug.cgi?id=1469

 * use ASSERT_TRUE instead of ASSERT_EQ

 * added pow and pown test (pow(val, 2.0f) and pown(val, 3))

Revert " * fixed pow and pown specification (both should take 2 parameters), spec bug reported at https://www.khronos.org/bugzilla/show_bug.cgi?id=1469"

This reverts commit c3d5a87e73.

Revert " * added pow and pown test (pow(val, 2.0f) and pown(val, 3))"

This reverts commit 7624aec720.
2016-03-02 15:27:26 -05:00
Lei Zhang
712bed0227 Fix issues reported by cppcheck.
Remove code not being used, add explicit to constructors, and
add missing fields in constructors.
2016-02-25 16:16:28 -05:00
Lei Zhang
b6ccd0d891 Remove spv_validate_options_t and change tests accrodingly.
Users always want to run all the checks. The spv_validate_options_t
mechanism, which provides little benefits to users, complicates the
internal implementation and also makes the tests exercise different
paths as users do.

Right now the tests are more like integration tests instead of
unit tests, which should be our next refactoring aim.
2016-02-23 16:19:33 -05:00
Lei Zhang
9413fbbf58 getWord() should not go beyond the end of the source text.
This addresses Bug #126 where EOL is missing at the end of
source file.
2016-02-22 17:25:08 -05:00
David Neto
4d2f2239bf SPIR-V Tools fully supports SPIR-V 1.0 Rev3
- Update version numbers in libspirv.h.
  Add a test for the relevant macros.
- Update the README
2016-02-17 16:01:39 -05:00
David Neto
53075ea82b Add MultiViewport capability, new in 1.0.3
Fix typos in previous tests with MultiViewport.
2016-02-17 15:29:05 -05:00
David Neto
5a70335bf1 Rearrange headers
Now we have public headers arranged as follows:
$SPIRV_TOOLS_ROOT/include/spirv-tools/libspirv.h
$SPIRV_TOOLS_ROOT/include/spirv/spirv.h
$SPIRV_TOOLS_ROOT/include/spirv/GLSL.std.450.h
$SPIRV_TOOLS_ROOT/include/spirv/OpenCL.std.h

A project should use -I$SPIRV_TOOLS_ROOT/include
and then #include "spirv-tools/libspirv.h"

The headers from the SPIR-V Registry can be accessed as "spirv/spirv."
for example.

The install target should also install the headers from the SPIR-V
Registry.  The libspirv.h header is broken otherwise.

The SPIRV-Tools library depends on the headers from the SPIR-V Registry.

The util/bitutils.h and util/hex_float.h are pulled into the internal
source tree.  Those are not part of the public API to SPIRV-Tools.
2016-02-17 14:49:44 -05:00
David Neto
58c4e1d57a Add GLSL instructions NMin, NMax, NClamp
These appear first in GLSL.std.450 in 1.0 Rev3
2016-02-17 13:35:13 -05:00
David Neto
1d9a876f95 Test OpImageSparseRead
Also tweak the image operands test with OpImageFetch so the input assembly
more closely matches the expected output.  But don't make it a round
trip test since we want to check the assembler's ability to read the
image operand mask with out-of-order mask names.

The OpImageSparseRead assembly test is also a round trip disassembler
test.
2016-02-17 13:32:37 -05:00
David Neto
2732f57ed2 Remove remaining float overflow value tests
Should fix tests on Windows.
2016-02-17 13:02:48 -05:00
David Neto
2889a0c21c Use syntax tables for SPIR-V 1.0 Rev3
- The SPIR-V spec generator has changed how it represents optional
  operands.  Now it tracks a separate boolean flag indicating optionality.
  However, SPIRV-Tools still wants to represent both operand class
  and optionality in the same enums space (SPV_OPERAND_TYPE_*).
  So there's extra work in the patch.

- In the spec generator, OperandImage is now OperandImageOperands.
  This affects enum translation in opcode.cpp.

- In the spec generator, image operands are explicitly followed by
  Id, and VariableIds.  However, SPIRV-Tools uses the bits set
  in the image operand bitmask to control the number and meaning
  of the Ids that follow.  So in writing the opcode.inc syntax
  table, drop all operands after OperandImageOperands.

- Some enums are now more explicitly represented in the generated
  opcode.inc:
    - AccessQualifier (e.g. on OpTypeImage), in both required and
      optional flavours.
    - MemoryAccess (e.g. on loads and stores)

- Add SPV_OPERAND_TYPE_OPTIONAL_ACCESS_QUALIFIER

- Add tests for the optional AccessQualifier operand on OpTypeImage.

- Update the AccessQualifier test for OpTypeImage so it's a round
  trip test through the disassembler as well.
2016-02-16 16:47:04 -05:00
David Neto
dd8a661b70 Update capabilities for 1.0 Rev3 2016-02-16 16:44:45 -05:00
David Neto
0c0a07f0aa Don't promise particular values when float parsing fails.
This should address problems on Windows:
https://github.com/KhronosGroup/SPIRV-Tools/issues/104
2016-02-16 12:13:51 -05:00
David Neto
c7a9a909a8 Parse overflow for fp16 like for 32- and 64-bit
In that case, set the stream fail bit, and set the maximum normal
value or lowest normal value, depending on the sign of the original
value.
2016-02-15 09:31:10 -05:00
David Neto
6bad02c320 Float literal parsing fixes
- For 32- and 64-bit floats, overflow is a parse error

  This works around a difference between Xcode's istringstream
  and other platforms.  Xcode's runtime library will happlily
  "round up" overflow values to infinity.  We want to make it fail.

- When parsing a float fails due to bad syntax, follow C++11
  behaviour for operator>> and set the value to zero.

- When parsing a 32-bit or 64-bit float overflows, follow C++11
  behaviour for operator>> and set the value to the nearest
  normal value: either max or lowest finite value for the type.

- Add FloatProxy<T>::max() and ::lowest()

- Make 16-bit overflow behaviour more consistent: we always get a
  16-bit infinity of the right sign, whether the original string
  is a normal value for 32-bit or an overflow value for 32-bit.
  That matches our earlier intent.
  Added TODO's to make 16-bit overflow always an error, just like
  for 32-bit and 64-bit.

- Simplify normal parsing of Float16 values by delegating to
  normal parsing of 32-bit floats.
2016-02-12 16:01:42 -05:00
David Neto
000cad9cc6 Reject float literals with two leading signs
E.g. --1 should be rejected.
2016-02-11 14:11:16 -05:00
David Neto
feda995c84 More parsing tests for literals with leading minus
Also checks some hex literal cases.

This addresses part of
https://github.com/KhronosGroup/SPIRV-Tools/issues/45
by removing the parseNumber case for "-0" on unsigned
integers.  We don't care about that platform difference
at the level of std::istringstream, since we reject it
at a higher parsing level.
2016-02-08 16:56:41 -05:00
Dejan Mircevski
7ef6da7b7f Make IsTypeNullable a transitive check. 2016-02-04 15:34:47 -05:00
Dejan Mircevski
4038195d81 Eliminate parameter-order check from ID-validation. 2016-02-03 12:34:52 -05:00
Dejan Mircevski
10fa696af7 Allow Op[No]Line between OpFunctionParameters.
Also ensure we don't get thrown off by too many parameters.
2016-02-03 10:26:59 -05:00
David Neto
b5267569d1 Add spvOperandIsConcreteMask 2016-02-02 12:05:34 -05:00
Dejan Mircevski
0c8bdfe163 Use AssemblyGrammar for capability validation.
Also:
- ForEach() for spv_capability_mask_t.
- Add capability min/max constants.
- Move max definition from validate_types.cpp to spirv_definition.h.
2016-02-02 11:40:05 -05:00
Dejan Mircevski
5f99fc33cd Forbid Generic variables. 2016-01-29 17:08:41 -05:00
Dejan Mircevski
8177fbea06 Fix in-function storage class validation.
Move tests into a fixture that properly turns on the relevant passes.
2016-01-29 16:30:23 -05:00
Dejan Mircevski
8db38e547b Initialize vector<string>s on first use, not statically. 2016-01-28 13:18:00 -05:00
Dejan Mircevski
1e157bc2e8 Fix validation of return value. 2016-01-28 10:58:03 -05:00
Dejan Mircevski
a4342f3f44 Remove spvOpcodeIsObject().
Also
- Add type_id to spv_id_info_t.
- Use spv_id_info_t::type_id instead of words[1].
  Triggered some asserts on tests, where the code incorrectly assumed
  words[1] had a type.  Remove the asserts and handle gracefully.
- Add tests for OpStore of a label, a void, and a function.
2016-01-27 16:20:10 -05:00
Umar Arshad
61a627586b Initial capability implementation and unit tests
* Register capabilility and checks
* Add validate storage class capabilities checks and tests
* Instruction pass refactor
  - More generic form of capability checking by checking operands
    instead of instructions
* Execution Model capabilities checks
* Decorate BuiltIn capability checks
* Addressing Model capability checks
* Memory Model capability checks
* Execution Mode capability checks
* Dim capability checks
* SamplerAddressingMode capability checks
2016-01-27 08:37:23 -05:00
Dejan Mircevski
276a724b25 Fix spvOpcodeIsScalarType() to include Boolean.
Remove redundant validations of OpConstant and OpConstantComposite.
Binary parser already performs these checks, so the validations can
never be triggered.

Enable bad-constant tests.
2016-01-22 16:40:27 -05:00
Dejan Mircevski
58852aa012 Fix OpLoad pointee type validation. 2016-01-21 14:07:19 -05:00
David Neto
c62f41e281 Add disassembler option to show byte offset
The option is disabled by default.

The offset is printed in hex, as a comment after each instruction.
2016-01-20 17:07:30 -05:00
Dejan Mircevski
961f5dc544 Track uses and defs during parsing.
Replace two other, imperfect mechanisms for use-def tracking.

Use ValidationState_t::entry_points to track entry points.

Concentrate undefined-ID diagnostics in a single place.

Move validate_types.h content into validate.h due to increased
inter-dependency.

Track uses of all IDs: TYPE_ID, SCOPE_ID, ...

Also update some blurbs.

Fix entry-point accumulation and move it outside ProcessIds().

Remove validate_types.h from CMakeLists.txt.

Blurb for spvIsIdType.

Remove redundant diagnostics for undefined IDs.

Join "can not" and reformat.
2016-01-20 17:00:58 -05:00
Umar Arshad
2a790fbc6d Fix missing OpNoLine layout checks 2016-01-18 13:44:42 -05:00
Umar Arshad
1ddeb246eb Validation refactor
* Organize passes into seperate files
* Remove module layout logic from Cfg pass
* Remove module layout logic from Functions class
* Refactor ModuleLayoutPass for readability
* Adapt consistent naming of layout sections (Stage/Section -> Section)
2016-01-14 21:59:28 -05:00
Umar Arshad
fa3b878119 Add missing branch instructions in SSA tests 2016-01-14 09:48:29 -05:00
Umar Arshad
c741385976 Function and block layout checks. very basic CFG.
This adds function and block layout checks to the validator. Very
basic CFG code has been added to make sure labels and branches
are correctly ordered.

Also:
* MemoryModel and Variable instruction checks/tests
* Use spvCheckReturn instead of CHECK_RESULT
* Fix invalid SSA tests
* Created libspirv::spvResultToString in diagnostic.h
* Documented various functions and classes
* Fixed error messages
* Fixed using declaration for FunctionDecl enum class
2016-01-13 10:06:58 -05:00
Andrew Woloszyn
ca50510ad4 Fixed use-after-free in isStartOfNewInst() tests. 2016-01-12 14:47:24 -05:00
David Neto
5d30edb36d spvDiagnosticDestroy is safe to call on nullptr
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/62
2016-01-11 14:26:46 -05:00
Andrew Woloszyn
3b69d05086 Fix endian-ness conversion in the binary parser.
When we were swapping endian-ness in the binary parser, we would
write outside of the bounds of our vector.
2016-01-11 13:54:30 -05:00
Andrew Woloszyn
7a35473573 Made compilation with gcc and clang more strict.
Added additional compilation flags to gcc and clang builds.
Adds -Wall -Wextra -Wno-long-long -Wshadow -Wundef -Wconversion
-WNo-sign-conversion and -Wno-missing-field-initializers
where appropriate.

Does not add -Wundef to tests, because GTEST tests undefined
macros all over the place.
2016-01-11 10:54:20 -05:00
Andrew Woloszyn
43401d2ed0 Support 16-bit float in assembler and disassembler
This adds half-precision constants to spirv-tools.
16-bit floats are always disassembled into hex-float format,
but can be assembled from floating point or hex-float inputs.
2016-01-08 10:48:39 -05:00
Dejan Mircevski
b6fe02fc39 Extend copyright to 2016. 2016-01-07 13:44:22 -05:00
David Neto
969ce4b323 Fix list of opcodes allowed for OpSpecConstantOp
Was missing BitcastXor, GenericCastToPtr.
Remove duplicate of SLessThanEqual
2016-01-05 18:22:22 -05:00
David Neto
d0de196439 operator<< on FloatProxy preserves float and fill
Fixes formatting of disassembler output after printing
a hex float, e.g. for a NaN or subnormal.
2016-01-05 12:49:55 -05:00
David Neto
3664bd5670 Fix parser assert failure for a bad OpSwitch
Emit a diagnostic if the OpSwitch selector refers to an ID that
is valid but has no type.

Discovered by afl-fuzz.
2016-01-05 11:25:58 -05:00
David Neto
1a3734d265 Avoid relative path in #include
Adds CMAKE_CURRENT_SOURCE_DIR to the include path for UnitSPIRV
2016-01-04 13:07:45 -05:00
David Neto
4c21571728 Rename endian.h to spirv_endian.h
If we later add a source/ as an -I include directory,
then avoid confusing other headers that want to include the
standard "endian.h" from /usr/include.

Also rename source/endian.cpp to source/spirv_endian.cpp
2016-01-04 10:47:27 -05:00
Umar Arshad
a3d0d3c719 Initial logical layout validation
* Validates module level instructions for logical layout
  conformance
* Does not validate:
  1. Function logical layout
  2. Minor cases with OpVariable
  3. Missing MemoryModel instruction in module
  4. Order of function definition and function declaration
* 782 unit tests for logical layout

Addressed feedback
2015-12-17 15:58:09 -05:00
Umar Arshad
6d37e3c5f3 Refactor validation types into another file 2015-12-17 15:56:58 -05:00
Umar Arshad
532af9c09c Fix tests which rely on OpName;Use EXPECT_THAT
All OpName calls should appear before annotation and type
declarations.
2015-12-14 14:33:26 -05:00
Umar Arshad
f76e0f5231 Basic SSA Validation
Most uses of an ID must occur after the definition
of the ID.  Forward references are allowed for
things like OpName, OpDecorate, and various cases
of control-flow instructions such as OpBranch, OpPhi,
and OpFunctionCall.

TODO: Use CFG analysis for SSA checks.  In particular,
an ID defined inside a function body is only usable inside
that function body.  Also, use dominator info to catch
some failing cases.

Also:
* Validator test cases use (standard) assignment form.
* Update style to more closely follow the Google C++ style guide
* Remove color-diagnostics flag.
  This is enabled by default on terminals with color. Prints
  hidden ASCII for terminals that can't handle color(Emacs)
* Pass functors to SSAPass to check if the
  operand can be forward referenced based on its index value
* Return SPV_ERROR_INVALID_ID for ID related errors
  spvBinaryParse returned SPV_ERROR_INVALID_BINARY for all types of
  errors. Since spvBinaryParse does some ID validation, this was
  returning inappropriate error codes for some tests.
* Common fixture for validation tests.
  It only runs certian validation passes.
* Add a SPV_VALIDATE_SSA_BIT for testing purposes
* Fixtures now return error codes
* Add OpName support in diag message and unit tests
* Binary parsing can fail with invalid ID or invalid binary error code

Tests include:
* OpDecorate
* OpName
* OpMemberName
* OpBranchConditional
* OpSelectionMerge
* OpMemberDecorate
* OpGroupDecorate
* OpDeviceEnqueue
* Enable several tests failing in ID validation.
2015-12-09 16:15:00 -05:00
Andrew Woloszyn
4e5bc928c0 Added Float16, and HexFloat conversions 2015-12-08 14:41:57 -05:00
David Neto
4b6a98fe16 Fix namespace on PrintTo 2015-12-02 11:55:35 -05:00
David Neto
590ff131ac PrintTo on WordVector should preserve the fill char 2015-12-01 18:25:03 -05:00
David Neto
5947c40483 Stated word count is several more than expected
These are extra binary parsing cases.
2015-12-01 16:45:46 -05:00
David Neto
66f649d501 Use static_cast instead of constructor for uint32_t 2015-12-01 16:19:44 -05:00
David Neto
39fa148234 OpDecorate should not accept any number of literal operands.
This is a grammar fix.  The Decoration operand of OpDecorate (and
OpMemberDecorate) determines the remaining operands.  Don't just
allow any number of literal numbers as operands.

(The OperandVariableLiterals operand class as the last member
of the OpDecorate and OpMemberDecorate entries in in opcode.inc is
an artifact of how the spec generates the opcode descriptions. It's
not suitable for parsing those instructions.)

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/34
2015-12-01 15:38:32 -05:00
David Neto
36909c05a5 binary parse test: extra words after string literal
Covers the case where the string literal is the
last operand.

TODO: Case where one more operand is expected after
the string literal.  Occurs only for the LinkageAttributes
decoration.  To test that, we need to update the grammar
as well.
2015-12-01 15:38:32 -05:00
Dejan Mircevski
15aebef8a0 Merge PR #32.
Simplify binary parser tests using GoogleMock.
2015-11-30 18:06:33 -05:00
Dejan Mircevski
7a3a459af5 Mention that ParsedInstruction owns its components.
Also close a parenthesis in ParsedInstruction printout.
2015-11-30 14:12:04 -05:00
David Neto
d9ad050a95 spvBinaryParse: fix overruns, handle image format
Add unit tests for all diagnostics issued by spvBinaryParse.

Handle image format operands in the binary parser and the
disassembler.

Document that the callback function pointers can be null,
in which case they are ignored.

Detect exhaustion of input when parsing an operand,
to avoid buffer overruns on some invalid input cases.

Fix the description strings for some operand types.
Make the diagnostic messages for those operand types
consistent between the assembler and binary parser.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/29
2015-11-30 10:44:23 -05:00
David Neto
750f205b63 Several unit tests for spvBinaryParse
Add a non-zero spv_result_t value SPV_REQUESTED_TERMINATION
which should be used to signal an ok result, but signals
early termination for a process, such as binary parsing.

Tests include:
 - correct contents sent to header and instruction callbacks
 - non-zero status from a callback should terminate parsing,
   but the parser should not generate its own diagnostic.

TODO: Check diagnostics generated by the parser itself.
2015-11-27 10:19:06 -05:00
David Neto
c9e0845c7f Aliasing through a union member is valid.
Take back my previous TODO.
2015-11-23 15:35:00 -05:00
David Neto
01656363a7 Put DiagnosticStream and clr exports in libspirv namespace
Each exported functions either has an "spv" prefix, or is inthe libspirv
namespace.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/18
2015-11-20 10:46:42 -05:00
Lei Zhang
39a83291fc Use test fixture for a test. 2015-11-19 11:39:11 -05:00
Andrew Woloszyn
5b9fff7175 Removed executable flag from HexFloat.cpp. 2015-11-19 10:12:44 -05:00
Andrew Woloszyn
3a4bc7e61a Turned warnings-as-errors on by default.
Fixed a few warnings that appear in builds on VS2013 and VS2015.
2015-11-19 09:46:59 -05:00
Lei Zhang
8bd75d650e Clean up CMake configuration and address compiler warnings.
- Removed dead configuration in CMakeLists.txt.
- Used target_compile_options() instead of CMAKE_{C|CXX}_FLAGS.
- Turned on warnings on tests.
- Fixed various warnings for comparing signed with unsigned values.
- Removed dead code exposed by compiler warnings.
2015-11-18 16:32:41 -05:00
David Neto
64a9be97ca Remove old names for enums: memory semantics, scope ID 2015-11-18 15:56:38 -05:00
David Neto
8ddd4ec102 Bottom byte of version header word should be 0
The assembler should always make it 0.
The disassembler should ignore it.

Remove the macro support for supplying a value for it.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/6
2015-11-18 15:19:43 -05:00
Lei Zhang
aa50c45e3b Fix test: version number has changed. 2015-11-17 16:46:55 -05:00
David Neto
2266ba1061 Register Glslang tool 2015-11-13 12:35:47 -06:00
David Neto
3d348a8440 The version header word has 3 byte-size components.
Bits 24-31: 0
Bits 16-23: SPIR-V major number (1)
Bits  8-15: SPIR-V minor number (0)
Bits   0-7: SPIR-V minor number (2)

The assembler will construct the word appropriately,
and the disassemble will print it in major.minor.revision form.
2015-11-13 12:35:34 -06:00
David Neto
14b93e49ed Generator word now has two 16-bit components
The high 16-bits are a registered generator tool.
These are registered at
https://www.khronos.org/registry/spir-v/api/spir-v.xml

The low 16-bits are tool-specific.  It might be a version number,
for example, but is not constrained by the spec or by the registration
process.

The disassembler prints the tool name when we know it.
If we don't, print "Unknown" and then the numeric tool number
in parentheses.
In all cases, the disassembler prints lower 16-bit number on the
same line but after the tool name.

Also add newly registered generators:
  6: Khronos LLVM/SPIR-V Translator
  7: Khronos SPIR-V Tools Assembler
2015-11-13 12:35:29 -06:00
David Neto
5f7ed91e18 Support capabilities StorageImageReadWithoutFormat
Also add capability StorageImageWriteWithoutFormat.

They only affect validation rules.
2015-11-12 16:27:51 -05:00
David Neto
12511c8a4f Add GeometryStreams capability
Decoration Stream depends on it.
GeometryStreams depends on Geometry capability.

Spot check dependence of OpEmitStreamVertex on GeometryStreams.
(Opcode dependencies on capabilities are automatically generated from
opcode.inc)
2015-11-12 16:27:51 -05:00
David Neto
0c6cf8cdff Support OpImage
It's already in the syntax table.  Just test it.
2015-11-12 16:27:51 -05:00
Lei Zhang
972788bf23 Use opaque context object to hold SPIR-V info tables.
Previously the opcode table is declared as an global array and we
have spvOpcodeTableInitialize() modifying it. That can result in
race condition. Now spvOpcodeTabelGet() copies the whole underlying
array.
2015-11-12 16:27:51 -05:00
Lei Zhang
321c3e206b Remove an obselete and redundant text. 2015-11-12 16:27:51 -05:00
David Neto
e7c426ac8d Disassembler tool indents to 15 by default
The assigned-to result Id appears to the left of the 15th column.

Add --no-indent option.

The API form of the disassembler does not indent by default.
2015-11-12 16:27:50 -05:00
Lei Zhang
39b01b9988 Simplify some tests 2015-11-12 16:27:46 -05:00
David Neto
d02f68ae79 Update to 1.0 Rev 2 work-in-progress headers
Updated readme.

Note: The header advertises itself as Rev 1, but contains
many (all?) the updates intended for Rev 2.  We might need
to update one more time before SPIR-V 1.0 Rev2 is published.

Regenerated syntax tables for 1.0.

Changed names:
  InputTriangles -> Triangles
  InputQuads -> Quads
  InputIsolines -> Isolines
  WorkgroupLocal -> Workgroup
  WorkgroupGlobal -> CrossWorkgroup
  PrivateGlobal -> Private
  (Dim) InputTarget -> SubpassData
  WorkgroupLocalMemoryMask -> WorkgroupMemoryMask
  WorkgroupGlobalMemoryMask -> CrossWorkgroupMemoryMask
  AsyncGroupCopy -> GroupAsyncCopy
  WaitGroupEvents -> GroupWaitEvents

Remove:
  IndependentForwardProgress capability
  Smooth decoration
  FragColor BuiltIn
  WorkgroupLinearId in favour of LocalInvocationId
  ImageSRGBWrite capability
  Special OpenCL image instructions

Add:
  image channel data type UnormInt101010_2
  AcquireReleaseMask

InputTargetIndex updates:
  InputTargetIndex -> InputAttachmentIndex
  InputAttachmentIndex depends on InputAttachment capability,
  and it takes a literal number argument.

Capability StorageImageExtendedFormats updates:
  Enum value changed from 26 to 49. (Changes position in tables).
  Replaces AdvancedImageFormat capability.

OpenCL source language -> OpenCL_C, OpenCL_CPP
2015-11-12 09:43:12 -05:00
Lei Zhang
aa056cd8c7 Move SPIR-V constants/limits to a separate header. 2015-11-12 09:43:09 -05:00
Lei Zhang
16f3ddfbb8 Use std::string instead of a huge array for storing literal strings. 2015-11-12 09:43:06 -05:00
Lei Zhang
2a0b773b27 Add missing copyright. 2015-11-12 09:43:03 -05:00
Lei Zhang
923f6c13fc Use quotation for libspirv.h and sort headers. 2015-11-12 09:43:01 -05:00
Lei Zhang
df920ecb71 Remove table parameters from API functions.
Opcode, operand, and external instruction tables are no longer
passed in as parameters to spvTextToBinary(), spvBinaryToText(),
and spvValidate().
2015-11-12 09:42:50 -05:00
Andrew Woloszyn
ec691fba2a Fixed permissions 2015-11-11 12:12:16 -05:00
Andrew Woloszyn
55ecc2e097 Fixed warnings on windows and constness of spv_binary.
Replaced uint64_t with size_t in the places that make sense and
added spv_const_binary{,_t} to allow the interface to accept non
modifiable spirv where appropriate.
2015-11-11 12:12:13 -05:00
Lei Zhang
9049bb4877 Get magic number and version from spirv.h.
This is a part of the effort to clean up libspirv.h.
2015-11-11 12:12:10 -05:00
David Neto
2119694775 Disassembler support for OpSpecConstantOp
Document the fact that we use names for extended instructions
and OpSpecConstantOp opcode operands.
2015-11-11 12:12:07 -05:00
David Neto
0f166be68d Assembler support for OpSpecConstantOp
Adds SPV_OPERAND_TYPE_SPEC_CONSTANT_OP_NUMBER.
2015-11-11 12:12:04 -05:00
David Neto
ce9cef71ac Fix Windows build errors.
- uint64_t != size_t sometimes
- don't use C99 runtime sized arrays
2015-11-11 09:55:51 -05:00
David Neto
003e288c35 Enable round trip tests for OpSwitch 2015-11-11 09:55:42 -05:00
Lei Zhang
aa3cd5abb9 Optional typed literal number should be concrete in BinaryParser. 2015-11-10 15:58:16 -05:00
David Neto
2ae4a68fe8 Fix handling of OpExtInstImport
The assembler tracks mapping of extended instruction import Id
to extended instruction type.

Adds a few new ways to fail.
2015-11-10 15:58:07 -05:00
David Neto
9e545d7968 Assembler supports hex float constants.
The bit pattern for a hex float is preserved through
assembly and disassembly.

You can use a hex float to express Inf and any kind of NaN
in a portable way.
2015-11-10 15:58:03 -05:00
David Neto
229b90f6f4 Print OpConstant values according to type.
Zero and normal floating point values are printed with enough
enough digits to reproduce all the bits exactly.
Other float values (subnormal, infinity, and NaN) are printed
as hex floats.

Fix a binary parse bug: Count partially filled words in a
typed literal number operand.

TODO: Assembler support for hex numbers, and therefore reading
infinities and NaNs.
2015-11-10 15:57:59 -05:00
Lei Zhang
8f6ba14b58 advance() should check current string index is in bound. 2015-11-10 15:57:52 -05:00
Lei Zhang
9042f40f7c Remove support for canonical assembly syntax format. 2015-11-10 15:57:49 -05:00
David Neto
201caf7001 spv_operand_type_t cleanup.
- Concrete operand types are never optional.
  Split them to make this so, e.g. add SPV_OPERAND_TYPE_IMAGE
  since there was SPV_OPERAND_TYPE_OPTIONAL_IMAGE.
  Similarly for SPV_OPERAND_TYPE_MEMORY_ACCESS.
  This entails duplicating two operand table entries.

- The above, plus some rearranging of enums, allows us to define
  first and last optional operand types, and first and last
  variable operand types.
  This lets us simplify the code for spvOperandIsOptional, and
  spvOperandIsVariable.

- Replace SPV_OPERAND_TYPE_MULTIWORD_LITERAL_NUMBER with the
  more accurately named SPV_OPERAND_TYPE_TYPED_LITERAL_NUMBER.
  Its special characteristic is that the type of the literal
  number is determined by some previous operand in the instruction.
  This is used for literals in OpSwitch, OpConstant, and OpSpecConstant.
  This lets us refactor operand parsing cases in the assembler.

- Remove the special required-thing-in-optional-tuple in favour of
  the corresponding concrete operand type:
        SPV_OPERAND_TYPE_ID_IN_OPTIONAL_TUPLE
    --> SPV_OPERAND_TYPE_ID
        SPV_OPERAND_TYPE_INTEGER_LITERAL_IN_OPTIONAL_TUPLE
    --> SPV_OPERAND_TYPE_INTEGER_LITERAL

- Constrain spvOpeandTypeStr to only have to work for non-variable
  operand types.  Add a test for this.
2015-11-10 15:57:45 -05:00
David Neto
0ca6b59bfd Refactor the binary parser.
The binary parser has a C API, described in binary.h.
Eventually we will make it public in libspirv.h.
The API is event-driven in the sense that a callback is called
when a valid header is parsed, and for each parsed instruction.

Classify some operand types as "concrete".  The binary parser uses
only concrete operand types to describe parsed instructions.

The old disassembler APIs are moved into disassemble.cpp

TODO: Add unit tests for spvBinaryParse.
2015-11-10 15:57:33 -05:00
Dejan Mircevski
0981b1514e Slay "undeflow." 2015-11-10 15:57:31 -05:00
Dejan Mircevski
fc10eac868 Refactor EncodeTestHelper() and DecodeTestHelper(). 2015-11-10 15:57:28 -05:00
David Neto
bae8851111 DiagnosticStream keeps a copy of the position.
Don't store the pointer, as the underlying storage
could disappear.  This a bit more flexible and robust.
2015-11-10 15:57:04 -05:00
Andrew Woloszyn
758b347983 Added double tests to HexFloat 2015-11-10 15:57:00 -05:00
David Neto
ea633a6427 Empty assembly text compiles to no instructions.
But it's still a valid module.
2015-11-10 15:56:57 -05:00
Lei Zhang
1a0334edee Run clang-format to enforce Google style globally.
Note that we are more strict than Google style for one aspect:
pointer/reference indicators are adjacent to their types, not
their variables.

find . -name "*.h" -exec clang-format -i {} \;
find . -name "*.cpp" -exec clang-format -i {} \;
2015-11-10 15:56:47 -05:00
Andrew Woloszyn
6dfd4186f5 Updated HexFloat parsing for windows.
It is valid for float values to be modified on copy if they are NaN,
so long as they remain the correct NaN. What this means is that
we can not rely on the float data-type for storing float values
if we want to retain bit patterns.

Added FloatProxy which stores data in an unsigned integer, and updated
the HexFloat template to deal with FloatProxy values instead.
2015-11-02 13:52:31 -05:00
Andrew Woloszyn
0b61c593a2 Added HexFloat reading to HexFloat.
This allows reading of hex-encoded floats.
2015-11-02 13:52:28 -05:00
Andrew Woloszyn
c2887f98bc Added HexFloat helper class to print out floating point numbers.
TODO Add double tests before we actually use this.
2015-11-02 13:52:25 -05:00
Lei Zhang
b36e704a47 Use spirv.h instead of spirv.hpp.
This is a part of the effort to make libspirv.h C-compatible.
2015-11-02 13:52:20 -05:00
David Neto
9f79d789ec Inclusion guards follow Google C++ style
Follow the scheme in
http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#The__define_Guard
except:
 - 'include/' is dropped from the guard token
 - 'source/' is dropped from the guard token
2015-11-02 13:52:15 -05:00
David Neto
db901b622e Move endian utilities to their own file. 2015-11-02 13:52:12 -05:00
David Neto
fcc7d58353 Move AssemblyGrammar into its own source files 2015-11-02 13:52:05 -05:00
David Neto
e5e99b57cc Add DISABLED failing test for ext inst import confusion
Currently, the assembler does not track external import
IDs when there are two or more.

TODO(dneto): Fix this functionality.
2015-11-02 13:52:00 -05:00
David Neto
b6a43383e7 Use basic_string<char> for the UTF-8 test string
This is an attempt to fix the unit tests on DeveloperStudio 2013.
Currently, the size of the earth_africa string is reported as 2
on Windows.  But I think that may be 2 16-bit characters.
2015-11-02 13:51:57 -05:00
David Neto
1780fc4fcf Update to latest registered generator enums
The registry is at:
https://www.khronos.org/registry/spir-v/api/spir-v.xml
2015-11-02 13:51:54 -05:00
Andrew Woloszyn
f731cbf6c4 Added set_bits<> to bitutils.
This allows us to get a constant with the given bits set at
compile-time. This is needed for a future patch for HexFloat.
2015-11-02 13:51:51 -05:00
David Neto
e169a7cd86 Test cleanup: remove useless std::string constructor 2015-11-02 13:51:48 -05:00
Andrew Woloszyn
fe6527fd80 Fixed typo in utf8 string literal 2015-10-26 12:55:33 -04:00
Andrew Woloszyn
4274f93065 Fixed UTF-8 encoding issues on windows.
Also cleaned up some warnings related to implicit size_t/uint64_t
conversions.
2015-10-26 12:55:33 -04:00
Andrew Woloszyn
157e41bf57 Added type tracking to the disassembler.
TODO: Actually use the tracked types to make sure that we print out
values correctly.
2015-10-26 12:55:33 -04:00
David Neto
4942a318f4 Remaining tests for OpenCL extended instructions. 2015-10-26 12:55:33 -04:00
David Neto
21c4ad4b22 Add OpenCL extended instructions.
Versions 1.2, 2.0, and 2.1 all use the same
extended instruction list.

Updated the source code patch for the SPIR-V doc generator,
so it can both generate the core syntax table, and also the
OpenCL extended instructions table.

Tested the Math and Common functions.
TODO: test the remaining entries.
2015-10-26 12:55:33 -04:00
Lei Zhang
6483bd7132 Enforce suitable literal number operands to be unsigned integers.
Except for OpConstant and OpSpecConstant, all other literal number
operands are indeed unsigned integers. So,

* Rename all *LITERAL_NUMBER* operand types to *LITERAL_INTEGER*.
* Expect unsigned integers for *LITERAL_INTEGER* operands.
* Keep MULITPLE_WORD_LITERAL untouched since it is only used by
  OpConstant and OpSpecConstant.

And we want to provide the capability to specify floating-point
numbers after !<integer> in the alternate parsing mode. So,
OPTIONAL_LITERAL_NUMBER is reserved for OPTIONAL_CIV.
2015-10-26 12:55:33 -04:00
Lei Zhang
62f92cdae6 Use normal string instead of raw string for simple strings. 2015-10-26 12:55:33 -04:00
Lei Zhang
4c2db8347e Simplify methods for compilation failure in test framework.
Remove  CompileWithFormatFailure() and make CompileFailure() accept
a default argument.
2015-10-26 12:55:33 -04:00
David Neto
9e11c7d301 Fix Android build: use std::numeric_limits<T>::max and friends
UINT32_MAX and friends are not available.
2015-10-26 12:55:33 -04:00
David Neto
470405e0ed Add disabled tests for disassembler literal emission
Currently, negative numbers are printed as if they were
first statically cast to unsigned.
2015-10-26 12:55:33 -04:00
Andrew Woloszyn
e59e6b72f9 Added proper string escaping to the disassembler.
The disassembler now generates correct string when encountering
quotes and slashes.
2015-10-26 12:55:33 -04:00
David Neto
51013d15ee SPV_FAILED_MATCH error mutes DiagnosticStream.
The DiagnosticStream will not emit the accumulated message
text if the error is SPV_FAILED_MATCH.

Change various interfaces to accept the intended error
code instead of a boolean "is_optional".  This allows
us to avoid repeating the following type of logic deep
inside helper methods:

  if (is_optional) return SPV_FAILED_MATCH;
  return diagnostic() << " message text ";
2015-10-26 12:55:33 -04:00
Andrew Woloszyn
f08c679e97 Removed un-needed comments and fixed merge issue. 2015-10-26 12:55:33 -04:00
Andrew Woloszyn
3e69cd1b9f Updated string escaping in the assembler.
Strings are now escaped correctly when assembling.
TODO dissassembler support for strange strings (newlines for example).
2015-10-26 12:55:33 -04:00
Dejan Mircevski
497b226c68 Add negative-coverage location to operand-class-test-coverage.csv. 2015-10-26 12:55:33 -04:00
David Neto
78e677b5cd Parse and encode literal integers to the right width
Affects OpConstant, and OpSwitch.

Adds constant libspirv::kUnknownType for readability.

Adds tests for hexadecimal number parsing.

Updates syntax.md to describe hex parsing, including
sign extension.
2015-10-26 12:55:33 -04:00
David Neto
6274120eb9 Add AssemblyContext::parseNumber
It parses a text string for a value of a given target type.
2015-10-26 12:55:33 -04:00
David Neto
ac508b0d80 DiagnosticStream can convert to a stored error code
Use this to shorten error return code in the assembler.

For example, change this:

   if (error = something()) {
      diagnostic() << " Bad integer literal " << value;
      return SPV_ERROR_INVALID_VALUE;
   }

to this:

   if (error = something())
      return diagnostic() << " Bad integer literal " << value;

Also shorten code due to the fact that binaryEncodeU32 and
binaryCodeU64 can't fail (short of failure to expand a std::vector).
2015-10-26 12:55:33 -04:00
Dejan Mircevski
cc936dc613 Negative test for FunctionControl. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
2fc334c701 Negative test for LoopControl. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
8386c57d0c Negative test for SelectionControl. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
c002213d95 Negative test for GroupOperation. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
9d0c813547 Negative test for LinkageType. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
d7b0f83bd1 Negative test for BuiltIn. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
10fa49cd4b Negative test for AccessQualifier. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
212ba355a6 Negative test for FuncParamAttr. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
374616d98f Negative test for Decoration. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
c0eb225044 Negative test for FPRoundingMode. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
355cc0c678 Negative test for FPFastMathMode. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
971b344150 Negative test for ImageFormat. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
d062f8b097 Make compilation input strings const.
Also rerun clang-format.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
57c4398759 Negative test for SamplerFilterMode. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
1e128260cb Negative test for SamplerAddressingMode. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
63af6fd409 Negative test for ImageOperands. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
2fd3792c3a Negative test for Dim. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
52ff534040 Test OpTypeForwardPointer. 2015-10-26 12:55:33 -04:00
Andrew Woloszyn
537e77663d Added tracking to types and validated certain instructions.
We need to know how to generate correct SPIRV for cases like
OpConstant %int64 42 since the current parser will encode the 42 as a
32-bit value incorrectly.

This change is the first of a pair. This one tracks types, and makes
sure that OpConstant and OpSpecConstant are only ever called with
Integer or Float types, and OpSwitch is only called with integer
generating values.
2015-10-26 12:55:33 -04:00
David Neto
9db3a53897 Remove spv_opcode_flags_t and flags fields.
The flags fields in both spv_opcode_desc_t and spv_operand_desc_t
are redundant with the capabilities mask field in the same
structure.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
725cc2a2df Negative test for ExecutionMode. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
865034263d Negative test for AddressingModel, MemoryModel. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
2d6796d45d Negative test for ExecutionModel. 2015-10-26 12:55:33 -04:00
Dejan Mircevski
d2c81cf34a Negative test for SourceLanguage.
Also, use "class" instead of "type" in the coverage CSV.
2015-10-26 12:55:33 -04:00
David Neto
f6b865110c Accept long UTF-8 Literal Strings 2015-10-26 12:55:33 -04:00
David Neto
b5dc8fcd5d Support strings with up to 65535 chars, and null.
Move the definition of spv_instruction_t to an internal
header file, since it now depends on C++ and is not
used by the external interface.

Use a std::vector<uint32_t> in spv_instruction_t
instead of a fixed size array.
2015-10-26 12:55:33 -04:00
David Neto
1b9d70a317 Test capabilities for enums sections 3.21-3.31
Fixes dependencies among capabilities.  (The table should store
the mask of capabilites, not the capability enum.)

Remove the old spot check test for capabilities of enums.
2015-10-26 12:55:33 -04:00
David Neto
ddda85a5c5 Fix capabilities for enums in Rev32, sec 3.3-3.20 2015-10-26 12:55:33 -04:00
David Neto
3d2bf53294 Move AutoText and EnumCase into spvtest namespace
Also fix using declaration order.
Also put a few tests into the anonymous namespace.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
78f6a4a649 Test operand-table capabilities. 2015-10-26 12:55:33 -04:00
David Neto
e3296f0945 Add TODO for fixing endianness testing.
Currently it uses a union, a write to one field, and read from
another of a different type.

Moves the endianness-determining macro close to the variable
it references.
2015-10-26 12:55:33 -04:00
David Neto
287fdb0eb0 Test SPV_CAPABILITY_AS_MASK macro 2015-10-26 12:55:33 -04:00
David Neto
0cd7352d7d Use 3-arg MakeInstruction to reduce logic in tests
Avoids open-coded vector inserts and two variables in various
tests.  Should improve readability.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
924997dc7f Test opcode table capability entries. 2015-10-26 12:55:33 -04:00
David Neto
ff5dce48a1 Add assembler test for OpEnqueueKernel.
Adds a form of spvtest::MakeInstruction which takes two vectors
of operands.  That leads to simpler test code.
We can clean up some other test code, in another CL.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
114206e0bc Clarify !<integer> parsing.
Implement some outstanding feedback from
Ic29c5a4a8178a62a5a1acad13d02f19cc1307097:

 - use "token" instead of "word" when referring to assembly text

 - specify how the numbers are parsed

Add a test for negative numbers.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
14c4b10d44 Detect overflow in !<integer>. 2015-10-26 12:55:33 -04:00
David Neto
8bed0cea13 Add a .csv showing test coverage for operand class
It shows which spv::OperandClass values are used in
the syntax table in source/opcode.inc, and what tests
exercise those operand types.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
897bff924a Simplify (and test) the alternate-parsing pattern. 2015-10-26 12:55:33 -04:00
David Neto
42bfd4bfab Assembly test for OpSwitch
Removes old weak and fragile tests for OpSwitch.

Adds spvtest::TextToBinaryTest::CompileWithFormatFailure
2015-10-26 12:55:33 -04:00
David Neto
e77a7dd821 Assembly failure cases for OpMemoryBarrier
Fully tests OperandMemorySemantics from the syntax table.
2015-10-26 12:55:33 -04:00
David Neto
cb3db4327d Assembler failing cases for OpCapability 2015-10-26 12:55:33 -04:00
Andrew Woloszyn
71fc05587b Refactored dynamic and static state out of text processing.
This reduces the number of arguments required to be passed
to every single function. This is in preparation for adding
id tracking.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
903f9d6b70 Implement alternate-parsing mode for !<integer>. 2015-10-26 12:55:33 -04:00
David Neto
c348d18486 Test bad 2nd target to OpGroupMemberDecorate 2015-10-26 12:55:33 -04:00
David Neto
454f51fa4d Assembly test for OpGroupMemberDecorate
Provides test coverage for OperandVariableIdLiteral
from the syntax table in the file 'opcode.inc'.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
1b6f1960a8 Uncomment some !<integer> tests. 2015-10-26 12:55:33 -04:00
David Neto
d83179af7e Cleanup: Use EnumCase in OpDecorateSimpleTest 2015-10-26 12:55:33 -04:00
David Neto
ab778dc1dc Cleanup: Use EnumCase for ExecutionMode test 2015-10-26 12:55:33 -04:00
David Neto
54b2ea1088 Assembler test for optional operands of OpSource
These are the first tests to cover OperandOptionalId
and OperandOptionalLiteralString from the grammar in
opcode.inc
2015-10-26 12:55:33 -04:00
David Neto
f1b6471670 Dissasembler test showing reordering of masks 2015-10-26 12:55:33 -04:00
David Neto
b14a727a30 Execution scope, memory semantics operands are IDs
They shouldn't be parsed or printed as masks.
2015-10-26 12:55:33 -04:00
David Neto
619db2612e Disassembler support for mask expressions. 2015-10-26 12:55:33 -04:00
David Neto
bfa3d86f7b Memory semantics Relaxed is a synonym for None
The disassembler should prefer to print Relaxed,
I think. (Untested.)
2015-10-26 12:55:33 -04:00
David Neto
212bafe4da Assembler tests for remaining Debug instructions
OpString, OpName, OpMemberName, OpLine, OpNoLine,
OpSourceContinued.
2015-10-26 12:55:33 -04:00
David Neto
e0890da603 Update core instruction syntax to Rev32
Many instructions added and a few changed structure.

Workarounds:
- Some operands can be enabled by either one of two
  capabilities.  The spv_operand_desc_t does not handle that
  now. For now just select the first one.

Fixes to tests:
- OpLoopMerge now takes a mandatory continue target.
- OpTypePipe drops the type argument.  Pipes are opaque.
- OpLine no longer takes a target ID argument.

The ID validator was fixed the OpLine and OpTypePipe
changes.  Those were the only ID validator tests affected.

The patch to the spec doc generator was updated so it handles
the two-capability case, even if in an hacky way.
2015-10-26 12:55:33 -04:00
David Neto
6b31ce4d50 Assembler test TODOs for image instructions. 2015-10-26 12:55:33 -04:00
David Neto
d768798d48 Assembler supports new decorations in Rev32
They are:
 - NoContraction
 - InputTargetIndex
 - Alignment
2015-10-26 12:55:33 -04:00
Lei Zhang
863ddbeeaa Rev32: Remove DepthAny and mark Xfb as requiring TransformFeedback. 2015-10-26 12:55:33 -04:00
David Neto
c66f5074e2 Assembler support for new capabilities in Rev32 2015-10-26 12:55:33 -04:00
David Neto
8576c9c327 Support Image operand MinLod 2015-10-26 12:55:33 -04:00
David Neto
2d1b5e5bba Assembler supports new builtins in Rev32
They are VertexIndex and InstanceIndex.
2015-10-26 12:55:33 -04:00
David Neto
49c299b094 Assembler support for Nontemporal memory access 2015-10-26 12:55:33 -04:00
David Neto
c09d3857ff Fix permissions on test/TextToBinary.Barrier.cpp 2015-10-26 12:55:33 -04:00
David Neto
aa0c3a5c07 Support Dim InputTarget 2015-10-26 12:55:33 -04:00
David Neto
9819adf4cb Support StorageClass PushConstant 2015-10-26 12:55:33 -04:00
David Neto
3e52dd915d Support ExecutionMode IndependentForwardProgress 2015-10-26 12:55:33 -04:00
David Neto
16df562ad3 Assembler test for Memory Semantics enum
Enables mask expression parsing for Memory Semantics arguments,
e.g. on OpMemoryBarrier.
2015-10-26 12:55:33 -04:00
Andrew Woloszyn
13804e5d63 All values now represent symbolic names instead of mixed with numeric.
Also removed un-necessary heap-allocation of spv_named_id_table.
This removed the necessity to expose a function to create/destroy it
and simplified the interface.
2015-10-26 12:55:33 -04:00
Lei Zhang
a66952d38c Remove executable file mode bits on source files. 2015-10-26 12:55:33 -04:00
David Neto
dbaf40718a Update to Rev32 headers. Part 1.
Just enough fixes to code make it build and pass tests.

Core changes:
 - Fix spelling for: NoPerspective, NonWritable, NonReadable,
 - Remove NoStaticUse, RelaxedMask

GLSL changes:
 - Fixed spelling for: InverseSqrt, FaceForward, MatrixInverse,
   SmoothStep, FindILsb, FindSMsb, FindUMsb
 - Replace Mix with IMix and FMix
 - Remove AddCarry, SubBorrow, MulExtended

Replace header OpenCLLib.h with OpenCL.std.h

TODO:
 - Regenerate the core instruction syntax table (source/opcode.inc)
 - Add test coverage for new enums and instructions.
2015-10-26 12:55:33 -04:00
David Neto
74af05f012 Cleanups for EnumCase
Make it a class, since it has non-trivial behaviour for converting
the enumerated value to a uint32_t value. (Comply with style guide.)

Merge EnumCaseWithOperands into EnumCase.
2015-10-26 12:55:33 -04:00
David Neto
1b5fd4962e Put the test fixture into spvtest namespace.
All test utility code should go into the spvtest namespace.
2015-10-26 12:55:33 -04:00
Andrew Woloszyn
815cb95247 Fix MSVC build for boolean opeartions on enums. 2015-10-26 12:55:33 -04:00
David Neto
d1dd2fbd7c Put const back on const char* in test case structs 2015-10-26 12:55:33 -04:00
Andrew Woloszyn
f2d0775f1b A bunch of small fixes to build in MSVC2013.
Fixed an issue where some of the tests were testing
the wrong word with the wrong operation. (| != ||).

Coalesced the many versions of EnumCase into one.
Added a get_value() to EnumCase to convert to a uint32_t.

Replaces ASSERT_TRUE(pointer), with ASSERT_NE(nullptr, pointer),
so that we do not do implicit pointer->bool conversion.

Removed const from some test structs since gtest needs to be
able to swap them.
2015-10-26 12:55:33 -04:00
David Neto
ee1b3bb3bb Assembler support for image operands from Rev31
Rev32 and later add many more image operands, and
rearrange their values.
2015-10-26 12:55:33 -04:00
Lei Zhang
184c76dbaf Let EncodeAndDecodeSuccessfully remove preamble comments. 2015-10-26 12:55:33 -04:00
Lei Zhang
6d41581c93 Clean up code for encoding literal operands. 2015-10-26 12:55:33 -04:00
David Neto
5bf88fcc95 Assembler: mask expressions where 1 bits imply operands
Properly support a memory access mask with a combination
of bits, including the Aligned bit. When the Aligned bit is
set, the parser should expect an alignment value literal operand.
2015-10-26 12:55:33 -04:00
David Neto
36b0c0f6b3 Assembler support for simple mask expressions
For example, support combining mask enums with "|",
such as "NotNaN|AllowRecip" for the fast math mode.

This is supported for mask values that don't modify the
expected operand pattern:
 - fast math mode
 - function control
 - loop control
 - selection control

TODO: disassembler support to print them as mask expressions.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
e3a19c0d63 Forbid !<integer> preceding or succeeding '='. 2015-10-26 12:55:33 -04:00
David Neto
b30a0c529b Assembler test for Dim, ImageFormat enums.
Adds SPV_OPERAND_TYPE_SAMPLER_IMAGE_FORMAT, and the
translation tables for its values from the spv::ImageFormat values.
2015-10-26 12:55:33 -04:00
David Neto
f7ee0ca5da Use generalized EnumCase in AccessQualifier assembly tests
This is in preparation for coming tests that will also
use the templated EnumCase instead of making their
own structs.

Also reformat AccessQualifier test.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
ba569fb1aa Handle IDs among !<integer> operands. 2015-10-26 12:55:33 -04:00
David Neto
5f33d31d89 Assembler test for SamplerAddressingMode, SamplerFilterMode
Uses OpConstantSampler instruction.
2015-10-26 12:55:33 -04:00
David Neto
5494dd4334 Assembler test for Storage Class enum values
This covers the storage classes in SPIR-V Rev31.  Rev32 has more.
2015-10-26 12:55:33 -04:00
Lei Zhang
b41d150b7f Support multiple word literal numbers as constants.
Add a new operand type SPV_OPERAND_TYPE_MULTIWORD_LITERAL_NUMBER
to represent those operands that can expand into multiple words.
Now only OpConstant and OpSpecConstant have such kind of operand.
2015-10-26 12:55:33 -04:00
David Neto
fadbf6220e Assembler test for ExecutionScope, with OpGroupIAdd
Use spvOperandTypeStr to generalize the error message
for failure to parse an ID.
Extend spvOperandTypeStr to cover SPV_OPERAND_TYPE_EXECUTION_SCOPE.
2015-10-26 12:55:33 -04:00
David Neto
abe51c4142 Assembler test for OpTypePipe
Covers all AccessQualifier enums.

In Rev32, OpTypePipe no longer has a type argument.
Added TODOs for this.
2015-10-26 12:55:33 -04:00
David Neto
4a29131dcd Assembler test for single-valued Memory Access flag. 2015-10-26 12:55:33 -04:00
David Neto
f4fde6c60d Assembler test for single-valued FunctionControl mask
Fixed name of "Inline" enumerant.

Support for combinations of function control masks should come later.
2015-10-26 12:55:33 -04:00
David Neto
c0b32ecb54 Assembler test for single-valued LoopControl mask
Support for combining masks should come later.
2015-10-26 12:55:33 -04:00
David Neto
ad18c77ac9 Assembler test for single-valued SelectionControl mask
Support for combining masks should come later.
2015-10-26 12:55:33 -04:00
Lei Zhang
a94701db39 Run clang-format. 2015-10-26 12:55:33 -04:00
David Neto
e8e3712c3b Assembler test for OpExecutionMode 2015-10-26 12:55:33 -04:00
David Neto
f6498bfc73 Assembler test for OpEntryPoint 2015-10-26 12:55:33 -04:00
Dejan Mircevski
58fc88e2ee Simplify format indication in CompileSuccesfully(). 2015-10-26 12:55:33 -04:00
Lei Zhang
4e092d3ac3 Move bitwisecast.h to source/ and add include guard. 2015-10-26 12:55:33 -04:00
David Neto
a48678ab92 Fix an infinite loop during message generation.
Rename getWord to spvGetWord and unit test it.
2015-10-26 12:55:33 -04:00
Dejan Mircevski
f79519c926 Handle operands when OpCode is !<integer>. 2015-10-26 12:55:33 -04:00
David Neto
4caa47c3d4 Assembler test for OpMemoryModel 2015-10-26 12:55:33 -04:00
Lei Zhang
29e667eb6c Add library function parameter to set assembly format for disassembler. 2015-10-26 12:55:33 -04:00
David Neto
c6402d64f4 Assembler tests for OpCapability.
Adds test file for instructions in the Mode-Setting section
of the SPIR-V spec.
2015-10-26 12:55:33 -04:00
David Neto
55bdfcb0bc Assembler test for LinkageAttributes decorations 2015-10-26 12:54:39 -04:00
David Neto
37547b2304 Assembler tests for all decorations except Linkage attributes
Fixes typos in various parser tables.

Updates readme.md with the fixes.
2015-10-26 12:54:39 -04:00
Lei Zhang
e78a7c19ff Run clang-format. 2015-10-26 12:54:39 -04:00
Lei Zhang
06efdc59e1 Add an API parameter to choose assembly syntax format for assembler.
Added a new enum for supported assembly syntax formats:
Canonical Assembly Format (CAF) and Assignment Assembly Format (AAF).

Updated assembler interface functions to support choice of assembly
syntax format.
2015-10-26 12:54:39 -04:00
David Neto
a08350a2c3 Assembler test for OpSourceExtension.
Add test utility function MakeVector(std::string) to encode
a string as a vector of 32-bit words, as per the SPIR-V literal
string encoding.
2015-10-26 12:54:39 -04:00
David Neto
08d89bb7a5 Test assembly of OpSource using all language enums
Adds a file to test assembly of instructions in the "Debug" section
of the SPIR-V spec.
2015-10-26 12:54:39 -04:00
David Neto
43f0e819c4 Avoid undefined pointer given to spvTextDestroy
The undefined pointer might get through to the call
to spvTextDestroy if the test fails on an earlier step.
In that case I just want to see the test failure, and
not a test failure followed by undefined behaviour.
2015-10-26 12:54:39 -04:00
David Neto
c88dcd6a72 Add OpNop, OpUndef tests for spvTextToBinary
Add text_fixture::TextToBinaryTestBase::CompiledInstructions,
to more easily just examine the generated instructions by skipping
over the header.

Add spvtest::MakeInstruction utility function to easily generate
a vector containing an opcode and its operands.
2015-10-26 12:54:39 -04:00
Lei Zhang
574352c7a9 Fix interface function calls to the new API. 2015-10-26 12:54:39 -04:00
Lei Zhang
610c525865 Preserve float values during encoding and decoding roundtrip. 2015-10-26 12:54:39 -04:00
Andrew Woloszyn
cfeac48a37 Removed the ambiguity in the API for cleaning input vs output data.
Previous the api used spv_text_t and spv_binary_t for both input
and output, but depending on the usage, you either MUST
call spvBinaryDestroy or you MUST NOT call spvBinaryDestroy on the
pointer.
2015-10-26 12:54:39 -04:00
David Neto
cac38f92dd Simplify uses of spvBinaryDestroy in tests
Always try to destroy the binary during common methods
of test fixtures.  This is safe if no other code in the test
attempted to destroy the binary.

Take advantage of the fact spvBinaryDestroy is a no-op on a nullptr,
by eliminating the null pointer check in the caller.
2015-10-26 12:54:39 -04:00
David Neto
ac6f71b2de spvTextDestroy is no-op on nullptr. 2015-10-26 12:54:39 -04:00
David Neto
a71138372e Fix spvBinaryDestroy test to use an API-created object 2015-10-26 12:54:39 -04:00
David Neto
b6a8898fa5 Enable OpcodeMake test, by sampling values.
The previous version of the test was disabled, presumably
because it took to long to run.
2015-10-26 12:54:39 -04:00
David Neto
f4fd780654 spvBinaryDestroy(nullptr) is a no-op. 2015-10-26 12:54:39 -04:00
David Neto
c9b5152b4f Remove spvOpcodeIsVariable
Nothing was using it.
2015-10-26 12:54:39 -04:00
Dejan Mircevski
1a3990233c Add hex-format tests for !<integer>. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
ea5a2a5242 Add invalid-operand tests for !<integer>. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
a4b834e456 Make all SpirvVectors const in ImmediateInt.cpp. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
d8454a7967 Tests for parsing recognizable words after !<integer>. 2015-10-26 12:52:01 -04:00
David Neto
f58d8c0965 Add disabled test to check float value parsing
Disabled for now because float parsing is broken.
2015-10-26 12:52:01 -04:00
David Neto
c978643748 Print diagnostics at the beginning of input.
A spv_diagnostic_t value knows if the source is textual rather
than binary.
2015-10-26 12:52:01 -04:00
Dejan Mircevski
e75b3e769d Avoid "operands" in the !<immediate> explanation.
Also declare "!<integer> = OpCode" legal.
2015-10-26 12:52:01 -04:00
Dejan Mircevski
d5769bf08a Test consecutive opcodes being !<integer>. 2015-10-26 12:52:01 -04:00
David Neto
78c3b43774 Use opcode operand definitions from SPIR-V specification generator.
The assembler and disassembler now use a dynamically adjusted
sequence of expected operand types.  (Internally, it is a deque,
for readability.)  Both parsers repeatedly pull an expected operand
type from the left of this pattern list, and try to match the next
input token against it.

The expected pattern is adjusted during the parse to accommodate:
- an extended instruction's expected operands, depending on the
  extended instruction's index.
- when an operand itself has operands
- to handle sequences of zero or more operands, or pairs of
  operands.  These are expanded lazily during the parse.

Adds spv::OperandClass from the SPIR-V specification generator.

Modifies spv_operand_desc_t:
 - adds hasResult, hasType, and operandClass array to the opcode
description type.
 - "wordCount" is replaced with "numTypes", which counts the number
   of entries in operandTypes.  And each of those describes a
   *logical* operand, including the type id for the instruction,
   and the result id for the instruction.  A logical operand could be
   variable-width, such as a literal string.

Adds opcode.inc, an automatically-generated table of operation
descriptions, with one line to describe each core instruction.
Externally, we have modified the SPIR-V spec doc generator to
emit this file.
(We have hacked this copy to use the old semantics for OpLine.)

Inside the assembler, parsing an operand may fail with new
error code SPV_FAIL_MATCH.  For an optional operand, this is not
fatal, but should trigger backtracking at a higher level.

The spvTextIsStartOfNewInst checks the case of the third letter
of what might be an opcode.  So now, "OpenCL" does not look like
an opcode name.

In assembly, the EntryPoint name field is mandatory, but can be
an empty string.

Adjust tests for changes to:
- OpSampedImage
- OpTypeSampler
2015-10-26 12:52:01 -04:00
Dejan Mircevski
6c03f87490 Print failing assembly text in CompileSuccessfully(). 2015-10-26 12:52:01 -04:00
David Neto
b3669d13fe Remove unused struct "bin" 2015-10-26 12:52:01 -04:00
Dejan Mircevski
741cdc4829 More !<integer> tests. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
5f45e596bd Use spvOpcodeMake() in ImmediateInt tests. 2015-10-26 12:52:01 -04:00
David Neto
d3ead501de Don't overload operators in std namespace.
Use a spvtest::WordVector proxy object to easily print
std::vector<uint32_t> and spv_binary_t values.
2015-10-26 12:52:01 -04:00
Dejan Mircevski
0a8f219d1e Add a few unit tests for !<integer>. More to come.
Start using GMock: modify CMakeLists, fix googletest URL in readme.

Add useful utilities to the TestFixture class.  Also make it conform to
go/gunit recommendations about setup/teardown.
2015-10-26 12:52:01 -04:00
David Neto
9fa9157c4d Add bin-to-text test for operand with operands 2015-10-26 12:52:01 -04:00
David Neto
c9a23a6fd5 Add binary-to-text test for single instruction
This is easier to debug!

Binary-to-text testing needs more tests, and more
specific tests.  That's for future work.
2015-10-26 12:52:01 -04:00
David Neto
e7ee4c4476 Getting the next word respects quoting and escaping.
Use double quotes (").  They can be interspersed with
other whitespace characters, just like shell quoting.

A backslash (\) always escapes the next character.

The end of the stream always terminates the word.

Add AutoText struct to unit test utilities, to easily
make spv_text_t values and reference them as spv_text values.
2015-10-26 12:52:01 -04:00
Dejan Mircevski
f184109d7b Move ImmediateInt tests into their own file.
This is in preparation of adding many more tests in accordance with the
evolved spec.

Also sort the test-source lines in CMakeLists.
2015-10-26 12:52:01 -04:00
Dejan Mircevski
73d7082245 Put test classes in anonymous namespace.
Put TestFixture.h classes in a namespace.

Remove unused #includes.
2015-10-26 12:52:01 -04:00
David Neto
574884cd7e Getting the next word ends at a comment (;) 2015-10-26 12:52:01 -04:00
David Neto
98290a243e String literals must be quoted. 2015-10-26 12:52:01 -04:00
David Neto
affa696027 Fix some bugs in parsing literals.
- a single hyphen is a string, not a number.
- a string with more than one period is a string, not a number
- check for string overflow

Add some unit tests
2015-10-26 12:52:01 -04:00
Lei Zhang
5b73214223 Add GLSL std450 extended instruction 72-80. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
afdbd2d303 Add std450 instructions 53-64. 2015-10-26 12:52:01 -04:00
Lei Zhang
3cb589639d Add GLSL std450 extended instruction 65-71. 2015-10-26 12:52:01 -04:00
Lei Zhang
85d4d6d677 Add test for Modf and ModfStruct. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
c48fcce978 Add std450 instructions 49-52. 2015-10-26 12:52:01 -04:00
Lei Zhang
dca65b3f8c Reformat GLSL std450 extended instruction table.
Also add test for Smoothstep.
2015-10-26 12:52:01 -04:00
Dejan Mircevski
c4ba8821e7 Add tests for Atan2 and Pow.
Fix a typo in "ParameterizedExtInst."
2015-10-26 12:52:01 -04:00
Lei Zhang
65bfc4d585 Unify tests for GLSL std450 extended instructions.
Previously we had two tests: one checks test to binary, the other
checks round trip. This patch merges the check in the former to
the latter.
2015-10-26 12:52:01 -04:00
Lei Zhang
e5ae7f677f Add GLSL std450 instructions 35-48. 2015-10-26 12:52:01 -04:00
Lei Zhang
0e149d7cc4 Move tests for GLSL std450 instructions to a separate file. 2015-10-26 12:52:01 -04:00
Dejan Mircevski
a5c171544b Add std450 instructions 25-34. 2015-10-26 12:52:01 -04:00
Lei Zhang
8a37520908 Disassemble in the format of "<result-id> = <opcode> <operand>..". 2015-10-26 12:52:01 -04:00
Lei Zhang
abafd5e674 Only use '%' as variable name prefix.
Since now we can distinguish between def and use according to
the variable's location, there is no need to keep two variable
prefixes.

Also reformat tests to use the value generating instruction
format ("<result-id> = <opcode> <operand>..").
2015-08-24 15:05:11 -04:00
Lei Zhang
977e9bcfc6 Bugfix: report the correct location for wrong opcode.
Also add more tests for the "<result-id> = <opcode> <operand>.."
format.
2015-08-24 15:05:08 -04:00
Lei Zhang
ee87cc2a1e Fix TextAdvance() problems involving whitespace around comment lines.
Fix the bug that TextAdvance() forgot to skip whitespace at the
beginning of the next line after a comment line.

Fix the bug that TextAdvanceLine() increase line number after going
over a character.
2015-08-24 15:05:05 -04:00
Andrew Woloszyn
2facab2d08 Added stream operators for spv_binary_t and std::vector<uint32_t> 2015-08-24 15:05:02 -04:00
Lei Zhang
dfc50086a6 Support "<result-id> = <opcode> <operand>.." format. 2015-08-24 15:04:58 -04:00
Andrew Woloszyn
0d350b5992 Make the disassembler print the Extended instruction name.
This allows the disassembled output to more closely follow the
original assembly.
2015-08-24 15:04:55 -04:00
Andrew Woloszyn
1d2a87ed1b Added the initial set of glsl450 instructions.
Also rewrote the extended-instruction tests so that they would actually
make sure that the instruction actually appears in the output.
2015-08-24 15:04:49 -04:00
Lei Zhang
fb76d81aa0 Move test fixture into a separate header file so it can be reused. 2015-08-24 15:04:45 -04:00
Kenneth Benzie
67b649fa01 Merge branch 'update-header-to-rev31' into 'master'
Update external headers to rev 31

See merge request !3
2015-08-18 05:34:27 -04:00
David Neto
f6184a8b37 Parenthesize SPV_BIT macro to avoid surprises. 2015-08-17 17:01:42 -04:00
Lei Zhang
604e5cea12 Update spirv.h to revision 31.
For enum Capability and enum Op, not all newly added enumerants are
registered into capabilityInfoEntries and opcodeTableEntries yet.
That will come in following commits.
2015-08-17 11:40:24 -04:00
Lei Zhang
3a7315498f Fix failing tests.
The generator number is set to SPV_GENERATOR_KHRONOS in the
spvBinaryHeaderSet function, so tests should catch up.
2015-07-30 15:21:42 -04:00
Kenneth Benzie (Benie)
83e5a29b06 Code drop of the Codeplay spirv-tools source.
This commit contains the source for the SPIRV static library, spirv-as,
spirv-dis, and spirv-val tools.
2015-05-22 18:26:19 +01:00