Commit Graph

1717 Commits

Author SHA1 Message Date
David Neto
618ee50942
Fix some clang-tidy issues in graphics_robust_access_pass (#2998)
One remains: the fact that the image-texel-pointer modification
is mostly dead code. But that's intentional for now.
2019-10-30 14:00:34 -04:00
Jakub Kuderski
f893d4d41d
[opt] Do not compare optimized binary with an invalidated buffer (#2999) 2019-10-30 10:01:28 -07:00
greg-lunarg
5ea7099374 Add two new simplifications. (#2984)
Implements the following simplifications:

(a - b) + b => a
(a * b) + (a * c) => a * (b + c)

Also adds logic to simplification to handle rules that create new operations
that might need simplification, such as the second rule above.

Only perform the second simplification if the multiplies have the add as their
only use. Otherwise this is a deoptimization of size and performance.
2019-10-28 08:19:38 -07:00
Alastair Donaldson
fac166162f
spirv-fuzz: Transformation to extract from a composite object (#2991)
At present, TransformationReplaceIdWithSynonym both extracts elements
from composite objects and replaces uses of ids with synonyms.  This
new TransformationCompositeExtract class will allow that
transformation to be broken into smaller transformations.
2019-10-28 09:33:08 +00:00
Alastair Donaldson
ec12de9131
spirv-fuzz: rename class, and fix bug related to dominance (#2990)
Class TransformationConstructComposite has been renamed to
TransformationCompositeConstruct, to correspond to the name of the
SPIR-V instruction (as is done with e.g. TransformationCopyObject).
Running tests revealed an issue related to checking dominance in
TransformationReplaceIdWithSynonym, which is also fixed here.
2019-10-27 18:11:07 +00:00
Alastair Donaldson
0dbd4e358a
spirv-fuzz: Rework management of data synonyms (#2989)
This change uses the recently-added equivalence relation class to
re-work the way synonyms between data values are managed by the fact
manager.

The tests for 'transformation_replace_id_with_synonym' have been
temporarily removed.  This is because those tests are going to be
split into a number of test classes in an upcoming PR, once some other
refactorings have been applied, and it would be burdensome to
temporarily refactor all the tests to be in a working state for this
intermediate change.
2019-10-25 17:37:55 +01:00
Alastair Donaldson
b34fa73193
spirv-fuzz: add class to represent equivalence relation (#2988)
Adds a templated class for representing an equivalence relation on a
value data type.  This will be used by spirv-fuzz for representing
sets of distinct pieces of data in a shader that are known to have
equal values.
2019-10-25 12:46:52 +01:00
Alastair Donaldson
570582d8d6
spirv-fuzz: fuzzer pass to adjust memory access operands (#2968)
A new pass that gives spirv-fuzz the ability to adjust the memory
operand masks associated with memory access instructions (such as
OpLoad and OpCopy Memory).

Fixes #2940.
2019-10-22 18:05:35 +01:00
greg-lunarg
02910ffdff Instrument: Add missing def-use analysis. (#2985) 2019-10-22 07:24:54 -07:00
Alastair Donaldson
8357b878d1
spirv-fuzz: add missing functionality for matrix composites (#2974)
Support for matrix composites had been omitted in a previous PR; this
change adds the support that was missing.

Fixes #2971.
2019-10-22 14:23:13 +01:00
Steven Perron
6a9be627c7
Keep NOPs when comparing with original binary (#2931)
We have a check that ensures that the optimizer did not change the
binary when it says that it did not.  However, when the binary is
converted back to a binary, we made a decision to remove OpNop
instructions.  This means that any spv file that contains a NOP
originally will fail this check.

To get around this, we convert the module to a second binary that keeps
the OpNop instructions.  That binary is compared against the original.

Fixes https://crbug.com/1010191
2019-10-18 09:53:29 -04:00
alan-baker
2a3cbe7c3f
Check that derivatives operate on 32-bit values (#2983)
* Add a check that derivative functions only operate on scalar or vector
32-bit floating point values
* Added tests to disallow half derivatives
2019-10-18 09:02:25 -04:00
Ryan Harrison
3cdd6444cf
Check text->str before destroying (#2981)
Fixes #2978
2019-10-17 14:56:13 -04:00
Jakub Kuderski
e3da3143b2
Disallow use of OpCompositeExtract/OpCompositeInsert with no indices (#2980) 2019-10-17 13:53:34 -04:00
Ryan Harrison
024417d836
Check binary->code existence before destroying (#2979)
Fixes #2975
2019-10-17 12:30:15 -04:00
Aaron Barany
9c0ae6bb8e Improved CMake install step. (#2963)
Added exports for libraries. External libraries that themselves use
libraries require all dependencies have exports, so not having exports can
cause major problems when used within other projects.

Install paths for exports are now placed in the proper directories expected
by Windows and *nix systems. Config files are generated as well, which
should work with CMake's find_package() function once installed.
2019-10-17 11:36:55 -04:00
Jakub Kuderski
e99b918221
Support constant-folding UConvert and SConvert (#2960) 2019-10-16 16:29:55 -04:00
Alastair Donaldson
00170cc5e6
spirv-fuzz: Refactor 'copy object' and 'construct composite' transformations (#2966)
Rework these transformations to identify instructions via (base,
opcode, skip-count) triples, rather than (base, offset) pairs.
2019-10-15 20:00:17 +01:00
Alastair Donaldson
1b6fd37fa6
spirv-fuzz: Refactor 'split blocks' to identify instructions differently (#2961)
This change refactors the 'split blocks' transformation so that an
instruction is identified via a base, opcode, and number of those
opcodes to be skipped when searching from the base, as opposed to the
previous design which used a base and offset.
2019-10-14 17:00:46 +01:00
alan-baker
2276e59788 Validate that selections are structured (#2962)
* Validate that selections are structured

WIP

* new checks that switch and conditional branch are proceeded by a
selection merge where necessary

* Don't consider unreachable blocks

* Add some tests

* Changed how labels are marked as seen

* Moved check to more appropriate place
* Labels are now marked as seen when there are encountered in a
terminator instead of when the block is checked
* more tests

* more tests

* Method comment

* new test for a bad case
2019-10-11 17:01:30 -04:00
Alastair Donaldson
3eda1b9ff1
spirv-fuzz: Rework id descriptors (#2959)
A refactoring that separates the identification of an instruction from
the identification of a use in an instruction, to enable the former to
be used independently of the latter.
2019-10-11 10:13:06 +01:00
Alastair Donaldson
eba98c4eb7
spirv-fuzz: Add fuzzer pass to add NoContraction decorations (#2950)
A new pass that allows the fuzzer to add NoContraction decorations to
arithmetic instructions.

Fixes #2936.
2019-10-11 09:15:47 +01:00
Alastair Donaldson
91232f7f75
spirv-fuzz: Add fuzzer pass to change function controls (#2951)
A new pass that allows the fuzzer to change the 'function control'
operand of OpFunction instructions.

Fixes #2939.
2019-10-11 07:10:47 +01:00
Paul Thomson
feb1549213
reduce: add large tests and fix (#2947)
* Add larger reducer tests. 
* Fix conditional_branch_to_simple_conditional_branch_opportunity pass.
2019-10-10 17:12:42 +01:00
Alastair Donaldson
253806adc4
spirv-fuzz: Add fuzzer pass to change loop controls (#2949)
A new pass that allows the fuzzer to change the 'loop control' operand
(and associated literal operands) of OpLoopMerge instructions.

Fixes #2938.
Fixes #2943.
2019-10-10 13:34:38 +01:00
Alastair Donaldson
1cea3b7853
Fixed include paths and order according to Google style. (#2957) 2019-10-10 11:26:51 +01:00
alan-baker
c1d42038f7
Disable scope validation for OpReadClockKHR (#2953)
See #2952

Disabled until specification is clarified
2019-10-09 15:02:07 -04:00
Corentin Wallez
df15a4a3cb CMake: Add support for building with emscripten (#2948) 2019-10-09 11:45:11 -04:00
Steven Perron
32f76efa6c
Link cfg and dominator analysis in the context (#2946)
Fixes #2889
2019-10-08 10:16:18 -04:00
Alastair Donaldson
5910bb8e94
spirv-fuzz: add transformation and pass to construct composites (#2941)
Adds a fuzzer pass and transformation to create a composite (array,
matrix, struct or vector) from available constituent components, and
inform the fact manager that each component of the new composite is
synonymous with the id that was used to construct it. This allows the
"replace id with synonym" pass to then replace uses of said ids with
uses of elements extracted from the composite.

Fixes #2858.
2019-10-08 14:04:10 +01:00
Paul Thomson
2f6a87f610
reduce: improve remove unref instr pass (#2945)
* Remove Impl struct in Reducer; we can re-add it later (in a cleaner fashion) if we need to. 
* Add cleanup passes in Reducer; needed so that removal of constants can be disabled during the main passes, and then enabled during cleanup passes, otherwise some main passes can perform worse due to lack of available constants. 
* Delete passes: remove op name, remove relaxed precision. And delete associated tests. 
* Add more tests for remove unreferenced instructions. 
* Always return and write the output file, even if there was a reduction failure. 
* Only exit with 0 if the reduction completed or we hit the reduction step limit.
2019-10-08 13:02:34 +01:00
Alastair Donaldson
81d227f36b
spirv-fuzz: add disabled test to document known issue (#2942)
Issue #2919 identifies a problem in spirv-fuzz's ability to determine
when it is safe to add a new control flow edge without breaking
dominance rules.  This change adds a (currently disabled) test to
expose the issue, and a comment to document that the current solution
is incomplete.
2019-10-08 11:26:08 +01:00
Alastair Donaldson
26dba32c43
spirv-fuzz: Add fuzzer pass to change selection controls (#2944)
A new pass that allows the fuzzer to change the 'selection control'
operand of OpSelectionControl instructions.

Fixes #2937.
2019-10-08 11:25:34 +01:00
Jeremy Hayes
3c7ff8d4f0 Enable OpTypeCooperativeMatrix specialization (#2927) 2019-10-07 09:52:48 -04:00
Steven Perron
c18c9ff6bc
Handle OpKill better (#2933)
We want to handle OpKill better.  The wrap opkill causes lots of extra
code to be generated, even when they are not needed to avoid the main
problem: OpKill cannot be found directly in a continue construct.

This change will be more selective on which functions the OpKill will be
wrapped and inlining will avoid inlining.

Fixes #2912
2019-10-04 13:05:32 -04:00
greg-lunarg
ad3d23f478 Generate null pointer by converting uint64 zero to pointer. (#2935)
Fixes #2929.
2019-10-04 12:26:38 -04:00
Alastair Donaldson
8fa0f1a656
spirv-fuzz: option to convert shader into a form that renders red (#2934)
Adds a spirv-fuzz option for converting a SPIR-V shader into a shader
that renders red, whilst containing the body of the original shader.
This is for aiding in compiler crash bug reporting.
2019-10-03 19:10:50 +01:00
Aaron Hagan
bc37fd585a Add SPV_KHR_shader_clock validation (#2879) 2019-10-03 13:35:35 -04:00
alan-baker
9d7428b052
Validate physical storage buffer restrictions (#2930)
* Physical storage buffer cannot be used with OpConstantNull,
OpPtrEqual, OpPtrNotEqual or OpPtrDiff
  * new tests
  * see also #2929
2019-10-02 21:12:57 -04:00
Steven Perron
9eb1c9a4c4
Add continue construct analysis to struct cfg analysis (#2922)
* Add continue construct analysis to struct cfg analysis

Add the ability to identify which blocks are in the continue construct for a
loop, and to get functions that are called from those blocks, directly or
indirectly.

Part of https://github.com/KhronosGroup/SPIRV-Tools/issues/2912.
2019-10-01 10:27:09 -04:00
Steven Perron
85c67b5e08
Record trailing line dbg instructions (#2926)
There is nothing in the spir-v spec that says the last
instructions in a module cannot be OpLine or OpNoLine.
However, the code that parses the module will simply drop
these instructions.

We add code that will preserve these instructions.

Strip-debug-info is updated to remove these instructions.

Fixes https://crbug.com/1000689.
2019-09-27 16:03:45 -04:00
Ryan Harrison
4075b921f9
Add removing references to debug instructions when removing them (#2923)
Fixes #2921
2019-09-27 13:23:06 -05:00
alan-baker
10951a7c9a
Refactor the InstructionPass (#2924)
* move checks to more appropriate locations
  * remove some duplicated checks
* New function to check valid storage classes
* updated tests
2019-09-27 00:06:36 -04:00
Alastair Donaldson
84b1976061
spirv-fuzz: do not allow a dead break to target an unreachable block (#2917)
Because dominance information becomes a bit unreliable when blocks are
unreachable, this change makes it so that the 'dead break'
transformation will not introduce a break to an unreachable block.

Fixes #2907.
2019-09-26 10:57:05 +01:00
Alastair Donaldson
27238bcca0
spirv-fuzz: preserve some analyses when permuting blocks (#2918)
The performance of the fuzzer was unacceptable in the 'permute blocks'
transformation, due to dominator analysis being repeatedly invalidated
and recomputed.  This change preserves the dominator analysis,
together with the CFG analysis, when a block is moved down.
2019-09-26 10:56:43 +01:00
alan-baker
510ca9d616
Only allow previously declared forward refs in structs (#2920)
Fixes https://crbug.com/1008130

* Restore a missing check that the only valid forward references in
structs are previously declared forward pointers
2019-09-25 18:11:22 -04:00
Steven Perron
2a11f365bc
Handle id overflow in wrap-opkill (#2916)
New code in wrap-opkill does not handle id overflow correctly.  We fix that up.

Fixes https://crbug.com/1007144
2019-09-25 17:42:58 -04:00
Alastair Donaldson
70097c7761
spirv-fuzz: do not replace struct indices with synonyms (#2915)
This change introduces a robust check for whether an index in an
access chain is indexing into a struct, in which case the index needs
to be an OpConstant and cannot be replaced with a synonym.

Fixes #2906.
2019-09-25 16:52:35 +01:00
Alastair Donaldson
c1e03834e3
spirv-fuzz: Fixes to preconditions for adding dead break/continue edges (#2904)
Issues #2898 and #2900 identify some cases where adding a dead
continue would lead to an invalid module, and these turned out to be
due to the lack of sensible dominance information when a continue
target is unreachable. This change requires that the header of a loop
dominates the loop's continue target if a dead continue is to be
added.

Furthermore, issue #2905 identified a shortcoming in the algorithm
being used to identify when it is OK, from a dominance point of view,
to add a new break/continue edge to a control flow graph. This change
replaces that algorithm with a simpler and more obviously correct
algorithm (that incidentally does not require the new edge to be a
break/continue edge in particular).

Fixes #2898.
Fixes #2900.
Fixes #2905.
2019-09-25 16:51:41 +01:00
Alastair Donaldson
7bc114ba2f
spirv-fuzz: do not replace a pointer argument to a function call with a synonym (#2901)
Before this change, spirv-fuzz would replace a pointer argument to a
function call with a synonym, which is problematic when the synonym is
not a memory object declaration, since function call arguments are
required to be memory object declarations. This change adds a check
to ensure that such a replacement is not made.

Fixes #2896.
2019-09-25 12:17:29 +01:00
Alastair Donaldson
290f6a820d
spirv-fuzz: do not replace boolean constant argument to OpPhi instruction (#2903)
Before this change, spirv-fuzz would replace a constant boolean
argument to an OpPhi with the result of a binary operation, inserting
the instruction to compute the binary operation right before the
OpPhi, leading to an invalid module. This change conservatively
disallows replacing OpPhi arguments. Issue #2902 notes that there is
scope for being less conservative.

Fixes #2897.
2019-09-25 12:16:25 +01:00
alan-baker
527a689307
Remove validate_datarules.cpp (#2911)
* Checks moved into individual opcode validation
  * removes duplicated checks
* Add check that forward pointer points to struct
2019-09-24 17:55:12 -04:00
Steven Perron
55ea57a785
Handle extract with no indexes (#2910)
* Handle extract with no indexes

It is possible that OpCompositeExtract instructions will not have any
indexes.  This is not handled well by scalar replacement and instruction
folding.

Fixes https://crbug.com/1006435

* Fix typo.
2019-09-24 16:19:31 -04:00
Steven Perron
6f26d9ad81
Handle id overflow in convert local access chains (#2908)
Fixes https://crbug.com/1004453
2019-09-24 14:04:54 -04:00
Alastair Donaldson
958f7e72a7
Employ the "swarm testing" idea in spirv-fuzz (#2890)
This change to spirv-fuzz uses ideas from "Swarm Testing" (Groce et al. 2012), so that a random subset of fuzzer passes are enabled. These passes are then applied repeatedly in a randomized fashion, with the aggression with which they are applied being randomly chosen per pass.

There is plenty of scope for refining the probabilities introduce in this change; this is just meant to be a reasonable first effort.
2019-09-23 16:29:19 +01:00
Alastair Donaldson
b83535da53
Fix operand index in spirv-fuzz (#2895)
This change rectifies a problem where an absolute operand index was
being used when an index restricted to input operands was required.

Fixes #2893.
2019-09-23 16:28:25 +01:00
David Neto
8d0ca43da5 Add method comment for opt::Function::WhileEachInst (#2867)
Also, say that ForEachInst and ForEachParam process instructions/parameters
in order.
2019-09-23 09:36:48 -04:00
Steven Perron
6b07212659
Use OpReturn* in wrap-opkill (#2886)
* Use OpReturn* in wrap-opkill

The warp-opkill pass is generating incorrect code.  It is placing an
OpUnreachable at the end of a basic block, when the block can be
reached.  We can't reach the end of the block, but we can reach the end.
Instead we will add a return instruction.

Fixes #2875.
2019-09-20 10:32:27 -04:00
Alastair Donaldson
7275a71654
Allow validation during spirv-fuzz replay (#2873)
To aid in debugging issues in spirv-fuzz, this change adds an option whereby the SPIR-V module is validated after each transformation is applied during replay.  This can assist in finding a transformation that erroneously makes the module invalid, so that said transformation can be debugged.
2019-09-20 10:54:09 +01:00
Steven Perron
61edde52a0 Revert "Use OpReturn* in wrap-opkill"
This reverts commit 87f0fa432f.
2019-09-19 22:39:56 -04:00
Steven Perron
87f0fa432f Use OpReturn* in wrap-opkill
The warp-opkill pass is generating incorrect code.  It is placing an
OpUnreachable at the end of a basic block, when the block can be
reached.  We can't reach the end of the block, but we can reach the end.
Instead we will add a return instruction.

Fixes #2875.
2019-09-19 22:34:57 -04:00
Ehsan
08fcf8a4ab
Fix header include syntax. (#2882) 2019-09-19 09:26:24 -05:00
Steven Perron
248c80b049
Handle OpConstantNull in copy-prop-arrays. (#2870)
Many of the places in copy propagate arrays assumes that integer constant will be defined by an OpConstant instruction.  That is not always true.  We fix these spots by allowing for an OpConstantNull.
2019-09-19 10:24:00 -04:00
David Neto
d06fe08489 Fix comment typo found by protobufs linter (#2884) 2019-09-19 09:47:46 -04:00
Alastair Donaldson
e59b60de07
Fix detection of blocks bypassed by new edge (#2874)
Fixes an issue where the blocks that would be bypassed by a new break
or continue control flow edge were not properly detected.

Fixes #2871.
2019-09-18 20:50:08 +01:00
Alastair Donaldson
ccd7bf1675
Fix CMake issue related to spirv-fuzz (#2877)
spirv-fuzz generates protobuf sources in a 'protobuf' directory.  When
building with Unix Makefiles, compilation would fail due to to this
directory not existing.  This change causes the directory to be
created when the build is prepared.
2019-09-18 20:47:58 +01:00
Alastair Donaldson
0a07cd1c9a
Add fuzzer pass to replace ids with synonyms (#2857)
If the fuzzer's fact manager knows that ids A and B are synonymous, it
can replace a use of A with a use of B, so long as various conditions
hold (e.g. the definition of B must dominate the use of A, and it is
not legal to replace a use of an OpConstant in a struct's access chain
with a synonym that is not an OpConstant).

This change adds a fuzzer pass to sprinke such synonym replacements
through the module.
2019-09-18 20:47:08 +01:00
alan-baker
bbb29870b5
Relaxed bitcast with pointers (#2878)
* When input or result is a pointer type also allow 32-bit integer
vectors for the other type
* Relaxation only applies to SPIR-V 1.5 or in the presence of
SPV_KHR_physical_storage_buffer
* new tests
2019-09-18 11:55:39 -04:00
Raun Krisch
99793fa67d Adding valilidation checks for OpEntryPoint duplicate names and execution mode (#2862) 2019-09-16 19:13:30 -04:00
alan-baker
9325619353
Extra resource interface validation (#2864)
* Vulkan specific checks
  * storage buffer variables must be structs or arrays of structs
  * storage buffer struct must be Block decorated
  * uniform struct must be Block or BufferBlock decorated
* new tests
2019-09-16 10:46:31 -04:00
alan-baker
5a48c0da15 SPIRV-Tools support for SPIR-V 1.5 (#2865)
* Ensure same enum values have consistent extension lists

* val: fix checking of capabilities

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

* Add basic support for SPIR-V 1.5

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

* Test validation of SPIR-V 1.5 incorporated extensions

Starting with 1.5, incorporated features no longer require
the associated OpExtension instruction.
2019-09-13 14:59:02 -04:00
Alastair Donaldson
ad7f2c5c4c
Add fuzzer pass to copy objects (#2853)
A new fuzzer pass that randomly introduces OpCopyObject instructions
that make copies of ids, and uses the fact manager to record the fact
that an id %id is synonymous with an id generated by an OpCopyObject
applied to %id. (A future pass will exploit such synonym facts.)
2019-09-11 23:45:20 +01:00
Ryan Harrison
67b87f22cf
Handle another case where creating a constant can fail (#2854)
Fixes #2847
2019-09-11 17:18:05 -04:00
Steven Perron
c7a39bc40f
Don't inline function containing OpKill (#2842)
If an OpKill instruction is inlined into a continue construct, then the
spir-v is no longer valid.  To avoid this issue, we do inline into an
OpKill at all.  This method was chosen because it is difficult to keep
track of whether or not you are in a continue construct while changing
the function that is being inlined into.  This will work well with wrap
OpKill because every will still be inlined except for the OpKill
instruction itself.

Fixes #2554
Fixes #2433

This reverts commit aa9e8f5380.
2019-09-11 13:26:55 -04:00
Steven Perron
4f9256db35
Handle id overflow in wrap op kill. (#2851)
Fixes https://crbug.com/997729
2019-09-11 13:26:42 -04:00
David Neto
9f188e3374 Assembler: Can't set an ID in instruction without result ID (#2852)
Fix tests that violated this rule.

Fixes #2257
2019-09-11 13:15:25 -04:00
Ryan Harrison
c0e9807094
Handle creating a new constant failing gracefully (#2848)
Fixes #2847
2019-09-10 12:51:19 -04:00
Alastair Donaldson
e2e95172df
Rework management of probabilities in spirv-fuzz (#2839)
Before this change there was quite a lot of duplication in the code
being used to choose random percentages, and some of it was incorrect
so that a percentage chance of (100-N)% instead of N% was being used.
Also there was a lot of duplicate code to choose a random index into a
vector.  This change eliminates that duplication (fixing up the
percentage problem), and gets rid of direct access to the random
number generator being used for fuzzing, so that all randomization
requests must go through the FuzzerContext class, discouraging future
ad-hoc uses of the random number generator.
2019-09-10 15:02:25 +01:00
Alastair Donaldson
7ee8f443ea
Fix add-dead-break and add-dead-continue passes to respect dominance (#2838)
The implementation of these passes had overlooked the fact that adding
a new edge to a control flow graph can change dominance information.
Adding a dead break/continue risks causing uses to no longer be
dominated by their definitions.  This change introduces various tests
to expose such scenarios, and augments the preconditions for these
transformations with checks to guard against the situation.
2019-09-10 14:48:27 +01:00
Steven Perron
35c9518c4e
Handle id overflow in the ssa rewriter. (#2845)
* Handle id overflow in the ssa rewriter.

Remove LocalSSAElim pass at the same time.  It does the same thing as the SSARewrite pass. Then even share almost all of the same code.

Fixes crbug.com/997246
2019-09-10 09:38:23 -04:00
Steven Perron
7f7236f1eb
Handle id overflow in the constant manager. (#2844)
Fixes crbug.com/997246
2019-09-09 15:12:26 -04:00
alan-baker
a464ac1a27
Add generic builtin validation of target (#2843)
* Validate the target's opcode is acceptable
* Update tests
* New tests
* move early exit for builtins a bit later in the pass
2019-09-09 14:53:30 -04:00
Steven Perron
6797173cf6
Don't register duplicate decoration in validator. (#2841)
As far as I know, it is legal to have multiple decoration adding the
same decoration to the same id.  The validator registers all of these
decoration as if they were distinct decorations.  This can cause poor
memory usage and performance in some cases.

This fix is to make sure that duplicates are not registers.

I keep the type of the decoration list as an std::vector because I
expect it to be small enough in most cases that the linear search will
still be faster that using some type of map.

No tests are added because we do not have a mechanism to test memory
usage in our unit tests.

Fixes #2837.  The total memory usage drop to 14,236KB.
2019-09-09 12:55:44 -04:00
Steven Perron
76261e2a7d
Replace CubeFaceCoord and CubeFaceIndexAMD (#2840)
Part of #2814.
2019-09-06 17:11:37 -04:00
Steven Perron
b218ad1994
Fold Min, Max, and Clamp instructions. (#2836)
Fixes #2830.
2019-09-05 13:30:03 -04:00
Steven Perron
a41520eaa4
Replace uses of SPV_AMD_shader_trinary_minmax extension (#2835)
Part of #2814
2019-09-05 09:29:04 -04:00
rumblehhh
1dfb5fc12e Export SPIRV-Tools targets on installation (#2785)
This allows the targets to be used in other cmake projects. See the following for more details:
https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#creating-packages
https://foonathan.net/blog/2016/07/07/cmake-dependency-handling.html
2019-09-04 12:45:26 -04:00
greg-lunarg
c77045b4a0 Instrument: Be sure Float16 capability on when generating float16 null (#2831) 2019-09-03 15:19:36 -04:00
greg-lunarg
d11725b1d4 Add --relax-float-ops and --convert-relaxed-to-half (#2808)
The first pass applies the RelaxedPrecision decoration to all executable
instructions with float32 based type results. The second pass converts
all executable instructions with RelaxedPrecision result to the equivalent
float16 type, inserting converts where necessary.
2019-09-03 13:22:13 -04:00
Steven Perron
b54d950298
Fold Fmix should accept vector operands. (#2826)
Fixes #2819
2019-09-03 09:17:18 -04:00
Alastair Donaldson
2c5ed16ba9 Fix end comments in header files (#2829)
The end comments for the #ifndef ... #endif macros in various header
files containd a stray #define.
2019-09-02 17:31:27 -04:00
Ben Clayton
65e362b7ae AggressiveDCEPass: Set modified to true when appending to to_kill_ (#2825)
Also add an assertion that these `modified` is true if to_kill_ has a non-zero size to catch this sort of issue in the pass.

Fixes: #2824
2019-08-30 16:27:22 -04:00
Steven Perron
d67130caca
Replace SwizzleInvocationsAMD extended instruction. (#2823)
Part of #2814
2019-08-30 14:07:24 -04:00
Steven Perron
ad71c057c7
Replace SwizzleInvocationsMaskedAMD extended instruction. (#2822)
Part of #2814
2019-08-30 10:48:42 -04:00
Steven Perron
35d98be3bc
Amd ext to khr (#2811)
Add the first steps to removing the AMD extension VK_AMD_shader_ballot.
Splitting up to make the PRs smaller.

Adding utilities to add capabilities and change the version of the
module.

Replaces the instructions:

OpGroupIAddNonUniformAMD = 5000
OpGroupFAddNonUniformAMD = 5001
OpGroupFMinNonUniformAMD = 5002
OpGroupUMinNonUniformAMD = 5003
OpGroupSMinNonUniformAMD = 5004
OpGroupFMaxNonUniformAMD = 5005
OpGroupUMaxNonUniformAMD = 5006
OpGroupSMaxNonUniformAMD = 5007

and extentend instructions

WriteInvocationAMD = 3
MbcntAMD = 4

Part of #2814
2019-08-29 12:48:17 -04:00
Ben Clayton
5a581e738c spvtools::Optimizer - don't assume original_binary and optimized_binary are aliased (#2799)
If they are not aliased, the function will always print the message:

     "Binary unexpectedly changed despite optimizer saying there was no change"

Which is (usually) totally bogus.

Fixes #2798
2019-08-29 10:04:55 -04:00
Steven Perron
73422a0a5e
Check feature mgr in context consistency check (#2818)
We add a check that the feature manager is correcter after each pass.

This resulted in a couple failing tests cases.  Those are fixed.

Part of #2814
2019-08-28 11:49:16 -04:00
Steven Perron
15fc19d091
Refactor instruction folders (#2815)
* Refactor instruction folders

We want to refactor the instruction folder to allow different sets of
rules to be added to the instruction folder.  We might want different
sets of rules in different circumstances.

We also need a way to add rules for extended instructions.  Changes are
made to the FoldingRules class and ConstFoldingRules class to enable
that.

We added tests to check that we can fold extended instructions using the
new framework.

At the same time, I noticed that there were two tests that did not tests
what they were suppose to.  They could not be easily salvaged. #2813 was
opened to track adding the new tests.
2019-08-26 18:54:11 -04:00
Alastair Donaldson
8336d1925f
Extend reducer to remove relaxed precision decorations (#2797)
Adds a reduction pass that removes OpDecorate and OpMemberDecorate
instructions that annotate instructions and members with
RelaxedPrecision.  As well as being useful in its own right, removing
such references allows other passes to remove further instructions.
2019-08-22 23:33:09 +01:00
Steven Perron
b00ef0d26e
Handle Id overflow in private-to-local (#2807)
We need to handle id overflow in the private to local pass.

Fixes https://crbug.com/962295
2019-08-22 09:14:48 -04:00
Steven Perron
aef8f92b2b
Even more id overflow in sroa (#2806)
Now we need to handle id overflow when we overflow while replacing uses of the variable.  While looking at this code, I noticed an error in the way we handle access chains that cannot be replaced because of overflow.  Name it will make some change, and then give up by returning SuccessWithoutChange.  But it was changed.

This is fixed up by returning Failure if we notice the error at the time of rewriting the users.  This is for both id overflow or out-of-bounds accesses.

Code is added to "CheckUses" to remove variables that have out-of-bounds accesses from the candidate list, so we don't even try to rewrite its uses.

Fixes https://crbug.com/995032
2019-08-21 13:12:42 -04:00
Steven Perron
c5d1dab99e
Add name for variables in desc sroa (#2805)
Fixes #2802.
2019-08-21 10:55:02 -04:00
David Neto
0cbdc7a2c3 Remove unimplemented method declaration (#2804) 2019-08-20 08:53:27 -04:00
Steven Perron
bc62722b80
Handle overflow in wrap-opkill (#2801)
Fixes https://crbug/994203
2019-08-18 19:00:18 -04:00
Steven Perron
9cd07272a6
More handle overflow in sroa (#2800)
If we run out of ids when creating a new variable, sroa does not recognize
the error, and continues doing work.  This leads to segmentation faults.

Fixes https://crbug/969655
2019-08-16 13:15:17 -04:00
greg-lunarg
06407250a1 Instrument: Add support for Buffer Device Address extension (#2792) 2019-08-16 09:18:34 -04:00
Toomas Remmelg
7b4e5bd5ec Update remquo validation to match the OpenCL Extended Instruction Set Specification (#2791) 2019-08-15 09:38:37 -04:00
Jaebaek Seo
ff872dc6bf
Change the way to include header (#2795)
`#include <source/util/string_utils.h>` works only when we specify
`include_directories(${CMAKE_CURRENT_SOURCE_DIR}/)` in
cmake. It is hard to set the source directory as a include path
in some build systems e.g., bazel. Using the relative path easily
solves this issue. This commit uses
`#include "source/util/string_utils.h"` instead of
`#include <source/util/string_utils.h>`.
2019-08-14 18:09:20 -04:00
alan-baker
bbd80462f5
Fix validation of constant matrices (#2794)
Fixes #2793

* Don't special case matrix validation compared to other composites
  * just check the constituents are constants or undefs
  * later checking validates the column type
  * new test
2019-08-14 11:26:41 -04:00
Steven Perron
60043edfa1
Replace OpKill With function call. (#2790)
We are no able to inline OpKill instructions into a continue construct.
See #2433.  However, we have to be able to inline to correctly do
legalization.  This commit creates a pass that will wrap OpKill
instructions into a function of its own.  That way we are able to inline
the rest of the code.

The follow up to this will be to not inline any function that contains
an OpKill.

Fixes #2726
2019-08-14 09:27:12 -04:00
greg-lunarg
95386f9e45 Instrument: Fix version 2 output record write for tess eval shaders. (#2782)
Fix output record write for tess eval shaders.

Also change command line for bindless instrumentation to use use
output record version 2.
2019-08-09 08:22:41 -04:00
Steven Perron
4b64beb1ae
Add descriptor array scalar replacement (#2742)
Creates a pass that will replace a descriptor array with individual variables.  See #2740 for details.

Fixes #2740.
2019-08-08 10:53:19 -04:00
greg-lunarg
29af42df12 Add SPV_EXT_physical_storage_buffer to opt whitelists (#2779)
This also fixes ADCE to not remove possibly needed OpTypeForwardPointer.
The bug, its fix and the corresponding test have a circular dependency
with the extension, so they are packaged together.
2019-08-08 09:45:59 -04:00
Steven Perron
b029d3697e
Handle RelaxedPrecision in SROA (#2788)
If a member of a struct has a relaxed precision, sroa will not split the
struct.  This means we do not get all cases.  This commit handles these
cases.  The other part is that the decoration needs to be passed on to
the new variables.

Fixes #2786
2019-08-07 12:17:26 -04:00
Alastair Donaldson
698b56a8f0
Add 'copy object' transformation (#2766)
This transformation can introduce an instruction that uses
OpCopyObject to make a copy of some other result id.  This change
introduces the transformation, but does not yet introduce a fuzzer
pass to actually apply it.
2019-08-05 18:00:13 +01:00
Geoff Lang
0b70972a29 Remove extra ';' after member function definition. (#2780)
This fixes a clang compiler warning about extra semicolons.
2019-08-01 19:33:55 -04:00
Ryan Harrison
5ada98d0bb Update WebGPU validation rules of OpAtomic*s (#2777)
Fixes #2723
2019-07-31 17:15:47 -04:00
alan-baker
3726b500b1
Treat access chain indexes as signed in SROA (#2776)
Fixes #2768

* In scalar replacement, interpret access chain indexes as signed counts
* Use Constant::GetSignExtendedValue and Constant::GetZeroExtendedValue
where appropriate
* new tests
2019-07-31 15:39:33 -04:00
David Neto
31590104ec
Add pass to inject code for robust-buffer-access semantics (#2771)
spirv-opt: Add --graphics-robust-access

Clamps access chain indices so they are always
in bounds.

Assumes:
- Logical addressing mode
- No runtime-array-descriptor-indexing
- No variable pointers

Adds stub code for clamping coordinate and samples
for OpImageTexelPointer.

Adds SinglePassRunAndFail optimizer test fixture.

Android.mk: add source/opt/graphics_robust_access_pass.cpp

Adds Constant::GetSignExtendedValue, Constant::GetZeroExtendedValue
2019-07-30 19:52:46 -04:00
Ryan Harrison
4a28259cc8
Update OpMemoryBarriers rules for WebGPU (#2775)
Part of #2724
2019-07-30 14:50:55 -04:00
David Neto
ac3d131054
Element type is const for analysis::Vector,Matrix,RuntimeArray (#2765)
This makes it symmetric with the result type of ...->element_type which
returns a const Type.

So now we can write code like this:

   analysis::Vector v = ...
   analysis::Vector(v->element_type(), 2);
2019-07-29 22:55:18 -04:00
Diego Novillo
49797609b7
Protect against out-of-bounds references when folding OpCompositeExtract (#2774)
This fixes #2608.

The original test case had an out-of-bounds reference that ended up
folding into OpCompositeExtract that was indexing right outside the
constant composite.

The returned constant would then cause a segfault during constant
propagation.
2019-07-29 13:27:40 -07:00
alan-baker
7fd2365b06
Don't move debug or decorations when folding (#2772)
Fixes #2764

* Don't replace all uses when simplifying instructions, instead only
update non-debug, non-decoration uses
  * added a test
* Add a new version of RAUW that takes a predicate to decide whether to
replace the use or not
  * used in simplification pass
2019-07-29 16:20:43 -04:00
Ryan Harrison
7bafeda284
Update OpControlBarriers rules for WebGPU (#2769)
* Update OpControlBarriers rules for WebGPU

Part of #2724
2019-07-29 12:53:27 -04:00
Diego Novillo
9559cdbdf0
Fix #2609 - Handle out-of-bounds scalar replacements. (#2767)
* Fix #2609 - Handle out-of-bounds scalar replacements.

When SROA tries to do a replacement for an OpAccessChain that is exactly
one element out of bounds, the code was trying to access its internal
array of replacements and segfaulting.

This protects the code from doing this, and it additionally fixes the
way SROA works by not returning failure when it refuses to do a
replacement.  Instead of failing the optimization pass, SROA will now
simply refuse to do the replacement and keep going.

Additionally, this patch fixes the SROA logic to now return a proper status so we can
correctly state that the pass made no changes to the IR if it only found
invalid references.
2019-07-26 12:33:40 -04:00
Steven Perron
bb0e2f65bb
Fix check for unreachable blocks in merge-return (#2762)
Merge return expects unreachable merge block to look a certain way, and
unreachable continue blocks to look a certain way.  What if an
unreachable block is both a merge and a continue?  The continue is
suppose to take precedent, but merge-return implements it with the merge
taking precedent.  This change flips that around.

Fixes #2746
2019-07-25 09:34:18 -04:00
Alastair Donaldson
1a89ac8b28
Transformation and fuzzer pass to add dead continues (#2758)
Similar to the existing 'add dead breaks' pass, this adds a pass to
add dead continues to blocks in loops where such a transformation is
viable.  Various functionality common to this new pass and 'add dead
breaks' has been factored into 'fuzzer_util', and some small
improvements to 'add dead breaks' that were identified while reviewing
that code again have been applied.

Fixes #2719.
2019-07-25 13:50:33 +01:00
Steven Perron
c7fcb8c3b9
Process OpDecorateId in ADCE (#2761)
* Process OpDecorateId in ADCE

When there is an OpDecorateId instruction that is live,
the ids that is references must be kept live.  This change
adds them to the worklist.

I've also updated a validator check to allow OpDecorateId
to be able to apply to decoration groups.

Fixes #1759.

* Remove dead code.
2019-07-24 14:43:49 -04:00
Steven Perron
fb83b6fbb5
Record correct dominators in merge return (#2760)
In merge return, we need to know the original dominator for a block in order to
traverse code from the original dominator to the new dominator and add
appropriate Phi nodes.  The current code gets this wrong because the dominator
tree is build as needed.  The first time we get the immediate dominator for a
function we just built the dominator tree and it takes into account that a
block has been split.  The second time it does not.

This inconsistency needs to be fixed.  We do that by recording the original
dominator for all blocks at the start of the pass.

If we were to record just the basic block, that could change if the block is
split.  We want to traverse the code in the body of the original dominator,
whatever block it ends up in.  To make this easy to track, we not save the
terminator instruction to represent the original dominator.

Fixes #2745
2019-07-24 13:56:54 -04:00
Steven Perron
c9190a54da
SSA rewriter: Don't use trivial phis (#2757)
When a phi candidate is marked as trivial, we are suppose to update all
of its uses to the reference the value that it is being folded to.
However, the code updates the uses misses `defs_at_block_`.  So at a
later time, the id for the trivial phi can reemerge.

Fixes #2744
2019-07-23 17:59:30 -04:00
alan-baker
aea4e6b1b9 Fix block depth rule priority (#2755)
Fixes #2743

* Continue depth calculation should take precedence over merge calculation
2019-07-23 13:57:44 -04:00
alan-baker
a94ddc267c
Case validation with repeated labels (#2689)
Fixes #2686

* Update validation to handle the default case being mentioned multiple
times
  * new tests
2019-07-23 11:23:32 -04:00
greg-lunarg
3855447d93 Bindless Instrument: Make init check depend solely on input_init_enabled (#2753)
* Bindless Instrument: Make init check depend solely on input_init_enabled

Previously was dependent on presense of descriptor_indexing extension
in SPIR-V, but this missed some cases. Tests updated to refect this new
policy.

* Fix format.
2019-07-22 13:51:39 -04:00
Kévin Petit
11516c0b9a Validate storage class OpenCL environment rules for atomics (#2750)
This change refactors all storage class validation for atomics
to reflect the similar refactoring in the specification.

It is currently not possible to write a test for the check
rejecting Generic in an OpenCL 1.2 environment as the required
GenericPointer capability isn't allowed there. I've decided
to keep the check nonetheless to guard against the capability
becoming available without the rules for atomics being updated.

The ID changes in existing tests aren't ideal but introducing
names drags in a substantial refactoring of this file.

Contributes to #2595.

Signed-off-by: Kevin Petit <kevin.petit@arm.com>
2019-07-22 08:38:42 -04:00
Jason Macnak
bac82f49aa Allow LOD ops in compute shaders with derivative group execution modes (#2752)
Also update existing derivative check to be based on the execution mode
instead of just the extension being present.

More info about extension:
- https://github.com/KhronosGroup/SPIRV-Registry/blob/master/extensions/NV/SPV_NV_compute_shader_derivatives.asciidoc
2019-07-22 08:37:44 -04:00
David Neto
76b75c40a1 Document opt::Instruction::InsertBefore methods (#2751) 2019-07-18 11:37:28 -04:00
Steven Perron
aa9e8f5380
Revert "Do not inline OpKill Instructions (#2713)" (#2749)
This reverts commit fe7cc9c612.
2019-07-17 14:59:05 -04:00
Jeff Bolz
58e2ec25ba For Vulkan, disallow structures containing opaque types (#2546) 2019-07-16 16:16:19 -04:00
Steven Perron
230c9e4371
Fix bug in merge return (#2734)
* Fix bug in merge return

The merge return pass seems to assume that the only new edges in the cfg
are from return block to merge blocks.  However, it is possible that a
merge block branches to a merge block when it did not before.

This change add a new variable to track all of the new edges.  It also
renames some other variables and cleans us the code to make it a bit
easier to read.

Fixes #2702.
2019-07-16 09:11:22 -04:00
Jason Macnak
1fedf72e50 Allow ray tracing shaders in inst bindle check pass. (#2733)
Adds the ray tracing stages (ray gen, intersection, any hit, closest hit,
miss, and callable) to the allowed stages in pass instrumentation and add
debug records for these stages to output the global launch id.

More information for ray tracing shaders:
- https://github.com/KhronosGroup/GLSL/blob/master/extensions/nv/GLSL_NV_ray_tracing.txt
2019-07-15 16:24:42 -04:00
greg-lunarg
92c41ff1e7 Remove Common Uniform Elimination Pass (#2731)
Remove Common Uniform Elimination Pass

Fixes #2520.
2019-07-12 11:02:10 -04:00
Ryan Harrison
55adf4cf70
Update execution scope rules for WebGPU (#2730)
Fixes #2722
2019-07-11 14:37:36 -04:00
alan-baker
1a2de48a12 Extra small storage validation (#2732)
Fixes #2729

* Check acceptable uses of small type generators
2019-07-11 13:05:14 -04:00
Jeff Bolz
327963765b Add validation for SPV_EXT_demote_to_helper_invocation (#2707) 2019-07-11 10:33:22 -04:00
Steven Perron
5ce8cf781f
Change the order branches are simplified in dead branch elim (#2728)
Dead branch elimination needs to know about the constructs that a block is contained it when determining what to do with its merge instruction.  We currently fold branches in block as we see them, which is parent constructs before their children.  This causes the struct cfg analysis to crash because it tries to get the parent construct for a block after the parent has been folded.

This can be fixed by folding the branch of the children before the parents.

Fixes #2667.
2019-07-10 14:59:44 -04:00
Thomas Roughton
cd153db8ed Add —preserve-bindings and —preserve-spec-constants (#2693)
Add optimizer options to for preservation of spec constants and variable with
binding decorations.  They are to be preserved even if they are unused.
2019-07-10 14:12:19 -04:00
Steven Perron
86e45efe15
Handle decorations better in some optimizations (#2716)
There are a couple spots where we are not looking at decorations when we should.

1. Value numbering is suppose to assign a different value number to ids if they have different decorations.  However that is not being done for OpCopyObject and OpPhi.

1. Instruction simplification is propagating OpCopyObject instruction without checking for decorations.  It should only do that if no decorations are being lost.

Add a new function to the decoration manager to check if the decorations of one id are a subset of the decorations of another.

Fixes #2715.
2019-07-10 11:37:16 -04:00
Ryan Harrison
3a252a267b
Update memory scope rules for WebGPU (#2725)
Fixes #2721
2019-07-10 10:34:50 -04:00
alan-baker
0c4feb643b
Remove extra semis (#2717)
* Remove extra semi-colons
* Update re2 dep
2019-07-08 15:07:36 -04:00
alan-baker
456cc598af
Validate usage of 8- and 16-bit types with only storage capabilities (#2704)
Fixes #2669

* Check capabilities when validating variables
* validate load and store types
* Constant check
* Don't checks pointers for stores, constants and loads
* Validate composite instructions
* Validate conversions for 8- and 16-bit limited types
* Unified tests and expanded them
* Disallow OpCopyMemory
* new tests and update old tests
2019-07-08 14:10:13 -04:00