Commit Graph

2197 Commits

Author SHA1 Message Date
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
Alastair Donaldson
c5ee1bc7bd
Fix opt fuzzer test harness (#4670)
The test harness for the opt fuzzer was failing to consider that the
input might use a very large id bound, despite no id approaching this
bound actually being used.

This change modifies the test harness to use the module's id bound,
rather than looking through the module for large ids.

Fixes: oss-fuzz:42386
2022-01-07 15:03:29 +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
Alastair Donaldson
f0351b7bc6
Avoid id bound errors during opt fuzzing (#4658)
Use a very large id bound when fuzzing the optimizer, and check that the
input does not ids that are too close to this bound. This should make it
impossible in practice for an id overflow to occur.

Fixes #4657.
2021-12-13 10:56:52 +00:00
Alastair Donaldson
e452792594
Simplify the as fuzzer target (#4647)
Makes the logic in the as fuzzer target closer to the logic of the
spirv-as tool.

Fixes #4643
2021-12-10 10:06:23 -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
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
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
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
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
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
Alastair Donaldson
8c91f14a9b
Add libFuzzer target for spirv-fuzz (#4434)
Fixes #4431.
2021-10-26 15:24:51 +00: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
Alastair Donaldson
0f3bc1d9b2
Fix i386 build issues related to random generation (#4586)
The OSS-Fuzz i386 build has been failing due to errors about
64-to-32-bit conversions, relating to random generation code. This
changre fixes the problem by explicitly using a 64-bit random generator,
and by adding a cast to size_t to avoid an implicit conversion.
2021-10-20 10:20:07 -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
Ryan Harrison
d31218c560
Use max enum instead of static array of legal values (#4571) 2021-10-13 17:53:11 -04: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
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
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
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
1d48824bae
Update SPIRV-Headers (#4543)
* Remove tests that expected fast math mode operands to require a
  capability
2021-09-22 15:52:19 -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
Alastair Donaldson
0f4508752f
Fix UBSan error in spirv-dis fuzzer (#4517)
Pending a more general solution for constructing a target environment
based on the bytes of a test input, this change avoids a UBSan error
caused by the existing approach.

Fixes https://crbug.com/38087
2021-09-21 15:07:30 +00: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
Alastair Donaldson
bf463fe37c
Fix UBSan kokoro config (#4522)
A test has been removed which depends on casting to spv_target_env from a value
outside the range of that enum. This is an undefined behaviour, thus the
test is invalid.
2021-09-13 16:55:51 +01: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
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
Alastair Donaldson
789de0dc4b
Adjust build for fuzzer targets to support OSS-Fuzz (#4498)
With OSS-Fuzz, the build system should not directly set options such as
-fsanitize=fuzzer. Instead, these are set by OSS-Fuzz, and
linker options are provided via the LIB_FUZZER_OPTIONS environment
variable. This change allows the fuzzers to be build stand-alone,
outside of OSS-Fuzz, in the way that was already supported, as well as
inside OSS-Fuzz, when the LIB_FUZZER_OPTIONS environment variable is
set.
2021-09-02 22:55:30 +00: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
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
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
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
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
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
Alastair Donaldson
3ab6fb9c03
Add CMake rules for libFuzzer targets (#4445)
Adds CMake rules for the libFuzzer targets, with a view to running
them on OSS-Fuzz.

Fixes #4448.
2021-08-05 08:11:21 +00: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
Alastair Donaldson
affe280c22
Add GraphicsFuzz shaders to fuzzer corpus (#4429)
Adds a set of SPIR-V shaders to the corpus used for fuzzing.

Fixes #4428.
2021-08-03 15:27:03 +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
Alastair Donaldson
17bf443767
spirv-fuzz: Add minimal SPIR-V example to test shaders (#4415)
Testing on ClusterFuzz has revealed that the fuzzer sometimes goes
wrong when a shader is very simple - e.g., there have been bugs where
a fuzzer pass has assumed that at least one basic type exists in the
module. This change adds an almost empty SPIR-V example to the shaders
used for testing, to help catch such cases locally.
2021-07-29 17:09:14 +01: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
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
dong-ja
4bcd13ff13
spirv-opt: Add more tests to control dependence (#4410)
In particular, adds tests for DoesBlockExist, ForEachBlockLabel, and
WhileEachBlockLabel.
2021-07-28 16:56:51 -04: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
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
alan-baker
2a7a561c0c
Fix local size hint id tests (#4400)
* Fix tests for updated grammar
* LocalSizeHintId should have three operands, not just 1
* Update deps
2021-07-22 15:23:22 -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
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
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
Alastair Donaldson
4d2832e3c8
spirv-fuzz: Check updated analyses in transformation tests (#4266)
Enhances the tests for TransformationSwapFunctionVariables to check that
analyses are updated.
2021-07-05 22:09:43 +01:00
Alastair Donaldson
7763360524
spirv-fuzz: Added tests for signedness analysis (#4361)
Adds skeleton tests to support #4345.
2021-07-04 12:26:11 +01:00
Ben Ashbaugh
c67f132087
add tests for SPV_KHR_bit_instructions (#4350) 2021-07-02 08:53:18 -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
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
8cc8b6562b
spirv-fuzz: Add illustrative tests for new issues (#4347)
Adds (currently disabled) tests related to #4345 and #4346.
2021-06-24 17:24:46 +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
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
c05f744154
Spirv-fuzz: Add tests for MaybeGet* functions in fuzzerutil (#4284)
Adds tests for all MaybeGet* functions in fuzzerutil.

Fixes #4179.
2021-06-05 00:36:23 +01: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
EGJ1996
c853a91144
spirv-fuzz: Added test to increase coverage of the add_parameter transformation (#4305)
Fixes #4294 by achieving full coverage of this transformation.
2021-06-02 17:44:42 +01:00
Mostafa Ashraf
126a826d3a
Spirv-fuzz: Achieve coverage of TransformationAddDeadBlock test (#4306)
Fixes #4290, by enhancing the test to get 100% of the lines covered.
2021-06-02 17:16:44 +01: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
EGJ1996
ec1bc3e2e5
spirv-fuzz: Added extra tests for AddTypeFloat and AddTypeInt transformations (#4292)
Tests some edge cases of these transformations more thoroughly.
2021-05-27 08:36:39 +01:00
EGJ1996
94f570d7aa
spirv-fuzz: Increase test coverage of TransformationCompositeConstruct (#4301)
Brings this class up to 100% statement coverage.

Fixes #4288
2021-05-26 21:31:55 +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
Mostafa Ashraf
91931ffcd2
spirv-fuzz: Enhance test to improve lines covered (#4289)
Fixes #4287 by enhancing the test to get 100% of lines covered.
2021-05-24 14:24:11 +01:00
Alastair Donaldson
0afe1f2b3f
spirv-fuzz: Cover protobuf message creation in tests (#4285)
The Transformation class tests did not cover the (trivial) ToMessage
methods of each transformation, nor the constructors that take a
protobuf message. This lac of coverage makes it hard to see which more
interesting pieces of code are not covered when looking at coverage
percentages. This change adapts the helper function for applying a
transformation and checking fresh ids so that it turns a
transformation into a protobuf message and back, thus covering
ToMessage and the protobuf constructor for every transformation. The
runtime overhead of doing this is very small.
2021-05-22 17:45:09 +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
David Neto
de1cae069c
val test: Update capability dependency (#4268)
Private storage class is now also enabled by VectorComputeINTEL

This should fix the CI bots
2021-05-11 10:40:45 -04: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
sfricke-samsung
693d564db4
spriv-val: Fix clang-format bug for VUID string (#4238) 2021-04-16 08:52:48 -04:00
Greg Fischer
48007a5c7f
Add interpolate legalization pass (#4220)
This pass converts an internal form of GLSLstd450 Interpolate ops
to the externally valid form. The external form takes the lvalue
of the interpolant. The internal form can do a load of the interpolant.
The pass replaces the load with its pointer. The internal form is
generated by glslang and possibly other frontends for HLSL shaders.
The new pass is called as part of HLSL legalization after all
propagation is complete.

Also adds internal interpolate form to pre-legalization validation
2021-03-31 14:26:36 -04:00
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
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
Alastair Donaldson
3d39517961
spirv-fuzz: Improve transformation test oracles (#4207)
To help ensure that optimizations that do less cautious invalidation
of analyses are implemented correctly, this change adds checks to the
tests of various transformations to ensure that analyses such as
def-use are up to date.
2021-03-23 13:31:14 +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
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
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
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
Vasyl Teliman
7779907584
spirv-fuzz: Add buggy test (#4180)
Part of #4170.
2021-03-14 01:52:05 +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
sfricke-samsung
f0c96f40c7
spriv-val: Vulkan image gather constant component (#4133) 2021-02-05 15:12:38 -05:00
sfricke-samsung
3ad7e5fcc0
spirv-val: Fix/Label UniformConstant VUID (#4134) 2021-02-05 09:57:00 -05:00
sfricke-samsung
f11f743481
spirv-val: Add Vulkan Invariant Decoration VUID (#4132) 2021-02-05 09:49:14 -05:00
sfricke-samsung
c91a25af13
spirv-val: label tests for VUID 04657 (#4119) 2021-02-02 10:54:26 -05:00
sfricke-samsung
d61a7d110d
spirv-val: Add Vulkan PSB64 convert VUID (#4122) 2021-02-01 10:39:44 -05:00
Steven Perron
297723d75a
Mark module as modified if convert-to-half removes decorations. (#4127)
* Mark module as modified if convert-to-half removes decorations.

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

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

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

This bug makes
https://github.com/google/amber/blob/main/tests/cases/debugger_hlsl_shadowed_vars.amber
fail. This commit fixes the bug.
2021-01-28 12:57:35 -05:00
Caio Marcelo de Oliveira Filho
b812fd634e
Validate SPV_KHR_workgroup_memory_explicit_layout (#4128)
* Validate SPV_KHR_workgroup_memory_explicit_layout

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

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

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

* Check layout decorations for Workgroup Blocks.

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

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

* Update SPIRV-Headers dependency

Bump it to include SPV_KHR_workgroup_memory_explicit_layout.

* Add option to validate Workgroup blocks with scalar layout

Validate the equivalent of scalarBlockLayout for Workgroup storage
class Block variables from SPV_KHR_workgroup_memory_explicit_layout.
Add option to the API and command line tool.
2021-01-27 19:38:38 -05:00
alan-baker
cc81f53d3d
Validate VK_KHR_zero_initialize_workgroup_memory (#4124)
* Allow OpConstantNull for Workgroup variable initializer in Vulkan
environment
* tests
2021-01-27 19:38:09 -05:00
sfricke-samsung
d71ac38b8e
spirv-val: Add Vulkan image gather offset VUID (#4118) 2021-01-27 19:37:45 -05:00
sfricke-samsung
a61600c763
spirv-val: Label Vulkan atomic semantics VUIDs (#4120) 2021-01-25 11:19:06 -05:00
sfricke-samsung
819117cd48
spirv-val: Label VUID 04662 (#4123) 2021-01-25 09:51:21 -05:00
sfricke-samsung
89ad2272ba
spirv-val: Label VUID 04683 (#4121) 2021-01-25 09:38:19 -05:00
sfricke-samsung
f37547c73a
spirv-val: Add Vulkan EXT builtins (#4115) 2021-01-20 10:40:31 -05:00
David Neto
56f8ed48ef
Validate Sampled=1 for Vulkan ImageQuerySizeLod, ImageQueryLevels, ImageQueryLod (#4103)
Also require image type parameter to OpTypeSampledImage to have
Sampled=0 or Sampled=1

Fixes #4102
2021-01-19 17:44:45 -05:00
sfricke-samsung
e25db023c4
spirv-val: Add Vulkan Memory Scope VUs (#4106)
* Fix test using Fragment execution
2021-01-19 08:37:42 -05:00
Ryan Harrison
9150cd441f
Remove WebGPU support (#4108)
Leaves SPV_ENV_WEBGPU_0 enum in place, but marked deprecated, so users
of the library are not broken by an API enum being removed.

Fixes #4101
2021-01-14 16:45:18 -05:00
sfricke-samsung
b2cfc5d1ce
spirv-val: Vulkan atomic storage class (#4079)
* spirv-val: Vulkan atomic storage class

* Add PhysicalStorageBuffer
2021-01-14 09:41:18 -05:00
Jaebaek Seo
cec658c116
Avoid integrity check failures caused by propagating line instructions (#4096)
Propagating the OpLine/OpNoLine to preserve the debug information
through transformations results in integrity check failures because of
the extra line instructions. This commit lets spirv-opt skip the
integrity check when the code contains OpLine or OpNoLine.
2021-01-13 09:08:28 -05:00
dan sinclair
7bbe1a3164
Revert "Generate differentiated error codes for buffer oob checking (#4097)" (#4100)
This reverts commit c32277c0ba.
2021-01-12 11:36:31 -05:00
greg-lunarg
c32277c0ba
Generate differentiated error codes for buffer oob checking (#4097)
This allows the GPU-AV layer to differentiate between errors with
uniform buffers versus storage buffers and map these to the relevant
VUIDs.
2021-01-11 08:42:48 -05:00
David Neto
f3ccb633df
use std::string::empty() to test for emptiness (#4098)
Fixes a clang-tidy complaint
2021-01-07 14:30:16 -05:00
sfricke-samsung
ad77ed7a8d
spirv-val: Label standalone Vulkan VUID (#4091) 2021-01-07 09:00:05 -05:00
sfricke-samsung
aa005e8bd4
spirv-val: Add Vulkan decroation VUID (#4090) 2021-01-06 14:30:56 -05:00
Steven Perron
4ed1f4fce9
Fix binding number calculation in desc sroa (#4095)
When there is an array of strutured buffers, desc sroa will only split
the array, but not a struct type in the structured buffer.  However,
the calcualtion of the number of binding a struct requires does not take
this into consideration.  This commit will fix that.
2021-01-06 13:59:04 -05:00
sfricke-samsung
94d1a80159
spirv-val: Add Vulkan FP Mode VUID (#4088) 2021-01-06 12:45:28 -05:00
sfricke-samsung
6d05ed8410
spirv-val: Fix Vulkan image sampled check (#4085)
* Fix SampledType logic
2021-01-06 12:36:13 -05:00
sfricke-samsung
37c03859de
spirv-val: Add Vulkan ForwardPointer VUID (#4089) 2021-01-06 11:26:58 -05:00
sfricke-samsung
d630e5f8c1
spirv-val: Add Vulkan ImageTexelPointer format check (#4087) 2021-01-06 08:51:15 -05:00
sfricke-samsung
1bb80d2778
spirv-val: Add Vulkan Group Operation VUID (#4086) 2021-01-05 09:51:07 -05:00
sfricke-samsung
17ffa89097
spirv-val: Add first StandAlone VUID 04633 (#4077) 2020-12-17 13:51:17 -05:00
sfricke-samsung
8f4b35c332
spirv-val: Add Subgroup VUIDs (#4074) 2020-12-17 08:37:43 -05:00
Alastair Donaldson
4e31fdd4aa
spirv-fuzz: Fix OpPhi handling in DuplicateRegionWithSelection (#4065)
Avoid generating OpPhi on void types, and allow the transformation to
take place on regions that produce pointer and sampled image result
ids if such ids are not used after the region.

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

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

Fixes #4057, #4058

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

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

Fixes #4061

* Allow SubpassData with Multisampled and Sampled==2
2020-12-10 10:40:46 -05:00
sfricke-samsung
3b85234542
spirv-val: Add last TessLevelOuter and TessLevelInner VUID (#4055) 2020-12-08 14:38:55 -05:00
sfricke-samsung
171290703a
spirv-val: Add last ClipDistance and CullDistance VUID (#4054) 2020-12-08 14:37:24 -05:00
sfricke-samsung
1a6b4053fa
spirv-val: Add last ViewportIndex and Layer VUID (#4053) 2020-12-08 14:34:51 -05:00
sfricke-samsung
9df5225e67
spirv-val: Add last Position VUID (#4052) 2020-12-08 14:31:40 -05:00