Commit Graph

44 Commits

Author SHA1 Message Date
alan-baker
a1fb255a2a
Validate location assignments (#3308)
* Add validation that input/output locations are assigned correctly
* Account for component assignment
* Account for 4 components per location and track the combined
coordinate
* Account for multiple output indexes
* handle specifically arrayed variables
* Arrayed variables that specify a component get locations determined
per index of the array for the sub type
  * Added tests that check locations and components can be assigned
  to interleave an array's locations and components
* Fix up which interfaces are allowed to be arrayed for various shader
stages based on glslang
2020-06-25 13:22:45 -04:00
Caio Marcelo de Oliveira Filho
c37c94929b
Validate Buffer and BufferBlock apply only to struct types (#3259) 2020-03-31 10:06:29 -04:00
David Neto
e70b009b0f
Add support for SPV_KHR_non_semantic_info (#3110)
Add support for SPV_KHR_non_semantic_info

This entails a couple of changes:

- Allowing unknown OpExtInstImport that begin with the prefix `NonSemantic.`
- Allowing OpExtInst that reference any of those sets to contain unknown
  ext inst instruction numbers, and assume the format is always a series of IDs
  as guaranteed by the extension.
- Allowing those OpExtInst to appear in the types/variables/constants section.
- Not stripping OpString in the --strip-debug pass, since it may be referenced
  by these non-semantic OpExtInsts.
- Stripping them instead in the --strip-reflect pass.

* Add adjacency validation of non-semantic OpExtInst

- We validate and test that OpExtInst cannot appear before or between
  OpPhi instructions, or before/between OpFunctionParameter
  instructions.

* Change non-semantic extinst type to single value

* Add helper function spvExtInstIsNonSemantic() which will check if the extinst
  set is non-semantic or not, either the unknown generic value or any future
  recognised non-semantic set.

* Add test of a complex non-semantic extinst

* Use DefUseManager in StripDebugInfoPass to strip some OpStrings

* Any OpString used by a non-semantic instruction cannot be stripped, all others
  can so we search for uses to see if each string can be removed.
* We only do this if the non-semantic debug info extension is enabled, otherwise
  all strings can be trivially removed.

* Silence -Winconsistent-missing-override in protobufs
2019-12-18 18:10:29 -05:00
alan-baker
1a18d491f2 Validate array stride does not cause overlap (#3028)
Fixes #3027

* Disallow array stride 0
* Check array stride against element size
* Fix up tests
* Add new tests
2019-11-12 13:36:53 -05:00
alan-baker
9325619353
Extra resource interface validation (#2864)
* Vulkan specific checks
  * storage buffer variables must be structs or arrays of structs
  * storage buffer struct must be Block decorated
  * uniform struct must be Block or BufferBlock decorated
* new tests
2019-09-16 10:46:31 -04:00
Caio Marcelo de Oliveira Filho
9702d47c6f Validate that in OpenGL env block variables have Binding (#2685)
* Add spvIsOpenGLEnv helper
* Validate that in OpenGL env block variables have Binding
2019-07-02 08:11:20 -04:00
Józef Kucia
888aeef8a9 Fix Component decoration validation for arrays (#2697) 2019-06-25 13:28:16 -04:00
Józef Kucia
7c294608ca Basic validation for Component decorations (#2679)
* Add basic validation for Component decoration
* Add validator tests for Component decoration
2019-06-20 18:16:12 -04:00
David Neto
f2803c4a7f
VK_KHR_uniform_buffer_standard_layout validation (#2562)
Add a command-line option to enable validating SPIR-V for
implementations that support VK_KHR_uniform_buffer_standard_layout.
2019-05-08 18:01:10 -04:00
alan-baker
ea5e1b62e1
Update priv-to-local for SPIR-V 1.4 (#2567)
Fixes #2555

* Fix a bug in validation where interfaces were considered non-unique
between different entry points targeting the same function
  * added a test
* Update private to local pass to remove localized private variables
from entry point interfaces
  * added tests
2019-05-08 12:38:49 -04:00
David Neto
63f57d95d6
Support SPIR-V 1.4 (#2550)
* SPIR-V 1.4 headers, add SPV_ENV_UNIVERSAL_1_4

* Support --target-env spv1.4 in help for command line tools

* Support asm/dis of UniformId decoration

* Validate UniformId decoration

* Fix version check on instructions and operands

Also register decorations used with OpDecorateId

* Extension lists can differ between enums that match

Example: SubgroupMaskEq vs SubgroupMaskEqKHR

* Validate scope value for Uniform decoration, for SPIR-V 1.4

* More unioning of exts

* Preserve grammar order within an enum value

* 1.4: Validate OpSelect over composites

* Tools default to 1.4

* Add asm/dis test for OpCopyLogical

* 1.4: asm/dis tests for PtrEqual, PtrNotEqual, PtrDiff

* Basic asm/Dis test for OpCopyMemory

* Test asm/dis OpCopyMemory with 2-memory access

Add asm/dis tests for OpCopyMemorySized

Requires grammar update to add second optional memory access operand
to OpCopyMemory and OpCopyMemorySized

* Validate one or two memory accesses on OpCopyMemory*

* Check av/vis on CopyMemory source and target memory access

This is a proposed rule. See
https://gitlab.khronos.org/spirv/SPIR-V/issues/413

* Validate operation for OpSpecConstantOp

* Validate NonWritable decoration

Also permit NonWritable on members of UBO and SSBO.

* SPIR-V 1.4: NonWrtiable can decorate Function and Private vars

* Update optimizer CLI tests for SPIR-V 1.4

* Testing tools: Give expected SPIR-V version in message

* SPIR-V 1.4 validation for entry point interfaces

* Allow only unique interfaces
* Allow all global variables
* Check that all statically used global variables are listed
* new tests

* Add validation fixture CompileFailure

* Add 1.4 validation for pointer comparisons

* New tests

* Validate with image operands SignExtend, ZeroExtend

Since we don't actually know the image texel format, we can't fully
validate.  We need more context.

But we can make sure we allow the new image operands in known-good
cases.

* Validate OpCopyLogical

* Recursively checks subtypes
* new tests

* Add SPIR-V 1.4 tests for NoSignedWrap, NoUnsignedWrap

* Allow scalar conditions in 1.4 with OpSelect

* Allows scalar conditions with vector operands
* new tests

* Validate uniform id scope as an execution scope

* Validate the values of memory and execution scopes are valid scope
values
* new test

* Remove SPIR-V 1.4 Vulkan 1.0 environment

* SPIR-V 1.4 requires Vulkan 1.1

* FIX: include string for spvLog

* FIX: validate nonwritable

* FIX: test case suite for member decorate string

* FIX: test case for hlsl functionality1

* Validation test fixture: ease debugging

* Use binary version for SPIR-V 1.4 specific features

* Switch checks based on the SPIR-V version from the target environment
to instead use the version from the binary
* Moved header parsing into the ValidationState_t constructor (where
version based features are set)
* Added new versions of tests that assemble a 1.3 binary and validate a
1.4 environment

* Fix test for update to SPIR-V 1.4 headers

* Fix formatting

* Ext inst lookup: Add Vulkan 1.1 env with SPIR-V 1.4

* Update spirv-val help

* Operand version checks should use module version

Use the module version instead of the target environment version.

* Fix comment about two-access form of OpCopyMemory
2019-05-07 12:27:18 -04:00
alan-baker
07c4dd4b9e Reduce runtime of array layout checks (#2534)
Fixes #2533

* Stop checking layouts once the offset gets back to a 16 byte alignment
2019-04-23 10:33:00 -04:00
Ehsan
5fb83a9708
Allow NonWritable to target struct members. (#2420)
It should be allowed for the NonWritable decoration to be applied to
structure type members.
2019-02-27 16:11:50 -05:00
Sarah
4c43afcade
It is invalid to apply both Restrict and Aliased to the same <id> (#2408)
to fix #2408 - It is invalid to apply both Restrict and Aliased to the same
2019-02-21 12:03:52 -05:00
Sarah
76730a46a1
In Vulkan, disallow BufferBlock on StorageBuffer variables (#2380)
To fix #2168.
2019-02-20 11:50:57 -05:00
Ryan Harrison
0167a20b0a
Move usage detection to after all instructions are registered (#2378)
This is required to properly handle uses of forward declared ids. Since forward
declared ids were not being properly covered by the validator this uncovered a
bunch of small issues that needed to be resolved to get tests passing again.

Fixes #2373
2019-02-13 14:06:56 -05:00
David Neto
7f3679a8b6
Validate NonWritable decoration (#2263)
Also permit NonWritable on members of structs used for UBO and SSBO.
(That seems inadvertently removed in recent revisions of the spec.)
2019-01-28 12:44:13 -08:00
alan-baker
cf011f9901 More layout check fixes (#2315)
* check array strides for multidimensional arrays
* check layouts of structs in arrays for multiple indices
* new tests
2019-01-24 14:24:31 -08:00
Steven Perron
e2279da714
Remove the static maps from CheckDecorationsCompatibility (#2327)
* Remove the static maps from CheckDecorationsCompatibility

There are a few data structures in the function
`CheckDecorationsCompatibility` that are allocated using `new` and their
address is stored in a static pointer.  This code pattern causes the
MSVC memory leak checker to say there is a memory leak.  Some people
are interested in keeping that clean.

To work around it, I have replaced them with either a function or an
array of POD types.  The array can be kept as a static directly because
it has a trivial destructor, and we don't have to worry about it being
destroyed too early.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/2317.
2019-01-24 14:50:58 -05:00
David Neto
4a405eda53
Fix layout checks for nested struct in relaxed layout; and descriptor arrays (#2312)
* Fixed layout checks for nested structures

Fixes #2303

* Incoming offsets accumulate through nested structures

* Check layouts through arrays

* Perform layout checks in the presence of descriptor arrays (and
runtime arrays)

* Fix formatting
2019-01-22 15:15:24 -08:00
David Neto
6958d11bc2
Validate decorations from SPV_KHR_no_integer_wrap (#2271)
Validates NoSignedWrap, NoUnsignedWrap.

We are permissive by allowing any extended instruction.
2019-01-09 10:36:17 -05:00
Jeff Bolz
5eab6df648 SPV_EXT_physical_storage_buffer (#2267) 2019-01-07 13:19:24 -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
David Neto
6df6194db8
Validate Uniform decoration (#2181) 2018-12-07 09:32:57 -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
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
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
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
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
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
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
David Neto
eea449a1e8 validator: FPRoundingMode can apply to vector conversions
Fixes #1972
2018-10-15 17:22:50 -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
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
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
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
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
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
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
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
Lei Zhang
4db9c789ff Add option to skip verifying block layout
We need this to avoid emitting errors on DirectX layout rules.
2018-07-11 18:00:54 -04:00
David Neto
2c6185e6bf Enforce block layout rules even when relaxed
- Vulkan 1.0 uses strict layout rules
- Vulkan 1.0 with relaxed-block-layout validator option
  enforces all rules except for the relaxation of vector
  offset.
- Vulkan 1.1 and later always supports relaxed block layout

Add spot check tests for the relaxed-block-layout scenarios.

Fixes #1697
2018-07-11 10:38:36 -04:00
dan sinclair
e70a412609
Move validation files to val/ directory (#1692)
This CL moves the various validate files into the val/ directory with
the rest of the validation infrastructure. This matches how opt/ is
setup with the passes with the infrastructure.
2018-07-11 10:27:34 -04:00