Commit Graph

2586 Commits

Author SHA1 Message Date
David Neto
b46995741b
Avoid bugprone-move-forwarding-reference warning in Clang (#4560)
Use std::forward<T> instead of std::move, on an argument with
rvalue-reference of template-deduced type.

See https://clang.llvm.org/extra/clang-tidy/checks/bugprone-move-forwarding-reference.html

Bug: crbug.com/1134310
2021-10-06 16:50:16 -04:00
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
63a3912326
Fix ConstantManager to not run AnalyzeInstDefUse if DefUse not valid (#4557)
This fixes inlining which has to create constant for DebugInlinedAt for
NonSemantic.Shader.DebugInfo. Also adds regression tests.
2021-10-05 14:55:06 -04:00
Ryan Harrison
2d12367ced
Stop consuming input in fuzzers to select target environment (#4544)
Instead calculate a hash based on the input and use that as a seed
into random data generation for the target env.

Also fixes issue where input data was not actually being fed into
one fuzzer.

Fixes #4450
2021-10-04 13:42:12 -04:00
Steven Perron
eeb973f502
More ADCE refactoring (#4548)
Split the code that processes the work list into multiple functions.

Move the code to remove the dead instructions in a function to its own function.
2021-10-04 08:33:10 -04:00
David Neto
9529d3c2c6
Avoid implicit fallthrough, by duplicating code (#4556)
The cleverness is probably not worth it.
2021-10-01 08:43:59 -04:00
Lukas Hermanns
24476c2e32
spirv-opt: Don't eliminate dead members from StructuredBuffer (#4553)
* Don't eliminate dead members from StructuredBuffer as layout(offset) qualifiers cannot be applied to structure fields.

* Traverse arrays when marking structs as fully used.

Co-authored-by: Steven Perron <stevenperron@google.com>
2021-10-01 08:31:40 -04:00
alan-baker
3234daada7
Do not assume there are execution modes (#4555)
Fixes #4550

* Do not assume that an entry point has any associated execution modes
  when checking derivative requirements
2021-09-30 19:20:28 -04:00
Alastair Donaldson
ba4b390c36
Suppress protobuf warning (#4551)
Suppresses a warning emitted by some versions of clang when compiling
protobufs.
2021-09-28 14:52:52 +00:00
Steven Perron
c3adcb034f
Adce refactor (NFC) (#4547)
* Have ADCE use cfg struct analysis (NFC)

ADCE has a lot of code and variables to keep track of
information that is easily obtains using the Struct
cfg analysis.  Most of this change is to refactor the
code to have small functions to get the information
from the struct cfg analysis.

A few other changes small refactoring changes are
done.

* Factor out work list initialization in ADCE (NFC)

We move the code that will initially populate the work list into its own
function.  We also simplify the code by making use of the struct cfg
analysis.  That way we can reduce the number of tables used to track
information as we traverse the CFG.
2021-09-24 13:21:45 -04:00
Greg Fischer
19dc86c48c
Handle NonSemantic.Shader Debug[No]Line (#4530)
Debug[No]Line are tracked and optimized using the same mechanism that tracks
and optimizes Op[No]Line.

Also:
    - Fix missing DebugScope at top of block.
    - Allow scalar replacement of access chain in DebugDeclare
2021-09-24 10:56:08 -04:00
Greg Fischer
f125452cf8
Fix inst_buff_addr_check to handle struct loads (#4489) 2021-09-23 12:59:38 -04:00
alan-baker
a6c5056db2
Fix checks for offset in nested structs (#4531)
Fixes #4533
Fixes https://crbug.com/38771

* Fixes offset checks to look through arrays for nested structures
2021-09-21 11:15:16 -04:00
Steven Perron
59f51bb4f8
Fix extract with out-of-bounds index (#4529)
* Fix extract with out-of-bounds index

When folding a OpCompositeExtract that is fed by an
OpCompositeConstruct, we handle and out of bounds
index, but only in the case where the result of the
OpCompostiteConstruct is a struct.  This change
refactors that folding rule and then improves it to
handle an out-of-bounds access when the result of the
OpCompositeConstruct is a vector.
2021-09-20 13:02:47 -04: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
Alastair Donaldson
9e65f054d1
spirv-fuzz: Account for differing signedness in WrapVectorSynonym (#4414)
Makes the fuzzer pass and transformation that wraps vector synonyms
aware of the fact that integer operations can have arguments that
differ in signedness, and that the result type of such an operation
can have different sign from the argument types.

Fixes #4413.
2021-09-14 21:09:39 +00:00
Alastair Donaldson
36ff135341
spirv-opt: Avoid integer overflow during constant folding (#4511)
In SPIR-V, integers use 2s complement representation, so that signed
integer overflow and underflow is well defined. However, the constant
folder was causing overflow / underflow at the C++ level. This change
avoids such overflows by performing constant folding for IAdd, ISub and
IMul in the context of unsigned values, which works because signedness
is irrelevant according to the SPIR-V semantics for these instructions.

Fixes #4510.
2021-09-14 21:09:05 +00:00
alan-baker
846b032b53
Fix infinite loop in validation (#4523)
* Fix infinite loop in validation

Fixes https://crbug.com/38548

* Fixes an issue in structured exit checking where an invalid merge
  could result in an infinite traversal

* formatting
2021-09-13 13:19:04 -04:00
alan-baker
5efeaad309
Fix bad order of checks in atomic validation (#4524)
Fixes https://crbug.com/38625

* Check the type is an integer before checking it's bit width
2021-09-13 11:16:37 -04:00
Steven Perron
8865b20295
Handle out-of-bounds accesses in VDCE (#4518)
It is possible that other optimization will propagate
a value into an OpCompositeExtract or OpVectorShuffle
instruction that is larger than the vector size.
Vector DCE has to be able to handle it.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/4513.
2021-09-13 09:57:44 -04:00
alan-baker
4f4f76037c
Change validator boolean tests to avoid asserts (#4503)
Fixes https://crbug.com/38102

* Check for valid instructions in many boolean tests instead of
  asserting in ValidationState_t
2021-09-12 19:14:33 -04:00
alan-baker
912460e46a
Fix infinite loop in GetBlockDepth (#4519)
Fixes #4515

* Sets block depth to 0 if it encountered multiple times and leaves
  finding the real error for other code
2021-09-11 03:27:14 +00:00
David Neto
013b1f3d6d
Fix validation message for cooperative matrix column type (#4502)
* Fix validation message for cooperative matrix column type

Fixes: #4497

* Add tests for cooperative matrix type validation
2021-09-10 11:28:00 -04:00
alan-baker
c16224c684
Add some missing switch validation (#4507)
Fixes #4506

* Add validation of selector and default operands
2021-09-08 10:09:01 +01:00
Alastair Donaldson
92868b8f3f
spirv-val: Fix ubsan error (#4505)
Fixes an issue where an arbitrary word was cast to SpvOp, leading to
undefined behaviour if the value of the word fell outside the range of
SpvOp values.

Fixes #4504.
2021-09-07 15:37:40 -04:00
gnl21
4db6b8dcc2
Remove environment features that are never used (#4491)
The validation state contained feature bits for scalar block layout and
workgroup memory scalar block layout which were never used (the
command-line option is used in every case).
2021-09-07 13:08:15 -04:00
David Neto
7e860e3831
fix parsing of bad binary exponents in hex floats (#4501)
- The binary exponent must have some decimal digits
- A + or - after the binary exponent digits should not be interpreted as
  part of the binary exponent.

Fixes: #4500
2021-09-03 12:27:12 -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
Steven Perron
bd3a271ce3
Handle exported functions in ADCE (#4495)
ADCE does not handle exported functions.  This was an explicit decision
because we did not believe that the linkage attribute could be used in
shaders, but it can now.  This change has been made.

While fixing this error, I noticed that the OpName for labels is
sometimes removed because the label instructions are not marked
explicitly marked as live.  This has able been fixed.
2021-08-31 12:39:46 -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
Greg Fischer
a1d5d67aeb
spirv-val: Validate vulkan debug info similarly to opencl debug info (#4466)
Co-authored-by: baldurk <baldurk@baldurk.org>
2021-08-23 17:38:26 -04:00
dong-ja
937227c761
Add divergence analysis to linter (#4465)
Currently, handles promotion of divergence due to reconvergence rules, but doesn't handle "late merges" caused by a later-than-necessary declared merge block.

Co-authored-by: Jakub Kuderski <kubak@google.com>
2021-08-23 17:03:28 -04:00
sfricke-samsung
d699296b4d
spirv-val: Fix WorkgroupSize VUID 04425 (#4482) 2021-08-19 16:06:01 -04:00
alan-baker
a9ce5e07c6
Fix matrix stride validation (#4468)
Fixes #4454

* Use MatrixStride from member decorations instead of from matrix
  decorations
2021-08-18 13:03:45 -04:00
alan-baker
e172833bd1
Don't double count variables for location validation (#4474)
Fixes #4403

* Pre-1.4 modules could have duplicate interface entries
  * Don't double count variables for locations
2021-08-18 13:01:37 -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
alan-baker
b2e36b67ec
Disallow loading a runtime-sized array (#4473)
* Disallow loading a runtime-sized array

Fixes #4472

* Disallow loading a runtime-sized array or a composite containing one
* Refactor type traversal into a separate function used by both runtime
  array checks and sized int/float checks
* Update invalid tests
2021-08-16 18:23:10 -04:00
Nicolas Capens
2c829c4155
Fix early-out for Clamp constant folding (#4461)
Only the first two operands were tested for constness, missing the third
one. Since the FoldFPBinaryOp() at the end of FoldClamp1() returns null
when not both of its operands are constant, this doesn't change any
behavior, but it avoids some needless work.

Also the comment for FoldClamp2() was fixed.
2021-08-16 14:11:38 -04:00
Nicolas Capens
869a550d26
Don't fold unsigned divides of an constant and a negation (#4457)
Negating an unsigned constant results in its two's complement which is
still interpreted as unsigned. For example -2u becomes 4294967294u.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/4456
2021-08-16 09:56:05 -04:00
alan-baker
00b106e769
Limit location validation (#4467)
Fixes #4464

* Add a limit to only check up to 4096 locations to prevent excessive
  memory consumption
  * still fully validates all reasonable inputs
2021-08-13 13:00:00 -04:00
alan-baker
54524ffa6a
Update SPIRV-Headers (#4463)
* Add SpvBuiltInCurrentRayTimeNV to unvalidated builtins
2021-08-12 10:34:29 -04:00
Greg Fischer
de69f32e89
spirv-opt: Add handling of vulkan debug info to DebugInfoManager (#4423)
Co-authored-by: baldurk <baldurk@baldurk.org>
2021-08-10 09:31:17 -04:00
dong-ja
c4c6f2ba5c
spirv-opt: Add dataflow analysis framework (#4402)
This PR adds a generic dataflow analysis framework to SPIRV-opt, with the intent of being used in SPIRV-lint. This may also be useful for SPIRV-opt, as existing ad-hoc analyses can be rewritten to use a common framework, but this is not the target of this PR.
2021-08-09 16:43:36 -04:00
dong-ja
f9d03bb40f
Remove PCH from source/lint/CMakeLists.txt (#4459)
Fixes #4458
2021-08-09 15:30:51 -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
alan-baker
175ecd49ed
Fix array layout validation slowdown (#4449)
* Improve the early exit logic for array layout validation to handle
  more cases
2021-08-05 09:56:52 -04:00
Mostafa Ashraf
07f1302352
spirv-fuzz: Support AtomicStore (#4440)
Adds support for atomic operations in TransformationStore and its
associated fuzzer pass.

Fixes #4337.
2021-08-05 14:08:44 +01:00
Ben Clayton
366d1be5e8
fuzzers: Disable suggest-destructor-override warning (#4439)
The protobuf generated code triggers this clang-12 warning, which some
projects may treat as an error.
2021-08-05 12:00:33 +01:00
Mostafa Ashraf
0065c5672d
spirv-fuzz: support AtomicLoad (#4330)
Enhances the TransformationLoad transformation and associated
fuzzer pass to support atomic operations.

Fixes #4324.
2021-08-03 21:51:25 +01:00
Ben Clayton
c5bda7ae5a
Fuzzer: Default the new constructor parameter (#4438)
Introducing a new mandatory parameter makes it very difficult to roll
Chromium to a new version of SPIRV-Tools, as this project is used by
several third-party projects, and an atomic update of all projects
is very hard to coordinate.
2021-08-02 13:37:37 +01:00
alan-baker
5737dbb068
Fix validator crash (#4418)
Fixes #4411

* Some GLSL.std.450 validation didn't handle an operand without a type
2021-07-29 12:56:58 -04:00
dong-ja
c6422cff33
spirv-opt: Rename ControlDependenceAnalysis::DoesBlockExist to HasBlock (#4412)
Suggested by Jakub as 'DoesBlockExist' was confusing.
2021-07-29 08:30:48 -04:00
Greg Fischer
983ee2313c
spirv-opt: Add specific handling of vulkan debug info differences (#4398)
Co-authored-by: baldurk <baldurk@baldurk.org>
2021-07-28 21:35:32 -04:00
Alastair Donaldson
9c4481419e
spirv-fuzz: Allow inapplicable transformations to be ignored (#4407)
spirv-fuzz features transformations that should be applicable by
construction. Assertions are used to detect when such transformations
turn out to be inapplicable. Failures of such assertions indicate bugs
in the fuzzer. However, when using the fuzzer at scale (e.g. in
ClusterFuzz) reports of these assertion failures create noise, and
cause the fuzzer to exit early. This change adds an option whereby
inapplicable transformations can be ignored. This reduces noise and
allows fuzzing to continue even when a transformation that should be
applicable but is not has been erroneously created.
2021-07-28 22:59:37 +01:00
Alastair Donaldson
c9e094cc4d
spirv-fuzz: Quit fuzzer pass when no types are available (#4409)
The fuzzer pass that adds global variables requires some basic
types. This change makes the fuzzer pass exit gracefully when none are
available.

Fixes #4408.
2021-07-28 22:59:02 +01:00
dong-ja
7dadcf9c76
Add control dependence analysis to opt (#4380)
Control dependence analysis constructs a control dependence graph,
representing the conditions for a block's execution relative to the
results of other blocks with conditional branches, etc.
This is an analysis pass that will be useful for the linter and
potentially also useful in opt. Currently it is unused except for the
added unit tests.
2021-07-28 12:44:32 -04:00
Alastair Donaldson
11cd875ed8
spirv-fuzz: Use reference in CanMakeSynonymOf (#4401)
The instruction parameter of CanMakeSynonymOf is an input parameter
that should never be null, so a const reference is a more appropriate
type than a const pointer.
2021-07-27 13:18:36 +01:00
Vasyl Teliman
63238d4f2a
Initialize context in opt::Instruction's move constructor (#4397)
Fixes #4396.
2021-07-23 10:09:51 +01:00
Alastair Donaldson
183fb9fe4c
spirv-fuzz: Fix problem with instruction context (#4394)
Adds an additional validity check to ensure that every instruction's
context pointer matches the enclosing IR context. Avoids a redundant
copy constructor call in TransformationDuplicateRegionWithSelection
that was leading to a bad IR context for some instructions.

Related: #4387, #4388.
Fixes #4393.
2021-07-22 23:44:29 +01:00
Alastair Donaldson
94bcae1344
spirv-fuzz: Avoid out-of-bounds access (#4395)
Fixes #4389.
2021-07-22 23:44:03 +01:00
Alastair Donaldson
cc3fe2b67b
spirv-fuzz: Fix vector wrapping fuzzer pass (#4392)
The fuzzer pass was passing the type of a scalar where a vector type
was required, and was not checking whether synonyms could be made for
the operands to the scalar instruction.
2021-07-22 23:43:45 +01:00
Alastair Donaldson
2419f3be86
spirv-fuzz: Tighten checks on null and undef pointers (#4367)
Adaps the transformations that add OpConstantUndef and OpConstantNull
to a module so that pointer undefs are not allowed, and null pointers
are only allowed if suitable capabilities are present.

Fixes #4357.
2021-07-22 21:34:11 +01:00
Greg Fischer
d9f8925785
spirv-opt: Where possible make code agnostic of opencl/vulkan debuginfo (#4385)
Co-authored-by: baldurk <baldurk@baldurk.org>
2021-07-21 12:04:38 -04:00
Shiyu Liu
033768c24b
spirv-fuzz: TransformationWrapVectorSynonym that rewrites scalar operations using vectors (#4376)
Adds a new transformation that rewrites a scalar operation (like
OpFAdd, opISub) as an equivalent vector operation, adding a synonym
between the scalar result and an appropriate component of the vector
result.

Fixes #4195.
2021-07-20 11:01:20 +01:00
Mostafa Ashraf
f084bcfe2b
spirv-fuzz: Support atomic operations opcode (#4348)
This change captures the fact that the signedness of memory semantics
and scope parameters of atomic operations does not matter.

Fixes #4345.
2021-07-20 10:03:58 +01:00
Greg Fischer
8966cc2b27
Add common enum for debug info instructions from either opencl or vulkan (#4377)
Co-authored-by: baldurk <baldurk@baldurk.org>
2021-07-16 16:28:14 -04:00
Mostafa Ashraf
e0937d7fd1
spirv-fuzz: Don't replace memory semantics / scope operands (#4349)
This change is responsible for avoiding the replacement of constant
operands with another one not constant, in the context of atomic
operations.  The related rule from the SPIR-V spec is: "All used for
Scope and Memory Semantics in shader capability must be of an
OpConstant."

Fixes #4346.
2021-07-15 19:03:51 +01:00
Jaebaek Seo
4baf3affe3
spirv-opt: support SPV_EXT_shader_image_int64 (#4379) 2021-07-14 08:43:35 -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
Alastair Donaldson
9ce7a2fb62
spirv-reduce: Eliminate skeletal structured control flow construct (#4360)
This change allows spriv-reduce to get rid of a selection, switch or
loop construct if none of the instructions defined in the construct
are used outside the construct.
2021-07-06 07:14:36 +01:00
Ben Ashbaugh
c67f132087
add tests for SPV_KHR_bit_instructions (#4350) 2021-07-02 08:53:18 -04:00
Alastair Donaldson
06f114d482
spirv-fuzz: Avoid out of bounds access (#4355)
In the extreme case where there are no basic types,
FuzzerPassPushIdsThroughVariables could trigger a bounds error. This
change fixes this problem.
2021-07-01 15:51:13 +01:00
Assiduous
74e8105eb8
Enabled tvOS platform (#4329) 2021-06-29 15:14:38 -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
John Zupin
eeff9af1e6
fix strncpy bound error (#4331) 2021-06-29 10:07:13 -04:00
Alastair Donaldson
b8587c984a
spirv-reduce: Allow merging unreachable blocks (#4303)
This change allows the reducer to merge together blocks even when they
are unreachable, but keeps the restriction of reachability in place
for the optimizer.

Fixes #4302.
2021-06-28 23:05:30 +01:00
Alastair Donaldson
4fcdc58946
Add IsReachable function to IRContext (#4323)
There was a lot of code in the codebase that would get the dominator
analysis for a function and then use it to check whether a block is
reachable. In the fuzzer, a utility method had been introduced to make
this more concise, but it was not being used consistently.

This change moves the utility method to IRContext, so that it can be
used throughout the codebase, and refactors all existing checks for
block reachability to use the utility method.
2021-06-28 20:00:14 +01:00
Alastair Donaldson
237173a070
spirv-reduce: Cleanup a few things (#4352)
Cleans up a CMakeLists.txt file and the header guard for a reduction
opportunity, and gets rid of an unnecessary parent function field that
can be derived from an existing block field.
2021-06-28 17:53:49 +01:00
Jason Ekstrand
3a02d11268
Add validation for SPV_EXT_shader_atomic_float16_add (#4325) 2021-06-24 08:59:43 -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
sfricke-samsung
f8eafd4d83
spirv-val: Label VUID 04780 (#4334) 2021-06-21 09:33:07 -04:00
sfricke-samsung
e84bcb251d
spirv-val: Add GLCompute to VUID 04644 message (#4333) 2021-06-21 09:31:55 -04:00
alan-baker
4d22f58a81
Support SPV_KHR_subgroup_uniform_control_flow (#4318)
* Support SPV_KHR_subgroup_uniform_control_flow

Covers:
- assembler
- disassembler
- validator
- optimizer (add to whitelists)

* fix copyright

Co-authored-by: David Neto <dneto@google.com>
2021-06-15 10:07:42 -04:00
sfricke-samsung
ecdd9a3e6b
spirv-val: Vulkan Storage Class for Execution Model (#4212) 2021-06-10 08:38:23 -04:00
Ashley Hauck
edc3a24781
Add SPV_KHR_vulkan_memory_model to aggressive_dead_code_elim (#4320) 2021-06-10 08:36:59 -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
Mostafa Ashraf
9dbca316aa
spirv-fuzz: Improve TransformationAddBitInstructionSynonym to check integer signedness (#4312)
Fixes #4170, by checking the signedness of bitwise operands in
TransformationAddBitInstructionSynonym, to avoid an "Expected Base
Type to be equal to Result Type" validation error.
2021-06-09 19:56:56 +01:00
EGJ1996
c1a75bfabf
spirv-fuzz: Support bitwise or and xor in TransformationAddBitInstructionSynonym (#4310)
Fixes #4172.
2021-06-09 16:23:26 +01:00
Jaebaek Seo
fb02131cb4
No error report for variable image offset when before-legal-hlsl is on (#4316)
PR #4118 (d71ac38b8e) let spirv-val report a validation error when we
use offset for an OpImage* instruction instead of ConstantOffset. Since
some compilers like DXC rely on spirv-opt for function inlining or loop
unrolling, the spirv-val change broke some working shaders when the
shader developers disable the optimization (spirv-opt).

For example, DXC recently got this issue from a few users e.g.,
https://github.com/microsoft/DirectXShaderCompiler/issues/3807

Since this error is reported only when the spirv-opt is disabled, it
looks like the exact case that we have to skip spirv-val when
`--before-legalize-hlsl` is given. Moreover, avoiding the error using
`--before-legalize-hlsl` on DXC is exactly what FXC and DXC's DXIL
do (they do not report the error if the offset becomes a constant after
function inlining or loop unrolling).
2021-06-08 09:35:27 -04:00
Shiyu Liu
26cdce984f
spirv-fuzz: add tests for full coverage of TransformationAccessChain (#4304)
Fixes #4286 by achieving full coverage of the transformation.
2021-06-02 17:46:56 +01:00
Ryan Harrison
8b3dc6bbed
Check that valid bitcasted constant was returned (#4311)
This call returns nullptr to indicate errors.

Fixes https://crbug.com/1213365
2021-06-01 09:09:31 -04:00
Alastair Donaldson
0861a8fa21
spirv-fuzz: Fix OutlineFunction in presence of unreachable blocks (#4308)
This change prevents TransformationOutlineFunction from outlining a
region of blocks if some block in the region has an unreachable
predecessor. This avoids a bug whereby the region would be outlined,
and the unreachable predecessors would be left behind, referring to
blocks that are no longer in the function.
2021-06-01 11:44:21 +01:00
Alastair Donaldson
9646c733e9
spirv-fuzz: Fix def-use update in PermutePhiOperands (#4309)
The def-use manager was being incorrectly updated in
TransformationPermutePhiOperands, and this was causing future
transformations to go wrong during fuzzing. This change updates the
def-use manager in a correct manner, and adds a test exposing the
previous bug.

Fixes #4300.
2021-06-01 08:37:45 +01:00
Mostafa Ashraf
00ce2bb474
spirv-fuzz: Enhancing permute function variables and its testing (#4295)
Fixes the way instruction swapping is implemented.

Fixes #4257.
Fixes #4259.
2021-05-26 00:41:31 +01:00
Vasyl Teliman
e2ac64bdf0
spirv-fuzz: Move ApplyTransformation to .cpp file (#4258)
Sometimes, you need to change these functions during debugging (e.g.,
figure out why the transformation is inapplicable). When that happens,
you need to recompile the whole fuzzer just because these functions
are in the header file. This PR fixes the situation.
2021-05-26 00:39:51 +01:00
Vasyl Teliman
f0d110e305
Invalidate analyses (#4260)
Some reduction opportunities don't invalidate all analyses. This PR
fixes the situation (although we might invalidate more analyses than
required).
2021-05-14 15:00:51 +01:00
Greg Fischer
18d45142e7
Fix crash when optimizing shaders with DebugPrintf (#4280)
Fixes #4219
2021-05-13 13:19:56 -04:00
alan-baker
010cd289db
Fix continue construct for single block loops (#4277)
Fixes https://crbug.com/tint/793

* When a loop has an empty loop construct, the loop construct and
  continue construct share the same header so don't disallow the loop
  header for the continue construct
2021-05-12 13:01:32 -04:00
Alastair Donaldson
f6b59599ae
spirv-fuzz: Respect control flow rules when merging returns (#4279)
Fixes #4278.

Some minor code cleanup is incorporated.
2021-05-12 10:45:58 -04:00
Shiyu Liu
1020e394cb
spirv-fuzz: Fix underflow problem in fuzzer_pass_swap_two_functions (#4253)
Addresses a comment mentioned in #4236.

Simplifies implementation of GetFunctionIterator().
2021-05-04 09:40:55 +01:00
ncesario-lunarg
f30465d2b5
build: Fix Android build (#4157) 2021-04-29 09:10:32 -04:00
Vasyl Teliman
f82f5af5e2
Invalidate DefUse analysis (#4255)
Fixes #4252.
2021-04-29 09:44:59 +01:00
Jaebaek Seo
089d716d25
Fix dangling phi bug from loop-unroll (#4239)
Fix dangling phi bug from loop-unroll

When unrolling the following loop:
```
%const0 = OpConstant ...
%const1 = OpConstant ...
...
%LoopHeader = OpLabel
%phi0 = OpPhi %float %const0 %PreHeader %phi1 %Latch
%phi1 = OpPhi %float %const1 %PreHeader %x    %Latch
...
%LoopBody = OpLabel
%x = OpFSub %float %phi1 %phi0
...
```

the loop-unroll pass sets the value of `%phi0` as `%phi1` for the second
copy of the loop body. For example, the second copy of
`%x = OpFSub %float %phi1 %phi0` will be
`%y = OpFSub %float %x %phi1`.

Since all phi instructions for inductions will are removed after the
loop unrolling, `%phi1` will be a dead dangling phi.

It happens only for the phi values of the first loop iteration. Replacing those
dangling phis with their initial values fixes this issue.

For example, the second copy of `%x = OpFSub %float %phi1 %phi0` should be
`%y = OpFSub %float %x %const1` because the value of `%phi1` from the
first loop iteration is `%const1`.
2021-04-27 16:27:09 -04:00
Jaebaek Seo
07ec4f83c5
Support folding OpBitcast with numeric constants (#4247)
Add constant folding rule for OpBitcast with numeric scalar or vector
constants.
2021-04-27 14:24:46 -04:00
Shiyu Liu
6cdf07d2b3
spirv-fuzz: Swap positions of two functions in a module (#4236)
Adds a new transformation class that swaps the syntactic position of
two functions in the module, and a fuzzer pass to apply it.

Fixes #4026.
2021-04-27 12:33:08 +01:00
Ben Clayton
9f23457eef
GraphicsRobustAccessPass: Set module_status_.modified (#4167)
When calling `replace_index`.

Fixes: #4166
2021-04-26 17:14:35 +01:00
Mostafa Ashraf
8fe39ad581
spirv-fuzz: Permute the order of variables at function scope issue (#4248)
Fixes #4194.
2021-04-26 16:53:55 +01:00
Alastair Donaldson
a02a9205ff
spirv-fuzz: Accept limitations in AddFunction (#4226)
There are some edge cases where adding livesafe functions does not
succeed, due to loop limiter edges breaking SPIR-V dominance rules. As
these edge cases are rare it does not seem worth implementing complex
additional logic to handle all cases. This change accepts that trying
to add a function in a livesafe manner may not succeed.
2021-04-13 09:45:30 +01:00
Alastair Donaldson
8da800c4cb
spirv-reduce: Remove redundant r-value references (#4232) 2021-04-09 13:55:51 +01: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
Alastair Donaldson
61e256c9c4
spirv-fuzz: Efficiency improvements to fuzzer pass (#4188)
FuzzerPassConstructComposites is adapted to use AvailableInstructions
to manage available instructions, and to use zero constants when
trying to construct a composite for which not all fields can otherwise
be constructed. The change uncovered some cases where we create
structs and arrays with struct fields or components that are
block-decorated; these possibilities have been eliminated.
2021-03-27 12:15:59 +00:00
Alastair Donaldson
2ee21fbdee
spirv-fuzz: Avoid invalidating analyses when splitting blocks (#4218)
It is easy to avoid the need to invalidate the def-use analysis and
instruction to block mapping when splitting blocks, and profiling has
revealed that invalidation of def-use in particular is expensive when
splitting many blocks. This change avoids these invalidations.
2021-03-27 12:13:23 +00:00
Alastair Donaldson
22eb528f17
spirv-fuzz: Do not add too many dead blocks (#4217)
Profiling has shown that adding large numbers of dead block
transformations can be expensive because each on requires dominator
analysis information, and each one invalidates this information. There
is currently no obvious mechanism for incrementally updating the
dominator analysis. This change restricts the number of these
transformations that a single fuzzer pass will apply, to restrict this
performance bottleneck.
2021-03-27 10:30:23 +00:00
Alastair Donaldson
d0c73fcee1
spirv-fuzz: Optimize transformations (#4216)
Avoids blanket invalidation of analyses in several transformations,
instead updating the def-use manager and instruction to block mapping.
2021-03-26 10:22:06 +00:00
Vasyl Teliman
f227930153
spirv-fuzz: Fix comments #4215
Related to #4214.
2021-03-25 17:20:45 +00:00
Jason Ekstrand
ecc840d30b
Add validation for SPV_EXT_shader_atomic_float_min_max (#4105)
* Add an "extra_defs" parameter to GenerateShaderCode in atomics_test

* Add validation for SPV_EXT_shader_atomic_float_min_max
2021-03-24 08:49:21 -04:00
David Neto
d20c9c2cf3
Make spirv-tools-build-version a common dependency (#4210)
Required to support latest Xcode

Fixes #4109
2021-03-23 16:55:56 -04:00
Alastair Donaldson
bed84792f9
spirv-fuzz: Call by value and move in transformations (#4208)
Adapts all transformation classes so that their protobuf message is
passed by value and then moved into the message_ field.
2021-03-23 13:31:44 +00:00
Alastair Donaldson
c0833ce620
spirv-fuzz: Remove destructors from FuzzerPass subclasses (#4209)
Subclasses of FuzzerPass no longer needlessly override the default
destructor of FuzzerPass.
2021-03-23 13:31:27 +00:00
Vasyl Teliman
edb8399b0f
spirv-fuzz: Add WGSL compatibility flag to context (#4193)
The new flags allows transformations and fuzzer passes to be enabled
and applied in a WGSL-compatible fashion.
2021-03-21 09:10:15 +00:00
Alastair Donaldson
6382cbb497
spirv-fuzz: Avoid invalidating analyses in various transformations (#4205)
Avoids invalidating all analyses in transformations that add
constants, OpUndef and global and local variables.
2021-03-20 22:48:02 +00:00
Alastair Donaldson
6578899781
spirv-fuzz: Manage available instructions efficiently (#4177)
Introduces a data structure for efficient management of available
instructions in the fuzzer.
2021-03-20 18:51:18 +00:00
Alastair Donaldson
75d7c14cfb
spirv-fuzz: Remove AddType methods from fuzzerutil (#4204)
Types should only be added to the module by spirv-fuzz via
transformations, so this change removes the AddType methods from
fuzzerutil, which were only called once each from the appropriate
transformation.

The transformations have been adapted so that they avoid redundantly
invalidating all analyses - they now update the def-use manager and
invalidate only the type manager.
2021-03-20 08:54:51 +00:00
sfricke-samsung
f2a19b0150
spirv-val: Refactor of atomic pass (#4200) 2021-03-19 09:23:02 -04:00
sfricke-samsung
8f421ced3e
spirv-val: Label VUID 04643 (#4202) 2021-03-19 09:02:48 -04:00
sfricke-samsung
2b0d16a059
spirv-val: Label VUID 04667 (#4201) 2021-03-19 08:57:36 -04:00
Alastair Donaldson
a732e4c03c
spirv-fuzz: Apply fuzzer pass before checking exit conditions (#4199)
Fixes #4198.
2021-03-19 05:32:54 +00:00
sfricke-samsung
a611be7782
spirv-val: Fix Int64Atomics check (#4192) 2021-03-18 10:50:16 -04:00
sfricke-samsung
c040bd3ae5
spirv-val: Add Vulkan Execution Scope checks (#4183)
* spirv-val: Add Vulkan Execution Scope checks
2021-03-17 10:00:11 -04:00
Alastair Donaldson
8866fd7ae2
spirv-fuzz: Locate instructions more efficiently (#4189)
Avoids redundantly searching the whome module when locating an
instruction from its descriptor - instead, only the block containing
the instruction needs to be searched.
2021-03-17 09:28:57 +00:00
Alastair Donaldson
db2a706467
spirv-fuzz: Make adding equation instructions more efficient (#4190)
Avoids unnecessary invalidation of analyses.
2021-03-17 09:28:46 +00:00
Alastair Donaldson
e8ab7101f6
spirv-fuzz: Make PermutePhiOperands more efficient (#4191)
Amends def-use information rather than invalidating all analyses in
TransformationPermutePhiOperands.
2021-03-17 09:28:36 +00:00
Jaebaek Seo
79ab273f99
Accept OpImageTexelPointer user in scalar-replacement (#4187)
We have to conduct the scalar replacement for an aggregate with an image
type even when it has OpImageTexelPointer users.
2021-03-16 16:40:51 -04:00
sfricke-samsung
042eff73fe
spirv-val: Add Vulkan Invocation Sematics check (#4182) 2021-03-16 10:53:37 -04:00
sfricke-samsung
03f23106c6
spirv-val: Label VUID 04634 (#4181) 2021-03-16 10:53:27 -04:00
David Neto
4100477e76
Support SPV_KHR_linkonce_odr, SPV_KHR_expect_assume (#4161)
* SPV_KHR_linkonce_odr

Covers:
- Assembler
- Disassembler
- Validator

* Support SPV_KHR_expect_assume

Covers:
- assembler
- disassembler
- validation
2021-03-16 09:51:59 -04:00
Alastair Donaldson
478754c005
spirv-fuzz: Avoid invalidating analyses (#4176)
The performance of spirv-fuzz is sometimes poor due to analyses being
conservatively invalidated. This can lead to quadratic time algorithms
when a fuzzer pass applies O(N) transformations, and where every
transformation e.g. depends on def-use analysis and invalidates
def-use analysis (because building def-use analysis is O(N)).

This change avoids invalidating analyses for certain transformations.
2021-03-14 01:53:21 +00:00
Corentin Wallez
9e93b165c7
Remove usage of std::iterator. (#4171)
This helper class was deprecated in C++17 and some compilers start
warning about it. Replaces usages of std::iterator with manual type
aliases.
2021-03-12 14:00:56 +00:00
Alastair Donaldson
f7cf3ec2a5
spirv-fuzz: Avoid unnecessary dependency (#4165)
The fuzzer library depended on CLIMessageConsumer, due to its explicit
use in a function. This change removes that dependency so that,
instead, a message consumer parameter is passed.
2021-03-10 15:37:14 +00:00
Corentin Wallez
4a59fd4763
Fix -Wextra-semi-stmt -Wsuggest-destructor-override -Wdeprecated-copy-dtor (#4164)
* Fix -Wextra-semi-stmt
* Fix -Wsuggest-destructor-override
* Fix -Wdeprecated-copy-dtor
2021-03-09 13:16:43 +00:00
sfricke-samsung
c6da5e343c
spirv-val: Vulkan 64-bit OpAtomicStore check (#4163) 2021-03-08 14:34:06 -05:00
Vasyl Teliman
e6a9f4e430
spirv-fuzz: Fix the bug in TransformationReplaceBranchFromDeadBlockWithExit (#4140)
Fixes #4136.
2021-03-05 14:27:37 +00:00
Vasyl Teliman
7d514cf1c7
spirv-fuzz: Fix PartialCount (#4159)
Fixes #4158.
2021-03-05 11:13:28 +00:00
Alastair Donaldson
f7043c0de6
spirv-fuzz: Handle Vulkan SPIR-V versions (#4156)
Fixes #4155.
2021-03-03 22:29:57 +00:00
Vasyl Teliman
43cfa9bc1d
spirv-fuzz: Add persistent state to the fuzzer (#4137)
Adds persistent state to the fuzzer so that it can be used as a custom
mutator for mutation-based fuzzing.
2021-03-03 15:34:53 +00:00
alan-baker
939bc02603
Require an OpSelectionMerge before an OpSwitch (#4154)
Fixes #4153

* OpSwitch is required to be preceeded by OpSelectionMerge
* Update newly invalid tests
2021-03-02 15:40:56 -05:00
seppala2
ef3290bbea
spirv-opt: Don't call GenerateCopy for mismatched image types (#4126)
Avoid an assertion that will cause some HLSL shader to fail.  They will be legalized by later passes that will do copy propagation.
2021-02-19 10:59:14 -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
dan sinclair
cfa1dadb1e
Update a few virtuals to overrides. (#4143)
These methods are overriding their base class, so switch to override
from virtual.
2021-02-10 13:21:38 -05:00
sfricke-samsung
f0c96f40c7
spriv-val: Vulkan image gather constant component (#4133) 2021-02-05 15:12:38 -05:00
sfricke-samsung
3ad7e5fcc0
spirv-val: Fix/Label UniformConstant VUID (#4134) 2021-02-05 09:57:00 -05:00
sfricke-samsung
f11f743481
spirv-val: Add Vulkan Invariant Decoration VUID (#4132) 2021-02-05 09:49:14 -05:00
sfricke-samsung
c91a25af13
spirv-val: label tests for VUID 04657 (#4119) 2021-02-02 10:54:26 -05:00
sfricke-samsung
d61a7d110d
spirv-val: Add Vulkan PSB64 convert VUID (#4122) 2021-02-01 10:39:44 -05:00
Steven Perron
297723d75a
Mark module as modified if convert-to-half removes decorations. (#4127)
* Mark module as modified if convert-to-half removes decorations.

If the convert-to-half pass does not change the body of the function,
but removes decorations, it returns that nothing changed.  This is
incorrect, and will be fixed.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/4117

* Update comment for RemoveDecorationsFrom
2021-01-28 15:53:34 -05:00
Jaebaek Seo
e8bd26e1f8
Set correct scope and line info for DebugValue (#4125)
The existing spirv-opt `DebugInfoManager::AddDebugValueForDecl()` sets
the scope and line info of the new added DebugValue using the scope and
line of DebugDeclare. This is wrong because only a single DebugDeclare
must exist under a scope while we have to add DebugValue for all the
places where the variable's value is updated. Therefore, we have to set
the scope and line of DebugValue based on the places of the variable
updates.

This bug makes
https://github.com/google/amber/blob/main/tests/cases/debugger_hlsl_shadowed_vars.amber
fail. This commit fixes the bug.
2021-01-28 12:57:35 -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
alan-baker
cc81f53d3d
Validate VK_KHR_zero_initialize_workgroup_memory (#4124)
* Allow OpConstantNull for Workgroup variable initializer in Vulkan
environment
* tests
2021-01-27 19:38:09 -05:00
sfricke-samsung
d71ac38b8e
spirv-val: Add Vulkan image gather offset VUID (#4118) 2021-01-27 19:37:45 -05:00
sfricke-samsung
a61600c763
spirv-val: Label Vulkan atomic semantics VUIDs (#4120) 2021-01-25 11:19:06 -05:00
sfricke-samsung
819117cd48
spirv-val: Label VUID 04662 (#4123) 2021-01-25 09:51:21 -05:00
sfricke-samsung
89ad2272ba
spirv-val: Label VUID 04683 (#4121) 2021-01-25 09:38:19 -05:00
sfricke-samsung
f37547c73a
spirv-val: Add Vulkan EXT builtins (#4115) 2021-01-20 10:40:31 -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
David Neto
56f8ed48ef
Validate Sampled=1 for Vulkan ImageQuerySizeLod, ImageQueryLevels, ImageQueryLod (#4103)
Also require image type parameter to OpTypeSampledImage to have
Sampled=0 or Sampled=1

Fixes #4102
2021-01-19 17:44:45 -05:00
sfricke-samsung
e25db023c4
spirv-val: Add Vulkan Memory Scope VUs (#4106)
* Fix test using Fragment execution
2021-01-19 08:37:42 -05:00
Ben Clayton
8383bd5d6f
Migrate all Kokoro build scripts over to use the docker VM image (#4114)
* Work around GCC-9 warning treated as error

```
../source/opt/instruction.h:101:23: error: '*((void*)& operand +32)' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  101 |     uint64_t result = uint64_t(words[0]);
```

* Migrate all Kokoro build scripts over to use the docker VM image

Required updating the NDK SDK and build scripts, as well as the check_copyright for handling 2021.
2021-01-18 13:36:26 -05:00
sfricke-samsung
ee39b5db5f
spirv-val: Add Vulkan Addressing Model check (#4107) 2021-01-15 09:35:17 -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
sfricke-samsung
b2cfc5d1ce
spirv-val: Vulkan atomic storage class (#4079)
* spirv-val: Vulkan atomic storage class

* Add PhysicalStorageBuffer
2021-01-14 09:41:18 -05:00
Jaebaek Seo
cec658c116
Avoid integrity check failures caused by propagating line instructions (#4096)
Propagating the OpLine/OpNoLine to preserve the debug information
through transformations results in integrity check failures because of
the extra line instructions. This commit lets spirv-opt skip the
integrity check when the code contains OpLine or OpNoLine.
2021-01-13 09:08:28 -05:00
Pierre Moreau
b1507d0d2b
Linker usability improvements (#4084)
* tools/linker: Error out on unrecognized options

Fixes #4083.

* tools/linker: Use early returns when parsing options

This was already the case for some linker options, and other tools were
doing so for all of their options.

* tools/linker: Rework the usage output

* The new formatting for long options taking a value makes it explicit
  that there is no equal sign between the option name and the value.
* The options are sorted by lexicographical order.
* Change the option formatting from 90 columns to 80, to match the other
  tools.

* tools/linker: Change the default environment to spv1.5

* tools/linker: Change the default output to spv.out

Instead of writing to the standard output when the "-o" option is not
specified, the resulting linked SPIR-V binary will be written to
"spv.out".
One can still have the output sent to the standard output by specifying
"-o -".

* tools/linker: Update the reported target for --version

Running `spirv-link --version` will now report the currently selected
environment.

* tools/linker: Sort header includes

* linker: Improve module-related error messages

* Use 1-based indexing of modules;
* Say which module could not be built;
* Use the correct total number of input modules in the error message
  when one fails to build.
2021-01-13 09:05:40 -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
sfricke-samsung
ad77ed7a8d
spirv-val: Label standalone Vulkan VUID (#4091) 2021-01-07 09:00:05 -05:00
sfricke-samsung
aa005e8bd4
spirv-val: Add Vulkan decroation VUID (#4090) 2021-01-06 14:30:56 -05:00
Steven Perron
4ed1f4fce9
Fix binding number calculation in desc sroa (#4095)
When there is an array of strutured buffers, desc sroa will only split
the array, but not a struct type in the structured buffer.  However,
the calcualtion of the number of binding a struct requires does not take
this into consideration.  This commit will fix that.
2021-01-06 13:59:04 -05:00
sfricke-samsung
94d1a80159
spirv-val: Add Vulkan FP Mode VUID (#4088) 2021-01-06 12:45:28 -05:00
sfricke-samsung
6d05ed8410
spirv-val: Fix Vulkan image sampled check (#4085)
* Fix SampledType logic
2021-01-06 12:36:13 -05:00
sfricke-samsung
37c03859de
spirv-val: Add Vulkan ForwardPointer VUID (#4089) 2021-01-06 11:26:58 -05:00
sfricke-samsung
d630e5f8c1
spirv-val: Add Vulkan ImageTexelPointer format check (#4087) 2021-01-06 08:51:15 -05:00
sfricke-samsung
1bb80d2778
spirv-val: Add Vulkan Group Operation VUID (#4086) 2021-01-05 09:51:07 -05:00
sfricke-samsung
17ffa89097
spirv-val: Add first StandAlone VUID 04633 (#4077) 2020-12-17 13:51:17 -05:00
sfricke-samsung
8f4b35c332
spirv-val: Add Subgroup VUIDs (#4074) 2020-12-17 08:37:43 -05:00
Alastair Donaldson
4e31fdd4aa
spirv-fuzz: Fix OpPhi handling in DuplicateRegionWithSelection (#4065)
Avoid generating OpPhi on void types, and allow the transformation to
take place on regions that produce pointer and sampled image result
ids if such ids are not used after the region.

Fixes #3787.
2020-12-17 11:45:52 +00:00
David Neto
ad898cb949
validation: validate return type of OpImageRead (#4072)
Vulkan: must be 4-element vector
WebGPU: must be 4-element vector
OpenCL:
- must be scalar float for depth image
- must be 4-element vector otherwise
2020-12-15 12:00:59 -05:00
David Neto
305caff2eb
validation: tighter validation of multisampled images (#4059)
* validation: tighter validation of multisampled images

- if MS=1, then Sample image operand is required
- Sampling operations are not permitted when MS=1

Fixes #4057, #4058

* Fail early for multisampled image for sampling, dref, gather
2020-12-14 14:45:48 -05:00
David Neto
a0370efd58
validate OpTypeImage Sampled values for environemnts (#4064)
Fixes #4063
2020-12-10 17:15:46 -05:00
David Neto
7170218b8d
validate StorageImageMultisampled capability (#4062)
* validate StorageImageMultisampled capability

The StorageImageMultisampled capability is required when declaring
an image type with with Multisampled==1 and it's a storage image (Sampled == 2)

Fixes #4061

* Allow SubpassData with Multisampled and Sampled==2
2020-12-10 10:40:46 -05:00
sfricke-samsung
3b85234542
spirv-val: Add last TessLevelOuter and TessLevelInner VUID (#4055) 2020-12-08 14:38:55 -05:00
sfricke-samsung
171290703a
spirv-val: Add last ClipDistance and CullDistance VUID (#4054) 2020-12-08 14:37:24 -05:00
sfricke-samsung
1a6b4053fa
spirv-val: Add last ViewportIndex and Layer VUID (#4053) 2020-12-08 14:34:51 -05:00
sfricke-samsung
9df5225e67
spirv-val: Add last Position VUID (#4052) 2020-12-08 14:31:40 -05:00
alan-baker
862d44a86e
Allow forward pointer to be used in types generally (#4044)
Fixes #4042

* Allow types to have forward declarations as long as that declaration
  is an OpTypeForwardPointer
2020-12-08 08:46:47 -05:00
Marijn Suijten
bda102d7a7
opt: Run DCE when SPV_KHR_shader_clock is used (#4049)
Similar to [1] DCE should be ran when this extension is enabled to
prevent unused bindings from showing up (in particular atomic counters
attached to buffers).

[1]: https://github.com/KhronosGroup/SPIRV-Tools/pull/4047
2020-12-07 14:42:25 -05:00
Ehsan
cd05078662
Take new (raytracing) termination instructions into account. (#4050)
* Take new (raytracing) termination instructions into account.

* Remove duplicate function and add unit test.

* Use KHR for symbols in the test.
2020-12-07 10:26:05 -05:00
Ehsan
10e0ae7946
Do run DCE if SPV_KHR_ray_query is used. (#4047) 2020-12-02 18:46:19 -05:00
greg-lunarg
c1d5a045f6
Change ref_analysis to RefAnalysis to follow coding standards. (#4045) 2020-12-01 19:16:49 -05:00
Steven Perron
c502a15f25
Handle 8-bit index in elim dead member (#4043)
The eliminate dead member pass is written assuming that the index to an
OpAccessChain will be a 32-bit integer or 64-bit integer.  That is
changed to work for any width 64-bits or less.

Fixes https://crbug.com/1151727
2020-12-01 14:48:25 -05:00
Daniel Koch
32573bb216
Add validation support for the ray tracing built-in variables (#4041)
* Add validation for ray tracing builtins

- Remove existing InstanceId testing that was combined with VertexId in awkward ways.
- Rather than adding a new set of functions for each ray tracing builtin, add
  an error table that maps the builtin ID to the 3 common VUIDs for each builtin
  (I could see this being extended for other builtins in the future).
- add F32 matrix validation function
- augment existing PrimitiveId validation to verify Input storage class for the
  RT stages this is accepted in, and correct the list of stages that it is actually
  accepted in (only Intersection / Any Hit / Closest Hit)

* add testing for ray tracing builtins

- remove exising InstanceId testing as it was tangled in with VertexId in now weird ways
  and combine it with the new tests
- add testing for ray tracing builtins
- builtins accepted in the same stages and of the same types are combined into test functions
- add some new matrix types to the code generator so they can be used for testing
2020-12-01 11:42:37 -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
Alastair Donaldson
1299436c8f
Reject SPIR-V that applies void to OpUndef, OpCopyObject, OpPhi (#4036)
Fixes #4035.
2020-11-27 16:31:04 +00:00
David Neto
2c458414c0
BuildModule: optionally avoid adding new OpLine instructions (#4033)
* BuildModule: optionally avoid adding new OpLine instructions

Fixes #4029 for my use case

* Fix formatting

* Create last_line_inst_ only if doing extra line tracking
2020-11-25 14:54:32 -05:00
David Neto
a79aa038ec
Remove prototype for unimplemented method (#4031) 2020-11-25 13:47:38 -05:00
Alastair Donaldson
b0e22d28f5
spirv-fuzz: Fix facts arising from CompositeConstruct (#4034)
Fixes #4023.
2020-11-25 12:03:05 +00:00
Alastair Donaldson
5ffa320fee
spirv-fuzz: Do not flatten conditionals that create synonyms (#4030)
Fixes #4024.
2020-11-24 20:18:23 +00:00
David Neto
cd590fa334
Update MeshShadingNV dependencies (and land Ray tracing updates) (#4028)
* Update to final ray tracing extensions

Drop Provisional from ray tracing enums
    sed -ie 's/RayQueryProvisionalKHR/RayQueryKHR/g' **/*
    sed -ie 's/RayTracingProvisionalKHR/RayTracingKHR/g' **/*
Add terminator support for SpvOpIgnoreIntersectionKHR and SpvOpTerminateRayKHR
Update deps for SPIRV-Headers

* Update capability dependencies for MeshShadingNV

Accommodate https://github.com/KhronosGroup/SPIRV-Headers/pull/180

MeshShadingNV: enables PrimitiveId, Layer, and ViewportIndex

Co-authored-by: Daniel Koch <dkoch@nvidia.com>
2020-11-23 12:23:54 -05:00
greg-lunarg
671914c28e
Fix buffer oob instrumentation for matrix refs (#4025)
Fix buffer oob instrumentation for matrix refs.

Matrix stride decoration is not on matrix type but is a member decoration
on the enclosing struct type. Also correctly apply matrix stride depending
on row or column major.
2020-11-18 12:39:15 -05:00
Alastair Donaldson
1f2fcddd39
spirv-opt: Set parent when adding basic block (#4021)
Ensures that the parent of a block is set in Function::AddBasicBlock.
Removes various now unnecessary calls to BasicBlock::SetParent.

Fixes #3912.
2020-11-13 12:33:15 -05:00
Jaebaek Seo
f686518cee
spirv-opt: properly preserve DebugValue indexes operand (#4022)
spirv-opt has a bug that `DebugInfoManager::AddDebugValueWithIndex()` does not
preserve `Indexes` operands of
[DebugValue](https://www.khronos.org/registry/spir-v/specs/unified1/OpenCL.DebugInfo.100.html#DebugValue).
It has to preserve all of those `Indexes` operands, but it preserves only the first index
operand.

This PR removes `DebugInfoManager::AddDebugValueWithIndex()` and lets the spirv-opt
use `DebugInfoManager::AddDebugValueForDecl()`.
`DebugInfoManager::AddDebugValueForDecl()` preserves the Indexes operand correctly.
2020-11-13 12:06:38 -05:00
David Neto
1cda495274
Use less stack space when validating Vulkan builtins (#4019)
Don't pass a constructed string as an argument to
ValidateNotCalledwithExecutionModel. That method is captured via
std::bind and it ends up using lots of stack space.
Instead, pass in:
- a Vulkan validation unique ID as an integer instead,
  (with -1 meaning no VUID), and
- the const char* for the explanator text.
2020-11-11 13:29:28 -05:00
sfricke-samsung
a61d07a727
spirv-val: Fix SPV_KHR_fragment_shading_rate VUID label (#4014)
in 3943 the new tests should have failed, but didn't due to the AnyVUID
check not handling case with trailing whitespace. Added trimming to handle
it as easily might happen again in future
2020-11-05 13:04:47 -05:00
sfricke-samsung
650acb575b
spirv-val: Label Layer and ViewportIndex VUIDs (#4013) 2020-11-05 13:04:07 -05:00
alan-baker
0c036df288
Add dead function elimination to -O (#4015)
Fixes #4003

Both legalization and size formulae already run dead function
elimination after inlining. This change does the same for performance
passes.
2020-11-05 13:03:45 -05:00
Jaebaek Seo
c2b2b57885
Add DebugValue for invisible store in single_store_elim (#4002)
The front-end language compiler would simply emit DebugDeclare for
a variable when it is declared, which is effective through the variable's
scope. Since DebugDeclare only maps an OpVariable to a local variable,
the information can be removed when an optimization pass uses the
loaded value of the variable. DebugValue can be used to specify the
value of a variable. For each value update or phi instruction of a variable,
we can add DebugValue to help debugger inspect the variable at any
point of the program execution.
For example,

float a = 3;
... (complicated cfg) ...
foo(a); // <-- variable inspection: debugger can find DebugValue of `float a` in the nearest dominant

For the code with complicated CFG e.g., for-loop, if-statement, we
need help of ssa-rewrite to analyze the effective value of each variable
in each basic block.

If the value update of the variable happens only once and it dominates
all its uses, local-single-store-elim pass conducts the same value update
with ssa-rewrite and we have to let it add DebugValue for the value assignment.

One main issue is that we have to add DebugValue only when the value
update of a variable is visible to DebugDeclare. For example,

```
{  // scope1
   %stack = OpVariable %ptr_int %int_3
   {  // scope2
       DebugDeclare %foo %stack    <-- local variable "foo" in high-level language source code is declared as OpVariable "%stack"
       // add DebugValue "foo = 3"
       ...
       Store %stack %int_7   <-- foo = 7, add DebugValue "foo = 7"
       ...
       // debugger can inspect the value of "foo"
    }
    Store %stack %int_11   <-- out of "scope2" i.e., scope of "foo". DO NOT add DebugValue "foo = 11"
}
```

However, the initalization of a variable is an exception.
For example, an argument passing of an inlined function must be done out of
the function's scope, but we must add a DebugValue for it.

```
// in HLSL
bar(float arg) { ... }
...
float foo = 3;
bar(foo);

// in SPIR-V
%arg = OpVariable
OpStore %arg %foo   <-- Argument passing. Out of "float arg" scope, but we must add DebugValue for "float arg"
... body of function bar(float arg) ...
```

This PR handles the except case in local-single-store-elim pass. It adds
DebugValue for a store that is considered as an initialization.

The same exception handling code for ssa-rewrite is done by this commit: df4198e50e.
2020-11-04 13:43:59 -05:00
Diego Novillo
c74d5523bb
Fix SSA re-writing in the presence of variable pointers. (#4010)
This fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/3873.

In the presence of variable pointers, the reaching definition may be
another pointer.  For example, the following fragment:

 %2 = OpVariable %_ptr_Input_float Input
%11 = OpVariable %_ptr_Function__ptr_Input_float Function
      OpStore %11 %2
%12 = OpLoad %_ptr_Input_float %11
%13 = OpLoad %float %12

corresponds to the pseudo-code:

layout(location = 0) in flat float *%2
float %13;
float *%12;
float **%11;
*%11 = %2;
%12 = *%11;
%13 = *%12;

which ultimately, should correspond to:

%13 = *%2;

During rewriting, the pointer %12 is found to be replaceable by %2.
However, when processing the load %13 = *%12, the type of %12's reaching
definition is another float pointer (%2), instead of a float value.

When this happens, we need to continue looking up the reaching definition
chain until we get to a float value or a non-target var (i.e. a variable
that cannot be SSA replaced, like %2 in this case since it is a function
argument).
2020-11-04 10:23:53 -05:00
Alastair Donaldson
02195a029c
spirv-fuzz: Fixes to pass management (#4011) 2020-11-04 10:45:53 +00:00
Alastair Donaldson
bcf5b211db
spirv-fuzz: Add support for reining in rogue fuzzer passes (#3987)
Adds some functions that allow a fuzzer pass to check whether it is
spiralling out of control and exit early.  The fuzzer pass for adding
bit instruction synonyms now uses this.  Also make many methods in
FuzzerContext const.
2020-11-03 16:51:10 +00:00
Vasyl Teliman
7d250ed510
spirv-fuzz: Fix assertion failure in FuzzerPassAddCompositeExtract (#3995) 2020-11-03 15:09:36 +00:00
Vasyl Teliman
f9937bcc83
spirv-fuzz: Fix invalid equation facts (#4009)
Fixes #4008.
2020-11-03 15:06:55 +00:00
Vasyl Teliman
aa6035f1c6
spirv-fuzz: Fix bugs in TransformationFlattenConditionalBranch (#4006)
Fixes #4005.
Fixes #3993.
2020-11-03 15:03:08 +00:00
André Perez
5735576f87
spirv-fuzz: Fix bug related to transformation applicability (#3990)
This PR fixes a bug related to the transformation applicability.
When the OpNot case was implemented, its opcode was not
added to the list of supported bit instructions in IsApplicable.
So, the changes made are the following.

- Add OpNot to the list of supported bit instructions.
- Update the tests.
2020-11-03 10:48:30 +00: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
Junda Liu
82b378d671
spirv-opt: Add support to prevent functions from being inlined if they have DontInline flag (#3858)
This commit add support for optimizer to not inline functions with DontInline control flag, so that the [noinline] attribute in HLSL will be useful in DXC SPIR-V generation.

This is part of work of github.com/microsoft/DirectXShaderCompiler/issues/3158
2020-10-29 16:38: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
Ben Clayton
7403dfafd8
CMake: Add SPIRV_TOOLS_BUILD_STATIC flag (#3910)
If enabled the following targets will be created:

* `${SPIRV_TOOLS}-static` - `STATIC` library. Has full public symbol visibility.
* `${SPIRV_TOOLS}-shared` - `SHARED` library. Has default-hidden symbol visibility.
* `${SPIRV_TOOLS}`        - will alias to one of above, based on BUILD_SHARED_LIBS.

If disabled the following targets will be created:

* `${SPIRV_TOOLS}`        - either `STATIC` or `SHARED` based on the new `SPIRV_TOOLS_LIBRARY_TYPE` flag. Has full public symbol visibility.
* `${SPIRV_TOOLS}-shared` - `SHARED` library. Has default-hidden symbol visibility.

Defaults to `ON`, matching existing build behavior.

This flag can be used by package maintainers to ensure that all libraries are built as shared objects.
2020-10-29 09:25:26 -04:00
David Neto
25ee275763
Avoid copying a ref in a loop (#4000)
Avoid triggering a warning from newer Clang, which turns into an error
on macOS.
2020-10-29 09:20:45 -04:00
Sidney Just
5edb328e81
spirv-val: Allow the ViewportIndex and Layer built-ins on SPIR-V 1.5 (#3986)
* spirv-val: Allow the ViewportIndex and Layer built-ins when their corresponding SPIR-V 1.5 capabilities are present
* Added tests for OpCapability ShaderViewportIndex and OpCapability ShaderLayer
2020-10-28 14:05:06 -04:00
Diego Novillo
cbd1fa6c42
Simplify logic to decide whether CCP modified the IR (#3997)
Simplify logic to decide whether CCP modified the IR.

The previous attempts at fixing this issue relied on marking the IR
changed only when CCP was able to fold an instruction during
propagation (https://github.com/KhronosGroup/SPIRV-Tools/pull/3799,
https://github.com/KhronosGroup/SPIRV-Tools/pull/3732).

Those fixes missed the case described in
https://github.com/KhronosGroup/SPIRV-Tools/issues/3991.  In this case,
the folder never actually succeeds in folding the instruction, but it
does create constants in the process.

Fixed with this change.
2020-10-28 10:18:34 -04:00
Jaebaek Seo
df4198e50e
Add DebugValue for DebugDecl invisible to value assignment (#3973)
For some cases, we have DebugDecl invisible to a value assignment, but
the value assignment information is important i.e., debugger cannot inspect
the variable without the information. For example, a parameter of an inlined
function must have its value assignment i.e., argument passing out of its
function scope. If we simply remove DebugDecl because it is invisible to the
argument passing, we cannot inspec the variable.

This PR
- Adds DebugValue for DebugDecl invisible to a value assignment. We use
the value of the variable in the basic block that contains DebugDecl, which is
found by ssa-rewrite. If the value instruction does not dominate DebugDecl,
we use the value of the variable in the immediate dominator of the basic block.
- Checks the visibility of DebugDecl for Phi value assignment based on the
all value operands of the Phi. Since Phi just references multiple values from
multiple basic blocks, scopes of value operands must be regarded as the scope
of the Phi.
2020-10-27 15:10:08 -04:00
greg-lunarg
34ae8a4757
Fix bounds check instrumentation to handle 16-bit values (#3983) 2020-10-26 09:31:35 -04:00
André Perez
abe2eff36f
spirv-fuzz: Add expand vector reduction transformation (#3869)
The following implementations are introduced:

- Transformation and fuzzer pass for expanding vector reduction.
- Unit tests to cover the instructions with different vector sizes.

Fixes #3768.
2020-10-23 14:59:08 +01:00
Vasyl Teliman
99ad4f1e29
spirv-fuzz: Don't replace irrelevant indices in OpAccessChain (#3988)
Part of #3980.
2020-10-23 14:52:22 +01:00
Vasyl Teliman
895dafcc1d
spirv-fuzz: Add FuzzerPassAddCompositeExtract (#3904)
Fixes #3806.
2020-10-23 14:49:50 +01:00
Alastair Donaldson
69f07da41b
spirv-fuzz: Fix mismatch with shrinker step limit (#3985)
Fixes #3984.
2020-10-22 23:23:59 +01:00
Alastair Donaldson
9223493f4d
spirv-fuzz: Fix off-by-one error in replayer (#3982)
Fixes #3981.
2020-10-22 20:07:09 +01:00
Alastair Donaldson
4f5423187d
spirv-fuzz: Get order right for OpSelect arguments (#3974)
Fixes #3948.
2020-10-22 16:05:51 +01:00
Alastair Donaldson
88f7bcb6af
spirv-fuzz: Do not add synonym-creating loops in dead blocks (#3975)
Fixes #3954.
2020-10-22 12:07:49 +01:00
Alastair Donaldson
64eaa9832f
spirv-fuzz: Skip OpTypeSampledImage when propagating up (#3976)
Fixes #3959.
2020-10-22 12:07:17 +01:00
Alastair Donaldson
53f2a69c19
spirv-fuzz: Pass OpUndef in function call if needed (#3978)
Fixes #3977.
2020-10-22 12:06:54 +01:00
Alastair Donaldson
de2c0ba202
spirv-fuzz: Fix off-by-one in TransformationCompositeConstruct (#3979) 2020-10-22 12:06:37 +01:00
Alastair Donaldson
dc4a182282
spirv-fuzz: Tolerate absent ids in data synonym fact management (#3966)
Fixes #3952.
2020-10-22 00:06:53 +01:00
Alastair Donaldson
8496780f57
spirv-fuzz: Fix to id availability (#3971)
Fixes #3958.
2020-10-21 22:52:47 +01:00
Alastair Donaldson
3b7aebca45
spirv-fuzz: Fix operand types (#3962)
Fixes #3945.
Fixes #3946.
2020-10-21 22:41:30 +01:00
Alastair Donaldson
a8d7062fe5
spirv-fuzz: Don't flatten conditional if condition is irrelevant (#3944)
Fixes #3942.
2020-10-21 21:26:59 +01:00
Alastair Donaldson
a3d5378df6
spirv-fuzz: Do not produce OpPhis of type OpTypeSampledImage (#3964)
Also removes some redundant validity checks in tests.

Fixes #3950.
2020-10-21 21:12:19 +01:00
Alastair Donaldson
7edd0525b9
spirv-fuzz: Restrict fuzzer pass to reachable blocks (#3970) 2020-10-21 20:52:58 +01:00
Alastair Donaldson
f03779a1a1
spirv-fuzz: Handle more types when extending OpPhi instructions (#3969)
Fixes #3953.
2020-10-21 20:52:36 +01:00
Alastair Donaldson
c794b70461
spirv-fuzz: Skip early terminator wrappers when merging returns (#3968)
Fixes #3955.
2020-10-21 20:51:10 +01:00
Alastair Donaldson
dc9c6407d6
spirv-fuzz: Avoid irrelevant constants in synonym-creating loops (#3967)
Fixes #3956.
2020-10-21 20:50:45 +01:00
Alastair Donaldson
26954c281e
spirv-fuzz: Skip dead blocks in FuzzerPassAddOpPhiSynonyms (#3965)
Fixes #3949.
2020-10-21 20:49:33 +01:00
Alastair Donaldson
5600fb85b6
spirv-fuzz: Avoid the type manager when looking for struct types (#3963)
Fixes #3947.
2020-10-21 18:28:05 +01:00
Alastair Donaldson
ba15b58862
spirv-fuzz: Fix to TransformationDuplicateRegionWithSelection (#3941)
Also incorporates a few style fixes.

Fixes #3940.
2020-10-20 18:59:53 +01:00
Alastair Donaldson
5984350044
spirv-fuzz: Skip OpFunction when replacing irrelevant ids (#3932)
Fixes #3927.
2020-10-20 18:58:42 +01:00
Alastair Donaldson
8362eae552
spirv-fuzz: Use component-wise selectors when flattening conditional branches (#3921)
Fixes #3920.
2020-10-20 18:57:56 +01:00
Tobski
ebe0ea09f0
Add SPV_EXT_shader_image_int64 (#3852)
* Add SPV_EXT_shader_image_atomic_int64
* Added 64-bit image tests


Co-authored-by: Arkadiusz Sarwa <arkadiusz.sarwa@amd.com>
2020-10-20 11:55:26 -04:00
Tobski
a1d38174b1
Support SPV_KHR_fragment_shading_rate (#3943) 2020-10-20 08:00:13 -04:00
Alastair Donaldson
6fac705e76
spirv-val: Fix validation of OpPhi instructions (#3919)
Fixes #3918.
2020-10-19 17:36:21 +01:00
Alastair Donaldson
b1350659b6
spirv-fuzz: Avoid void struct member when outlining functions (#3936)
Fixes #3935.
2020-10-19 17:34:31 +01:00
Alastair Donaldson
fd0f295da6
spirv-fuzz: Do not allow Block-decorated structs when adding parameters (#3931)
Fixes #3929.
2020-10-19 17:34:04 +01:00
Alastair Donaldson
5d7893b376
spirv-fuzz: Fix to operand id type (#3937)
Fixes #3934.
2020-10-19 17:33:25 +01:00
Alastair Donaldson
cd1d3b6e0c
spirv-fuzz: Handle dead blocks in TransformationEquationInstruction (#3933)
Fixes #3926.
2020-10-19 17:32:56 +01:00
Alastair Donaldson
6cdae9da72
spirv-fuzz: Do not allow sampled image load when flattening conditionals (#3930)
Fixes #3928.
2020-10-19 17:32:26 +01:00
Alastair Donaldson
7e1825a596
spirv-fuzz: Take care of OpPhi instructions when inlining (#3939)
Fixes #3938.
2020-10-19 09:41:01 +01:00
Alastair Donaldson
502e982956
spirv-fuzz: Fix to TransformationInlineFunction (#3913)
This fixes a problem where TransformationInlineFunction could lead to
distinct instructions having identical unique ids. It adds a validity
check to detect this problem in general.

Fixes #3911.
2020-10-16 22:58:09 +01:00
Alastair Donaldson
bf1a11dab7
spirv-fuzz: Wrap early terminators before merging returns (#3925)
Incorporates some other fixes for issues that were brought to light by
adding this functionality.

Fixes #3717.
Fixes #3924.
2020-10-16 19:29:39 +01:00
Jaebaek Seo
fd3948e161
Add DebugValue for function param regardless of scope (#3923)
`DebugInfoManager::AddDebugValueIfVarDeclIsVisible()` adds
OpenCL.DebugInfo.100 DebugValue from DebugDeclare only when the
DebugDeclare is visible to the give scope. It helps us correctly
handle a reference variable e.g.,

{ // scope #1.
  int foo = /* init */;
  { // scope #2.
    int& bar = foo;
    ...

in the above code, we must not propagate DebugValue of `int& bar` for
store instructions in the scope #1 because it is alive only in
the scope #2.

We have an exception: If the given DebugDeclare is used for a function
parameter, `DebugInfoManager::AddDebugValueIfVarDeclIsVisible()` has
to always add DebugValue instruction regardless
of the scope. It is because the initializer (store instruction) for
the function parameter can be out of the function parameter's scope
(the function) in particular when the function was inlined.

Without this change, the function parameter value information always
disappears whenever we run the function inlining pass and
`DebugInfoManager::AddDebugValueIfVarDeclIsVisible()`.
2020-10-16 10:18:41 -04:00
Alastair Donaldson
dd534e877e
spirv-fuzz: Lower probability of adding bit instruction synonyms (#3917)
Fixes #3914.
2020-10-15 15:20:05 +01:00
Alastair Donaldson
53aeba10cd
spirv-fuzz: Fix handling of OpPhi in FlattenConditionalBranch (#3916)
Fixes #3915.
2020-10-15 14:41:23 +01:00
Alastair Donaldson
5c64374dd6
spirv-fuzz: Avoid creating blocks without parents (#3908)
The validity check during fuzzing and in unit tests is strengthened to
require that every block has its enclosing function as its parent.
TransformationMergeFunctionReturns is fixed so that it ensures parents
are set appropriately.

Fixes #3907.
2020-10-13 19:48:18 +01:00
Alastair Donaldson
57b3723c5c
spirv-fuzz: Do not allow creation of constants of block-decorated structs (#3903)
Fixes #3902.
2020-10-13 18:35:41 +01:00
Alastair Donaldson
12ca825a60
spirv-fuzz: Fixes related to irrelevant ids (#3901)
Fixes #3899.
Fixes #3900.
2020-10-13 18:01:42 +01:00
Alastair Donaldson
2e6cf706ee
spirv-fuzz: Fix to transformation that adds a synonym via a loop (#3898)
Fixes #3897.
2020-10-13 14:26:47 +01:00
Alastair Donaldson
4b884928db
spirv-fuzz: Fix to duplicate region with selection (#3896)
Fixes #3895.
2020-10-13 14:25:43 +01:00
Alastair Donaldson
c2553a315f
spirv-fuzz: Do not expose synonym facts for non-existent ids (#3891)
Fixes #3888.
2020-10-09 07:18:46 +01:00
Alastair Donaldson
3602287858
spirv-fuzz: Do not add synonyms involving irrelevant ids (#3890)
Fixes #3886.
2020-10-08 22:34:39 +01:00
Alastair Donaldson
d52f79122a
spirv-fuzz: Do not replace irrelevant ids that are not in blocks (#3892)
Fixes #3889.
2020-10-08 22:33:46 +01:00
Alastair Donaldson
e022659922
spirv-fuzz: Wrap OpKill and similar in function calls (#3884)
Part of #3717.
2020-10-08 22:33:14 +01:00
dan sinclair
11d5924227
Update val to handle reversed instruction sections. (#3887)
Currently the validator, when checking an instruction is in the correct
section, always advances the current section. This means if we have an
instruction from a previous section we'll end up reporting it as invalid
in a function definition. This error is confusing.

This CL updates the validator to check if the given opcode is from a
previous layout section before advancing the current section. If it is
from a previous layout section an error is emitted.
2020-10-08 13:10:12 -04:00
Alastair Donaldson
fc8264854c
spirv-fuzz: Replace dead-block terminators with OpKill etc. (#3882)
Fixes #3615.
2020-10-06 15:59:05 +01:00
Vasyl Teliman
63cc22d645
spirv-fuzz: TransformationPropagateInstructionDown (#3692)
Fixes #3691.
2020-10-06 13:38:19 +01:00
Alastair Donaldson
65b2a9e814
spirv-fuzz: Transformation to add wrappers for OpKill and similar (#3881)
Part of #3717.
2020-10-06 12:07:56 +01:00
Alastair Donaldson
624b16cd0c
spirv-fuzz: Use overflow ids when duplicating regions (#3878)
Fixes #3786.
2020-10-06 12:07:20 +01:00
Vasyl Teliman
bd0dd9cef1
spirv-fuzz: Fix rvalue references (#3883)
Fixes #3659.
2020-10-06 12:06:53 +01:00
Alastair Donaldson
f151337880
spirv-fuzz: Avoid using block-decorated structs in transformations (#3877)
Fixes #3875.
2020-10-02 20:01:08 +01:00
Alastair Donaldson
0e85530728
spirv-fuzz: Use overflow ids when inlining functions (#3880)
Fixes #3751.
2020-10-02 16:53:54 +01:00
Jaebaek Seo
67f8e2eddc
Debug info preservation in convert-local-access-chains pass (#3835)
1. DebugValue/DebugDeclare references of load/store must not change
the behaviors of the convert-local-access-chains pass
2. We have to properly set the scope and line information of new
instructions made by the convert-local-access-chains pass
2020-10-02 10:45:24 -04:00
Alastair Donaldson
b920b620ad
spirv-fuzz: Integrate spirv-reduce with shrinker (#3849)
This extends shrinking so that spirv-reduce is employed to simplify
the functions that are added by TransformationAddFunction.
2020-10-02 04:53:12 +01:00
Alastair Donaldson
74a711a76d
spirv-fuzz: Only recommend passes when a pass had an effect (#3863)
Fixes #3817.
2020-10-02 04:48:39 +01:00
Stefano Milizia
fc7860e2db
spirv-fuzz: Merge the return instructions in a function (#3838)
This PR introduces TransformationMergeFunctionReturns, which changes
a function so that it only has one reachable return statement.

Fixes #3655.
2020-10-02 04:45:44 +01:00
Jaebaek Seo
57abfd88c5
Debug info preservation in redundancy-elimination pass (#3839)
* Debug info preservation in redundancy-elimination pass
2020-10-01 09:22:16 -04:00
Jaebaek Seo
e246038364
Debug info preservation in if-conversion pass (#3861)
* Debug info preservation in if-conversion pass
2020-10-01 09:20:27 -04:00
Vasyl Teliman
16cc197c8c
spirv-fuzz: Refactor conditions in the fact manager (#3867)
Refactors conditions and names of some methods in the fact manager. Part of #3698.
2020-10-01 11:48:47 +01:00
Vasyl Teliman
615fbe6cbc
spirv-fuzz: TransformationWrapRegionInSelection (#3674)
Fixes #3675.
2020-10-01 09:54:10 +01:00
Alastair Donaldson
f2b8a4ee51
spirv-fuzz: Enable some passes with high probability (#3860)
Fixes #3764.
2020-10-01 09:07:06 +01:00
Alastair Donaldson
50e04f6123
spirv-fuzz: Do not add constants for Block-decorated structs (#3862)
Fixes #3794.
2020-10-01 09:06:36 +01:00
Vasyl Teliman
8edd79ddcc
spirv-fuzz: Fix to FuzzerPassFlattenConditionalBranches (#3865)
Fixes #3864.
2020-10-01 09:06:00 +01:00
Vasyl Teliman
719bade4ff
spirv-fuzz: Fix TransformationRecordSynonymousConstants (#3868)
Fixes #3866.
2020-09-30 17:05:10 +01:00
Alastair Donaldson
009facc978
spirv-fuzz: Fix flatten conditional branch transformation (#3859)
Fixes #3850.
2020-09-30 11:43:40 +01:00
Alastair Donaldson
fcb22ecf0f
spirv-fuzz: Report fresh ids in transformations (#3856)
Adds a virtual method, GetFreshIds(), to Transformation. Every
transformation uses this to indicate which ids in its protobuf message
are fresh ids. This means that when replaying a sequence of
transformations the replayer can obtain a smallest id that is not in
use by the module already and that will not be used by any
transformation by necessity. Ids greater than or equal to this id
can be used as overflow ids.

Fixes #3851.
2020-09-29 22:12:49 +01: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
Maksim Ivanov
446adb05ff
Fix use-after-move in val/validate.cpp (#3848)
Fix a use-after-move (potential) bug found by the
"bugprone-use-after-move" clang-tidy check.

This is part of a Chromium-related effort (see
https://crbug.com/1122844).
2020-09-28 10:49:24 -04:00
Antoni Karpiński
4b07d50cd9
spirv-fuzz: Fix bug in TransformationDuplicateRegionWithSelection (#3819)
The following changes are introduced:

1. Entry block might have more than one predecessor, even if it is not
   a selection/loop merge block. However Apply method asserts that
   there is only one predecessor. Now, IsApplicable method ensures
   that there is only one predecessor.

2. In fuzzer pass we exclude both loop headers and selection headers
as potential exit blocks.

Fixes #3827.
2020-09-26 19:18:41 +01:00
André Perez
fec56146a7
spirv-fuzz: Support OpNot bit instruction case (#3841)
This PR implements the OpNot instruction for the
add bit instruction synonym transformation. In addition,
some code improvements have been made.
2020-09-26 10:42:46 +01:00
Alastair Donaldson
9e17b9d07a
spirv-fuzz: Return IR and transformation context after replay (#3846)
Before this change, the replayer would return a SPIR-V binary. This
did not allow further transforming the resulting module: it would need
to be re-parsed, and the transformation context arising from the
replayed transformations was not available. This change makes it so
that after replay an IR context and transformation context are
returned instead; the IR context can subsequently be turned into a
binary if desired.

This change paves the way for an upcoming PR to integrate spirv-reduce
with the spirv-fuzz shrinker.
2020-09-25 09:58:10 +01:00
Alastair Donaldson
9edeeafdb6
spirv-fuzz: Use unique_ptr<FactManager> in TransformationContext (#3844)
TransformationContext now holds a std::unique_ptr to a FactManager,
rather than a plain pointer. This makes it easier for clients of
TransformationContext to work with heap-allocated instances of
TransformationContext, which is needed in some upcoming work.
2020-09-24 17:28:49 +01:00
Vasyl Teliman
330c72549a
spirv-fuzz: Support dead blocks in TransformationAddSynonym (#3832)
Fixes #3830.
2020-09-24 14:18:07 +01:00
Vasyl Teliman
36185f8b09
spirv-fuzz: Move IRContext parameter into constructor (#3837)
This PR converts IRContext parameter in fact managers into a class field. Part of #3698.
2020-09-24 12:27:59 +01:00
Ryan Harrison
d1bb98fd48
Validate SPIRV Version number when parsing binary header (#3834)
Fixes #3831
2020-09-23 11:59:41 -04:00
Stefano Milizia
67525bded1
spirv-fuzz: Create synonym of int constant using a loop (#3790)
This transformation, given a constant integer (scalar or vector) C,
constants I and S of compatible type and scalar 32-bit integer constant
N, such that C = I - S*N, adds a loop which subtracts S from I, N
times, creating a synonym for C.

The related fuzzer pass randomly chooses constants to which to add
synonyms using this transformation, and the location where they should
be added.

Fixes #3616.
2020-09-23 14:10:02 +01:00
Richard S. Wright Jr
7cc4b4d2ca
Fix compiler error on macOS with XCode12 (#3836) 2020-09-22 19:12:23 -04:00
Vasyl Teliman
5a5b750aaf
spirv-fuzz: Handle OpPhis in TransformationInlineFunction (#3833)
Fixes #3829.
2020-09-22 21:35:56 +01:00
Alastair Donaldson
125b642419
spirv-fuzz: Refactor fuzzer, replayer and shrinker (#3818)
In preparation for some upcoming work on the shrinker, this PR changes
the interfaces of Fuzzer, Replayer and Shrinker so that all data
relevant to each class is provided on construction, meaning that the
"Run" method can become a zero-argument method that returns a status,
transformed binary and sequence of applied transformations via a
struct.

This makes greater use of fields, so that -- especially in Fuzzer --
there is a lot less parameter passing.
2020-09-22 10:07:58 +01: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
Stefano Milizia
2945963cce
spirv-fuzz: Consider all ids from dead blocks irrelevant (#3795)
This PR modifies the FactManager methods IdIsIrrelevant and GetIrrelevantIds so
that an id is always considered irrelevant if it comes from a dead block.

Fixes #3733.
2020-09-18 11:45:02 +01:00
Alastair Donaldson
50ae4c5f44
Fix header guard macros (#3811) 2020-09-18 05:37:30 +01:00
Antoni Karpiński
296e9c7bc8
spirv-fuzz: Fix TransformationDuplicateRegionWithSelection (#3815)
Introduces two changes:

- duplicated_exit_region refers to a correct block, regardless of the order
  of the blocks in the enclosing function.
- Exclude the case where the continue target is the exit block.
2020-09-18 05:36:08 +01:00
sfricke-samsung
937a757f04
spirv-val: Add DeviceIndex (#3812) 2020-09-17 08:27:40 -04:00
Ryan Harrison
34ef0c3fdc
Fix missed modification flagging (#3814)
Fixes #3813
2020-09-16 19:57:04 -04:00
André Perez
748edbf8c1
spirv-fuzz: Use an irrelevant id for the unused components (#3810)
Fixes #3808.
2020-09-16 21:23:32 +01:00
Stefano Milizia
8d49fb2f4d
spirv-fuzz: Improvements to random number generation (#3809)
This PR extends the RandomGenerator interface and fixes the
PseudoRandomGenerator class. It:

- Fixes a problem that made the RandomUint32 of PseudoRandomGenerator
  segfault.
- Adds the RandomUint64 function to RandomGenerator and
  PseudoRandomGenerator.

Fixes #3805.
2020-09-16 15:45:05 +01:00
greg-lunarg
7e28d809c6
Add buffer oob check to bindless instrumentation (#3800) 2020-09-16 09:23:46 -04:00
Vasyl Teliman
8fc504110a
spirv-fuzz: Remove CanFindOrCreateZeroConstant (#3807)
Replace FuzzerPass::CanFindOrCreateZeroConstant with
fuzzerutil::CanCreateConstant.
2020-09-16 14:22:22 +01:00
André Perez
e8ce4355ae
spirv-fuzz: Add bit instruction synonym transformation (#3775)
This PR implements part of the add bit instruction synonym transformation.
For now, the implementation covers the OpBitwiseOr, OpBitwiseXor and
OpBitwiseAnd cases.
2020-09-15 23:36:23 +01:00
Vasyl Teliman
e7c84feda0
spirv-fuzz: Skip unreachable blocks (#3729)
Fixes #3722, fixes #3713, fixes #3714.
2020-09-15 23:35:42 +01:00
Alastair Donaldson
f20b523cb1
Fix build errors (#3804) 2020-09-15 21:02:20 +01:00
Vasyl Teliman
3131686d2e
spirv-fuzz: Handle invalid ids in fact manager (#3742)
Fixes #3741.
2020-09-15 17:03:09 +01:00
Vasyl Teliman
4c239bd81b
spirv-fuzz: Support memory instructions MoveInstructionDown (#3700)
Part of #3605.
2020-09-15 15:04:39 +01:00
Stefano Milizia
1e1c308ded
spirv-fuzz: Pass submanagers to other submanagers when necessary (#3796)
This PR changes the fact manager so that, when calling some of the
functions in submanagers, passes references to other submanagers if
necessary (e.g. to make consistency checks).

In particular:

- DataSynonymAndIdEquationFacts is passed to the AddFactIdIsIrrelevant
  function of IrrelevantValueFacts

- IrrelevantValueFacts is passed to the AddFact functions of
  DataSynonymAndIdEquationFacts

The IRContext is also passed when necessary and the calls to the
corresponding functions in FactManager were updated to be valid and
always use an updated context.

Fixes #3550.
2020-09-15 13:27:14 +01:00
Stefano Milizia
f62357e7b8
spirv-fuzz: Transformation to flatten conditional branch (#3667)
This transformation, given the header of a selection construct with
branching instruction OpBranchConditional, flattens it.
Side-effecting operations such as OpLoad, OpStore and OpFunctionCall
are enclosed within smaller conditionals.
It is applicable if the construct does not contain inner selection
constructs or loops, or atomic or barrier instructions.

The corresponding fuzzer pass looks for selection headers and
tries to flatten them.

Needed for the issue #3544, but it does not fix it completely.
2020-09-15 10:31:01 +01:00
sfricke-samsung
5df9300549
spirv-val: Add BaseInstance, BaseVertex, DrawIndex, and ViewIndex (#3782)
* spirv-val: Add BaseInstance and BaseVertex

* spirv-val: Add DrawIndex

* spirv-val: Add ViewIndex
2020-09-14 10:23:44 -04:00
Diego Novillo
286b3095dd
Properly mark IR changed if instruction folder creates more than one constant. (#3799)
In #3636, I missed that the instruction folder may create more than a
single constant per call.  Since CCP was only checking whether one
constant had been created after folding, it was wrongly thinking that
the IR had not changed.

Fixes #3738.
2020-09-14 09:00:38 -04:00
Antoni Karpiński
244e6c1be6
spirv-fuzz: Add TransformationDuplicateRegionWithSelection (#3773)
Adds a transformation that inserts a conditional statement with a
boolean expression of arbitrary value and duplicates a given
single-entry, single-exit region, so that it is present in each
conditional branch and will be executed regardless of which branch will
be taken.

Fixes #3614.
2020-09-11 11:48:19 +01: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
Alastair Donaldson
de7d57984d
spirv-reduce: Refactoring (#3793)
Avoids the use of "using" in favour of explicit qualification, to be
consistent with spirv-fuzz. Fixes indentation in a TODO comment.
Addresses and removes two existing TODO comments by moving some helper
functionality into reduction_util.

Related issue: #2184.
2020-09-10 22:03:40 +01:00
Alastair Donaldson
ed9863e46e
Favour 'integrity' over 'coherence' as a replacement for 'sanity'. (#3619) 2020-09-10 09:52:21 -04:00
Antoni Karpiński
8743d385f3
spirv-fuzz: Fix header guards in transformations/fuzzer passes (#3784) 2020-09-10 11:07:20 +01:00
Paul Thomson
2de7d3af0c
spirv-fuzz: Add SPIRV_FUZZ_PROTOC_COMMAND (#3789)
Add CMake option SPIRV_FUZZ_PROTOC_COMMAND for overriding the protoc
command. This is needed when cross-compiling, such as when building
for Android.
2020-09-10 08:32:48 +01:00
Paul Thomson
a715b1b405
Improve spirv-fuzz CMake code (#3781)
This change improves spirv-fuzz CMake code to be more compatible with other projects that might want to include spirv-fuzz as a sub-project.

* Add a CMake option for building spirv-fuzz. 
* We now check if protobuf targets are already available. 
* We no longer specify `-DGOOGLE_PROTOBUF_NO_RTTI -DGOOGLE_PROTOBUF_USE_UNALIGNED=0`; a newer version of protobuf does not require this. Note that we probably should have specified this for protobuf targets as well, but this is no longer needed. 
* Updated protobuf version in Kokoro scripts and README.md.
2020-09-09 09:56:32 +01:00
Steven Perron
a187dd58a0
Allow SPV_KHR_8bit_storage extension. (#3780) 2020-09-08 14:13:01 -04:00
Stefano Milizia
1ab52e54ab
spirv-opt: Add function to compute nesting depth of a block (#3771)
This PR adds the NestingDepth function to StructuredCFGAnalysis.
This function, given a block id, returns the number of merge
constructs containing it.

This is needed by spirv-fuzz, but it makes sense to add it to
StructuredCFGAnalaysis, which contains related functionalities.
2020-09-08 12:01:56 +01:00
Stefano Milizia
fd05605bef
spirv-fuzz: Transformation to convert OpSelect to conditional branch (#3681)
This transformation takes an OpSelect instruction and replaces it with
a conditional branch, selecting the correct value using an OpPhi
instruction.

Fixes part of the issue #3544.
2020-09-03 10:19:02 +01:00
sfricke-samsung
2c60d16a64
spirv-val: Add Vulkan VUID labels to BuiltIn (#3756)
The Vulkan 1.2.152 headers/spec now include Valid Usage IDs (VUID)
for every BuiltIn. This change adds labeling to help aid tracking
the coverage gap in Vulkan targeted validation. This is done with
a script in the Validation Layers that parses the source for VUID
strings, both that there is an implementation and a test for it.

There are 2 main changes:

1. A VUID string is added where applicable. It is wrapped in a function
that at runtimes checks if Vulkan is the target so that other targets
will not be effected as the output error only changes for Vulkan and
the overhead only occurs if there is an error at all.

2. For unit test, a new parameter value was added to allow make sure
that for each VUID there is a matching test. There are cases where the
same unit test checks multiple VUs via the parameter feature of gtest.
For this, I added a custom gMock Matcher to simply loop over a list
of VUID strings
2020-09-02 14:02:13 -04:00
Vasyl Teliman
c341f7a6cd
spirv-fuzz: Add support for BuiltIn decoration (#3736)
Fixes #3676.
2020-09-02 14:14:58 +01:00
Stefano Milizia
c278dada96
spirv-fuzz: Fix GetIdEquivalenceClasses (#3767)
Pointer (if VariablePointers is enabled) to find sets of potential
synonyms.

However, some instructions with these types cannot be used in an OpPhi:

- OpFunction cannot be used as a value
- OpUndef should not be used, because it yields an undefined value for
  each use
Fixes #3761.
2020-09-02 01:07:59 +01:00
Stefano Milizia
788468408e
spirv-fuzz: Replace id in OpPhi coming from a dead predecessor (#3744)
This transformation takes the id of an OpPhi instruction, of a dead
predecessor of the block containing it and a replacement id of
available to use and of the same type as the OpPhi, and changes
the id in the OpPhi corresponding to the given predecessor.

For example, %id = OpPhi %type %v1 %p1 %v2 %p2
becomes %id = OpPhi %type %v3 %p1 %v2 %p2
if the transformation is given %id, %p1 and %v3, %p1 is a dead block,
%v3 is type type and it is available to use at the end of %p1.

The fuzzer pass randomly decides to apply the transformation to OpPhi
instructions for which at least one of the predecessors is dead

Fixes #3726.
2020-09-02 01:06:38 +01:00
Stefano Milizia
3daabd3212
spirv-fuzz: Transformation to replace the use of an irrelevant id (#3697)
A transformation that replaces the use of an irrelevant id with
another id of the same type.

The related fuzzer pass, for every use of an irrelevant id,
checks whether the id can be replaced in that use by another
id of the same type and randomly decides whether to replace
it.

Fixes #3503.
2020-09-01 16:28:04 +01:00
Vasyl Teliman
d7f078f27d
spirv-fuzz: TransformationMutatePointer (#3737)
Fixes #3624.
2020-09-01 12:45:13 +01:00