Commit Graph

2586 Commits

Author SHA1 Message Date
sfricke-samsung
90728d2dff
spirv-val: Clean up VariablePointers logic (#4755) 2022-03-24 12:02:29 -04:00
Roy.li
cab0b7715a
Use types have same widths in loop condition. (#4763) 2022-03-24 14:07:22 +00:00
sfricke-samsung
b3c1790632
spirv-val: Add Vulkan 32-bit bit op Base (#4758) 2022-03-23 13:55:42 -04:00
sfricke-samsung
9668d2e4e4
spirv-val: Label and add test for PSB Aligned (#4756) 2022-03-23 11:08:21 -04:00
Greg Fischer
9d1b572884
spirv-opt: (WIP) Eliminate Dead Input Component Pass (#4720)
This adds the --eliminate-dead-input-components pass which currently
removes trailing unused components from input arrays.

Fixes #4532
2022-03-22 20:50:52 -06:00
sfricke-samsung
f8cd51431e
spirv-val: Add better error code for invalid operand (#4753) 2022-03-22 15:37:38 -04:00
Daniel Thornburgh
3820c4f6e2
Qualify std::move. (#4741)
Clang added -Wunqualified-std-cast-call in
https://reviews.llvm.org/D119670, which warns on unqualified std::move
and std::forward calls. This change qualifies these calls to allow the
project to build on HEAD Clang -Werror.
2022-03-22 11:20:11 -04:00
sfricke-samsung
0ab57c2c42
spirv-val: Small Cleanup of validate image (#4752) 2022-03-14 11:08:47 -04:00
sfricke-samsung
7963fa13c7
spirv-val: Add Vulkan Dref not allowed 3D dim VUID (#4751) 2022-03-10 13:08:26 -05:00
sfricke-samsung
5c9d55a59a
spirv-val: Add Vulkan Image VUID 06214 (#4750) 2022-03-10 13:06:48 -05:00
sfricke-samsung
9700708570
spirv-val: Label Vulkan RuntimeArray VUID (#4749) 2022-03-10 13:05:26 -05:00
sfricke-samsung
ca59914c7a
spirv-val: Disallow array of push constants (#4742) 2022-03-10 12:57:20 -05:00
Steven Perron
0741f42738
Reset the id bound on the module in compact ids (#4744)
If the body of the module does not have any ids change, compact ids will
not change the id bound.  This can cause problems because the id bound
could be much higher than the largest id in that is used.  It should be
reset any time it is not the larger id used + 1.

Fixes #4604
2022-03-07 20:33:01 +00:00
Steven Perron
48a36c72e4
Better handling of 0xFFFFFFFF when folding vector shuffle (#4743)
When folding a vector shuffle feeding a vector shuffle, we do not
propagate an 0xFFFFFFFF, which has a special meaning, correctly.  We
adjust the value making it lose it meaning as an undefined value.

Fixes #4581
2022-03-07 19:35:57 +00:00
Steven Perron
4fa1a6f9b4
Generalize assert in ccp (#4735)
CCP does not want to fold an instruction unless it folds to a constant.
There is an asser to check for this.  The question if a spec constant
counts as a constant.  The constant folder considers a spec constant a
constand, but CCP does not.  I've fixed the assert in CCP to match what
the folder does.  It should not require any new changes to CCP.
2022-03-07 19:33:10 +00:00
Steven Perron
920156cf18
Add pass to remove DontInline function control (#4747)
Swift shader needs a way to inline all functions, even those marked as
DontInline.  See https://github.com/KhronosGroup/SPIRV-Tools/pull/4471.
This implements the suggestion I made in the PR.  We add a pass that
will remove the DontInline function control, so that the inlining passes
will inline them.

SwiftShader will still have to modify their code to add this pass before
the other passes are run.
2022-03-07 12:45:17 -05:00
sfricke-samsung
273d2a45ad
spirv-val: Label VUID 06491 (#4745) 2022-03-07 12:30:05 -05:00
Steven Perron
0b8426346d
Don't rebuilt valid analyses. (#4733)
The function `BuildInvalideAnalyses` will be rebuilt for every analysis that
has been requested, but it is not necessary.  It also can cause problems
because if the CFG needs to be rebuilt, so do the dominator trees.

This change will make the functionality match the description of the
function.
2022-03-04 20:16:42 +00:00
sfricke-samsung
d1addc44b2
spirv-val: Label Vulkan VUID 04734 (#4739) 2022-03-04 10:07:24 -05:00
Jeremy Hayes
598bc6744a
spirv-val: Validate DebugTypeMatrix (#4732) 2022-03-04 08:54:05 -05:00
pd-valve
d18d0d92e5
Optimize DefUseManager allocations (#4709)
* Optimize DefUseManager allocations

Saves around 30-35% of compilation time.

For inst->use_ids, use a pool linked list instead of allocating vectors for every instruction.  For inst->uses, use a "PooledLinkedList"' -- a linked list that has shared storage for all nodes.  Neither re-use nodes, instead we do a bulk compaction operation when too much memory is being wasted (tuneable).

Includes separate PooledLinkedList templated datastructure, a very special case construct, but split out to make the code a little easier to understand.
2022-02-15 19:17:30 -05:00
pd-valve
a123632ed9
Optimize Type::HashValue (#4707)
Incrementally compute the hash instead of collecting words

Avoids allocating temporary space in a std::vector and std::u32string, and making three passes over all the hashed data.
Switch to using std::vector to prevent processing duplicates instead of std::unordered_set: avoids an allocation/deletion every call to ComputeHashValue, and ends up faster due to much better cache behaviour and smaller constant-factor when searching the (generally very small) list.

In my test case, made Type::HashValue go from 7.5% of compilation time to .5%
2022-02-15 18:57:39 +00:00
sfricke-samsung
471428a04f
spirv-opt: Add OpExecutionModeId support (#4719)
Needed for Vulkan1.3 adding LocalSizeId support
2022-02-14 14:33:29 +00:00
Natalie Chouinard
72e4475b41
Handle propagation of arrays with decorations (#4717)
When copy propagating, OpDecorate instructions can be copied as is. For
array flattening, they should be ignored.
2022-02-11 16:13:14 -05:00
sfricke-samsung
53078eec1e
Add OpModuleProcessed to debug opcode (#4694) 2022-02-11 19:24:17 +00:00
Shahbaz Youssefi
0ad83f9139
spirv-diff: Match OpSpecConstantComposite correctly (#4704)
OpSpecConstantComposite is not decorated with SpecId, and so is matched
similarly to OpConstantComposite.
2022-02-11 15:29:42 +00:00
pd-valve
940127a77d
avoid unnecessary reallocations in GetOperandConstants (#4708)
reserve capacity since we know the size exactly
2022-02-10 18:31:24 +00:00
pd-valve
44923beb52
Optimize Instruction::Instruction (#4705)
Avoid constructing temporary vector + copying operands multiple times.
Add SmallVector(InputIt first, InputIt last), matching std::vector.
2022-02-10 18:31:07 +00:00
Greg Fischer
ff91f9449b
[spirv-val] Allow 0 Component Count for DebugTypeArray for Shader (#4706)
Rev 7 of NonSemantic.Shader.DebugInfo.100 was updated to allow zero
component count for for DebugTypeArray to represent runtime array.
2022-02-09 17:58:55 -07:00
Shahbaz Youssefi
332475dbc9
spirv-diff: Handle OpSpecConstant array sizes (#4700)
Previously, array sizes were presumed to be OpConstant, which is not
necessarily true.  This change ensures OpSpecConstant array sizes as
matched exactly, instead of taken as OpConstant and matched by value.
2022-02-09 09:06:46 -05:00
Shahbaz Youssefi
9beb54513c
Stabilize the output of spirv-diff (#4698)
* Reimplement LCS used by spirv-diff

Two improvements are made to the LCS algorithm:

- The LCS algorithm is reimplemented to use a std::stack instead of
  being recursive.  This prevents stack overflow in the LCSTest.Large
  test.
- The LCS algorithm uses an NxM table.  Previously, entries of this
  table were {size_t, bool, bool}, which is now packed in 32 bits.  The
  first entry can assume a maximum value of min(N, M), which
  realistically for SPIR-V diff will not be larger than 1 billion
  instructions.  This reduces memory usage of LCS by 75%.

This partially reverts 845f3efb8a and
enables LCS tests.

* Stabilize the output of spirv-diff

std::map is used instead of std::unordered_map to ensure the output of
spirv-diff is identical everywhere.

This partially reverts 845f3efb8a and
enables spirv-diff tests.
2022-02-07 09:37:04 -05:00
Steven Perron
5b371918b9
Have scalar replacement use undef instead of null (#4691)
Scalar replacement generates a null when there value for a member will
not be used.  The null is used to make sure things are
deterministic in case there is an error.

However, some type cannot be null, so we will change that to use undef.
To keep the code simpler we will always use the undef.

Fixes #3996
2022-02-03 15:51:15 +00:00
Shahbaz Youssefi
7fa9e746ef
Introduce spirv-diff (#4611)
spirv-diff is a new tool that produces diff-style output comparing two
SPIR-V modules.  The instructions between the src and dst modules are
matched as best as the tool can, and output is produced (in src
id-space) that shows which instructions are removed in src, added in dst
or modified between them.  The order of instructions are not retained.

Matching instructions between two SPIR-V modules is not trivial, and
thus a number of heuristics are applied in this tool.  In particular,
without debug information, it's hard to match functions as they can be
reordered.  As such, this tool is primarily useful to produce the diff
of two SPIR-V modules derived from the same source.

This tool can be useful in a number of scenarios:

- Compare the SPIR-V before and after modifying a shader
- Compare the SPIR-V produced from a shader before and after compiler
  codegen changes.
- Compare the SPIR-V produced from a shader before and after some
  transformation or optimization.
- Compare the SPIR-V produced from a shader with different compilers.
2022-02-02 10:33:18 -05:00
Steven Perron
b846f8f1dc
Complete handling of RayQueryKHR type (#4690)
The handling of the RayQueryKHR type is not complete in the type
manager.  The tests were not picking this up.  I've added a test to make
sure that the `GenerateAllTypes` function actually does generate all of
the types.  Once it is added there other tests should pick up on the
other parts that were missing.
2022-01-31 15:44:32 +00:00
alan-baker
20b122b2e0
Fix handling of Nontemporal image operand (#4692)
* Nontemporal image operand shouldn't expect a following operand
2022-01-28 21:12:03 -05:00
luzpaz
65ecfd1093
Fix various source comment (doxygen) typos (#4680)
Found via `codespell -q 3 -L fo,lod,parm
2022-01-26 15:13:08 -05:00
Jaebaek Seo
fb9a10cd48
spirv-opt: add pass to Spread Volatile semantics (#4667)
Add a pass to spread Volatile semantics to variables with SMIDNV,
WarpIDNV, SubgroupSize, SubgroupLocalInvocationId, SubgroupEqMask,
SubgroupGeMask, SubgroupGtMask, SubgroupLeMask, or SubgroupLtMask BuiltIn
decorations or OpLoad for them when the shader model is the ray
generation, closest hit, miss, intersection, or callable shaders. This
pass can be used for VUID-StandaloneSpirv-VulkanMemoryModel-04678 and
VUID-StandaloneSpirv-VulkanMemoryModel-04679 (See "Standalone SPIR-V
Validation" section of Vulkan spec "Appendix A: Vulkan Environment for
SPIR-V").

Handle variables used by multiple entry points:

1. Update error check to make it working regardless of the order of
   entry points.
2. For a variable, if it is used by two entry points E1 and E2 and
   it needs the Volatile semantics for E1 while it does not for E2
  - If VulkanMemoryModel capability is enabled, which means we have to
    set memory operation of load instructions for the variable, we
    update load instructions in E1, but do not update the ones in E2.
  - If VulkanMemoryModel capability is disabled, which means we have
    to add Volatile decoration for the variable, we report an error
    because E1 needs to add Volatile decoration for the variable while
    E2 does not.

For the simplicity of the implementation, we assume that all functions
other than entry point functions are inlined.
2022-01-25 13:14:36 -05:00
alan-baker
6938af7f82
Vulkan 1.3 (#4686)
* Add new environment enum for Vulkan 1,3
* Do not require --allow-localsizeid in Vulkan 1.3 to use LocalSizeId
  execution mode
2022-01-25 10:36:08 -05:00
smikims
e8439c1c9d
Avoid infinite recursion in comparison operators on SmallVector (#4681)
C++20 automatically adds reversed versions of operator overloads for
consideration; in this particular instance this results in infinite
recursion, which has now been pointed out elsewhere as a known issue
when migrating to C++20. Here we just disable one of the overloads in
C++20 mode and let the auto-reversing take care of it for us.
2022-01-25 09:07:40 -05:00
Pierre Moreau
58d8b4e29c
linker: Address conversion error introduced in earlier rework (#4685)
* linker: Address conversion error introduced in earlier rework

Also rework the code slightly to first compute the new ID bound and
validate it, and only then, offset all existing IDs.

This makes those two steps clearer, and avoids potentially overflowing
the IDs within a module (even if that would have been caught later on).

Fixes: c3849565 ("Linker improvements (#4679)")
Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/4684

* test/linker: Disable IdsLimit tests for now

They are taking too long to run and results in the CI jobs timing out.
2022-01-24 13:40:57 -05:00
Pierre Moreau
c38495656d
Linker improvements (#4679)
* test/linker: Code factorisation and small tweaks

* linker: Do not fail when going over limits

The limits are minima and implementations or APIs might support higher
limits, so just warn the user about it. And only check for the limits
right before emitting the binary, as limits might change earlier when
removing duplicate instructions, function prototypes, etc.
The only check performed right before merging, is making sure the ID
bound will not overflow the 32 bits following the merge.

Also, use the defines for the limits instead of hard-coding them.

* linker: Require a memory model in each input module

The existing code could run into weird situation. For example, if the
first module had no memory model, it would not emit any memory model
(sort of reasonable) and would accept without complains all possible mix
from later modules as it would not verify them.

* linker: Replace hex version with SPV_SPIRV_VERSION_WORD

* linker: Error out when linking together different versions

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

* tools/linker: Do not write to disk if linking failed

Also, do not consider warnings as errors.

* tools/linker: Fix formatting in help message

* tools/linker: Further clarify the use of --target-env

Also update the text for the default version to reflect the change made
in 7d768812 ("Basic support for SPIR-V 1.6 (#4663)").
2022-01-22 15:40:19 -05:00
David Neto
8a40f6de57
Add SPIR-V 1.6 support to wasm build (#4674)
* Add SPIR-V 1.6 support to wasm build

* Fix formatting
2022-01-13 13:49:35 -05:00
Pierre Moreau
42dc678913
Remove duplicated "the" from comments (#4666) 2022-01-12 19:04:13 -05:00
Pierre Moreau
05c839ca01
Improvements to disassembly within PassManager (#4677)
* PassManager: Print errors occurring during disassembly

Otherwise one could be greeted by the following text when running
spirv-opt withe the `--print-all` flag:

    ; IR before pass wrap-opkill

    ; IR before pass eliminate-dead-branches

    ; IR before pass merge-return

With this commit, one will instead get:

    error: line 143: Invalid opcode: 400
    warning: line 0: Disassembly failed before pass wrap-opkill

    error: line 143: Invalid opcode: 400
    warning: line 0: Disassembly failed before pass eliminate-dead-branches

    error: line 143: Invalid opcode: 400
    warning: line 0: Disassembly failed before pass merge-return

* PassManager: Use the right target environment when disassembling

Disassembly would fail if features from a newer version of SPIR-V than
1.2 were used.
2022-01-10 10:55:47 -05:00
Steven Perron
b9e0e13d19
Remove misleading comment. (#4676)
The comment in `Array::GetExtraHashWords` is misleading because getting
the hash words is split up between the generic `Type::GetHashWords` and
the type specific `Type::GetExtraHashWords`.  While `IsSameImpl` is
self-contained.  Removing the comment since it is misleading and no
comment is really needed.

Fixes #3248
2022-01-10 09:24:44 -05:00
Alastair Donaldson
75e53b9f68
Avoid uninitialized access to instruction opcode (#4673)
Ensures that instruction's opcode is set to something default when
parsing the module with --preserve-numeric-ids enabled. This avoids
uninitialized accesses and knock-on buffer overflows.

Fixes #4672.
2022-01-04 17:33:33 +00:00
David Neto
df2aad68b9
val: interface struct with builtins must be Block (#4665)
For a shader input/output interface variable of structure type:
If the structure has BuiltIn members, then the structure type
must be Block decorated.

Otherwise, the variable, or the struct members must have locations,
but nothing can have both a location be a BuiltIn.

Implements validation needed to reject the example in
https://github.com/KhronosGroup/SPIRV-Registry/issues/134
2021-12-16 16:48:12 -05:00
David Neto
5d0e3240f0
Patch location validation VUIDs (#4664)
* spirv-val: Add Vulkan Location VUID

* Simplify: interface checking already does all the work

Co-authored-by: sfricke_samsung <s.fricke@samsung.com>
2021-12-16 15:25:23 -05:00
alan-baker
7d768812e2
Basic support for SPIR-V 1.6 (#4663)
* Basic support for SPIR-V 1.6

* Update SPIRV-Headers deps
* Add new environment enum for SPIR-V 1.6
* Make default environment 1.6 for most tools
* Update tests
* Disallow conditional branch with duplicate labels
* Disallow Dim=Buffer with sampled images
* Do not require the non-semantic extension after SPIR-V 1.5
2021-12-15 14:38:28 -05:00
Steven Perron
b7251d4fb7
reflect debug (#4662)
The pass to remove the nonsemantic information and instructions
is used for drivers or tools that may not support them.  Debug
information was only partially handle, which is causing a
problem.  We need to either fully remove debug information or
not remove it all.  Since I can see it being useful to keep the
debug information even when the nonsemantic instructions are
removed, I propose we do not remove debug info.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/4269
2021-12-15 11:06:51 -05:00
Steven Perron
354a46a2a2
Rename strip reflect to strip nonsemantic (#4661)
In https://github.com/KhronosGroup/SPIRV-Tools/pull/3110, the strip reflect
pass was changed to also remove all explicitly nonsemantic instructions.  This
makes it so that the name of the pass no longer reflects what the pass actually
does.  This change renames the pass so that it reflects what the pass actaully does.
2021-12-15 09:55:30 -05:00
Shahbaz Youssefi
4322c4b5a7
Refactor the disassembler code for reuse (#4616)
The upcoming spirv-diff tool also outputs disassembly, although in a
per-instruction basis.  This change refactors the disassembler code to
support such a use case.
2021-12-14 09:46:59 -05:00
Dave Airlie
3156158878
optimizer: restore previous ABI. (#4653)
The change in
commit 4ac8e5e541
Author: Greg Fischer <greg@lunarg.com>
Date:   Wed Sep 15 12:38:34 2021 -0600

    Add preserve_interface mode to aggressive_dead_code_elim (#4520)

Broke the C++ ABI for spirv-tools shared libraries on Linux, for not a great reason.

Restore the previous ABI.
2021-12-09 15:58:53 -05:00
Sebastien Alaiwan
a2260d3b1f
Fix compilation (#4656)
* Delete public accessor, whose only user is one unit-test

The underlying container type becomes invisible from the outside.

* Fix compilation
2021-12-09 12:42:53 -05:00
jiaxin.lai
d240d0db92
fix file encoding (#4654) 2021-12-09 09:43:55 -05:00
Andrei Malashkin
6926c3d9a3
treat google user type as normal semantic google. It's a backport from diligent fork (#4632) 2021-12-09 09:42:40 -05:00
Sebastien Alaiwan
b9e255b366
DefUseManager: rename comparison operators to 'CompareAndPrintDifferences' (#4624)
This make sense, as those are actually debug functions
and shouldn't be used in production code.
2021-12-09 09:41:42 -05:00
Sebastien Alaiwan
f37551d2b6
Use a struct (instead of tuple), with explicit member names. (#4621)
* Cleanup includes.

* Simplify assertion.

* Use a struct with named members for 'UserEntry'
2021-12-09 09:40:29 -05:00
Sebastien Alaiwan
64328e94db
Avoid an extra map lookup (#4623)
Speedup: 5% less time on a real-world compilation batch
(nearly 10k parallel compilations)
(Durations: Before: 156.5s, After: 147.4s)
2021-12-08 14:53:36 -05:00
Marius Hillenbrand
1ed847f438
Fix endianness of string literals (#4622)
* Fix endianness of string literals

To get correct and consistent encoding and decoding of string literals
on big-endian platforms, use spvtools::utils::MakeString and MakeVector
(or wrapper functions) consistently for handling string literals.

- add variant of MakeVector that encodes a string literal into an
  existing vector of words
- add variants of MakeString
- add a wrapper spvDecodeLiteralStringOperand in source/
- fix wrapper Operand::AsString to use MakeString (source/opt)
- remove Operand::AsCString as broken and unused
- add a variant of GetOperandAs for string literals (source/val)
... and apply those wrappers throughout the code.

Fixes  #149

* Extend round trip test for StringLiterals to flip word order

In the encoding/decoding roundtrip tests for string literals, include
a case that flips byte order in words after encoding and then checks for
successful decoding. That is, on a little-endian host flip to big-endian
byte order and then decode, and vice versa.

* BinaryParseTest.InstructionWithStringOperand: also flip byte order

Test binary parsing of string operands both with the host's and with the
reversed byte order.
2021-12-08 12:01:26 -05:00
Shahbaz Youssefi
b162ede0de
Use schema instead of reserved in header description (#4615)
For consistency with SPIR-V disassembly which outputs Schema for this
field.
2021-12-08 11:55:36 -05:00
Alastair Donaldson
1f3f0f185b
Avoid uninitialised read when parsing hex float (#4646)
Ensures that when an attempt to read a floating-point value from an
input stream fails, the recieving variable for the read does not end up
uninitialised.

Fixes OSS-Fuzz:40432
Fixes #4644
2021-12-08 11:09:25 -05:00
Alastair Donaldson
f9bcc82ec7
Exit when ID overflow occurs in a fuzzing build (#4652)
Currently if an ID overflow occurs, spirv-opt (and other users of
IRContext) emits a warning and starts returning 0 when fresh ids are
requested. This tends to lead to crashes - such as null pointer
exceptions. When these arise during fuzzing they lead to auto-reported
bugs.

This change uses an ifdef guard to instead gracefully exit as soon as an
ID overflow occurs when the build is a fuzzing build.

Related issue: #4539.
2021-12-04 07:18:21 +00:00
Diego Novillo
c75a1a46f3
Fix https://github.com/KhronosGroup/SPIRV-Tools/issues/4462 (#4651)
This prevents CCP from making constant -> constant transitions when
evaluating instruction values.  In this case, FClamp is evaluated twice.
On the first evaluation, if computes FClamp(0.5, 0.5, -1) which returns
-1.  On the second evaluation, it computes FClamp(0.5, 0.5, VARYING)
which returns 0.5.

Both fold() computations are correct given the semantics of FClamp() but
this causes a lateral transition in the constant lattice which was not
being considered VARYING by CCP.
2021-12-02 10:40:28 -05:00
Natalie Chouinard
d0a827a9f3
Copy OpDecorateStrings in DescriptorScalarReplacementPass (#4649)
Along with OpDecorate, also clone the OpDecorateString instructions for
variables created in the descriptor scalar replacement pass.

Fixes microsoft/DirectXShaderCompiler#3705
2021-11-29 02:11:22 -05:00
Natalie Chouinard
b023c0da1d
Remove default arguments from lambda (#4648)
Fixes compile failure due to pedantic warning:
`error: default argument specified for lambda parameter [-Werror=pedantic]`
2021-11-26 12:58:43 -05:00
Steven Perron
8c155b364c
Manually fold floating point division by zero (#4637)
See https://github.com/KhronosGroup/SPIRV-Tools/issues/4636 for details.

Fixes #4636.
2021-11-24 14:13:58 -05:00
alan-baker
4b092d2ab8
Allow ADCE to remove dead inputs (#4629)
* https://github.com/KhronosGroup/Vulkan-Docs/issues/666 clearly
  specified that interfaces do not require an input if there is an
  associated output
* ADCE can now remove unused input variables (though they are kept if
  the preserve interfaces option is used)
2021-11-16 15:54:17 -05:00
alan-baker
21e3f681e2
Update SPIRV-Headers (#4628)
* Fix compile
* Fix test
2021-11-10 16:32:09 -05:00
alan-baker
b014238e08
Allow WorkgroupSize on variables for Kernels (#4627)
* Update tests
2021-11-10 15:06:39 -05:00
Greg Fischer
352a411278
Fix handling of OpPhi in convert-relaxed-to-half (#4618)
Fixes #4452
2021-11-09 10:36:50 -07:00
alan-baker
339d4475c1
Improve decoration validation (#4490)
Fixes #4469

* Checks that decorations only usable with structure members are not
  used by OpDecorate or OpDecorateId
* Checks that decorations not allowed on structure members are not used
  with OpMemberDecorate
* Checks decoration targets for most core decorations
* Performs some Vulkan specific validation on deorations
2021-11-05 13:18:19 -04:00
Jaebaek Seo
1589720e10
spirv-opt: create OpDecorate for OpMemberDecorate in desc-sroa (#4617)
The scalar replacement of a resource array/struct variable must create
OpDecorate for elements if OpMemberDecorate instructions decorate
the elements.
2021-11-05 11:05:36 -04:00
Pelle Johnsen
0d0013002a
Add Wasm build (#3752)
* Add wasm build

* Run wasm ci on push

* Add copyright notice to wasm files

* [wasm] Update Emscripten

* [wasm] Change global lambda to regular function

* [wasm] Show detected core count during build

* [wasm] Set JS version from CHANGES, GITHUB_RUN_ID

Also remove custom docker emscripten build with brotli, as not used

* [wasm] Change github actions to use npm-publish

* [wasm] Us docker-compose up for CI

* [wasm] pass GITHUB_RUN_ID to docker

* [wasm] Change GITHUB_RUN_ID to GITHUB_RUN_NUMBER

* [wasm] Fix GITHUB_RUN_NUMBER in docker-compose.yml
2021-11-01 16:45:51 -04:00
Steven Perron
1082de6bb3
Handle overflowing id in merge return (#4606)
If the ids overflow when creating an integer constant in the ir_builder, there will be a nullptr dereference.  This is happening from inside merge return.

We need to propagate the error up, and make sure it is handled appropriately.
2021-11-01 08:45:32 -04:00
Alastair Donaldson
97d4495600
Avoid bitwise and in boolean expression (#4603)
In #3404 a logical && was replaced with a bitwise & to ensure that
both side-effecting arguments were evaluated. However, this leads to
warnings from some compilers (leading to the OSS-Fuzz build breaking,
in particular).

This change reworks the relevant code so that both arguments to the
logical && are evaluated into temporaries.
2021-10-29 15:36:51 -04:00
Ralf Habacker
e3c7098104
In generated cmake config file for SPIRV-Tools only access cmake target, if present (#4590)
Fixes #4582
2021-10-29 14:05:45 -04:00
sfricke-samsung
c194bb2a7f
spirv-val Update LocalSizeId VUID (#4602) 2021-10-29 11:58:02 -04:00
Steven Perron
6c7885dbde
Change branch handling in ADCE to fix errors (#4596)
Consider the new test case.  The conditional branch in the continue
block is never marked as live.  However, `IsDead` will say it is not
dead, so it does not get deleted.  Because it was never marked as live,
`%false` was not mark as live either, but it gets deleted.  This results
in invalid code.

To fix this properly, we had to reconsider how branches are handle.  We
make the following changes:

1) Terminator instructions that are not branch or OpUnreachable must be
kept, so they are marked as live when initializing the worklist.

2) Branches and OpUnreachable instructions are marked as live if
  a) the block does not have a merge instruction and another instruction
     in the block is marked as live, or
  b) the merge instruction in the same block is marked as live.

3) Any instruction that is not marked as live is removed.

4) If a terminator is to be removed, an OpUnreachable is added.  This
happens when the entire block is dead, and the block will be removed.
The OpUnreachable is generated to make sure the block still has a
terminator, and is valid.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/4509.
2021-10-29 10:46:43 -04:00
Steven Perron
bd5bf754b1
Fix Linker generator ID (#4601)
The generator ID is located in the upper 16 bits. The lower bits are
reserved for a version number.

Co-authored-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
2021-10-29 10:32:41 -04:00
alan-baker
791f5b463a
Only validate workgroup layout for explicit workgroup memory (#4542)
Fixes #4537

* Only validate the layout of workgroup variables if the
  WorkgroupMemoryExplicitLayoutKHR capability is declared
2021-10-28 16:27:56 -04:00
David Neto
2feb7074d4
Avoid confusing short-circuiting (#3404)
When checking the OpBranchConditional for selection headers,
we intend to register both the true and false targets.
Short circuiting was getting in the way.

Co-authored-by: Steven Perron <stevenperron@google.com>
2021-10-28 15:57:36 -04:00
Steven Perron
7c5b17d379
Update passes to handle function declarations (#4599)
Spirv-opt has not had to handle module with function declarations.  This
lead many passes to assume that every function has a body.  This is not
always true.  This commit will modify a number of passes to handle
function declarations.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/4443
2021-10-28 11:54:37 -04:00
Steven Perron
b2ba019bf6
Delete decorations before replaces uses in dead branch elim (#4598)
If we do not delete the decoration before all ReplaceAllUses, the decorations will be transferred to the new id.  This can cause problems.

Fixes #4442.
2021-10-28 10:25:37 -04:00
Steven Perron
3291b6951e
Do not fold snegate feeding sdiv. (#4600)
When the variable value is INT_MIN, we cannot fold the negate into the divide, so we have to turn off that folding rule.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/4487.
2021-10-28 10:02:57 -04:00
Jaebaek Seo
d997c83b10
Add spirv-opt pass to replace descriptor accesses based on variable indices (#4574)
This commit adds a spirv-opt pass to replace accesses to
descriptor array based on variable indices with constant
elements.

Before:
```
%descriptor = OpVariable %_ptr_array_Image Uniform
...
%ac = OpAccessChain %_ptr_Image %descriptor %variable_index
(some image instructions using %ac)
```
After:
```
%descriptor = OpVariable %_ptr_array_Image Uniform
...
OpSwitch %variable_index 0 %case0 1 %case1 ...
...
%case0 = OpLabel
%ac = OpAccessChain %_ptr_Image %descriptor %uint_0
...
%case1 = OpLabel
%ac = OpAccessChain %_ptr_Image %descriptor %uint_1
...
(use OpPhi for value with concrete type)
```
2021-10-26 17:20:58 -04:00
Steven Perron
d78c1c4cd3
Make IsLocalVar in ADCE work at any time. (NFC) (#4595)
Having IsLocalVar work only sometimes is something that could easily
lead to an error.  This change refactors the code so that the function
can be called at any point.  The current implementation was used because
we did not want to do multiple searches to see if a function was an
entry point or if it had a call.  This was maintained by added a cache
that will store of a given function is an entry point with no calls.
2021-10-26 13:24:29 -04:00
alan-baker
17a5bacfa7
Handle missing execution modes for limitation check (#4594)
Fixes https://crbug.com/40216

* Handle entry points with no execution modes when checking implicit
  derivative execution model checks
2021-10-25 17:40:11 -04:00
David Neto
7326b494d0
opt: set upper bits of spec constant according to spec (#4589)
When setting default value for spec constants, for numeric bit types smaller
than 32 bits, follow the SPIR-V rules for narrow literals:
- signed integers are sign-extended
- otherwise, upper bits are zero.

Followup to #4588
2021-10-21 09:44:54 -04:00
Dave Airlie
f3fbd98ff5
opt/spec_constants: fix bit pattern width checks. (#4588)
* test: add a test to show 8/16-bit

* opt/spec_constants: fix bit pattern width checks.

The input bit patterns are always at least 32-bits, so let the test
pass for 8/16-bit values as well. This shouldn't have any effect on the
64-bit patterns I assume this was introduced for.
2021-10-20 11:53:24 -04:00
Greg Fischer
001604bd4a
Generate constants directly in CreateDebugInlinedAt (#4572)
Do this if Constant or DefUse managers are invalid. Using the
ConstantManager attempts to regenerate the DefUseManager
which is not valid during inlining.
2021-10-19 18:27:16 -06:00
JiaoluAMD
387cae472e
Opt passes should apply to the exported functions (#4554)
This is follow-up to the commit
bd3a271ce3
2021-10-18 13:18:16 -04:00
alan-baker
35fd0e17d0
Consider 0xffffffff offset as missing (#4564)
Fixes #4561

* When checking for offsets, don't accept 0xffffffff
2021-10-15 10:23:15 -04:00
alan-baker
06ebc4806b
Account for strided components in arrays (#4575)
* Account for strided components in arrays

Fixes #4567

* If the element type of an array takes less than a location in size,
  calculate the location usage in a strided manner

* formatting
2021-10-14 17:47:05 -04:00
Greg Fischer
3e6a85303d
Mark DebugInfoNone as live in ADCE when DebugInfo present (#4568)
Otherwise KillInst() tries to generate it when the module is
inconsistent.
2021-10-14 13:29:54 -04:00
David Neto
e6e77dbdfa
Enable OpConstFunctionPointerINTEL outside function (#4576)
According to spec this opcode is a constant instruction - that's it
can appear outside of function bodies.

Co-authored-by: DmitryBushev <dmitry.bushev@intel.com>
2021-10-14 12:21:11 -04:00
Alastair Donaldson
5ed637caa3
Fix output of SPIR-V version in diagnostic (#4562)
Fixes #4552.
2021-10-14 14:13:47 +01:00
alan-baker
0292d6b16a
Update SPIRV-Headers (#4573)
* Add pass-through validation for Offsets image operand
  * it is counted as an offset parameter though
* Update DEPS
2021-10-13 17:50:17 -04:00
Greg Fischer
6dd73728e9
Fix merge-block assertions with debugInfo (#4563)
Fixes DefUse assertions and invalid DebugScope instruction
between OpLoopMerge and OpBranch for included test shader.
2021-10-13 11:42:40 -06:00
Jaebaek Seo
e4349dd8f4
Fix CI failure (#4570) 2021-10-13 12:16:54 -04:00
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