Commit Graph

884 Commits

Author SHA1 Message Date
Ehsan Nasiri
4fb79b54f2 Validation for struct nesting depth.
According to sectin 2.17 in SPIR-V Spec, the structure nesting depth may
not be larger than 255. This is interpreted as structures nested in
structures. The code does not look into arrays or follow pointers to see
if it reaches a structure downstream.

Use memoization to avoid exponential runtime.
2016-12-07 16:15:56 -05:00
David Neto
d5b0cd34c9 An OpVariable initializer can be a module-scope variable
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/482
2016-12-07 16:04:51 -05:00
Ehsan Nasiri
aadf696fce Fixing bug in OpAccessChain validation code.
The validation code for OpAccessChain was missing OpTypeRuntimeArray as
a possible type that can be indexed into.

This was caught by running the validator on VKCTS.

Also adding unit tests for it.
2016-12-06 09:55:39 -05:00
Ehsan Nasiri
1f6123fa5f Add a test that exercises wrong usage of result id
Result <id> resulting from an instruction within a function may not be
used outside that function.
2016-12-06 09:50:08 -05:00
Ehsan Nasiri
bab1aad856 Adding validation code for OpAccessChain.
* Result Type must be an OpTypePointer. Its Type operand must be the
type reached by walking the Base’s type hierarchy down to the last
provided index in Indexes, and its Storage Class operand must be the
same as the Storage Class of Base.

* Base must be a pointer, pointing to the base of a composite object.

* Indexes walk the type hierarchy to the desired depth, potentially down
to scalar granularity. The first index in Indexes will select the
top-level member/element/component/element of the base composite. All
composite constituents use zero-based numbering, as described by their
OpType... instruction. The second index will apply similarly to that
result, and so on. Once any non-composite type is reached, there must
be no remaining (unused) indexes. Each of the Indexes must:
- be a scalar integer type,
- be an OpConstant when indexing into a structure.

* Check for the case where no indexes are passed to OpAccessChain.

Minor improvements based on code review.
2016-12-02 13:50:41 -05:00
Ehsan Nasiri
e6e7bd7d30 No need to install cmake for new osx images.
It seems that the osx image has been updated and already includes ctest.
As a result, all jobs fail with this error:
Error: cmake-3.6.2 already installed
2016-12-02 13:37:31 -05:00
Ehsan Nasiri
4b26d514ef Validate the number of global and local variables.
According to the Universal Limits section of the SPIR-V Spec (2.17), the
number of global variables may not exceed 65,535 and the number of local
variables may not exceed 524,287.

Also added unit tests for each one.
2016-12-01 16:04:13 -05:00
Ehsan Nasiri
490617133e Validate the number of arguments in OpTypeFunction
According to the SPIR-V spec (section 2.17: Universal Limits), the
OpTypeFunction instruction may not take more than 255 arguments for the
function. Also added unit tests for it.
2016-12-01 15:49:31 -05:00
David Neto
5f2d40915e Say how the validator checks universal limits
Indicate it's future work to allow parameterization of those
limits.
2016-11-30 15:48:39 -05:00
Ehsan Nasiri
3c8bc80e3a Adding validation code for OpSwitch limits
The number of (literal, label) pairs passed to OpSwitch may not exceed
16,383. Added code to validate this and added unit tests for it.

Also fixed a typo in another validor error message.
2016-11-30 15:36:05 -05:00
Ehsan Nasiri
bef80716d7 Validation for number of Struct members.
The number of members in a struct may not exceed 16,383.
Also Adding unit tests for Struct size limit check.
2016-11-30 15:29:37 -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
f72189c249 Validation for OpSampledImage instruction.
This change implements the validation for usages of OpSampledImage
instruction as described in the Data Rules section of the Universal
Validation Rules of the SPIR-V Spec.
2016-11-24 09:29:10 -05:00
Ehsan Nasiri
6fa6a3f647 Adding validation for OpSpecConstantComposite.
SpecConstantComposite may specialize to a vector, matrix, array, or
struct. In each case, the number of components and type of components
that are being specialized to must match the expected result type.

Removed use of macros in these tests.
Now using the spvValidateBase class. Using CompileSuccessfully(), and
ValidateInstructions() to compile to binary and run the validator. Also
using getDiagnosticString() to check the proper error message string.
All the heavy lifting is done in ValidateBase class.
2016-11-19 15:47:28 -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
David Neto
5c19de2510 Skip building example executable when asked 2016-11-16 10:52:31 -05:00
David Neto
c935253c91 Make friendly number-based names for OpConstant
For example:
  %int_42 = OpConstant %int 42
  %int_n42 = OpConstant %int -42
  %float_3_14 = OpConstant %float 3.14
2016-11-15 14:05:03 -05:00
David Neto
4f750c0dcc Extract EmitNumericLiteral from disassembler
Test with disassembly of numeric literals.
2016-11-15 14:05:03 -05:00
Ehsan Nasiri
d0620061c7 Adding validation code for more data rules.
These rules are under "Data Rules" in 2.16.1 (Universal Validation
Rules) part of the SPIR-V 1.1 Specification document:

* Scalar floating-point types can be parameterized only as 32 bit, plus
any additional sizes enabled by capabilities.

* Scalar integer types can be parameterized only as 32 bit, plus any
additional sizes enabled by capabilities.

* Vector types can only be parameterized with numerical types or the
OpTypeBool type.

* Matrix types can only be parameterized with floating-point types.

* Matrix types can only be parameterized as having only 2, 3, or 4
columns.

* Specialization constants (see Specialization) are limited to integers,
Booleans, floating-point numbers, and vectors of these.
2016-11-15 13:38:39 -05:00
Lei Zhang
38036a7203 Rename validation source files to comply with Google style guide. 2016-11-08 17:19:56 -08:00
Lei Zhang
2881fe958f Rename validation tests to comply with Google style guide. 2016-11-08 17:19:11 -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
Lei Zhang
4f57e140bf Renaming test files to comply with Google style guide.
Also posfixing test files with `_test' to make it more clear.
2016-11-07 14:41:51 -05:00
David Neto
bf190ec839 Remove source/instruction.cpp
Avoids linker problems on Windows and OSX with duplicate object file
names.  Avoids collision with source/val/instruction.cpp

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/451
2016-11-03 11:40:52 -04:00
Jamie Madill
b371439d6f enum_set: Fix bool performance warning.
Implicit casts from int to bool cause a warning in visual studio.
2016-10-27 16:09:06 -04:00
Christopher Gautier
2d89b6a9c5 Do not gitignore source/opt/build_module.* 2016-10-14 12:45:27 +02:00
David Neto
ee6c877b53 Test SPV_KHR_shader_draw_parameters support
In assembler, disassembler, parser.
2016-10-12 10:47:28 -04:00
Corentin Wallez
f92e87a8f8 Fix compilation errors when building inside Chromium
Example of an error:
    spirv-tools/source/validate_cfg.cpp:516:45: error: chosen constructor is
    explicit in copy-initialization:
      _.current_function().RegisterBlockEnd({}, opcode);
2016-10-04 17:47:19 -04:00
Lei Zhang
c1d5e660ee Add begin() and end() for TypeManager. 2016-09-30 16:56:42 -04:00
David Neto
f0a96c91f8 Remove unnecessary #include
This will make it easier to port these tests to different contexts.
2016-09-29 16:44:18 -04:00
Lei Zhang
689df65966 Add examples to demo C++ library APIs. 2016-09-28 15:24:00 -04:00
Lei Zhang
f9cb7c282c Avoid appending EOL in StringifyMessage().
EOL should be appended when outputing to streams by the tool.
2016-09-23 15:13:24 -04:00
Lei Zhang
069b0a7339 Fix operand class test coverage table.
* Fix a missing column.
* Convert line endings.

This will make the table beautiful and searchable on Github.
2016-09-23 11:58:25 -04:00
Lei Zhang
dc6e4834d6 Clean up header dependency. 2016-09-22 18:15:23 -04:00
David Neto
c6b23f8237 Handle parse failure for setting spec constants 2016-09-22 17:45:56 -04:00
Umar Arshad
a6ef1ea29e Fix forward reference issues with forword pointer
* Allows OpTypeForwardPointer to reference IDs not yet declared in
  the module
* Allows OpTypeStruct to reference IDs not yet declared in
  the module

Possible Issue: OpTypeStruct should only allow forward references
if the ID is a pointer that is referenced by a forward pointer. Need
Type support in Validator which is currently a work in progress.
2016-09-22 16:54:02 -04:00
qining
01df41dfdb Command line option for set default value for spec constant
Format:
```
--set-spec-constant-default-value "<spec id A>:<default value A> <spec id
B>:<default value B> ..."
```

Example:
  shader: `test.vert`
```

layout(constant_id = 100) const int myint = 10;
layout(constant_id = 101) const int myuint = 100;
layout(constant_id = 200) const float myfloat = 1.25;
layout(constant_id = 201) const double mydouble = 2.34;

void main() {}
```
  command line:
```
spirv-opt --set-spec-const-default-value "100:12   101:200 200:1.2323
201:1.2345" test.vert -o output.spv
```
  output:
```
      ...
               OpDecorate %7 SpecId 100
               OpDecorate %8 SpecId 101
               OpDecorate %10 SpecId 200
               OpDecorate %12 SpecId 201
       %void = OpTypeVoid
          %3 = OpTypeFunction %void
        %int = OpTypeInt 32 1
          %7 = OpSpecConstant %int 12
          %8 = OpSpecConstant %int 200
      %float = OpTypeFloat 32
         %10 = OpSpecConstant %float 1.23232
     %double = OpTypeFloat 64
         %12 = OpSpecConstant %double 2.34232
      ...
```
2016-09-22 14:28:59 -04:00
Lei Zhang
1ca817a38e Use nullptr as the default message consumer to ignore all messages.
There is no difference between the previous IgnoreMessage() function
and a null std::function, from functionality's perspective.
The user can set nullptr as the MessageConsumer, so need to guard
against nullptr before calling the consumer anyway. It's better
we use it internally so that it may expose problems by us instead
of the user.
2016-09-21 17:23:03 -04:00
Lei Zhang
6effeaa7f1 Change some asserts to normal errors in IrLoader. 2016-09-21 17:22:00 -04:00
Lei Zhang
3767e32b1f Add two more utility functions for sending errors to consumer. 2016-09-21 16:19:18 -04:00
Lei Zhang
74afb5d112 Change parameter name from file to source in Log() and Logf(). 2016-09-21 16:13:54 -04:00
Lei Zhang
5edf054926 Add more Assemble(), Disassemble() and Validate() overloads. 2016-09-21 14:42:04 -04:00
Lei Zhang
620f05e679 Publish the C++ interface. 2016-09-21 14:41:47 -04:00
Lei Zhang
92411caa3b Rename SpvTools to SpirvTools. 2016-09-21 14:28:33 -04:00
Lei Zhang
6849a3cefd Use C style names for MessageLevel. 2016-09-21 12:44:37 -04:00
Lei Zhang
80eb0793c9 Change to use enum instead of enum class for MessageLevel.
This allows us to create C interface with MessageLevel later.
2016-09-21 11:30:41 -04:00
Lei Zhang
f18e1f293b Add a C++ interface to the optimization functionalities. 2016-09-20 16:52:05 -04:00
Lei Zhang
1bc0b275dd Allow changing MessageConsumer in Pass & PassManager.
Default-constructed Pass/PassManager will have a MessageConsumer
which ignores all messages. SetMessageConsumer() should be called
to supply a meaningful MessageConsumer.
2016-09-20 16:48:00 -04:00
Lei Zhang
f8dbed0455 Change BuildModule() to accept pointer-size pair for binary. 2016-09-20 16:44:24 -04:00
Lei Zhang
2cbb2cce3e Change interface of Pass::Process() to return possible failures. 2016-09-20 16:40:17 -04:00