Commit Graph

346 Commits

Author SHA1 Message Date
Ryan Harrison
7f57887e05
Remove check for SpvCapabilityAtomicStorage (#2243)
Per conversation on
https://github.com/KhronosGroup/glslang/issues/1618 and other places.
2018-12-18 13:34:30 -05:00
Ryan Harrison
a719fc18a5 Disable checking that AtomicStorage capability is present (#2193)
There is inconsistencies between the different specs about whether or
not this capability is required/allowed, so tooling like glslang
currently ignores it. Once this is resolved the check and test can be
re-enabled.
2018-12-11 14:19:44 -05:00
Alejandro Lopez
de797ddcb5 Check that certain decorations cannot be used more than once and/or are mutually exclusive (#2171)
Fixes #1636

* Add a hash functor for decoration types for c++11 compliance
* Change non-POD static variables and add test for Block+BufferBlock
2018-12-07 12:46:27 -05:00
Ryan Harrison
7c38fee64a
Restrict mask bits for memory semantics in WebGPU (#2180)
Fail to validate memory semantics value if it includes set bits that
are not on the whitelist from the spec.

Fixes #2070
2018-12-07 10:38:52 -05:00
David Neto
6df6194db8
Validate Uniform decoration (#2181) 2018-12-07 09:32:57 -05:00
Ryan Harrison
cf37ab7213
Merge two implementations of ValidateMemorySemantics (#2175)
Fixes #2170
2018-12-06 14:38:15 -05:00
Ryan Harrison
378b7f3a29
Check for recursion in Vulkan and WebGPU entry points (#2161)
Fixes #2061
Fixes #2160
2018-12-05 13:58:43 -05:00
Alejandro Lopez
2f5f5308b6 Validate that there is at most one push constant block (#2163)
Fixes #2006

Validates that there is at most one PushConstant interface per entry point for Vulkan environment.
2018-12-05 13:30:04 -05:00
Ryan Harrison
3e645b9d67
Check that if A calls B, B is defined before A for WebGPU (#2169)
Fixes #2067
2018-12-05 11:47:24 -05:00
alan-baker
68d1dc66d2
Loosen binding and descriptor check (#2167)
* Only check for binding and descriptor set on variables that are
statically used by an entry point
 * updated tests and added a couple new ones
 * new method for collecting entry points that statically reference an
 id
2018-12-05 08:10:02 -05:00
Steven Perron
a0816d03e9
Validate OpForwardPointer (#2156)
* Validate OpForwardPointer

The validator does not have a a check that OpForwardPointer is giving
a forward reference to a pointer type.  We add that check.

https://crbug.com/910852

* Remove more specialized check.

There was a check that the forward pointer is actually a poiner type,
but it was only done if it was used in a struct.  This was too specific.
Remove it in favour of the more general check that was added.

* Format

* Check the storage type in OpTypeForwardPointer

* Fix typo is test case epxected results.
2018-12-04 13:35:49 -05:00
Alejandro Lopez
a1439604ea Check binding annotations in resource variables (#2151)
Fixes #2007

Add checks that all uniform, uniform constant and storage buffer variables have descriptor set and binding decorations
2018-12-04 10:05:41 -05:00
alan-baker
b1ff8ba5b9
Check device scope for Vulkan memory model (#2149)
Fixes #2147

* Checks that device scope is not used for availability and visibility
operations unless VulkanMemoryModelDeviceScopeKHR capability is present
* implemented for atomics, barriers and memory instructions currently
2018-12-03 17:15:47 -05:00
dan sinclair
d835d664bd
[val] Fixup id name output (#2158)
This CL changes the id/name output from the validator to always use a
consistent id[%name] style. This removes the need for getIdOrName. The
name lookup is changed to use the NameMapper so the output is consistent
with what the disassembler will produce.

Fixes #2137
2018-12-03 17:01:30 -05:00
David Neto
0c172a6b74
Allow Float16/Int8 for Vulkan 1.0 (#2153) 2018-12-03 12:50:12 -05:00
Steven Perron
ae1826154e
Validate uses of ids defined in unreachable blocks. (#2146)
* Validate uses of ids defined in unreachable blocks.

For some reason we do not make sure the uses of ids that are defined
in unreachable blocks are dominated by their def.  This is causing
invalid code to pass the validator.

Fixes #2143

* Add test for unreachable code after a return.

We want to allow code like:

```
void foo() {
  a = ...;
  ...
    return; // for debugging
  <use of a>;
  ...
}
```

I added a test to make sure that something like this is still accepted
by the validator.

* Add test for unreachable def used in phi.
2018-12-03 12:49:27 -05:00
alan-baker
d80259d35e
Strict validation of where type ids are acceptable (#2142)
Fixes https://crbug.com/910239

* IdPass catches many instances of invalid references to types
* Test updates
* Added test to catch OpArrayLength issue
2018-12-03 11:03:52 -05:00
Ryan Harrison
b9f9a3bc9f
Add WebGPU Execution scope check (#2148)
Fixes #2069
2018-12-03 10:56:55 -05:00
alan-baker
6af3c5cbe4
Clean uses of EvalInt32IfConst (#2145)
Fixes #2133

* Don't return OpSpecConstant* as constants in that method
 * cleaned up uses
* added tests to catch shader semantics and scope bugs
2018-11-30 14:00:56 -05:00
Alejandro Lopez
b8e2a9f258 Validate PushConstants annotation and type (#2140)
* Validate PushConstants have Block annotation and are struct or array of structs
* Add passing test and split into universal/vulkan environment tests
2018-11-30 13:12:05 -05:00
Ryan Harrison
625db3890d
Add check for QueueFamilyKHMR memory scope (#2144)
This also fixes a small typo that was causing my test case to fail.

Fixes #2136
2018-11-30 12:52:31 -05:00
Ryan Harrison
2cd040b0d3
Merging two ValidateMemoryScope implementations (#2132)
Fixes #2125
2018-11-29 14:51:17 -05:00
Ryan Harrison
8ce3dbabb8
Merge two implementations of ValidateExecutionScope (#2131) 2018-11-29 13:48:42 -05:00
Ryan Harrison
3ee605d7cc
Ensure that only whitelisted extensions are used in WebGPU (#2127)
Fixes #2058
2018-11-28 10:49:05 -05:00
Ryan Harrison
525e36d1cd
Move OpExtInst validation into validate_extensions.cpp (#2124)
Fixes #2123
2018-11-27 17:05:54 -05:00
alan-baker
3d56cddb75
Validate pointer variables (#2111)
Fixes #2104

* Checks the rules for logical addressing and variable pointers
 * Has an out for relaxed logical pointers
* Updated PassFixture to expose validator options
 * enabled relaxed logical pointers for some tests
* New validator tests
2018-11-27 16:47:10 -05:00
Ryan Harrison
4759082bbc
Ensure that imported extended instructions for WebGPU are only "GLSL.std.450" (#2119)
Ensure that imported extended instructions for WebGPU are GLSL.std.450

Fixes #2059
2018-11-27 16:20:01 -05:00
Ryan Harrison
dab634da93
Ensure that function parameter's type is not void (#2118)
Fixes #2094
2018-11-27 09:40:19 -05:00
Ryan Harrison
48d923907b
Restrict capabilities to WebGPU spec (#2113)
Restrict capabilities to WebGPU spec

This covers whitelisting Matrix, Shader, Sampled1D, Image1D,
DerivativeControl, and ImageQuery. These are the allowed capabilities
that don't require an extension. Whitelisting VulkanMemoryModelKHR
will be handled by whitelisting its extension in a seperate patch.

Fixes #2101
2018-11-27 09:39:37 -05:00
alelenv
f989b2dbd7 Add precise check for allowing use of gl_InstanceID for specific vulkan raytracing stages . (#2096)
* Checks that gl_InstanceID is only used in specific execution models
2018-11-27 08:35:29 -05:00
Steven Perron
4e22b60122
Add validation for OpArrayLength. (#2117)
The validation rules for OpArrayLength are not checked by the validator.
This with add them.

Fixes https://crbug.com/907451.
2018-11-26 19:46:08 -05:00
alan-baker
e799bfb923
Prevent diagnostic memory leak (#2110)
Fixes https://crbug.com/906669

* Don't free diagnostics in spvBinaryParse
* When invoking the parser we wish to ignore the error messages from,
instead create a hijacked context and replace the message consumer with
a null consumer
2018-11-26 16:58:09 -05:00
Daniel Koch
3b210d6a63 Add basic support for EXT_fragment_invocation_density (#2100)
Whitelisting the extension in optimizations
* copying what was done for NV_shading_rate
2018-11-23 10:21:19 -05:00
Ryan Harrison
7a3493e887
Make sure that initialized variable have correct storage class (#2092)
Make sure that initialized variable have correct storage class

For WebGPU and Vulkan environments, variables must have the storage
class; Output, Private, or Function, if they have an initializer.

Fixes #2071
2018-11-22 12:52:04 -05:00
Ryan Harrison
981763ec74
Ensure correct Addressing and Memory model set for WebGPU (#2093)
Adding validation that the addressing declared by OpMemoryModel is
Logical and the memory model declared is VulkanKHR. Updating a bunch
of tests that were broken by this.

Fixes #2060
2018-11-21 16:41:59 -05:00
Ryan Harrison
3adb7977da
Check forbidden Annotation instructions for WebGPU env (#2090)
Check forbidden Annotation instructions for WebGPU env

From the WebGPU SPIR-V Execution Enviroment spec:
  OpDecorationGroup, OpGroupDecorate, OpGroupMemberDecorate are not
  allowed.

Fixes #2062
2018-11-20 16:40:38 -05:00
Ryan Harrison
11c7a9e067
Validate that debugging instructions are not present for WebGPU (#2089)
Validate that debugging instructions are not present for WebGPU

For WebGPU execution environments, check that all of the debug
instructions have already been stripped before validation.

Fixes #2063
2018-11-20 16:12:28 -05:00
alan-baker
d41ff27f17
Add support for VK_EXT_Transform_feedback capabilities (#2088)
* Added support for Transform Feedback capabilities.
* Fix tests
2018-11-20 12:41:03 -05:00
alan-baker
f5b4a8eee3
Catch invalid input type to OpConvertUToPtr (#2078)
Fixes https://crbug.com/906426

* Fails validation if the input operand is a type
* Added a test
2018-11-19 15:08:38 -05:00
Ryan Harrison
8cd2a9d187
Validate component literals for OpVectorShuffle in WebGPU environment (#2077)
Validate component literals for OpVectorShuffle in WebGPU environment

Fixes #2072
2018-11-19 14:32:18 -05:00
Alan Baker
d652ed3029 Vulkan memory model: semantics validation
Ban sequentially consistent with VulkanKHR

* Added validation check that SequentiallyConsistent memory semantics
are not used if the memory model is VulkanKHR
 * Added tests
* Fixed a bug in evaluating constant 32-bit integers and updated some
handling to avoid inferring a value from a spec constant default

Remaining memory semantics validation

* Adds checks that OutputMemoryKHR, MakeAvailableKHR and MakeVisibleKHR
are only used if the VulkanMemoryModelKHR capabailty is present
* Added checks that MakeAvailableKHR requires release semantics
* Added checks that MakeVisibleKHR requires acquire semantics
* Added checks that MakeAvailableKHR and MakeVisibleKHR require a
storage class
2018-11-19 11:44:20 -05:00
Alan Baker
cd22b31557 Catch branch condition being a type
Fixes https://crbug.com/903691

* Added a test
2018-11-16 16:40:39 -05:00
David Neto
8e9be303b0 Validator: Support VK_EXT_scalar_block_layout
Adds validator option to specify scalar block layout rules.

Both VK_KHR_relax_block_layout and VK_EXT_scalar_block_layout can be
enabled at the same time.  But scalar block layout is as permissive
as relax block layout.

Also, scalar block layout does not require padding at the end of a
struct.

Add test for scalar layout testing ArrayStride 12 on array of vec3s

Cleanup: The internal getSize method does not need a round-up argument,
so remove it.
2018-11-16 15:55:30 -05:00
alan-baker
28d8d7bc67
Fix min base alignment (#2075)
Fixes #2073

* Added a test
2018-11-16 14:22:42 -05:00
Ryan Harrison
d7cd1203a4 Ensure for OpVariable that result type and storage class operand agree (#2052)
From SPIR-V spec, section 3.32.8 on OpVariable:
  Its Storage Class operand must be the same as the Storage Class
  operand of the result type.

Fixes #941
2018-11-16 11:22:11 -05:00
greg-lunarg
c37388f1ad Add passes to propagate and eliminate redundant line instructions (#2027). (#2039)
These are bookend passes designed to help preserve line information
across passes which delete, move and clone instructions. The propagation
pass attaches a debug line instruction to every instruction based on
SPIR-V line propagation rules. It should be performed before optimization.
The redundant line elimination pass eliminates all line instructions
which match the previous line instruction. This pass should be performed
at the end of optimization to reduce physical SPIR-V file size.

Fixes #2027.
2018-11-15 14:06:17 -05:00
fjhenigman
ab76e332de
Validate uniform variable type in Vulkan (#1949) (#2055)
From the Vulkan 1.1 spec 14.5.2:
  Variables identified with the Uniform storage class are used to access
  transparent buffer backed resources. Such variables must be typed as
  OpTypeStruct, or an array of this type.

Fixes #1949
2018-11-15 13:42:17 -05:00
David Neto
a29a9947ac UniformConstant variables can have RuntimeArray, TypeAccelerationStructureNV 2018-11-14 21:50:09 -05:00
alan-baker
5c334514d6
Allow InstanceId for NV ray tracing (#2049)
* Allow InstanceId for NV ray tracing

Fixes #2046

* Allows InstanceId in the Vulkan environment if RayTracingNV
capability is specified
2018-11-14 15:03:40 -05:00
Ryan Harrison
a362e60d5a
Validate variable types for UniformConstant storage in Vulkan (#2008) (#2044)
Validate variable types for UniformConstant storage in Vulkan (#2008)

From the Vulkan 1.1 spec 14.5.2:
  Variables identified with the UniformConstant storage class are used
  only as handles to refer to opaque resources. Such variables must be
  typed as OpTypeImage, OpTypeSampler, OpTypeSampledImage, or an array
  of one of these types.

Fixes #2008
2018-11-14 15:00:03 -05:00
Neil Henning
2b1f6b373c Validate that VertexId and InstanceId are not allowed in Vulkan. (#2036)
The Vulkan specification does not permit use of the VertexId and
InstanceId BuiltIn decorations, so add a check to ensure they are not
being used when the target environment is Vulkan.
2018-11-13 09:22:48 -05:00
Steven Perron
91f33503fc
Validate the id bound. (#2031)
* Validate the id bound.

Validates that the id bound for the module is not larger than the max id
bound.  Also adds an option to set the max id bound.  Allows the
optimizer option to set the max id bound to also set the id bound for
the validation run done by the optimizer.

Fixes #2030.
2018-11-06 11:30:19 -05:00
alelenv
1c1e749f0b Add support for nv-raytracing-final (#2010)
Add support for nv-raytracing (non-experimental)
2018-10-25 14:07:46 -04:00
alan-baker
20bbfb6f4d
Layout checks should recurse through runtime arrays (#1999)
Fixes #1985

* Added test to catch bug
* Tested aginst Vulkan CTS
2018-10-22 08:50:45 -04:00
alan-baker
89b8e238eb
Better checking of the index operand (#1992)
Fixes https://crbug.com/897069

* Code previously assumed the index instruction had a type
* Added a test to reproduce
2018-10-22 08:47:56 -04:00
Neil Henning
d29a1f98f3 Add validaton for SPV_KHR_8bit_storage + convert to/from floats. (#1990)
The SPV_KHR_8bit_storage extension does not permit 8-bit integers to be
cast directly to floating point types. We are seeing shaders in the
wild, being produced by toolchains like glslang, that are generating
invalid SPIR-V.

This change adds validation to check for the patterns not permitted, and
some tests that expose the failure.
2018-10-19 13:45:26 -04:00
alan-baker
9aa14a38f4
OpGroupDecorate may not target OpDecorationGroup (#1977)
Fixes https://crbug.com/896200

* Adds a check to validation of OpGroupDecorate that OpDecorationGroup
cannot be targeted
2018-10-17 13:45:05 -04:00
Steven Perron
b407163ef3
Checks for variable pointers (#1976)
In logical addressing mode, we are not allowed to generate variables
pointers.  There is already a check for OpSelect.  However, OpPhi 
and OpPtrAccessChain are not checked to make sure it does not 
generate an variable pointer.  I've added those checks.

Fixes #1957.
2018-10-16 14:57:55 -04:00
David Neto
eea449a1e8 validator: FPRoundingMode can apply to vector conversions
Fixes #1972
2018-10-15 17:22:50 -04:00
alan-baker
72bac04d73
Memory access checks for vulkan mem model (#1909)
* MakePointerVisibleKHR cannot be used with OpStore
* MakePointerAvailableKHR cannot be used with OpLoad
* MakePointerAvailableKHR and MakePointerVisibleKHR both require
NonPrivatePointerKHR
* NonPrivatePointerKHR is limited to a subset of storage classes
* many tests
2018-10-15 09:30:47 -04:00
David Neto
bdecee8c86 Validator: TaskNV can use LocalSize or LocalSizeId (#1970)
Correponds to the update to Rev2 of SPV_NV_mesh_shader

Fixes #1968
2018-10-12 08:54:52 -04:00
Alan Baker
1c128aa9ef Validating for new image operands
* Validation checks for new image operands MakeTexelAvailableKHR and
MakeTexelVisibleKHR
 * added tests
* Tests that NonPrivateTexelKHR is accepted for all image operands

Updating test environments

* fixed build errors
* changed image types for *FetchSuccess tests to use a type defined in
1.3 shader body
2018-10-11 17:47:18 -04:00
alan-baker
bc09f53c96
Fix calculation of case fall through (#1965)
Fixes #1959

* Code erroneously concluded that the target's fall through was itself
* Added a test
2018-10-10 13:25:48 -04:00
alan-baker
fae1e61ab8
Fix bug in construct block calculation (#1964)
Fixes #1960

* Only allows blocks that are dominated by the header
* Fixed a bad loop fusion test
* Added a test derived from the reported bug
2018-10-10 11:14:01 -04:00
Ben Ashbaugh
d3f88b0841 allow atomics on Function pointers for OpenCL (#1955) 2018-10-09 11:33:01 -04:00
Jaebaek Seo
03cbf33a69 Validator: FPRoundingMode decoration (#1482)
This commit checks the following when Shader capability exists:
"The FPRoundingMode decoration can be applied only to a width-only
conversion instruction that is used as the Object operand of an
OpStore storing through a pointer to a 16-bit floating-point object
in the StorageBuffer, Uniform, PushConstant, Input, or Output
Storage Classes.".
2018-10-05 13:33:03 -04:00
Jaebaek Seo
ebcc58b5f8 Validator: function scope variable at start of entry block #1923
All OpVariable instructions in a function must be the first
instructions in the first block.
2018-10-04 15:05:47 -04:00
Steven Perron
19c07731fc
Change handling of unknown extentions in validtor. (#1951)
This commit will change the message for unknown extensions from an error
to a warning.

Code was added to limit the number of warning messages so that consummer
of the messages are not overwhelmed.  This is standard practice in
compilers.

Many other issues were found at while looking into this. They have been
documented in #1950.

Fixes http://crbug.com/875547.
2018-10-03 15:59:40 -04:00
Jaebaek Seo
d73b9d8dfb [Validator] AMD_gpu_shader_half_float_fetch allow float16 (#1393)
SPV_AMD_gpu_shader_half_float_fetch extension should implicitly
allow declaring 16bit float.
2018-10-02 16:06:13 -04:00
Jaebaek Seo
37c99ab7e5 Validator: OpImageQuerySize validation (#1538)
Validation of OpImageQuerySize is missing that is a TODO. This
commit implements its validation based on the spec.
2018-10-02 15:53:52 -04:00
Alan Baker
a77bb2e54b Add validation for execution modes
* Check rules from Execution Mode tables, 2.16.2 and the Vulkan
environment spec

* Allows MeshNV execution model with the following execution modes
 * LocalSize, LocalSizeId, OutputPoints and OutputVertices
 * Done to not break their validation
2018-10-02 10:22:23 -04:00
Jaebaek Seo
f0aa6f4e3a Fixed Validator adjacency bug for OpPhi (#1922)
OpPhi instruction must appear before all non-OpPhi instructions
except for OpLine. Without this commit, Validator does not check
the case that an OpPhi is preceeded by an OpLine and the OpLine is
preceeded by a non-OpPhi instruction that is not OpLine.
2018-09-28 12:40:57 -04:00
alan-baker
ad0232dee5 Unify memory instruction validation style (#1934)
* Rename ValidateMemoryInstructions to MemoryPass
* Changed functions to take pointer to an instruction instead of
reference
2018-09-27 12:34:14 -04:00
Jaebaek Seo
4b4bd4c53a Validator: Validate OpImageTexelPointer (#487)
Checked all instructions whose object is OpTypeSampledImage or
OpTypeImage as suggested in #487. OpImageTexelPointer instruction
is missing and others look good. This commit adds only
OpImageTexelPointer.
2018-09-27 09:53:30 -04:00
Lei Zhang
1225324ae2
VK_KHR_shader_atomic_int64 covers OpAtomic{Load|Store} 2018-09-26 16:45:37 -04:00
Jaebaek Seo
026309ab27 Validator: OpGroupNonUniformBallotBitCount validation (#1486) 2018-09-26 15:52:39 -04:00
Alan Baker
90a12b3d4d Decoration validation for Vulkan memory model
* Adds a check that using Coherent or Volatile decorations with the
Vulkan memory model is a validation error
 * Adds tests
2018-09-21 21:55:01 -04:00
Alan Baker
1492111332 Validate vulkan mem model capabilty
* Check that if the VulkanMemoryModelKHR capability is specified that
the memory model must be VulkanKHR
 * added tests
2018-09-21 21:50:20 -04:00
Chao Chen
6e2dab2ffd Add support for Nvidia Turing extensions 2018-09-19 20:46:14 -04:00
Jaebaek Seo
0cd3e599ae Validator: correct out of bound check for OpMemberDecorate (#1881)
The number that indicates a member in OpMemberDecorate must be less
than the number of total members of struct.
2018-09-18 10:16:46 -04:00
Steven Perron
7f0a8877a2
Move the registration of decorations. (#1895)
We currently register decorations in the first pass through the
instructions.  This is a problem because the validator has not even
checked if the decoration instructions are valid yet.  This can lead to
unexpected behaviour from these side table.  For example, in
https://github.com/KhronosGroup/SPIRV-Tools/issues/1882, we use 5GB of
data to store 1 decoration for ids that are not even defined.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1882.
2018-09-18 08:53:09 -04:00
Lei Zhang
63265097e5
Add support for VK_KHR_shader_atomic_int64 in validator 2018-09-14 14:07:25 -04:00
Jaebaek Seo
2c2fee7979 Validator: check OpTypeBool inside Blocks (#1405)
OpTypeBool can only be used with non-externally visible shader
Storage Classes: Workgroup, CrossWorkgroup, Private, and Function.
2018-09-10 13:33:13 -04:00
Steven Perron
f62d7978fc
Add validation check for arrays of void type. (#1880)
In the definition of an array
(https://www.khronos.org/registry/spir-v/specs/1.2/SPIRV.html#Array),
it specfically mentions that array elements have non-void type.  I've
added a check for that in this PR.

http://crbug.com/879016
2018-09-10 09:21:32 -04:00
David Neto
571251c8f8 Support SPV_KHR_vulkan_memory_model rev2
Support collapsed into one commit:
- Asm/Dis support for SPV_KHR_vulkan_memory_model
- Add Vulkan mem model image operands to switch
- Add TODO for source/validate_image.cpp
- val: Image operands NonPrivateTexelKHR, VolatileTexelKHR have no operands
  This is required for memory model tests to pass SPIR-V validation.
- Round trip tests: Test new flags on OpCopyMemory*
2018-09-06 13:30:32 -04:00
Alan Baker
cb0f1f565b Remove struct member offset monotonicity check
Fixes #1822

* Remove check that struct member offsets must be monotonic
 * All environments match Vulkan behaviour now
 * updated offending tests
2018-08-31 09:45:45 -04:00
Steven Perron
482b1744ca
Validate all type ids. (#1868)
* Validate all type ids.

The validator does not check if the type of an instruction is actually
a type unless the OpCode has a specific requirement.  For example,
OpFAdd is checked, but OpUndef is not.

The commit add a generic check that if there is a type id then the id
defines a type.

http://crbug.com/876694

* Merge other checks for type into new one.

There are a couple check that the type id is a type for specific
opcodes.  Those have been mereged into 1.

Small changes to other test cases to make them valid enough for the
purpose of the test.
2018-08-27 23:45:32 -04:00
Steven Perron
06b42949b6
Validate uses of OpTypeFunction. (#1867)
In the specification of `OpTypeFunction`, it says

> OpFunction is the only valid use of OpTypeFunction.

This commit add a check in the validator for this rule.

A test started to fail because the new check happens before the check
the test case is testing.  Updated the test case to still fail the
check it was suppose to fail originally.

http://crbug.com/874571
2018-08-27 11:41:25 -04:00
alan-baker
d94a2077d6
Remove idUsage
* Moved remaining validation out of idUsage and deleted it
* Deleted unused functions
2018-08-27 11:06:09 -04:00
Alan Baker
6d27a8350f Fixing instances of iteration over unordered containers
* There were several instances found in the validator
 * validate_id.cpp
 * validate_decorations.cpp
 * validate_interfaces.cpp
2018-08-23 14:49:10 -04:00
Alan Baker
c5b38062ec Moving constant opcode validation into a new file
* Split constant opcode validation out of idUsage and into
validate_constants.cpp
 * minor style fixes
 * reduced duplication
 * fixed an issue with array sizing
2018-08-21 17:30:26 -04:00
Alan Baker
197b4597a0 Fix EvalInt32IfConst to fail on type instructions.
Fixes https://crbug.com/875842

* EvalInt32IfConst dereferenced a null pointer if a type instruction was
sent as the id
2018-08-21 11:59:00 -04:00
Steven Perron
36d675a404
Change when instruction is registered in validator. (#1840)
When doing the validator checks, an instruction is currently registered
at the end of IdPass.  This creates an inconsistency.  In IdPass, an
instruction that uses its own result will treat that use as a forward
reference.  Then in the following passes it will not because the
definition can be found.

It seems best to update the state after all of the check have been done
for the current instruction.  This makes it consistent for all of the
passes.

This makes a different when trying to verify OpTypeStruct.

Fixes https://crbug.com/874372.
2018-08-15 13:18:47 -04:00
dan sinclair
ef678672fb
Remove source/message.h (#1838)
The code in source/message was only used in a single set of tests to
format the output results. This CL changes the test to verify the
message instead of all the error values and removes the source/message
code.
2018-08-14 15:41:21 -04:00
Alan Baker
8cb949ad34 Validate correct opcode uses of OpFunction
Fixes https://crbug.com/873457

* Filed Khronos SPIR-V issue 352
* Updated bad tests
* Added new test
2018-08-14 10:13:06 -04:00
alan-baker
ce4547bdc7
Disallow void types in structs (#1832)
Fixes #1831

* Adds validation check that void is not a member of a struct
 * added a test
2018-08-14 08:55:49 -04:00
Alan Baker
e7fdcdba75 Split function opcode validation into new files.
* Moved function opcode validation out of idUsage and into new files
 * minor style changes
 * General opcode checking is in validate_function.cpp
 * Execution limitation checking is in
 validate_execution_limitations.cpp
* Execution limitations was split into a new pass as it requires other
validation to register those limitations first.
2018-08-13 17:04:57 -04:00
Alan Baker
397e02442e Fixing heap overflow in validation.
* Changed entry point validation to check storage class of variable
instead of pointer
 * added a test
* Moved several checks after opcode validation
 * These checks should be able to guarantee individual instructions are
 ok
* Updated tests due to reordered checks
2018-08-13 15:23:30 -04:00
Alan Baker
6cd4441c87 Move cfg opcode validation to another file.
* Moved cfg opcode validation out of idUsage and into validate_cfg.cpp
 * minor style updates
2018-08-13 11:30:08 -04:00
Alan Baker
714bf84e58 Split mode setting opcode validation into new file.
* Moved mode setting opcode validation out of idUsage and into a new
pass
 * minor style updates
2018-08-08 15:45:53 -04:00
Alan Baker
7d4b0464a3 Split annotation opcode validation into new file.
* Moves annotation opcode checks from idUsage into a new pass
 * minor style updates
2018-08-08 15:43:11 -04:00
Alan Baker
ca7278cff7 Split debug opcode validation into new file
* Removes debug opcode validation from idUsage and puts it in a separate
file
 * minor updates
2018-08-08 13:47:09 -04:00
Alan Baker
f2a990022a Move type instruction validation into separate file
* Moved type instruction validation out of validation idUsage into a new
file
* Consolidate type unique pass into new file
* Removed one bad test
* Reworked validation ordering
2018-08-08 12:55:39 -04:00
Alan Baker
3a20879f4d Unify validation of OpCopyMemory*
Fixes #1800

* Refactored duplication of code between OpCopyMemory and
OpCopyMemorySized validation
* Fixed some bugs in OpCopyMemorySized validation
* Replaced asserts with checks
* Added new tests
2018-08-07 19:01:58 -04:00
Alan Baker
2896b8f0e5 Refactor where opcodes are validated
* Replaced uses in opcode validation of current_function()
* Added non-const accessor to function lookup in ValidationState_t
* Updated a couple bad tests due to check reordering
2018-08-07 10:29:30 -04:00
dan sinclair
9991d661f8
Fix readbility/braces warnings (#1804) 2018-08-07 09:09:47 -04:00
dan sinclair
eda2cfbe12
Cleanup includes. (#1795)
This Cl cleans up the include paths to be relative to the top level
directory. Various include-what-you-use fixes have been added.
2018-08-03 15:06:09 -04:00
dan sinclair
58a6876cee
Rewrite include guards (#1793)
This CL rewrites the include guards to make PRESUBMIT.py include guard
check happy.
2018-08-03 08:05:33 -04:00
dan sinclair
d38a0a3b44
Validation within function body when doing a FunctionCall. (#1790)
When validating a FunctionCall we can trigger an assert if we are not
currently within a function body. This CL adds verification that we are
within a function before attempting to add a function call.

Issue 1789.
2018-08-02 16:58:45 -04:00
dan sinclair
6aa8a59415
Simplify validation ProcessInstruction (#1786)
This CL moves most of the logic out of validation ProcessInstruction and
groups it into validate. This places all of the validation logic in the
same place making it clearer what is running.

The Instruction class is changed to allow setting the function and block
after creation.
2018-08-02 15:12:06 -04:00
dan sinclair
1946fb4ddb
Remove ValidateInstructionAndUpdateValidationState (#1784)
This CL changes the stats aggregator to use
ValidateBinaryAndKeepValidationState to process the binary. This means
we can remove ValidateInstructionAndUpdateValidationState which expects
to be able to call ProcessInstruction in the validate anonymous
namespace. This decouples the stats aggregator from how validation
processes the binary.
2018-08-02 12:01:26 -04:00
dan sinclair
53afb3b77b
Combine ordered_instruction loops in validation. (#1782)
There are several validation passes which loop over all ordered
instructions. This CL combines those into a single loop, calling each
pass as needed.
2018-08-02 10:00:52 -04:00
dan sinclair
c9cd73b33a
Remove instruction_counter from ValidationState. (#1781)
The instruction counter is the same as the size of the
ordered_instruction list when we insert a new instruction. This Cl
removes instruction_counter_ and uses that instead.
2018-08-01 16:12:07 -04:00
Alan Baker
d49bedcaa6 Move memory class instructions to new pass
* Refactored the Memory class of instructions in the spec out Id
validation and into a new pass
 * Tests unmodified
 * some minor disassembly changes
 * minor style changes
2018-08-01 16:10:11 -04:00
dan sinclair
a5a5ea0e2d
Remove using std::<foo> statements. (#1756)
Many of the files have using std::<foo> statements in them, but then the
use of <foo> will be inconsistently std::<foo> or <foo> scattered
through the file. This CL removes all of the using statements and
updates the code to have the required std:: prefix.
2018-08-01 14:58:12 -04:00
dan sinclair
ebd6c75a71
Remove diag() overloads. (#1776)
This CL removes the two diag() overloads and leaves only the version
which accepts an Instruction. This is safer as we never use the
implicit location from the validation state.
2018-08-01 14:55:20 -04:00
dan sinclair
aa81e62cbe
Update diag() calls in validate_capability. (#1759)
This CL updates the diag() call in validate_capability to provide the
instruction.
2018-08-01 13:48:16 -04:00
dan sinclair
ab061afc83
Update diag() calls in validate_type_unique. (#1775)
This CL updates the diag() calls in validate_type_unique to pass the
relevant instruction.
2018-08-01 13:13:44 -04:00
dan sinclair
78335c927a
Update diag() calls in validate_primitives. (#1774)
This CL updates the diag() calls in validate_primitives to provide the
relevant instruction.
2018-08-01 13:00:38 -04:00
dan sinclair
6bb9ab48b8
Update diag() calls in validate_non_uniform. (#1773)
This CL upldates diag() calls in validate_non_uniform to provide the
relevant instruction.
2018-08-01 12:49:43 -04:00
dan sinclair
7c9a73fc30
Update diag() calls in validate_logicals. (#1772)
This CL updates the diag() calls in validate_logicals to provide the
Instruction.
2018-08-01 12:41:57 -04:00
dan sinclair
72766d9e88
Update diag() calls in validate_literals. (#1771)
This CL updates the diag() call in validate_literals to provide the
relevant instruction.
2018-08-01 12:41:46 -04:00
dan sinclair
e1e20f1abe
Update diag() calls in validate_layout. (#1770)
This CL updates the diag() calls in validate_layout to pass the relevant
instruction.
2018-08-01 12:01:35 -04:00
dan sinclair
f37e8d74e7
Update diag() call in validate_interface. (#1769)
This CL upldates validate_interface to pass the instruction to the
diag() method.
2018-08-01 11:58:37 -04:00
dan sinclair
d792ccd1ee
Update diag() calls in validate_instruction. (#1768)
This CL updates validate_instruction to pass the Instruction to diag().
2018-08-01 11:37:02 -04:00
dan sinclair
176cb5e593
Update diag() calls in validate_image. (#1767)
This CL updates the diag() calls in validate_image to provide the
relvant instruction.
2018-08-01 11:30:28 -04:00
dan sinclair
c64bad70d9
Update diag() calls in validate_ext_inst. (#1766)
This CL updates the diag() usage in validate_ext_inst to provide the
relevant instruction.
2018-08-01 11:11:23 -04:00
dan sinclair
441c0190eb
Update diag() calls in validate_derivatives. (#1765)
This CL updates diag() in validate_derivatives to provide the
instruction of interest.
2018-08-01 11:04:22 -04:00
dan sinclair
83b7f2b674
Update diag() calls in validate_decorations. (#1764)
Several of the diag() calls in validate_decorations do not provide the
line number, and will output the last line in the file. This CL updates
the diag() calls to provide the instruction of interest.
2018-08-01 10:44:27 -04:00
dan sinclair
a504656dad
Remove std::deque in favour of std::vector. (#1755)
This CL removes the two deque's from ValidationState and converts them
into std::vectors. In order to maintain the stability of instructions we
walk over the binary and counter the instructions and functions in the
ValidationState constructor and reserve the required number of items in
the module_functions_ and ordered_instructions_ vectors.

Issue #1176.
2018-08-01 10:37:36 -04:00
dan sinclair
fae987b470
Update diag() calls in validate_datarules. (#1763)
This CL updates validate_datarules to provide the instruction to diag().
2018-08-01 10:35:19 -04:00
dan sinclair
5a59a06e24
Update diag() calls in validate_conversion. (#1762)
This CL updates validate_conversion to provide the instruction to diag()
calls.
2018-08-01 10:18:06 -04:00
dan sinclair
eb03b152da
Update diag() calls in validate_composites. (#1761)
This CL updates the diag() calls in validate_composites to provide the
instruction directly.
2018-08-01 10:07:53 -04:00
dan sinclair
2c5f1b01d8
Update diag() calls in validate_cfg. (#1760)
This CL updates the diag() calls in validate_cfg to provide the
associated instruction. This fixes a couple places where we output the
last line of the file instead of the instruction as the disassembly.
2018-08-01 09:52:16 -04:00
dan sinclair
3619de9ad5
Update diag() use in validate_builtin. (#1758)
This CL updates the calls to diag() in vlidate_builtings to provide the
instruction.
2018-08-01 09:31:31 -04:00
dan sinclair
12c1f2b603
Update diag() usage in validate_bitwise. (#1757)
This Cl upldates the diag() calls to pass the instruction in
validate_bitwise.
2018-08-01 09:19:37 -04:00
dan sinclair
111933537b
Update diag() in validate_barriers (#1754)
This CL updates validate_barriers to provide an explicit instruction
when calling diag().
2018-07-31 18:44:35 -04:00
dan sinclair
32ccf0d04c
Update diag() in validate_atomics (#1753)
This CL updates validate_atomics to explicitly provide the instruction
when caling diag().
2018-07-31 17:20:43 -04:00
dan sinclair
a4fe771da7
Pass the instruction to diag in arithmetic validation (#1752)
This CL updates the diag() calls in validate_arithmetics to explicitly
provide the instruction the diagnostic is attached too.
2018-07-31 16:26:58 -04:00
dan sinclair
dfb53f9f1a
Fix disassembly line for adjacency validations. (#1751)
Previously the adjacency messages would output the last line of the file
as the disassembly. This is incorrect, as we have an instruction they
can be attached too. This CL fixes the messages to attach to the correct
line number.
2018-07-31 15:31:09 -04:00
dan sinclair
b7afe4e7ae
Switch validate to use explicit diag() method. (#1750)
This CL changes validate.cpp to use diag providing an explicit
instruction. This changes the result of the function end checks to not
output a disassembly anymore as printing the last line of the module
didn't seem to make sense.
2018-07-31 14:53:10 -04:00
dan sinclair
a9d8fceec9
Change ValidationState::diag to accept an Instruction. (#1749)
This CL changes the signature of diag() to accept an Instruction instead
of the instructions position.

A deprecated variant that accepts the position is available but will be
removed in the near future.
2018-07-31 14:19:34 -04:00
Dan Sinclair
f28ed82fd9 Make sure all instructions are in the ordered list.
Currently, some instructions will be missing from the list of
ordered_instructions. This will cause issues due to the debug change
which passed the last instruction into subsequent passes.

This CL moves the addition to the ordered list out of the
RegisterInstruction method into AddOrderedInstruction. This method is
called first in ProcessInstruction and the CapabilitiesPass and IdPass
are updated to take an Instruction parameter.
2018-07-31 09:55:57 -04:00
dan sinclair
dcea11fa03
Update error messages in validate_composites. (#1743)
This CL removes the redundant operator name from the error messages in
validate_composites. The operator will be printed on the next line with
the disassembly.
2018-07-31 09:52:14 -04:00
dan sinclair
dcb0dc21de
Split ImagePass into individual methods. (#1742)
This CL splits the switch in ImagePass into individual validate
functions. The error messages have been updated to drop the
suffix/prefix of the opcode name since it will be displayed in the
disassembly.
2018-07-30 16:59:29 -04:00
dan sinclair
673483d6a7
Move OpVectorShuffle check into validate_composites (#1741)
This CL moves the OpVectorShuffle ID check out of validate_id and into
validate_composites with the rest of the composite checks.
2018-07-30 16:12:49 -04:00
dan sinclair
ee22928bd9
Move CompositePass code into methods. (#1740)
This Cl splits the CompositePass switch to have one method per case
label. This makes the code a lot simpler to follow.
2018-07-30 13:06:03 -04:00
Dan Sinclair
8c7dab5caa Fixup line number for OpVectorShuffle ID error.
This CL updates the code to pull a valid instruction for the line number
when outputting a component error in OpVectorShuffle. The error line
isn't the best at this point as it points at the component, but it's
better then a -1 (turning to max<size_t>) that was being output.

The error messages has been updated to better reflect what the error is
attempting to say.

Issue 1719.
2018-07-16 14:18:53 -04:00
Steven Perron
63c1d8fb15
Fix size error when folding vector shuffle. (#1721)
When folding a vector shuffle that feeds another vector shuffle causes
the size of the first operand to change, when other indices have to be
adjusted reletive to the new size.
2018-07-13 11:20:02 -04:00
dan sinclair
7603944a10
Remove dead code (#1720)
Remove commented out code from validate_id.
2018-07-12 20:26:44 -04:00