Commit Graph

656 Commits

Author SHA1 Message Date
Jeff Bolz
ce92630396
Add validation for SPV_NV_tensor_addressing and SPV_NV_cooperative_matrix2 (#5865) 2024-10-24 13:55:04 -04:00
alan-baker
a832c13331
Fix switch case construct validation (#5852)
* Fix switch case construct validation

Fixes https://crbug.com/tint/372311599

* Stop using block depth in switch validation and instead use the more
  robust structured exit logic from the switch construct
  * This is valid because the function has already handled the
    additional valid cases for case constructs

* formatting
2024-10-16 11:09:21 -04:00
alan-baker
42b315c15b
Fix result type check in ValidateImageTexelPointer (#5848)
Fixes https://crbug.com/oss-fuzz/42537207

* Fix check and messages in ValidateImageTexelPointer
2024-10-10 14:10:07 -04:00
JN Mo
44936c4a9d
Add support for SPV_KHR_compute_shader_derivative (#5817)
* Add support for SPV_KHR_compute_shader_derivative

* Update tests for SPV_KHR_compute_shader_derivatives

---------

Co-authored-by: MagicPoncho <magicponcho@gmail.com>
2024-09-25 09:59:33 -04:00
alan-baker
362ce7c60d
Allow more levels of arrays with component decoration (#5820)
Fixes #5819

* Allow multiple levels of arrays in a variable with component
  decoration
2024-09-24 11:14:28 -04:00
Sven van Haastregt
7ba72f14f2
spirv-val: Disallow stores according to VUID 06924 (#5368)
Ensure that the validator rejects stores to objects of types
`OpTypeImage`, `OpTypeSampler`, `OpTypeSampledImage`,
`OpTypeAccelerationStructureKHR`, and arrays of these types, according
to `VUID-StandaloneSpirv-OpTypeImage-06924`.

Guard the check behind the before_hlsl_legalization option, as
sometimes we may have temporaries or local variables that are expected
to get optimized away.

Fixes #4796


Change-Id: Ie035c01c5f94e7bdfc16b5c6c85705f302b7bda3

Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
2024-09-23 08:34:30 -04:00
Viktoria Maximova
01c8438ee4
[SPV_KHR_untyped_pointers] Fix verification for OpenCL.std instructions (#5810)
Allow `p` to be untyped pointer for `fract`, `frexp`, `lgamma_r`,
`modf`, `remquo`, and `sincos`.

```
operand must be a pointer(p1, ...).If it is a typed pointer, it must
point to data types.

```

https://htmlpreview.github.io/?https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/KHR/SPV_KHR_untyped_pointers.html#_modifications_to_the_opencl_std_extended_instruction_set
2024-09-20 11:31:46 -04:00
alan-baker
380275eacd
Do not check structurally unreachable continue target predecessors (#5800)
Fixes #5784

* Rules only apply to structurally reachable blocks
2024-09-11 14:50:30 -04:00
alan-baker
e9915cea8d
Update sampled image validation (#5789)
Fixes #5781

* Requires all image operands to match except for depth between operand
  and result
2024-09-09 13:09:19 -04:00
Viktoria Maximova
f914d9c8a4
[SPV_KHR_untyped_pointers] Fix verification of vload/vstore OpenCL.std instructions (#5788)
* [SPV_KHR_untyped_pointers] Fix verification of vload/vstore OpenCL.std instructions

Allow `p` to be untyped pointer.

```
operand must be a pointer(p1, ...).If it is a typed pointer, it must point to data types.

```

https://htmlpreview.github.io/?https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/KHR/SPV_KHR_untyped_pointers.html#_modifications_to_the_opencl_std_extended_instruction_set

* relax printf check as well
2024-09-06 10:59:59 -04:00
alan-baker
61d6952e2e
Revert "OpSampledImage extra validation (#5695)" (#5785)
This reverts commit 70ad4dae7d.

Contributes to #5781

SPIR WG 2024-09-04: decision to relax validation requirement in the spec.
2024-09-04 14:59:51 -04:00
Kévin Petit
b21dda0ee7
Validate presence of Stride operand to OpCooperativeMatrix{Load,Store}KHR (#5777)
* Validate Stride operand to OpCooperativeMatrix{Load,Store}KHR

The specification requires the Stride operand for the RowMajorKHR and
ColumnMajorKHR layouts.

Signed-off-by: Kevin Petit <kevin.petit@arm.com>
Change-Id: I51084b9b8dedebf9cab7ae25334ee56b75ef0126

* Update source/val/validate_memory.cpp

Co-authored-by: alan-baker <alanbaker@google.com>

* add test to exercise memory layout from spec constant and fix validation

Change-Id: I06d7308c4a2b62d26d69e88e03bfa009a7f8fff3

* format fixes

Change-Id: I9cbabec0ed2172dcd228cc385551cb7a5b79df1a

---------

Signed-off-by: Kevin Petit <kevin.petit@arm.com>
Co-authored-by: alan-baker <alanbaker@google.com>
2024-08-29 08:15:31 -04:00
alan-baker
8731673a5d
Allow ArrayStride on untyped pointers (#5746) 2024-07-24 13:36:11 -04:00
alan-baker
3ab0d22608
Support SPV_KHR_untyped_pointers (#5736)
* Support SPV_KHR_untyped_pointers

Covers:
- assembler
- disassembler
- validator

fix copyright

Validate OpTypeUntypedPointerKHR

* Disallow an untyped pointer in a typed pointer
* Validate capability requirements for untyped pointer
* Allow duplicate untyped pointer declarations

Add round trip tests

Validate OpUntypedVariableKHR

Validate untyped access chains

* Add a test for opcodes that generate untyped pointers
* simplify some checks for operands needing types
* validate OpUnypedAccessChainKHR, OpUntypedInBoundsAccessChainKHR,
  OpUntypedPtrAccessChainKHR, OpUntypedInBoundsPtrAccessChainKHR

Unify variable validation

Validate OpCopyMemorySized

* Fix some opcode tests to accound for untyped pointers
* Add validation for OpCopyMemorySized for shaders and untyped pointers
* fix up tests

Validate pointer comparisons and bitcast

* Update more helpers
* Fix entry validation to allow OpUntypedVariableKHR
* Validate OpPtrEqual, OpPtrNotEqual and OpPtrDiff
* Validate OpBitcast

Validate atomics and untyped pointers

Make interface variable validation aware of untyped pointers

* Check OpUntypedVariableKHR in interface validation

More untyped pointer validation

* Validate interfaces more thoroughly
* Validate layouts for untyped pointer uses
* Improve capability checks for vulkan with OpTypeUntypedPointerKHR
* workgroup member explicit layout validation updates

More validation

* validate function arguments and parameters
* handle untyped pointer and variable in more places

Add a friendly assembly name for untyped pointers

Update OpCopyMemory validation and tests

Fix test for token update

Fixes for validation

* Allow typed pointers to contain untyped pointers
* Fix decoration validation
* add untyped pointer as a case for size and alignments

Fix interface validation

* Grabbed the wrong storage class operand for untyped variables
* Add ability to specify assembler options in validation tests

Add passthrough validation for OpUntypedArrayLengthKHR

More validation of untyped pointers

* Validate OpUntypedArrayLengthKHR
* Validate layout for OpLoad, OpStore, and OpUntypedArrayLengthKHR

Validation support for cooperative matrix and untyped pointers

* Allow untyped pointers for cooperative matrix KHR load and store

Updates to match spec

* Remove extra capability references
* Swap untyped variable data type and storage class operands
* update validation of variables

* update deps

---------

Co-authored-by: David Neto <dneto@google.com>
2024-07-17 14:51:37 -04:00
LU-JOHN
7c778973e5
Allow fmt arg to printf to be an array of i8 in non-constant space (#5677)
* In spirv-val allow format arg to printf to be an array of i8 in Generic space

Signed-off-by: Lu, John <john.lu@intel.com>

* Allow more addr spaces for printf format string

Signed-off-by: Lu, John <john.lu@intel.com>

* Update printf format arg testcase

Signed-off-by: Lu, John <john.lu@intel.com>

* Apply clang-format

Signed-off-by: Lu, John <john.lu@intel.com>

* Reorder code for clarity

Signed-off-by: Lu, John <john.lu@intel.com>

* Only allow other addr spaces if extension is seen

Signed-off-by: Lu, John <john.lu@intel.com>

* Add test to check printf format with extension

Signed-off-by: Lu, John <john.lu@intel.com>

* Add extension correctly

Signed-off-by: Lu, John <john.lu@intel.com>

---------

Signed-off-by: Lu, John <john.lu@intel.com>
2024-07-16 09:20:04 -04:00
Nathan Gauër
ce46482db7
Add KHR suffix to OpExtInstWithForwardRef opcode. (#5704)
The KHR suffix was missing from the published SPIR-V extension.
This is now fixed, but requires some patches in SPIRV-Tools.

Signed-off-by: Nathan Gauër <brioche@google.com>
2024-06-06 03:17:51 -07:00
Steven Perron
9db5b5ec19
Add assert header to val/decoration.h (#5703)
Some platforms fail to compile if the cassert header is not included in
decoration.h. Adding it to make those work.
2024-06-05 06:22:58 -07:00
Nathan Gauër
6a2bdeee75
spirv-val, core: add support for OpExtInstWithForwardRefs (#5698)
* val, core: add support for OpExtInstWithForwardRefs

This commit adds validation and support for
OpExtInstWithForwardRefs. This new instruction will be used
for non-semantic debug info, when forward references are
required.

For now, this commit only fixes the code to handle this new instruction,
and adds validation rules. But it does not add the pass to generate/fix
the OpExtInst instruction when forward references are in use.
Such pass would be useful for DXC or other tools, but I wanted to land
validation rules first.

This commit also bumps SPIRV-Headers to get this new opcode.

---------

Signed-off-by: Nathan Gauër <brioche@google.com>
2024-06-04 16:18:06 +02:00
alan-baker
70ad4dae7d
OpSampledImage extra validation (#5695)
* Validate that the type of Image operand matches the result type's
  Image operand
2024-06-03 10:43:26 -04:00
Spencer Fricke
3d24089292
spirv-val: Add Duplicate EntryPoint Builtin check (#5678)
* spirv-val: Add Decoration::builtin()
* spirv-val: Add Duplicate EntryPoint Builtin check
* spirv-val: Handle Built-ins in/out of block
* spirv-val: Remove extra CheckBuiltInVariable
2024-05-29 14:38:37 -04:00
Sven van Haastregt
e2646f5e95
spirv-val: Consider target env for OpReadClockKHR scope (#5681)
The Scope operand of `OpReadClockKHR` was always validated using the
Vulkan environment rules, which only allow `Subgroup` or `Device`.
For the OpenCL environment, `Workgroup` is also a valid Scope, so
`Workgroup` should not be rejected in the universal environment.

Guard the existing Scope check behind `spvIsVulkanEnv` and add a new
Scope check for the OpenCL environment.

Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
2024-05-21 13:02:17 -04:00
alan-baker
ccf3e3c103
Improve matrix layout validation (#5662)
* Check for matrix decorations on arrays of matrices
  * MatrixStide, RowMajor and ColMajor can be applied to matrix or
    arrays of matrix members
  * Check that matrix stride satisfies alignment in arrays
2024-05-14 15:13:54 -04:00
Sven van Haastregt
199038f10c
spirv-val: Validate MemoryAccessMask of OpCooperativeMatrixStoreKHR (#5668)
Reject `OpCooperativeMatrixStoreKHR` with a `MakePointerVisibleKHR`
MemoryAccess operand, as `MakePointerVisibleKHR` is not supposed to be
used with store operations.

The `CoopMatKHRStoreMemoryAccessFail` test failed to catch this
because it used the helper function `GenCoopMatLoadStoreShader` which
generates `...NV` instead of `...KHR` instructions.  Add a new helper
function to generate similar shaders for the KHR extension, as the NV
and KHR extensions have various subtle differences that makes
parameterizing the original helper function non-trivial.

Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
2024-05-10 15:49:10 -04:00
Spencer Fricke
57a42e6c1d
spirv-val: Separate Location check for tess patch (#5654) 2024-04-30 12:29:22 -04:00
Wooyoung Kim
53c0736064
A fix to support of SPV_QCOM_image_processing2 (#5646)
Fixing validation of decorations attached to
texture/sampler operands of OpImageBlockMatchWindowSSDQCOM
and OpImageBlockMatchWindowSADQCOM
2024-04-18 17:30:20 -04:00
Spencer Fricke
2904985aee
spirv-val: Add Vulkan check for Rect Dim in OpTypeImage (#5644) 2024-04-15 10:56:12 -04:00
alan-baker
02470f606f
Validate duplicate decorations and execution modes (#5641)
* Disallow duplicate decorations generally

* Only FuncParamAttr and UserSemantic can be applied to the same target
  multiple times
* Unchecked: completely duplicate UserSemantic and FuncParamAttr

* Disallow duplicate execution modes generally
  * Exceptions for float controls, float controls2 and some intel
    execution modes

* Fix invalid fuzzer transforms
2024-04-12 08:51:41 -04:00
Rodrigo Locatti
6761288d39
Validator: Support SPV_NV_raw_access_chains (#5568) 2024-04-10 10:40:10 -04:00
Wooyoung Kim
9bd44d028e
Suppot for SPV_QCOM_image_processing2 (#5582) 2024-02-28 16:26:28 -05:00
Viktoria Maximova
0b027bafa5
Support operand kind for SPV_INTEL_maximum_registers (#5580)
* Support operand kind for SPV_INTEL_maximum_registers

* improvements

* Update DEPS
2024-02-28 13:58:09 -05:00
alan-baker
fbc7a14b3e
Fix access chain struct checks (#5592)
* Fix access chain struct checks

Fixes https://crbug.com/oss-fuzz/66948

* Negative indices are invalid for struct access
* Fix typos

* formatting
2024-02-27 15:54:08 -05:00
Spencer Fricke
1b643eac5d
spirv-val: Make Constant evaluation consistent (#5587)
Bring 64-bit evaluation in line with 32-bit evaluation.
2024-02-21 17:52:13 -05:00
Jeff Bolz
b0a5c4ac12
SPV_NV_shader_atomic_fp16_vector (#5581) 2024-02-14 15:58:12 -05:00
Spencer Fricke
f9184c6501
spirv-val: Revert Validate PhysicalStorageBuffer Stage Interface (#5575) 2024-02-13 21:24:20 -05:00
Spencer Fricke
20ad38c18d
spirv-val: Multiple interface var with same SC (#5528) 2024-02-13 15:55:43 -05:00
Spencer Fricke
784b064f90
spirv-val: Validate PhysicalStorageBuffer Stage Interface (#5539)
Disallow PhysicalStorageBuffer pointers in Input and Output storage classes.
2024-02-12 09:51:38 -05:00
Spencer Fricke
61c51d4baf
spirv-val: Add Mesh Primitive Built-In validaiton (#5529) 2024-02-01 14:20:42 -05:00
ruiminzhao
b951948eaa
SPV_KHR_quad_control (#5547)
* SPV_KHR_quad_control

1. Add two new execute modes: RequireFullQuadsKHR and QuadDerivativesKHR
2. Add two opCodes: OpGroupNonUniformQuadAllKHR and
   OpGroupNonUniformQuadAnyKHR
3. Add one Capability: QuadControlKHR

* update DEPS

* Fixes

* Build fixes
* Formatting fixes
* Test fixes

* formatting

---------

Co-authored-by: Alan Baker <alanbaker@google.com>
2024-01-26 15:49:56 -05:00
alan-baker
ef2f432364
Add support for SPV_KHR_float_controls2 (#5543)
* Test asm/dis for SPV_KHR_float_controls2
* SPV_KHR_float_controls2 validation

---------

Co-authored-by: David Neto <dneto@google.com>
2024-01-25 10:22:09 -05:00
alan-baker
de3d5acc04
Add tooling support for SPV_KHR_maximal_reconvergence (#5542)
* Validation for SPV_KHR_maximal_reconvergence
* Add pass to add/remove maximal reconvergence execution mode
---------

Co-authored-by: David Neto <dneto@google.com>
2024-01-25 09:39:49 -05:00
Spencer Fricke
c96fe8b943
spirv-val: Re-enable OpControlBarrier VU (#5527) 2024-01-17 11:18:23 -05:00
Sajjad Mirza
246e6d4c68
spirv-val: Loosen restriction on base type of DebugTypePointer and DebugTypeQualifier (#5479)
* Allow base type for DebugTypePointer and DebugTypeQualifier to be any DebugType
2023-11-17 10:22:46 -05:00
Spencer Fricke
c87755bb9f
spirv-val: Add WorkgroupMemoryExplicitLayoutKHR check for Block (#5461) 2023-11-01 10:48:40 -04:00
Nathan Gauër
47b63a4d7d
val: re-add ImageMSArray validation (#5394)
This has been removed in #4752, but not added since.

* fixup! val: re-add ImageMSArray validation

clang-format
2023-09-07 09:39:28 -04:00
Wooyoung Kim
89ca3aa571
SPV_QCOM_image_processing support (#5223) 2023-08-15 15:15:21 -04:00
Nathan Gauër
29431859f5
NFC: replace EnumSet::ForEach with range-based-for (#5322)
EnumSet now supports iterators, meaning we can remove the custom
ForEach.

Signed-off-by: Nathan Gauër <brioche@google.com>
2023-07-13 14:40:47 -04:00
Nathan Gauër
3424b16c10
enumset: STL-ize container (#5311)
This commit adds forward iterator, and renames functions to
it matches the std::unordered_set/std::set better.
This goes against the SPIR-V coding style, but might be better in
the long run, especially when this set is used along real STL
sets.
(Right now, they are not compatible, and requires 2 syntaxes).

This container could in theory handle bidirectional
iterator, but for now, only forward seemed required for
our use-cases.

Signed-off-by: Nathan Gauër <brioche@google.com>
2023-07-12 11:34:44 -04:00
alan-baker
0530a532fc
Validate GroupNonUniform instructions (#5296)
Fixes #5283

* Validate group non-uniform instructions
2023-07-11 08:40:40 -04:00
Nathan Gauër
0f3bea06ef
NFC: rewrite EnumSet to handle larger enums. (#5289)
The current EnumSet implementation is only efficient for enums with
values < than 64. The reason is the first 63 values are stored as a
bitmask in a 64 bit unsigned integer, and the other values are stored
in a std::set.
For small enums, this is fine (most SPIR-V enums have IDs < than 64),
but performance starts to drop with larger enums (Capabilities,
opcodes).

Design considerations:
----------------------

This PR changes the internal behavior of the EnumSet to handle enums
with arbitrary values while staying performant.
The idea is to extend the 64-bits buckets sparsely:
 - each bucket can store 64 value, starting from a multiplier of 64.
This could be considered as a hashset with linear probing.

- For small enums, there is a slight memory overhead due to the bucket
storage, but lookup is still constant.
- For linearly distributed values, lookup is constant.
- Worse case for storage are for enums with values which are multiples of 64.
But lookup is constant.
- Worse case for lookup are enums with a lot of small ranges scattered in
the space (requires linear probing).

For enums like capabilities/opcodes, this bucketing is useful as values
are usually scatters in distinct, but almost contiguous blocks.
(vendors usually have allocated ranges, like [5000;5500], while [1000;5000]
is mostly unused).

Benchmarking:
-------------

Benchmarking was done in 2 ways:
 - a benchmark built for the occasion, which only measure the EnumSet
   performance.
 - SPIRV-Tools tests, to measure a more realist scenario.

Running SPIR-V tests with both implementations shows the same
performance (delta < noise). So seems like we have no regressions.
This method is noisy by nature (I/O, etc), but the most representative
of a real-life scenario.

Protocol:
 - run spirv-tests with no stdout using perf, multiple times.
Result:
 - measure noise is larger than the observed difference.

The custom benchmark was testing EnumSet interfaces using SPIRV enums.
Doing thousand of insertion/deletion/lookup, with 2 kind of scenarios:
 - add once, lookup many times.
 - add/delete/loopkup many time.

For small enums, results are similar (delta < noise). Seems relevant
with the previously observed results as most SPIRV enums are small, and
SPIRV-Tools is not doing that many intensive operations on EnumSets.

Performance on large enums (opcode/capabilities) shows an improvement:

+-----------------------------+---------+---------+---------+
| Metric                      |  Old    |   New   | Delta % |
+-----------------------------+---------+---------+---------+
| Execution time              |   27s   |   7s    |  -72%   |
| Instruction count           |  174b   |  129b   |  -25%   |
| Branch count                |   28b   |   33b   |  +17%   |
| Branch miss                 |  490m   |   26m   |  -94%   |
| Cache-misses                |  149k   |   26k   |  -82%   |
+-----------------------------+---------+---------+---------+

Future work
-----------

This was by-design an NFC change to compare apples-to-apples.
The next PR aims to add STL-like iterators to the EnumSet to allow
using it with STL algorithms, and range-based for loops.

Signed-off-by: Nathan Gauër <brioche@google.com>
2023-07-07 10:41:52 -04:00
Spencer Fricke
870fd1e17a
spirv-val: Label SPV_KHR_cooperative_matrix VUID (#5301) 2023-07-04 09:01:04 -04:00