Commit Graph

2685 Commits

Author SHA1 Message Date
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
Steven Perron
7604147c25
[OPT] Add removed unused interface var pass to legalization passes (#5579)
DXC does not do a good job of recognizing which variables need to be
on the entry point for which functions. This is because it does not
want to have to walk the call tree to determine which instructions
are reachable from which entry points.

This is also useful if the same input variable gets used from two
different shader, but the uses in one get optimized away.

Will parially fix
https://github.com/microsoft/DirectXShaderCompiler/issues/4621. Will not
fix code compiled with -fcgl.
2024-02-14 13:08:25 -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
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
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
Natalie Chouinard
de65e81740
[NFC] Remove unused code (#5554) 2024-02-01 09:47:42 -05:00
Nathan Gauër
ad11927e6c
opt: add SPV_EXT_mesh_shader to opt allowlist (#5551)
Add this extension to the allowlist, allowing DCE and other
optimizations on modules exposing this.
Note: NV equivalent is already allowed.
2024-01-30 12:13:46 -05:00
Natalie Chouinard
0a6f0d1893
opt: Add TrimCapabilities pass to spirv-opt tool (#5545)
Add an option to the spirv-opt tool to run the TrimCapabilitiesPass.
2024-01-26 16:15:29 -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
Spencer Fricke
c96fe8b943
spirv-val: Re-enable OpControlBarrier VU (#5527) 2024-01-17 11:18:23 -05:00
Steven Perron
155728b2e9
Add preserver-interface option to spirv-opt (#5524)
The optimizer is able to preserve the interface variables of the
shaders, but that feature has not been exposed to the command line
tool.

This commit adds an option `--preserve-interface` to spirv-opt that will
cause all calls to ADCE to leave the input and output variables, even if
the variable is unused. It will apply regardless of where the option
appears on the command line.

Fixes #5522
2024-01-12 14:45:17 -05:00
Nathan Gauër
c7affa1707
opt: add Int16 and Float16 to capability trim pass (#5519)
Add support for Int16 and Float16 trim.

Signed-off-by: Nathan Gauër <brioche@google.com>
2024-01-04 20:01:03 +01:00
Ben Clayton
d75b3cfbb7
Zero initialize local variables (#5501)
Certain versions of GCC warn about these variables being potentially uninitialized when used.
I believe this is a false-positive, but zero-init'ing them is a safe way to fix this.
2023-12-11 10:32:45 -05:00
Jeremy Gebben
6b4f0c9d0b
instrument: Fix handling of gl_InvocationID (#5493)
This is an int and needs to be cast to a unit for inclusion in the
stage specific data passed to the instrumentation check function.
2023-12-05 09:59:51 -07:00
Jeremy Gebben
b5d60826e9
printf: Remove stage specific info (#5495)
Remove stage specific debug info that is only needed by GPU-AV.
This allows debug printfs to be used in multi-stage shader modules.

Fixes #4892
2023-12-04 15:43:36 -07:00
ncesario-lunarg
2da75e152e
Do not crash when tryingto fold unsupported spec constant (#5496)
Remove assertion in FoldWithInstructionFolder; there are cases where
folding spec constants is unsupported.

Closes #5492.
2023-12-04 08:48:16 -05:00
Juan Ramos
afaf8fda2a
Fix iOS / Android CMake builds (#5482)
* cmake: Simplify usage of option

boolean OFF is the default value:
https://cmake.org/cmake/help/latest/command/option.html

* Fix iOS / Android CMake builds

closes #4437
2023-11-28 10:53:56 -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
ChristianReinbold
0df791f97a
Fix nullptr argument in MarkInsertChain (#5465)
Fixes an access violation issue that sporadically occured for me when DXC uses spirv-opt to legalize generated spirv code.
2023-11-16 19:36:32 +00:00
Spencer Fricke
8ee3ae5244
Add comment to --inst-debug-printf option (#5466) 2023-11-14 13:00:54 -05:00
Nathan Gauër
f43c464d53
opt: add PhysicalStorageBufferAddresses to trim (#5476)
The PhysicalStorageBufferAddresses capability can now be
trimmed. From the spec, it seems any instruction enabled by this
required some operand to have the PhysicalStorageBuffer storage class.
This means checking the storage class is enough.

Now, because the pass uses the grammar, we don't need to add any
new logic.

Signed-off-by: Nathan Gauër <brioche@google.com>
2023-11-14 12:49:04 -05:00
Nathan Gauër
c91e9d09b5
opt: add StorageImageReadWithoutFormat to cap trim (#5475)
The StorageImageReadWithoutFormat capability is only required when
an image type with the format set to Unknown is used with some specific
OpImageRead or OpImageSparseRead instructions.

This patch adds the required code to the capability trimming pass to
remove the StorageImageReadWithoutFormat capability when not required.

Signed-off-by: Nathan Gauër <brioche@google.com>
2023-11-14 09:29:31 -05:00
Steven Perron
9e7a1f2ddd
Fix array size calculation (#5463)
The function that get the number of elements in a composite variable
returns an incorrect values for the arrays. This is fixed, so that it
returns the correct number of elements for arrays where the number of
elements is represented as a 32-bit integer and is known at compile
time.

Fixes #4953
2023-11-02 13:29:57 -04:00
Steven Perron
a08f648c86
Remove references to __FILE__ (#5462)
* Remove references to __FILE__

Uses of `__FILE__` leak the directory structure of the machine used to
build because it adds a string to the string table with the full path
name. I've removed the uses that show up in the release builds.

Fixes #5416
2023-11-01 15:19:48 -07:00
Spencer Fricke
c87755bb9f
spirv-val: Add WorkgroupMemoryExplicitLayoutKHR check for Block (#5461) 2023-11-01 10:48:40 -04:00
Cassandra Beckley
73876defc8
opt: support 64-bit OpAccessChain index in FixStorageClass (#5446)
The SPIR-V specification allows any scalar integer type as an index. DXC
usually emits indexes as 32-bit integer types, however, in some cases it
is possible to make it emit 64-bit indexes instead (as in
https://github.com/microsoft/DirectXShaderCompiler/issues/5638).
2023-10-19 20:02:46 +00:00
Steven Perron
5bb595091b
Add ComputeDerivativeGroup*NV capabilities to trim capabilities pass. (#5430)
* Add ComputeDerivativeGroup*NV capabilities to trim capabilities pass.

* Add SPV_NV_compute_shader_derivatives to allow lists

No tests needed for this. The code path is well tested. Just adding new
data.
2023-10-16 19:03:33 +00:00
Cassandra Beckley
023a8c79e9
opt: add Float64 capability to trim pass (#5428) 2023-10-05 11:12:09 +02:00
Jeremy Gebben
847715d6c6
instrument: Ensure linking works even of nothing is changed (#5419)
spirv-link requires that memory models match between its input files.
Ensure this is the case by always returning SuccessWithChange and
always changing the memory model to match the instrumentation
code in Vulkan-ValidationLayers.

Also, disable the DCE pass in the --inst-* command line options, since
it will only work after linking.
2023-10-02 09:15:39 -06:00
Cassandra Beckley
1bc0e6f59a
Add a new legalization pass to dedupe invocation interlock instructions (#5409)
Add a new legalization pass to dedupe invocation interlock instructions

DXC will be adding support for HLSL's rasterizer ordered views by using
the SPV_EXT_fragment_shader_interlock_extension. That extension
stipulates that if an entry point has an interlock ordering execution
mode, it must dynamically execute OpBeginInvocationInterlockEXT and
OpEndInvocationInterlockEXT, in that order, exactly once. This would be
difficult to determine in DXC's SPIR-V backend, so instead we will emit
these instructions potentially multiple times, and use this legalization
pass to ensure that the final SPIR-V follows the specification.

This PR uses data-flow analysis to determine where to place begin and
end instructions; in essence, determining whether a block contains or is
preceded by a begin instruction is similar to a specialized case of a
reaching definitions analysis, where we have only a single definition,
such as `bool has_begun = false`. For this simpler case, we can compute
the set of blocks using BFS to determine the reachability of the begin
instruction.

We need to do this for both begin and end instructions, so I have
generalized portions of the code to run both forward and backward over
the CFG for each respective case.
2023-09-27 19:54:10 -04:00
Jeremy Gebben
ee7598d497
instrument: Use Import linkage for instrumentation functions (#5355)
These functions are getting far too complicated to code in SPIRV-Tools
C++. Replace them with import stubs so that the real implementations
can live in Vulkan-ValidationLayers where they belong.

VVL will need to define these functions in spirv and link them to the
instrumented version of the user's shader.

From here on out, VVL can redefine the functions and any data they use
without updating SPIRV-Tools. Changing the function declarations will
still require both VVL and SPIRV-Tools to be updated in lock step.
2023-09-20 10:50:30 -06:00
David Neto
a996591b1c
Update SPIRV-Headers, add cache control operand kinds (#5406)
* Update SPIRV-Headers, add cache control operand kinds

Adds SPV_OPERAND_TYPE_LOAD_CACHE_CONTROL
and  SPV_OPERAND_TYPE_STORE_CACHE_CONTROL,
from SPV_INTEL_cache_controls

Fixes: #5404

* Update tests: remove Kernel from constant sampler enum dependencies

This corresponds to header change
https://github.com/KhronosGroup/SPIRV-Headers/pull/378
2023-09-13 17:43:12 -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
Steven Perron
d660bb55be
Add SPV_KHR_physical_storage_buffer to allowlists (#5402)
Fixes #4896
2023-09-06 16:35:57 +00:00
Steven Perron
440f018cc4
Fix AddMemberDecoration variable names. (#5399)
The prototype does not match the implementation.

Fixes Typo in declaration DecorationManager::AddMemberDecoration #5392
2023-09-05 19:38:49 +00:00
Nathan Gauër
4e0b94ed7a
opt: add ImageMSArray capability to trim pass. (#5395)
From the Capability's text in the SPIRV spec:

```
An MS operand in OpTypeImage indicates multisampled, used with an
OpTypeImage having Sampled == 2 and Arrayed == 1.
```

Adding this logic to the capability trimming pass.
2023-09-05 18:36:03 +00:00
Cassandra Beckley
d474a07088
Add SPV_EXT_fragment_shader_interlock to allow lists (#5393) 2023-09-05 12:10:16 -04:00
Nathan Gauër
1f07f483ef
opt: add raytracing/rayquery to trim pass (#5397)
Adds the RayTracingKHR and RayQueryKHR capabilities to
the supported capabilities list (this includes the linked extension).
(NV and KHR capabilities/extensions shared the same IDs, so it also
works for NV flavors of those).
2023-09-05 14:36:14 +00:00