Commit Graph

350 Commits

Author SHA1 Message Date
Toomas Remmelg
7b4e5bd5ec Update remquo validation to match the OpenCL Extended Instruction Set Specification (#2791) 2019-08-15 09:38:37 -04:00
alan-baker
bbd80462f5
Fix validation of constant matrices (#2794)
Fixes #2793

* Don't special case matrix validation compared to other composites
  * just check the constituents are constants or undefs
  * later checking validates the column type
  * new test
2019-08-14 11:26:41 -04:00
Ryan Harrison
5ada98d0bb Update WebGPU validation rules of OpAtomic*s (#2777)
Fixes #2723
2019-07-31 17:15:47 -04:00
Ryan Harrison
4a28259cc8
Update OpMemoryBarriers rules for WebGPU (#2775)
Part of #2724
2019-07-30 14:50:55 -04:00
Ryan Harrison
7bafeda284
Update OpControlBarriers rules for WebGPU (#2769)
* Update OpControlBarriers rules for WebGPU

Part of #2724
2019-07-29 12:53:27 -04:00
Steven Perron
c7fcb8c3b9
Process OpDecorateId in ADCE (#2761)
* Process OpDecorateId in ADCE

When there is an OpDecorateId instruction that is live,
the ids that is references must be kept live.  This change
adds them to the worklist.

I've also updated a validator check to allow OpDecorateId
to be able to apply to decoration groups.

Fixes #1759.

* Remove dead code.
2019-07-24 14:43:49 -04:00
alan-baker
aea4e6b1b9 Fix block depth rule priority (#2755)
Fixes #2743

* Continue depth calculation should take precedence over merge calculation
2019-07-23 13:57:44 -04:00
alan-baker
a94ddc267c
Case validation with repeated labels (#2689)
Fixes #2686

* Update validation to handle the default case being mentioned multiple
times
  * new tests
2019-07-23 11:23:32 -04:00
Kévin Petit
11516c0b9a Validate storage class OpenCL environment rules for atomics (#2750)
This change refactors all storage class validation for atomics
to reflect the similar refactoring in the specification.

It is currently not possible to write a test for the check
rejecting Generic in an OpenCL 1.2 environment as the required
GenericPointer capability isn't allowed there. I've decided
to keep the check nonetheless to guard against the capability
becoming available without the rules for atomics being updated.

The ID changes in existing tests aren't ideal but introducing
names drags in a substantial refactoring of this file.

Contributes to #2595.

Signed-off-by: Kevin Petit <kevin.petit@arm.com>
2019-07-22 08:38:42 -04:00
Jason Macnak
bac82f49aa Allow LOD ops in compute shaders with derivative group execution modes (#2752)
Also update existing derivative check to be based on the execution mode
instead of just the extension being present.

More info about extension:
- https://github.com/KhronosGroup/SPIRV-Registry/blob/master/extensions/NV/SPV_NV_compute_shader_derivatives.asciidoc
2019-07-22 08:37:44 -04:00
Jeff Bolz
58e2ec25ba For Vulkan, disallow structures containing opaque types (#2546) 2019-07-16 16:16:19 -04:00
Ryan Harrison
55adf4cf70
Update execution scope rules for WebGPU (#2730)
Fixes #2722
2019-07-11 14:37:36 -04:00
alan-baker
1a2de48a12 Extra small storage validation (#2732)
Fixes #2729

* Check acceptable uses of small type generators
2019-07-11 13:05:14 -04:00
Jeff Bolz
327963765b Add validation for SPV_EXT_demote_to_helper_invocation (#2707) 2019-07-11 10:33:22 -04:00
Ryan Harrison
3a252a267b
Update memory scope rules for WebGPU (#2725)
Fixes #2721
2019-07-10 10:34:50 -04:00
alan-baker
456cc598af
Validate usage of 8- and 16-bit types with only storage capabilities (#2704)
Fixes #2669

* Check capabilities when validating variables
* validate load and store types
* Constant check
* Don't checks pointers for stores, constants and loads
* Validate composite instructions
* Validate conversions for 8- and 16-bit limited types
* Unified tests and expanded them
* Disallow OpCopyMemory
* new tests and update old tests
2019-07-08 14:10:13 -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
alan-baker
2b84d25f10
Fix store to uniform Vulkan check (#2688)
* Wrong operands were used for pointer and array types
* added tests to catch the wierd number corner
2019-06-20 14:22:41 -04:00
alan-baker
3d5fb7b908
Validate Volatile memory semantics bit (#2672)
* Can only be used with Vulkan memory model
* Can only be used with atomics
* Bit setting must match for compare exchange opcodes
* Updated memory semantics checks to allow constant instructions
generally with CooperativeMatrixNV
2019-06-17 13:35:40 -04:00
alan-baker
400dbde0ba
Disallow stores to UBOs (#2651)
Fixes #2638

* Adds a check that errors out if there is a store to a UBO in the
Vulkan environment
  * tests
* Function to trace pointers
2019-06-17 13:13:07 -04:00
alan-baker
59983a6010 Validate variable initializer type (#2668)
Fixes #249

* The pointed to type of Result Type must match the initializer type
* Had to update some opt tests to be valid
2019-06-15 00:34:18 -04:00
alan-baker
b4bf7bcf0a
Add validation for Subgroup builtins (#2637)
Fixes #2611

* Validates builtins in the Vulkan environment:
  * NumSubgroups
  * SubgroupId
  * SubgroupEqMask
  * SubgroupGeMask
  * SubgroupGtMask
  * SubgroupLeMask
  * SubgroupLtMask
  * SubgroupLocalInvocationId
  * SubgroupSize
2019-06-13 08:47:05 -04:00
Daniel Koch
0755d6ce82 Add builtin validation for SPV_NV_shader_sm_builtins (#2656)
Also add a Builtin test generator variant that takes
capabilities and extensions.

Tests
 - verify that the SMCountNV, SMIDNV, WarpsPerSMNV, and WarpIDNV Builtins are
   accepted as Inputs in Vertex, Fragment, TessControl, TessEval, Geometry,
   and Compute.
 - verify that the SMCountNV, SMIDNV, WarpsPerSMNV, and WarpIDNV Builtins are
   accepted as Inputs in MeshNV and TaskNV shaders.
 - verify that the SMCountNV, SMIDNV, WarpsPerSMNV, and WarpIDNV Builtins are
   accepted as Inputs in the 6 ray tracing stages
 - verify that the SMCountNV, SMIDNV, WarpsPerSMNV, and WarpIDNV Builtins are
   NOT accepted as Outputs.
 - verify that the SMCountNV, SMIDNV, WarpsPerSMNV, and WarpIDNV Builtins are
   NOT accepted as non-scalar integers (f32, uvec3)
 - verify that the SMCountNV, SMIDNV, WarpsPerSMNV, and WarpIDNV Builtins are
   NOT accepted as non-32-bit integers (u64)
2019-06-06 14:53:48 -04:00
Jeff Bolz
2c0111e6eb Add validation for SPV_EXT_fragment_shader_interlock (#2650) 2019-06-03 10:55:07 -04:00
Ryan Harrison
699e167d78
Remove asserts from GetUnderlyingType (#2646)
Fixes #2463
2019-05-31 08:57:41 -07:00
Kévin Petit
f99d7ad5c0 Validate OpenCL rules for ImageRead and OpImageSampleExplicitLod (#2643)
Fixes #2594.

Signed-off-by: Kevin Petit <kevin.petit@arm.com>
2019-05-31 10:05:34 -04:00
Sahil Parmar
b8fe7211c4 Allow arrays of out per-primitive builtins for mesh shaders (#2617)
- PrimitiveID, Layer, ViewportIndex
* Add validation tests for mesh builtins
2019-05-23 15:08:59 -04:00
Kévin Petit
07a1019717 Validate OpenCL environment rules for OpImageWrite (#2619)
Fixes #2593.

Signed-off-by: Kevin Petit <kevin.petit@arm.com>
2019-05-23 08:35:14 -04:00
Toomas Remmelg
13f61bf859 Update vloadn and vstoren validation to match the OpenCL Extended Instruction Set Specification (#2599) 2019-05-22 08:09:50 -04:00
alan-baker
713da30b63 Disallow merge targeting block with OpLoopMerge (#2610)
Fixes #2588

* Add a check that the merge block of OpLoopMerge may not be the block
that contains the OpLoopMerge
  * add a test
2019-05-21 23:02:53 -07:00
alan-baker
60aaafbc70 Allows breaks selection breaks to switches (#2605)
Fixes #2604

* Allow selection constructs to branch to the nearest selection merge
whose header is terminated by an OpSwitch
  * Cleanup break and continue checks generally
  * add tests
2019-05-21 22:49:37 -07:00
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
Kévin Petit
47741f0504 Validate OpenCL memory and addressing model environment rules (#2589)
Signed-off-by: Kevin Petit <kevin.petit@arm.com>
2019-05-17 08:25:20 -04:00
alan-baker
ff4feb44b4 Validate construct exits (#2459)
Validate structured exits from constructs

* Add checks that exits from a construct are valid
* Add Construct::IsStructuredExit()
 * uses specific rules for each type of construct
* Added a test and check for #2213
* Adding tests for bad loop and continue exits
* Fix identification of continue block that prevented some selections
from having any blocks
2019-05-16 14:59:30 -07:00
alan-baker
7e7745fce8 Validate loop merge (#2579)
Fixes #2559

* Validate OpLoopMerge including loop controls
  * add tests
  * fix some bad tests
2019-05-15 19:38:41 -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
alan-baker
45fb696668 Use last version (#2578)
* Use grammar last version

Fixes #2560

* Parse last version and use it in checks

* Update grammar header generation

* Fix NonWritable tests

* Fix check and add specific tests
2019-05-10 11:02:01 -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
Steven Perron
106c98d0fa
Validate sign of int types. (#2549)
Fixes https://crbug.com/959011.
2019-05-06 13:05:31 -04:00
Ryan Harrison
c8b09744c6
Add validation specific to OpExecutionModeId (#2536)
Fixes #1565
2019-05-01 13:29:39 -04:00
Ryan Harrison
a5da68d446
Remove stale comment (#2542)
Fixes #1121
2019-05-01 10:56:39 -04:00
Ryan Harrison
736376dbf9
Remove Acquire, Release, and Relaxed from allowed Mem Sem bits for WebGPU (#2526)
Fixes #2524
2019-04-23 13:27:40 -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
Ryan Harrison
7aad9653f9
Remove legacy utility functions (#2530)
These are not called/referenced by anything, and are marked as being
unused. They were brought to my attention by a coverity based bug
report.

Fixes #2537
2019-04-18 14:57:19 -04:00
alan-baker
ac878fcbdd
Remove unreachable block validation (#2525)
* Remove the check that blocks terminated by OpUnreachable are not
statically reachable in the CFG
* Updated tests
2019-04-17 18:21:19 -04:00
Ryan Harrison
21712068fe
Validate that SPIR-V binary is encoded as little endian for WebGPU (#2523)
Fixes #2522
2019-04-17 12:44:54 -04:00