Commit Graph

2354 Commits

Author SHA1 Message Date
Victor Lomuller
3bc9744d0a
Add FPEncoding operand type. (#5726)
This patch adds the optional FPEncoding operand that can be added to OpTypeFloat.
At the moment there is no usable operand, so support is limited to adding the entry.

Co-authored-by: Kévin Petit <kevin.petit@arm.com>
Co-authored-by: David Neto <dneto@google.com>
2024-07-03 13:18:40 -04:00
Steven Perron
ca004da9f9
Add knowledge of cooperative matrices (#5720)
* Add knowledge of cooperative matrices

Some optimizations are not aware of cooperative matrices, and either do
nothing or assert. This commits fixes that up.

* Add int tests, and a handle a couple more cases.

* Add float tests, and a handle a couple more cases.

* Add NV coop matrix as well.
2024-06-26 08:00:29 -04:00
Steven Perron
581279dedd
[OPT] Zero-extend unsigned 16-bit integers when bitcasting (#5714)
The folding rule `BitCastScalarOrVector` was incorrectly handling
bitcasting to unsigned integers smaller than 32-bits. It was simply
copying the entire 32-bit word containing the integer. This conflicts with the
requirement in section 2.2.1 of the SPIR-V spec which states that
unsigned numeric types with a bit width less than 32-bits must have the
high-order bits set to 0.

This change include a refactor of the bit extension code to be able to
test it better, and to use it in multiple files.

Fixes https://github.com/microsoft/DirectXShaderCompiler/issues/6319.
2024-06-19 19:17:05 +02:00
Shahbaz Youssefi
7564e142d6
spirv-dis: Add --nested-indent and --reorder-blocks (#5671)
With --nested-indent, the SPIR-V blocks are nested according to the
structured control flow.  Each OpLabel is nested that much with the
contents of the block nested a little more.  The blocks are separated by
a blank line for better visualization.

With --reorder-blocks, the SPIR-V blocks are reordered according to the
structured control flow.  This is particularly useful with
--nested-indent.

Note that with --nested-indent, the disassembly does not exactly show
the binary as-is, and the instructions may be reordered.
2024-06-17 09:54:18 -04:00
Nathan Gauër
bc28ac7c19
opt: add OpExtInst forward ref fixup pass (#5708)
This pass fixups the opcode used for OpExtInst instructions
to use OpExtInstWithForwardRefsKHR when it contains a forward
reference.
This pass is agnostic to the extension used, hence the validity
of the code depends of the validity of the usage:

If a forward reference is used on a non-semantic extended instruction,
the generated code will remain invalid, but the opcode will change.
What this pass guarantees is valid code won't become invalid.

---------

Signed-off-by: Nathan Gauër <brioche@google.com>
Co-authored-by: Steven Perron <stevenperron@google.com>
2024-06-13 02:09:58 -07:00
Nathan Gauër
65d30c3150
opt: fix Subgroup* trimming (#5706)
PR #5648 added support for the GroupNonUniformPartitionedNV. But there
was an issue: the opcodes are enabled by multiple capabilities, and the
actual operand is what matters.

Added testing coverage and the implementation to correctly trim a few
NonUniform capabilities.

Signed-off-by: Nathan Gauër <brioche@google.com>
2024-06-11 17:13:46 +02:00
Shahbaz Youssefi
c3178da8ea
spirv-dis: add decorations to comments (#5675) 2024-06-10 15:22:25 -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
alan-baker
7b5691084a
update tests for disassembly changes (#5694)
* update tests for disassembly changes
* use DEPS in wasm build
2024-06-05 13:23:01 -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
Steven Perron
148c97f687
Avoid use of type manager in extact->construct folding (#5684)
* Avoid use of type manager in extact->construct folding

When dealing with structs the type manager merge two different structs
into a single entry if they have all of the same decorations and
element types. This is because they hash to the same value in the hash
table. This can cause problems if you need to get the id of a type from
the type manager because you could get either one. In this case, it
returns the wrong one.

The fix avoids using the type manager in one place. I have not
looked closely at other places the type manager is used to make
sure it is used safely everywhere.

Fixes #5624

* Remove use of TypeManager::GetId

This removes a use of TypeManager::GetId by keeping the id around. This
avoid a potential problem if the type manager gets confused. These types
of bugs are hard to generate test cases for, so I do not have a test.
However, existing tests make sure that do not regress.
2024-05-31 14:13:20 +02:00
Kévin Petit
7e1a8cdc53
Basic support for SPV_EXT_replicated_composites (#5690)
* Basic support for SPV_EXT_replicated_composites

Validation will follow as a separate PR (still need to write a test suite)

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

* Update SPIRV-Headers

Change-Id: I6c0df248d99c13b49d78528d035a4222027c0232

---------

Signed-off-by: Kevin Petit <kevin.petit@arm.com>
2024-05-30 10:58:44 -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
Steven Perron
336b5710a5
Do not fold mul and adds to generate fmas (#5682)
This removes the folding rules added in #4783 and #4808. They lead to
poor code generation on Adreno devices when 16-bit floating point values
were used. Since this change is transformation is suppose to be neutral,
there is no general reason to continue doing it.

I have talked to the owners of SwiftShader, and they do not mind if the
transform is removed. They were the ones the requested the change in the
first place.

Fixes #5658
2024-05-22 13:01:26 -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
Jeremy Gebben
9241a58a80
opt: Remove bindless and buff addr instrumentation passes (#5657)
These were only used by Vulkan-Validation layers, but they
have been replaced by other code for several months.
2024-05-02 18:52:17 -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
Diego Novillo
3983d15a1d
Fix rebuilding types with circular references (#5623). (#5637)
This fixes the problem reported in #5623 using the observation that if
we are re-building a type that already exists in the type pool, we
should just return that type.

This makes type rebuilding more efficient, and it also prevents the
type builder from getting itself into infinite recursion (as reported in
this issue).

In fixing this, I found a couple of other bugs in the type builder:

- When rebuilding an Array type, we were not re-building the element
  type. This caused stale type references in the rebuilt type.

- This bug had not been caught by the test, because the test itself had
  a bug in it: the test was rebuilding types on top of the same ID (the
  ID counter was never incremented).

Initially, the bug in the test caused a failure with the new logic in
the builder because we now return types from the pool directly, which
causes a failure when two incompatible types are registered under the
same ID.

Fixing that issue in the test exposed another bug in the rebuilder: we
were not re-building the element type for Array types. This was causing
a stale type reference inside Array types which was later caught by the
type removal logic in the test.
2024-04-09 10:36:21 -04:00
Jeremy Hayes
ade1f7cfd7
Add AliasedPointer decoration (#5635)
Fix #5607

When inlining, decorate return variable with AliasedPointer if the
storage class of the pointee type is PhysicalStorageBuffer.
2024-04-05 11:45:55 -06:00
Wooyoung Kim
9bd44d028e
Suppot for SPV_QCOM_image_processing2 (#5582) 2024-02-28 16:26:28 -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
Steven Perron
e08c012b19
[OPT] Identify arrays with unknown length in copy prop arrays (#5570)
* [OPT] Identify arrays with unknown length in copy prop arrays

The code in copy propagate arrays assumes that the length of an
OpTypeArray is known at compile time, but that is not true when the size
is an OpSpecConstant. We try to fix that assumption.

Fixes https://crbug.com/oss-fuzz/66634
2024-02-13 14:41:38 -05:00
Ben Ashbaugh
0c986f596d
update image enum tests to remove Kernel capability (#5562)
We are removing Kernel from the image channel order and image
channel data type enums because Kernel is already required
transitively, so we need to update the tests to match.
2024-02-13 11:07:39 -05:00
Steven Perron
b7413609cf
[OPT] Use new instruction folder for for all opcodes in spec consti folding (#5569)
* [OPT] Use new instruction folder for for all opcodes in spec consti folding

When folding and OpSpecConstantOp, we use the new instruction folder for
a small number of opcodes. This enable the new instruction folder for
all opcodes and uses the old one as a fall back. This allows us to
remove some code from the older folder that is now covered by the new
one.

Fixes #5499
2024-02-12 19:52:55 +00: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
Steven Perron
a8959dc653
Fold 64-bit int operations (#5561)
Adds folding rules that will fold basic artimetic for signed and
unsigned integers of all sizes, including 64-bit.

Also folds OpSConvert and OpUConvert.
2024-02-09 14:02:48 -05:00
Steven Perron
032c15aaf5
[NFC] Refactor code to fold instruction in fold tests. (#5558)
We repeat basically the same code multiple times in the different types of
folding tests. This commit adds a function that builds the module, finds the
instruction to fold, and folds it. Doing the routine checks at the same
time. We also have a couple generic functions for checking that an
instruction is a constant with the expected value.
2024-02-06 13:05:05 -05:00
Nathan Gauër
ab59dc6087
opt: prevent meld to merge block with MaximalReconvergence (#5557)
The extension SPV_KHR_maximal_reconvergence adds more constraints
around the merge blocks, and how the control flow can be altered.

The one we address here is explained in the following part of the spec:

  Note: This means that the instructions in a break block will execute as if
  they were still diverged according to the loop iteration. This restricts
  potential transformations an implementation may perform on the IR to match
  shader author expectations. Similarly, instructions in the loop construct
  cannot be moved into the continue construct unless it can be proven that
  invocations are always converged.

Until the optimizer is clever enough to determine if the invocation
have already converged, we shall not meld a block which branches to a
merge block into it, as it might move some instructions outside of the
convergence region.

This behavior being only required with the extension, this commit
behavior change is gated by the extension.
This means using wave operations without the maximal reconvergence
extension might lead to undefined behaviors.

Co-authored-by: Natalie Chouinard <chouinard.nm@gmail.com>
2024-02-06 06:12:00 -05:00
Ben Doherty
8d3ee2e8f0
spirv-opt: Fix OpCompositeExtract relaxation with struct operands (#5536) 2024-02-01 15:19:02 -07:00
Spencer Fricke
61c51d4baf
spirv-val: Add Mesh Primitive Built-In validaiton (#5529) 2024-02-01 14:20:42 -05:00
Natalie Chouinard
5d3c8b73f7
opt: Add OpEntryPoint to DescriptorScalarReplacement pass (#5553)
Add OpEntryPoint to the list of instructions processed by the
DescriptorScalarReplacement pass. This is necessary for SPIR-V 1.4 and
above where global variables must be included in the interface.

Fixes microsoft/DirectXShaderCompiler#5962
2024-02-01 09:50:36 -05:00
Scott Todd
80bc99c3d4
Skip entire test/ folder if SPIRV_SKIP_TESTS is set. (#5548)
Without this (or similar filtering), the `spirv-tools_expect_unittests` and `spirv-tools_spirv_test_framework_unittests` Python tests at `test/tools/` get defined even when `SPIRV_SKIP_TESTS` is set.
2024-01-26 16:47:13 -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
Natalie Chouinard
0045b01ff9
opt: Add VulkanMemoryModelDeviceScope to trim (#5544)
Add the VulkanMemoryModelDeviceScope capability to the capability
trimming pass. According the the spec, "If the Vulkan memory model is
declared and any instruction uses Device scope, the
VulkanMemoryModelDeviceScope capability must be declared." Since this
case, based on the type of an operand, is not covered by the JSON
grammar, it is added explicitly.
2024-01-25 14:05:04 -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
David Neto
14000ad47a
Use python3 explicitly. (#5540)
Some Linux images don't ship with a plain 'python'
2024-01-23 15:42:34 -05:00
Spencer Fricke
c96fe8b943
spirv-val: Re-enable OpControlBarrier VU (#5527) 2024-01-17 11:18:23 -05:00
Steven Perron
36be541ee3
Remove unnecessary debug code (#5523) 2024-01-11 07:55:04 -08:00