Commit Graph

1015 Commits

Author SHA1 Message Date
Ehsan Nasiri
f2867d7485 The Signedness in OpTypeInt must always be 0.
When Kernel capability is used, The Signedness in OpTypeInt must always
be 0. Fixes issue #492.
2017-02-10 12:21:16 -05:00
Kenneth Benzie (Benie)
f980d8c671 Add vim-spirv plugin description to the README
Fixes #359
2017-02-01 21:43:01 +00:00
David Neto
ab03b879ca Encourage use of the validator 2017-01-29 22:53:50 -05:00
Ehsan Nasiri
affbc31849 Making the unit tests more robust.
It is best to check the error messages of unit tests that fail
validation. This will ensure that a validation failure is due to what we
expect and not due to some secondary reason.

Updating SPIR-V Validator unit tests with error message checks.
2017-01-29 22:50:37 -05:00
Ehsan Nasiri
cb009b3862 Fixes issue #497.
The Linkage Attributes Decoration cannot be applied to functions
targeted by an OpEntryPoint instruction.
2017-01-19 16:34:47 -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
3a7df2cf1b Fixes issue #532.
It is acceptable for OpAccessChain, OpInBoundsAccessChain,
OpPtrAccessChain, OpInBoundsPtrAccessChain, OpCompositeInsert, and
OpCompositeExtract to not take any indexes as arguments. In such cases,
no indexing will be done on the Base pointer/composite.
2017-01-19 11:03:04 -05:00
Ehsan Nasiri
eb7d2534df Fixes issue #493.
Check function call operands and return type agree with the called
function type.

The validation code exists. I have fixed the unit tests.
2017-01-18 17:04:00 -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
David Neto
699943d297 Say why we allow override of build timestamp
It's for reproducible builds.

Also, fix Python formatting.
2017-01-17 15:42:02 -05:00
Bernhard M. Wiedemann
29b37fb310 make build reproducible
see https://reproducible-builds.org/ for why this is good
2017-01-17 19:36:39 +01:00
Ehsan Nasiri
fcf7df069d Adding decoration class and tests.
* Added the decoration class as well as the code that registers the
decorations for each <id> and also decorations for struct members.

* Added unit tests for decorations in ValidationState as well as
decoration id tests.
2017-01-16 16:52:08 -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
Lei Zhang
d5e4f06eec Update Travis CI configuration.
* Stop updating brew.
* Shadow clone of dependencies.
* Fix `nproc` on macOS.
2017-01-13 09:53:16 -05:00
David Neto
545a6c1dc3 Provide friendly names for true and false 2017-01-11 16:33:45 -05:00
Ehsan Nasiri
d1868b9361 Validation for Composite Extract and Insert.
The validity of each command is checked based on the descripton in
SPIR-V Spec Section 3.32.12 (Composite Instructions).

Also checked that the number of indexes passed to these commands does
not exceed the limit described in 2.17 (Universal Limits).

Also added unit tests for each one.
2017-01-06 17:14:38 -05:00
Ehsan Nasiri
109ce225c9 Fixes bug #517.
entry_block_to_construct_ maps an entry block to its construct. The key
in this map (the entry block) is not unique, and therefore the entry for
the continue construct gets overwritten when the selection construct is
discovered.

Since a given block may be the entry block of different types of
constructs, the (basic_block, construct_type) pair should be able to
uniquely identify the construct.

Adds test:
- In this test, a basic block is the entry block of a continue construct
  as well as the entry block of a selection construct.
  It can be shown that this unit test would crash without the fix in this
  PR and passes with the fix in this PR.
2017-01-06 14:23:17 -05:00
David Neto
558ac1e5aa Allow trailing whitespace on version lines in CHANGES 2017-01-06 13:18:50 -05:00
David Neto
20b2035f20 Use the default Xcode image on OSX
As of November 2016, the default OSX image is Xcode 7.3.1, which works.
2017-01-05 16:06:31 -05:00
Ehsan Nasiri
ff272a9820 Adding validation code for PtrAccessChain.
Validation for OpPtrAccessChain is similar to OpAccessChain with the
following difference: OpPtrAccessChain takes an extra argument (word 4)
which is the Element <id> argument.

Validation for OpInBoundsPtrAccessChain is also similar to OpPtrAccessChain.

Also added tests for all access chain instructions:
Modified the existing parameterized tests to accommodate OpPtrAccessChain and
OpInBoundsPtrAccessChain.

Also fixed a typo in previous commits.
2017-01-03 16:36:35 -05:00
Ehsan Nasiri
c656c23ad3 Refactoring unit tests using TEST_P.
Using parameterized unit tests to avoid duplicate code that runs the
tests of OpAccessChain and OpInBoundsAccessChain.

This is also a steppingstone to adding tests for OpPtrAccessChain and
OpInBoundsPtrAccessChain.
2017-01-03 14:58:48 -05:00
Ehsan Nasiri
6993fc413d Validation code for control flow nesting depth.
According to Section 2.17 (Universal Limits) of the SPIR-V Spec, the
control flow nesting depth may not be larger than 1023.

This is checked only when we are required to have structured
control flow.  Otherwise it's not clear how to compute control
flow nesting depth.
2016-12-23 14:14:50 -05:00
David Neto
37422e9dba Support building under CYGWIN
- Parse CHANGES file with Universal Python line endings in case
  the source tree was checked out with Windows line endings.
- Use our own clone of strnlen_s which might not be available
  everywhere.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/508
2016-12-21 10:34:23 -05:00
David Neto
e0e4044ffe Update Travis notification emails
Remove deki, add ehsann
2016-12-21 10:33:03 -05:00
David Neto
f8cc397573 Generate spvasm.vim
Generate a vim syntax file for SPIR-V assembly.
Copy the resulting spvasm.vim into your $HOME/.vim/syntax directory
to get syntax highlighting in Vim.

Also, suggest that the grammar file include information
about what opcodes can be used in OpSpecConstantOp.
2016-12-20 11:36:41 -05:00
David Neto
68c5f0436f Start v2016.7-dev 2016-12-13 11:49:50 -05:00
David Neto
5f5fa3a3f1 Finalize v2016.6 2016-12-13 11:49:09 -05:00
David Neto
5a0b5ca4a7 Get vendor tool info from the SPIR-V registry file
Update old tests to use officially registered vendor names;
this affected "Codeplay".
2016-12-09 14:01:43 -05:00
David Neto
945e9fc4b4 Document the use of the GitHub Project feature 2016-12-08 18:22:26 -05:00
Ehsan Nasiri
d004cd46db Adding validation for OpInBoundsAccessChain.
The validation for this instruction is similar to OpAccessChain.

Include a test for testing a struct with (valid) depth of 255.
2016-12-08 15:11:30 -05:00
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