Commit Graph

73 Commits

Author SHA1 Message Date
Kévin Petit
9f035269d6 Validate OpenCL environment rules for OpTypeImage (#2606)
It is currently not possible to use an Image Format that is
not Unknown without requiring a capability forbidden by the
OpenCL environment. As such the validation of Image Format
currently leans on capability validation entirely.

Fixes #2592.

Signed-off-by: Kevin Petit <kevin.petit@arm.com>
2019-05-21 09:17:50 -04:00
Steven Perron
e935dac9ef
Make pointers to isomorphic type interchangeable with option. (#2570)
* Make pointers to logically matching types interchangeable with option.

DXC will be generating code where the function parameters will be a more
generic type that the actual parameter.  They should be logically
matching and the decorations of the actual parameter must be a superset
of the decorations of the formal parameter.

We want to accept this code with an options so that spirv-opt can then
inline and fix the type mismatch.  We will accept this under a new
options `--before-hlsl-legalization`.

The new option will also imply `relax-logical-pointer` so that HLSL
frontends will need to use just the one more generic option.

Moved the |LogicallyMatches| to the validation state to make it
available in more places.  Also added a parameter to have it check the
decorations.  I did not do a separate function for the decorations
because checking the decorations involves making sure the types
logically match anyway.

Fixes #2535
2019-05-13 13:48:17 -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
Ryan Harrison
08b54d9e45
Convert sampled consumers to being Instructions instead of IDs (#2464)
Changing the stored value for a sampled image consumer to be the
instruction instead of result ID, since not all instructions have
result IDs. Using result IDs led to a potential crash when using
OpReturnValue, which doesn't have a result ID. OpReturnValue is not a
legal consumer, but the validator needs to look at the instruction to
determine this, thus storing the pointer to the instruction, instead
of trying to fetch the pointer using the instruction.

Issue #1528 covers fixing the check.

Fixes #2463
2019-03-19 12:39:37 -04:00
Jeff Bolz
002ef361ca Add validation for SPV_NV_cooperative_matrix (#2404) 2019-02-25 17:43:11 -05:00
Sarah
fc3897b5f5
Validate: (data) Block can't appear within a Block (#2410)
A Block or BufferBlock cannot be nested within another Block or BufferBlock
2019-02-25 10:37:43 -05:00
David Neto
df5bd2d05a
Permit UConvert spec-constant op for SPV_AMD_gpu_shader_int16 (#2264)
See https://github.com/KhronosGroup/glslang/issues/848
2019-01-08 19:00:18 -05:00
Jeff Bolz
5eab6df648 SPV_EXT_physical_storage_buffer (#2267) 2019-01-07 13:19:24 -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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
David Neto
fec6315fad Vulkan permits non-monotonic offsets for block members
Other environments do not.
Add tests for OpenGL 4.5 and SPIR-V universal 1.0 to ensure
they still check monotonic layout.

For universal 1.0, we're assuming it otherwise follows Vulkan
rules for block layout.

Fixes #1685
2018-07-10 17:16:54 -04:00
dan sinclair
a3e3869540
Convert validation to use libspriv::Instruction where possible. (#1663)
For the instructions which execute after the IdPass check we can provide
the Instruction instead of the spv_parsed_instruction_t. This
Instruction class provides a bit more context (like the source line)
that is not available from spv_parsed_instruction_t.
2018-07-10 10:57:52 -04:00
dan sinclair
43144e36c1
Move the validation code into the val:: namespace (#1682)
This CL moves the validation code to the val:: namespace. This makes it
clearer which instance of the Instruction and other classes are being
referred too.
2018-07-09 23:18:44 -04:00
dan sinclair
3dad1cda11
Change libspirv to spvtools namespace (#1678)
This CL changes all of the libspirv namespace code to spvtools to match
the rest of the code base.
2018-07-07 09:38:00 -04:00
David Neto
30a9cefa1d Support SPV_KHR_8bit_storage
- Add asm/dis test for SPV_KHR_8bit_storage
- validator: SPV_KHR_8bit_storage capabilities enable declaration of 8bit int

TODO:
- validator: ban arithmetic on 8bit unless Int8 is enabled
  Covered by https://github.com/KhronosGroup/SPIRV-Tools/issues/1595
2018-07-03 15:53:19 -04:00
dan sinclair
51091045fe
Produce better error diagnostics in the CFG validation. (#1660)
Produce better error diagnostics in the CFG validation.

This CL fixes up several issues with the diagnostic error line output
in the CFG validation code. For the cases where we can determine a
better line it has been output. For other cases, we removed the
diagnostic line and the error line number from the results.

Fixes #1657
2018-07-03 15:06:54 -04:00
Corentin Wallez
ba602c9059 Add a WIP WebGPU environment. It disallows OpUndef
Add SPV_ENV_WEBGPU_0 for work-in-progress WebGPU.

val: Disallow OpUndef in WebGPU env

Silence unused variable warnings when !defined(SPIRV_EFFCE)

Limit visibility of validate_instruction.cpp's symbols
  Only InstructionPass needs to be visible so all other functions are put
  in an anonymous namespace inside the libspirv namespace.
2018-06-21 15:53:15 -04:00
dan sinclair
f80696eaf6
[val] Add extra context to error messages. (#1600)
[val] Add extra context to error messages.

This CL extends the error messages produced by the validator to output the
disassembly of the errored line.

The validation_id messages have also been updated to print the line number of
the error instead of the word number. Note, the error number is from the start
of the SPIR-V, it does not include any headers printed in the disassembled code.

Fixes #670, #1581
2018-06-19 16:02:44 -04:00
Alan Baker
ea7239fa73 Structured switch checks
Fixes #491

* Basic blocks now have a link to the terminator
* Check all case sepecific rules
* Missing check for branching into the middle of a case (#1618)
2018-06-13 15:04:47 -04:00
dan sinclair
3b87dac56b Validate presence of OpMemoryModel.
According to the SPIR-V Spec, section 2.4 Logical Layout of a Module there
should be a single required OpMemoryModel instruction provided. This CL adds
validation that OpMemoryModel is provided to the SPIR-V validator.

Fixes #1207
2018-05-23 08:17:39 -04:00
Lei Zhang
efcc33e8a9
Support SpvOpExecutionModeId in SPIR-V logical layout 2018-05-16 08:43:50 -04:00
Alan Baker
38359ba800 Fixes #1483. Validating Vulkan 1.1 barrier execution scopes
* Reworked how execution model limitations are checked
 * Now OpFunction checks which entry points call it and checks its
 registered limitations instead of building a call stack in the entry
 point
* New tests
* Moving function to entry point mapping into VState
2018-04-17 10:26:38 -04:00
Andrey Tuganov
03b8a3fe54 AMD_gpu_shader_half_float enables float16
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/1375

Hardcoded float16 feature enabling if extension
SPV_AMD_gpu_shader_half_float is present.
2018-03-07 11:07:58 -05:00
David Neto
5f69f75126 Support SPV_GOOGLE_decorate_string and SPV_GOOGLE_hlsl_functionality1
This commit add assembling, disassembling, and basic validation for two
Google extensions to better support HLSL translation.
2018-03-05 13:34:13 -05:00
Andrey Tuganov
2f0c3aaa11 Add Vulkan-specific validation rules for atomics
Added atomic instructions validation rules from
https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#spirvenv-module-validation
2018-02-07 13:31:35 -05:00
David Neto
3c2e4c7d99 Fix validation of group ops in SPV_AMD_shader_ballot
This needs custom code since the rules from the extension
are not encoded in the grammar.

Changes are:
- The new group instructions don't require Group capability
  when the extension is declared.
- The Reduce, InclusiveScan, ExclusiveScan normally require the Kernel
  capability, but don't when the extension is declared.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/991
2017-11-30 10:26:04 -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
Andrey Tuganov
3e08a3f718 Add validation checks for Execution Model
Currently checks that these instructions are called from entry points
with Fragment execution model.
OpImageImplicit*
OpImageQueryLod
OpKill
2017-11-23 23:38:03 -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
Lei Zhang
063dbea0f1 Turn all function static non-POD variables into global POD variables
Function static non-POD data causes problems with DLL lifetime.
This pull request turns all static info tables into strict POD
tables. Specifically, the capabilities/extensions field of
opcode/operand/extended-instruction table are turned into two
fields, one for the count and the other a pointer to an array of
capabilities/extensions. CapabilitySet/EnumSet are not used in
the static table anymore, but they are still used for checking
inclusion by constructing on the fly, which should be cheap for
the majority cases.

Also moves all these tables into the global namespace to avoid
C++11 function static thread-safe initialization overhead.
2017-10-25 15:44:19 -04: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