Commit Graph

77 Commits

Author SHA1 Message Date
Andrey Tuganov
25d396b4a2 Add ExtInst validation pass (GLSL only for now)
Validates all GLSL.std.450 extended instructions.
2018-01-02 16:53:25 -05:00
Jesus Carabano
4dbcef62ee validate & test of literal's upper bits
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/660
2017-12-19 13:19:56 -05:00
Jeremy Hayes
cdfbf26c13 Add primitive instruction validation pass 2017-12-15 09:53:29 -05:00
Andrey Tuganov
532b327d4d Add validation rules for atomic instructions
Validates all OpAtomicXXX instructions.
2017-12-13 18:29:38 -05:00
Andrey Tuganov
94e3e7b8ef Add composite instruction validation pass
Validates instructions in the opcode range from OpVectorExtractDynamic
to OpTranspose.
2017-12-05 10:15:51 -05:00
Diego Novillo
83228137e1 Re-format source tree - NFC.
Re-formatted the source tree with the command:

$ /usr/bin/clang-format -style=file -i \
    $(find include source tools test utils -name '*.cpp' -or -name '*.h')

This required a fix to source/val/decoration.h.  It was not including
spirv.h, which broke builds when the #include headers were re-ordered by
clang-format.
2017-11-27 14:31:49 -05:00
David Neto
d9129f00a5 Test for pollution of the global namespace
Works on Linux only for now.  That's a good start.

Move ValidateBinaryUsingContextAndValidationState into anonymous
namespace in source/validate.cpp.
2017-11-23 21:27:21 -05:00
Andrey Tuganov
ab892f7bd6 Add derivatives validation pass
Checks operands of instructions in opcode range from OpDPdx to
OpFwidthCoarse.
2017-11-23 14:17:10 -05:00
Andrey Tuganov
f407ae2b50 Validator pass for image instructions
Includes validation rules for OpImageXXX and ImageOperand.

Doesn't include OpTypeImage and OpImageSparseXXX.

Disabled an invalid test.
2017-11-22 14:34:15 -05:00
Diego Novillo
d2938e4842 Re-format files in source, source/opt, source/util, source/val and tools.
NFC. This just makes sure every file is formatted following the
formatting definition in .clang-format.

Re-formatted with:

$ clang-format -i $(find source tools include -name '*.cpp')
$ clang-format -i $(find source tools include -name '*.h')
2017-11-08 14:03:08 -05:00
Andrey Tuganov
39e25fd8ab Add validation pass for conversion instructions
The pass checks correctness of operands of instruction in opcode range
OpConvertFToU - OpBitset.

Disabled invalid tests

Disabled UConvert validation until Vulkan CTS can catch up.

Add validate_conversion to Android.mk

Also remove duplicate entry in CMakeLists.txt.
2017-10-20 13:51:24 -04:00
Andrey Tuganov
64d5e5214f Add bitwise operations validator pass
The pass checks correctness of operand types of all bitwise instructions
(opcode range from SpvOpShiftRightLogical to SpvOpBitCount).
2017-09-26 14:22:37 -04:00
Andrey Tuganov
cf85ad1429 Add validate logicals pass to the validator
New pass checks operands of all instructions listed under
3.32.15. Relational and Logical Instructions
2017-09-20 10:37:12 -04:00
Andrey Tuganov
82df4bbd68 Add validation pass for arithmetic operations
The pass checks if arithmetic operations (such as OpFMul) receive
correct operands.
2017-09-05 12:21:53 -04:00
Chris Forbes
c14966b882 Move spv_instruction_t's into vector
No need to incur another copy here. These guys have embedded vectors
we'd rather not copy.
2017-06-28 11:13:26 -04:00
Chris Forbes
1cd47d7af2 Reserve expected length of instructions vector 2017-06-28 11:13:26 -04:00
Gabríel Arthúr Pétursson
d71d976875 Fix memory leak in ValidateBinaryUsingContextAndValidationState 2017-06-03 23:08:22 +00:00
Andrey Tuganov
b4cf371936 Stats analyzer uses validator
Stats analyzer calls validator to check the instruction and update
validator state.

Fixed unit tests (validator was failing).
2017-05-09 11:17:23 -04:00
Andrey Tuganov
971ede33b2 Validator dissallows unsupported Vulkan capability
If environment is SPV_ENV_VULKAN_1_0, disallow OpCapability operands
which are not supported by Vulkan 1.0.

See https://github.com/KhronosGroup/SPIRV-Tools/issues/572
2017-03-17 10:28:35 -04:00
Andrey Tuganov
c804c125c5 Autogenererating enum-string mappings from grammar
Autogenerating the following code:
- extension enum
- extension-to-string
- string-to-extension
- capability-to-string

Capability mapping table will not compile if incomplete.
TODO: Use "spirv-latest-version.h" instead of 1.1.

Added function to generate capability tables for tests.
2017-03-16 15:29:17 -04:00
Andrey Tuganov
b011633171 Validator checks if operands require extension
If required extension is not found, returning new error
SPV_ERROR_MISSING_EXTENSION.
2017-03-14 13:39:43 -04:00
Andrey Tuganov
0e9c24fdd1 Issue 559: check type declaration uniqueness
Adds PassTypeUnique to the validator.
Disallows repeated declarations of all types except for aggregates.
2017-02-28 22:27:08 -05:00
Ehsan Nasiri
da4ae05638 Add command line options struct for the validator
The limit for the number of struct members is parameterized using
command line options.

Add --max-struct-depth command line option.
Add --max-switch-branches command line option.
Add --max-function-args command line option.
Add --max-control-flow-nesting-depth option.
Add --max-access-chain-indexes option.
2017-02-28 12:00:06 -05:00
Ehsan Nasiri
9c71c572e5 Check BuiltIn Decoration rules.
When applied to a structure-type member, all members of that structure
type must also be decorated with BuiltIn. (No allowed mixing of built-in
variables and non-built-in variables within a single structure.)

When applied to a structure-type member, that structure type cannot be
contained as a member of another structure type.

There is at most one object per Storage Class that can contain a
structure type containing members decorated with BuiltIn, consumed per
entry-point.
2017-01-19 16:01:06 -05:00
Ehsan Nasiri
d75bf5ef03 Validation for decoration rules. Fixes issue #499.
Added a new file where all the decoration validation can be performed.

In this change the SPIRV Spec Section 2.16.1 is implemented:
"It is illegal to initialize an imported variable. This means
that a module-scope OpVariable with initialization value cannot be
marked with the Import Linkage Type."

Also added unit tests.
2017-01-18 16:29:14 -05:00
Ehsan Nasiri
1c11c8690f Validation of OpEntryPoint usage.
According to the SPIRV Spec (2.16.1):
* There is at least one OpEntryPoint instruction, unless the Linkage
capability is being used.

* No function can be targeted by both an OpEntryPoint instruction and an
OpFunctionCall instruction.

Also updated unit tests to includ OpEntryPoint.
2017-01-13 16:15:11 -05:00
Ehsan Nasiri
68e36ec7e9 Introducing a new flow for running the Validator.
We are adding a new API which can be called to run the SPIR-V validator,
and retrieve the ValidationState_t object. This is very useful for
unit testing.

I have also added basic unit tests that demonstrate usage of this flow
and ease of use to verify correctness.
2017-01-13 16:07:03 -05:00
Ehsan Nasiri
bd5b0bfca1 Checks that result IDs are within the ID bound specified in the SPIR-V header
This is described in Section 2.17 of the SPIR-V Spec.

* Updated existing unit test 'SemanticsIdIsAnIdNotALiteral' to pass by
manipulating the ID bound in its binary header.

* Fixed boundary check in the code.

* Added unit test to check the case that the largest ID is equal to the
ID bound.
2016-11-28 11:44:10 -05:00
Ehsan Nasiri
8c414eb579 Adding validation code for OpTypeStruct.
According to the Data Rules section of 2.16.1. Universal Validation
Rules of the SPIR-V Spec:

Forward reference operands in an OpTypeStruct
* must be later declared with OpTypePointer
* the type pointed to must be an OpTypeStruct
* had an earlier OpTypeForwardPointer forward reference to the same <id>
2016-11-16 16:41:56 -05:00
Lei Zhang
38036a7203 Rename validation source files to comply with Google style guide. 2016-11-08 17:19:56 -08:00
Ehsan Nasiri
6c899a52f9 Adding validation for vector data rule.
Number of components in a vector can be 2 or 3 or 4. If Vector16
capability is used, 8 and 16 components are also allowed.
Also added unit tests for vector data rule.
2016-11-08 17:48:30 -05:00
Umar Arshad
bf467da9c9 Update validate interface to accept binary pointers 2016-09-19 16:43:28 -04:00
Lei Zhang
755f97f534 Add a callback mechanism for communicating messages to callers.
Every time an event happens in the library that the user should be
aware of, the callback will be invoked.

The existing diagnostic mechanism is hijacked internally by a
callback that creates an diagnostic object each time an event
happens.
2016-09-15 12:35:48 -04:00
David Neto
9fc8658ef3 Relicense SPIRV-Tools under Apache 2.0
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/383

Finalize v2016.4
2016-09-02 10:00:29 -04:00
Lei Zhang
5abf40816a Kill the spvCheckReturn macro. 2016-09-02 09:51:44 -04:00
Lei Zhang
75bf78c70b Kill diagnostic_helper & the wrapping DIAGNOSTIC macro. 2016-09-02 09:49:56 -04:00
Umar Arshad
816f29805b Refactor Id -> Instruction 2016-08-09 15:50:03 -04:00
Umar Arshad
ffa42994fd Remove needless copies. Delete copy constructor.
* Deletes the ValidationState_t copy constructor
* Removes needless copies of the copy constructor
2016-08-06 12:24:19 -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
886dd352d5 Fix several violations of the style guide 2016-06-27 10:45:46 -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
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
0b9fd50d31 Control Flow Graph Validation 2016-06-02 12:11:52 -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
Lei Zhang
2923806314 Remove stale code. 2016-02-26 15:38:42 -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
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
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
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