Граф коммитов

202 Коммитов

Автор SHA1 Сообщение Дата
Alastair Donaldson 0c4deebc96
Include a maximum value for spv_target_env (#4559)
To allow querying the range of target environments (to ensure that a
target environment value is within the valid range of the associated
enum), this change adds a maximum value to the spv_target_env
enumeration.
2021-10-06 14:50:12 +00:00
Greg Fischer 1454c95d1b
spirv-opt: Switch from Vulkan.DebugInfo to Shader.DebugInfo (#4493)
Includes:
- Shift to use of spirv-header extinst.nonsemantic.shader grammar.json
- Remove extinst.nonsemantic.vulkan.debuginfo.100.grammar.json
- Enable all optimizations for Shader.DebugInfo

Also fixes scalar replacement to only insert DebugValue after all
OpVariables. This is not necessary for OpenCL.DebugInfo, but it is
for Shader.DebugInfo.

Likewise, fixes Private-to-Local to insert DebugDeclare after all
OpVariables.

Also fixes inlining to handle FunctionDefinition which can show up
after first block if early return processing happens.

Co-authored-by: baldurk <baldurk@baldurk.org>
2021-09-15 14:38:53 -04:00
Greg Fischer 4ac8e5e541
Add preserve_interface mode to aggressive_dead_code_elim (#4520)
This mode is needed by GPU-assisted validation instrumentation which
cannot change the shader entry point interface.
2021-09-15 14:38:34 -04:00
Jaebaek Seo 0c09258e07
Set threshold for reduce-load-size pass (#4499)
Allow uses to set the threshold for spirv-opt reduce-load-size pass
2021-09-02 10:45:51 -04:00
Jakub Kuderski b8fce5f9e6
spirv-lint: Add lint based on divergence analysis (#4488)
This PR is a rebased version of #4479 by James Dong.
---

The primary purpose of this PR is to add the code from my prototype as a PR, for licensing reasons.
The commit history is messy, and the code is not especially clean.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/3196.
2021-08-27 14:43:23 -04:00
gnl21 ee30773650
Add a feature for allowing LocalSizeId (#4492)
Allow LocalSizeId as a way of sizing compute workgroups where the
environment allows it. A command-line switch is also added to force
acceptance even where the environment would not otherwise allow it.
2021-08-26 14:33:19 -04:00
Jaebaek Seo 57e1d8ebe3
Add spirv-opt convert-to-sampled-image pass (#4340)
convert-to-sampled-image pass converts images and/or samplers with
given pairs of descriptor set and binding to sampled image.

If a pair of an image and a sampler have the same pair of descriptor
set and binding that is one of the given pairs, they will be
converted to a sampled image. In addition, if only an image has the
descriptor set and binding that is one of the given pairs, it will
be converted to a sampled image as well.

For example, when we have

  %a = OpLoad %type_2d_image %texture
  %b = OpLoad %type_sampler %sampler
  %combined = OpSampledImage %type_sampled_image %a %b
  %value = OpImageSampleExplicitLod %v4float %combined ...

1. If %texture and %sampler have the same descriptor set and binding

  %combine_texture_and_sampler = OpVaraible %ptr_type_sampled_image_Uniform
  ...
  %combined = OpLoad %type_sampled_image %combine_texture_and_sampler
  %value = OpImageSampleExplicitLod %v4float %combined ...

2. If %texture and %sampler have different pairs of descriptor set and binding

  %a = OpLoad %type_sampled_image %texture
  %extracted_image = OpImage %type_2d_image %a
  %b = OpLoad %type_sampler %sampler
  %combined = OpSampledImage %type_sampled_image %extracted_image %b
  %value = OpImageSampleExplicitLod %v4float %combined ...
2021-08-18 08:30:48 -04:00
dong-ja 706dc27a62
Add new target for spirv-lint (#4446)
This PR adds a new executable spirv-lint with a simple "Hello, world!"
program, along with its associated library and a dummy unit test.

For now, only adds to CMake and Bazel; other build systems will be added
in a future PR.

Issue: #3196
2021-08-06 14:03:59 -04:00
Greg Fischer 3b6abf41cc
Add non-semantic vulkan extended instruction set (#4362)
This is based on a legacy commit which installs a local grammar. A
followup commit will change to the grammar in SPIRV-Headers.

Co-authored-by: baldurk <baldurk@baldurk.org>
2021-07-12 05:51:08 -04:00
ZHOU He f9893c4549
spirv-opt: A pass to removed unused input on OpEntryPoint instructions. (#4275)
The new pass will removed interface variable on the OpEntryPoint instruction when they are not statically referenced in the call tree of the entry point.

It can be enabled on the command line using the options `remove-unused-interface-variables`.
2021-06-29 11:33:58 -04:00
Kévin Petit e065c482c6
Initial support for SPV_KHR_integer_dot_product (#4327)
* Initial support for SPV_KHR_integer_dot_product

- Adds new operand types for packed-vector-format
- Moves ray tracing enums to the end

- PackedVectorFormat is a new optional operand type, so it requires
  special handling in grammar table generation.

- Add SPV_KHR_integer_dot_product to optimizer whitelists.

- Pass-through validation: valid cases pass validation
  Validation errors are not checked.

- Update SPIRV-Headers

Patch by David Neto <dneto@google.com>
Rebase and minor tweaks by Kevin Petit <kevin.petit@arm.com>

Signed-off-by: David Neto <dneto@google.com>
Signed-off-by: Kevin Petit <kevin.petit@arm.com>
Change-Id: Icb41741cb7f0f1063e5541ce25e5ba6c02266d2c

* format fixes

Change-Id: I35c82ec27bded3d1b62373fa6daec3ffd91105a3
2021-06-23 13:32:24 -04:00
David Neto bbc660edab
Support Intel extensions for fixed point and hls-float (#4321)
See https://github.com/KhronosGroup/SPIRV-Headers/pull/177

Assembly, disassembly should work, but are untested.
2021-06-09 16:20:39 -04:00
Greg Fischer 87a2867976
Add kInstErrorMax to instrument.hpp (#4315)
To allow for extending GPU-AV error codes outside of spirv-tools.
2021-06-07 08:06:10 -04:00
Greg Fischer 48007a5c7f
Add interpolate legalization pass (#4220)
This pass converts an internal form of GLSLstd450 Interpolate ops
to the externally valid form. The external form takes the lvalue
of the interpolant. The internal form can do a load of the interpolant.
The pass replaces the load with its pointer. The internal form is
generated by glslang and possibly other frontends for HLSL shaders.
The new pass is called as part of HLSL legalization after all
propagation is complete.

Also adds internal interpolate form to pre-legalization validation
2021-03-31 14:26:36 -04:00
Daniel Koch 1746ed39d5
Add `void` in function declaration to keep some compilers happy (#4160)
fixes

error: function declaration isn't a prototype [-Werror=strict-prototypes]

Change-Id: I73dad8edbe82b5b481c6b87d773d6e6f8d191a45
2021-03-10 08:55:29 -05:00
greg-lunarg c79edd260c
Generate differentiated error codes for buffer oob checking (#4144)
This allows the GPU-AV layer to differentiate between errors with
uniform buffers versus storage buffers and map these to the relevant
VUIDs.

This is a resubmit of a previously reverted commit. The revert was
done as someone erroneously attempted to build the latest validation
layers with a TOT spirv-tools. The validation layers must be built with
their known-good glslang and its known-good spirv-tools and spirv-headers.
2021-02-11 17:24:04 -05:00
Caio Marcelo de Oliveira Filho b812fd634e
Validate SPV_KHR_workgroup_memory_explicit_layout (#4128)
* Validate SPV_KHR_workgroup_memory_explicit_layout

* Check if SPIR-V is at least 1.4 to use the extension.

* Check if either only Workgroup Blocks or only Workgroup non-Blocks
  are used.

* Check that if more than one Workgroup Block is used, variables are
  decorated with Aliased.

* Check layout decorations for Workgroup Blocks.

* Implicitly use main capability if the ...8BitAccess or
  ...16BitAccess are used.

* Allow 8-bit and 16-bit types when ...8BitAccess and ...16BitAccess
  are used respectively.

* Update SPIRV-Headers dependency

Bump it to include SPV_KHR_workgroup_memory_explicit_layout.

* Add option to validate Workgroup blocks with scalar layout

Validate the equivalent of scalarBlockLayout for Workgroup storage
class Block variables from SPV_KHR_workgroup_memory_explicit_layout.
Add option to the API and command line tool.
2021-01-27 19:38:38 -05:00
David Neto 1bd539b9bf
Support pending Intel extensions (#4116)
This patch supports new Intel extensions added via
https://github.com/KhronosGroup/SPIRV-Headers/pull/176

SPV_INTEL_fooat_controls2 requires extra support to add
two new operand types:
   SPV_OPERAND_TYPE_FPDENORM_MODE
   SPV_OPERAND_TYPE_FPOPERATION_MODE
2021-01-20 09:39:51 -05:00
Ryan Harrison 9150cd441f
Remove WebGPU support (#4108)
Leaves SPV_ENV_WEBGPU_0 enum in place, but marked deprecated, so users
of the library are not broken by an API enum being removed.

Fixes #4101
2021-01-14 16:45:18 -05:00
dan sinclair 7bbe1a3164
Revert "Generate differentiated error codes for buffer oob checking (#4097)" (#4100)
This reverts commit c32277c0ba.
2021-01-12 11:36:31 -05:00
greg-lunarg c32277c0ba
Generate differentiated error codes for buffer oob checking (#4097)
This allows the GPU-AV layer to differentiate between errors with
uniform buffers versus storage buffers and map these to the relevant
VUIDs.
2021-01-11 08:42:48 -05:00
greg-lunarg 7046c05d2f
Add texel buffer out-of-bounds checking instrumentation (#4038)
This instruments ImageRead, ImageWrite and ImageFetch when applied to
texel buffers.

Also add new (but not yet generated) buffer OOB error codes differentiated
for VUID classification.
2020-12-01 11:28:16 -05:00
Jaebaek Seo f7da527757
Temporarily add EmptyPass to prevent glslang from failing (#4004)
Removing PropagateLineInfoPass and RedundantLineInfoElimPass from
56d0f5035 makes unit tests of many open source projects fail.
It will happen before submitting this glslang PR
https://github.com/KhronosGroup/glslang/pull/2440. This commit will be
git-reverted after merging the glslang PR.
2020-10-30 18:03:56 -04:00
Jaebaek Seo 56d0f50357
Propagate OpLine to all applied instructions in spirv-opt (#3951)
Based on the OpLine spec, an OpLine instruction must be applied to
the instructions physically following it up to the first occurrence
of the next end of block, the next OpLine instruction, or the next
OpNoLine instruction.

```
OpLine %file 0 0
OpNoLine
OpLine %file 1 1
OpStore %foo %int_1
%value = OpLoad %int %foo
OpLine %file 2 2
```

For the above code, the current spirv-opt keeps three line
instructions `OpLine %file 0 0`, `OpNoLine`, and `OpLine %file 1 1`
in `std::vector<Instruction> dbg_line_insts_` of Instruction class
for `OpStore %foo %int_1`. It does not put any line instruction to
`std::vector<Instruction> dbg_line_insts_` of
`%value = OpLoad %int %foo` even though `OpLine %file 1 1` must be
applied to `%value = OpLoad %int %foo` based on the spec.

This results in the missing line information for
`%value = OpLoad %int %foo` while each spirv-opt pass optimizes the
code. We have to put `OpLine %file 1 1` to
`std::vector<Instruction> dbg_line_insts_` of
both `%value = OpLoad %int %foo` and `OpStore %foo %int_1`.

This commit conducts the line instruction propagation and skips
emitting the eliminated line instructions at the end, which are the same
with PropagateLineInfoPass and RedundantLineInfoElimPass. This
commit removes PropagateLineInfoPass and RedundantLineInfoElimPass.

KhronosGroup/glslang#2440 is a related PR that stop using
PropagateLineInfoPass and RedundantLineInfoElimPass from glslang.
When the code in this PR applied, the glslang tests will pass.
2020-10-29 13:06:30 -04:00
Tobski a1d38174b1
Support SPV_KHR_fragment_shading_rate (#3943) 2020-10-20 08:00:13 -04:00
dan sinclair c6ca885c0b
[spirv-dis] Add some context comments to disassembly. (#3847)
This CL adds some extra new lines and context comments into the
spirv-dis output format. This CL adds:

 - Blank line and '; Annotations' before decorations
 - Blank line and '; Debug Information' before debug instructions
 - Blank line and '; Types, variables and constants' before type section
 - Blank line and '; Function <name>' before each function.

Issue #788
2020-09-28 10:59:50 -04:00
Alastair Donaldson 60ce96e2ff
spirv-fuzz: Add pass recommendations (#3757)
This change introduces various strategies for controlling the manner
in which fuzzer passes are applied repeatedly, including infrastructure
to allow fuzzer passes to be recommended based on which passes ran
previously.
2020-09-18 15:51:35 +01:00
greg-lunarg 7e28d809c6
Add buffer oob check to bindless instrumentation (#3800) 2020-09-16 09:23:46 -04:00
Alastair Donaldson 5dcb576b69
spirv-reduce: Support reducing a specific function (#3774)
Motivated by integrating spirv-reduce into spirv-fuzz, so that an
added function can be made smaller during shrinking, this adds support
in spirv-reduce for asking reduction to be restricted to the
instructions of a single specified function.
2020-09-11 06:29:43 +01:00
alan-baker 50300450af
Validator support for non-semantic clspv reflection (#3618)
* Generate ext inst table for reflection
* Change build to use grammar files from SPIRV-Headers instead of
  SPIRV-Tools
* Add enum for clspv reflection extended instruction set
  * count it as non-semantic
* validate clspv reflection extended instruction set
* Remove local extended inst sets
* update headers deps
* Update nbuilds to use grammars from SPIRV-Headers instead of
  local duplicates
2020-07-30 12:08:53 -04:00
David Neto 31c8213935
Avoid operand type range checks (#3379)
* Avoid operand type range checks

Deprecates the SPV_OPERAND_TYPE_FIRST_* and SPV_OPERAND_TYPE_LAST_*
macros.

The "variable" and "optional" operand types are only for internal use.
Export spvOperandIsConcrete instead, as that should cover intended
external uses.

Test that each operand type is classified either as one of:
- a sentinel value
- a concrete operand type
- an optional operand type (which includes variable-expansion types)

Test that each concrete and optional non-variable operand type
has a name for use internally when generating messages.

Co-authored-by: Steven Perron <stevenperron@google.com>
2020-07-27 13:14:03 -04:00
alan-baker f3cec93665
Support SPV_KHR_terminate_invocation (#3568)
Covers:
- assembler
- disassembler
- validator
- optimizer

Co-authored-by: David Neto <dneto@google.com>
2020-07-22 11:45:02 -04:00
Alastair Donaldson 3e7238c68d
spirv-fuzz: Add replay range option (#3535)
This change adds a --replay-range argument to spirv-fuzz that
facilitates applying only a prefix of transformations.
2020-07-15 12:13:23 +01:00
greg-lunarg 282392dda2
Add support to GPU-AV instrumentation for Task and Mesh shaders (#3512) 2020-07-14 11:55:24 -04:00
greg-lunarg 4410272bdd
Remove deprecated interfaces from instrument passes (#3361) 2020-05-21 13:10:42 -04:00
Daniel Koch 5a97e3a391
Add support for KHR_ray_{query,tracing} extensions (#3235)
Update validator for SPV_KHR_ray_tracing.

* Added handling for new enum types
* Add SpvScopeShaderCallKHR as a valid scope
* update spirv-headers

Co-authored-by: alelenv <alele@nvidia.com>
Co-authored-by: Torosdagli <ntorosda@amd.com>
Co-authored-by: Tobias Hector <tobias.hector@amd.com>
Co-authored-by: Steven Perron <stevenperron@google.com>
2020-03-17 15:30:19 -04:00
greg-lunarg 1fe9bcc108
Instrument: Debug Printf support (#3215)
Create a pass to instrument OpDebugPrintf instructions.  This pass replaces all OpDebugPrintf instructions with instructions to write a record containing the string id and the all specified values into a special printf output buffer (if space allows). This pass is designed to support the printf validation in the Vulkan validation layers.

Fixes #3210
2020-03-12 09:19:52 -04:00
Steven Perron 4a80497a88
Make spvOpcodeString part of the public API (#3174)
Fixes #3138
2020-02-20 14:07:57 -05:00
David Neto 5d786f6cc7
Clarify mapping of target env to SPIR-V version (#3150)
* Clarify mapping of target env to SPIR-V version

It depends on the API method.

* Update SPIR-V version comments on validator
2020-01-24 16:26:07 -05:00
David Neto bb236c326d
Add spvParseVulkanEnv (#3142)
This new API lets clients request a minimal spv_target_env value
that supports a given Vulkan and SPIR-V version, by a generic
numbering scheme (as already defined by Vulkan and SPIR-V specs).

This breaks a formal source dependency from Glslang to SPIRV-Tools.
When a new API is rolled out, such as Vulkan 1.2, Glslang currently
needs to reference a specific SPIRV-Tools enum by name.
2020-01-23 17:20:32 -05:00
David Neto d46a1b0487 Add basic support for Vulkan 1.2: SPV_ENV_VULKAN_1_2 2020-01-14 20:06:19 -05:00
greg-lunarg 578c5ac133 Change default version for CreatInstBindlessCheckPass to 2 (#3119) 2019-12-27 10:46:43 -05:00
greg-lunarg 9215c1b7df Fix convert-relax-to-half invalid code (#3099) (#3106) 2019-12-20 21:08:12 -05:00
David Neto 64f36ea529
Support OpenCL.DebugInfo.100 extended instruction set (#3080)
* Clone opencl.debuginfo.100 grammar from debuginfo grammar

Update version number to 200 revision 2

* Apply content from OpenCL.DebugInfo.100 extension text

* Rename grammar file

* Support OpenCL.DebugInfo.100 extended instructions

Add support for prefixing operand type names, to disambiguate
them between different instruction sets.

* Add tests for OpenCL.DebugInfo.100

* Support lookup of OpenCL.DebugInfo.100 extinst

* Add tests for enum values

* Recognize 2017-2019 as copyright date range

* Android.mk: support OpenCL.DebugInfo.100 extended instruction set

Also, stop generating core instruction tables for non-unified1 versions
of the grammar.

* Imported entity operand type is concrete

* Bazel: Suppoort OpenCL.DebugInfo.100

* BUILD.gn: Support OpenCL.DebugInfo.100
2019-12-19 17:16:26 -05:00
David Neto e70b009b0f
Add support for SPV_KHR_non_semantic_info (#3110)
Add support for SPV_KHR_non_semantic_info

This entails a couple of changes:

- Allowing unknown OpExtInstImport that begin with the prefix `NonSemantic.`
- Allowing OpExtInst that reference any of those sets to contain unknown
  ext inst instruction numbers, and assume the format is always a series of IDs
  as guaranteed by the extension.
- Allowing those OpExtInst to appear in the types/variables/constants section.
- Not stripping OpString in the --strip-debug pass, since it may be referenced
  by these non-semantic OpExtInsts.
- Stripping them instead in the --strip-reflect pass.

* Add adjacency validation of non-semantic OpExtInst

- We validate and test that OpExtInst cannot appear before or between
  OpPhi instructions, or before/between OpFunctionParameter
  instructions.

* Change non-semantic extinst type to single value

* Add helper function spvExtInstIsNonSemantic() which will check if the extinst
  set is non-semantic or not, either the unknown generic value or any future
  recognised non-semantic set.

* Add test of a complex non-semantic extinst

* Use DefUseManager in StripDebugInfoPass to strip some OpStrings

* Any OpString used by a non-semantic instruction cannot be stripped, all others
  can so we search for uses to see if each string can be removed.
* We only do this if the non-semantic debug info extension is enabled, otherwise
  all strings can be trivially removed.

* Silence -Winconsistent-missing-override in protobufs
2019-12-18 18:10:29 -05:00
greg-lunarg fccbc00aca Make Instrumentation format version 2 the default (Step 1) (#3096)
* Make Instrumentation format version 2 the default (Step 1)

Add new interfaces without version number argument. Remove version 1
logic and tests. Version interfaces will be removed in step 2 after
layers have transitioned to new interface.

* Add error messages to InstrumentPass().
2019-12-16 14:18:47 -05:00
David Neto af7410597e graphics robust access: use signed clamp (#3073)
Access chain indices are always interpreted as signed integers.
So use signed clamp instead of unsigned clamp.  We must also
clamp to the max signed int for the index type.

Fixes #3072
2019-12-03 11:18:56 -05:00
Alastair Donaldson 52e9cc9301
spirv-fuzz: Improve debugging facilities (#3074)
Adds an option to run the validator on the SPIR-V binary after each
fuzzer pass has been applied, to help identify when the fuzzer has
made the module invalid.  Also adds a helper method to allow dumping
of the sequence of transformations that have been applied to a JSON
file.
2019-11-27 18:05:56 +00:00
Alastair Donaldson 7275a71654
Allow validation during spirv-fuzz replay (#2873)
To aid in debugging issues in spirv-fuzz, this change adds an option whereby the SPIR-V module is validated after each transformation is applied during replay.  This can assist in finding a transformation that erroneously makes the module invalid, so that said transformation can be debugged.
2019-09-20 10:54:09 +01:00
alan-baker 5a48c0da15 SPIRV-Tools support for SPIR-V 1.5 (#2865)
* Ensure same enum values have consistent extension lists

* val: fix checking of capabilities

The operand for an OpCapability should only be
checked for the extension or core version.
The InstructionPass registers a capability, and all its implied
sub-capabilities before actually checking the operand to an
OpCapability.

* Add basic support for SPIR-V 1.5

- Adds SPV_ENV_UNIVERSAL_1_5
- Command line tools default to spv1.5 environment
- SPIR-V 1.5 incorporates several extensions.  Now the disassembler
  prefers outputing the non-EXT or non-KHR names.  This requires
  updates to many tests, to make strings match again.
- Command line tests: Expect SPIR-V 1.5 by default

* Test validation of SPIR-V 1.5 incorporated extensions

Starting with 1.5, incorporated features no longer require
the associated OpExtension instruction.
2019-09-13 14:59:02 -04:00