Commit Graph

3243 Commits

Author SHA1 Message Date
Steven Perron
438096e0c2
Fix kokoro asan run (#4655)
With a change in the VM, the kokoro asan run is failing because it does
not have the correct permissions.  Adding the ptrace capability will
hopefully fix that.
2021-12-08 15:26:29 -05:00
Sebastien Alaiwan
64328e94db
Avoid an extra map lookup (#4623)
Speedup: 5% less time on a real-world compilation batch
(nearly 10k parallel compilations)
(Durations: Before: 156.5s, After: 147.4s)
2021-12-08 14:53:36 -05:00
Marius Hillenbrand
1ed847f438
Fix endianness of string literals (#4622)
* Fix endianness of string literals

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

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

Fixes  #149

* Extend round trip test for StringLiterals to flip word order

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

* BinaryParseTest.InstructionWithStringOperand: also flip byte order

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

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

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

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

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

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

Fixes #4636.
2021-11-24 14:13:58 -05:00
alan-baker
4b092d2ab8
Allow ADCE to remove dead inputs (#4629)
* https://github.com/KhronosGroup/Vulkan-Docs/issues/666 clearly
  specified that interfaces do not require an input if there is an
  associated output
* ADCE can now remove unused input variables (though they are kept if
  the preserve interfaces option is used)
2021-11-16 15:54:17 -05:00
Jakub Kuderski
ccdf836207 Start SPIRV-Tools v2021.5 2021-11-11 12:09:30 -05:00
Jakub Kuderski
ab8eb60775 Finalize SPIRV-Tools v2021.4 2021-11-11 12:06:08 -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
Jakub Kuderski
c72c454203
Clarify how to update DEPS (#4626)
-  Mention that `depot_tools` are required and link to that repo.
-  Make `roll_deps.sh` exit on error. The script passes `shellcheck`
   with this change.
-  Reword instruction in the README.
2021-11-09 10:28:01 -05:00
Jakub Kuderski
6f9fa48012
Update DEPS (#4625)
Update DEPS ahead of the next Vulkan SDK release.

* Roll external/effcee/ 2ec8f8738..ddf5e2bb9 (1 commit)

2ec8f87381...ddf5e2bb92

$ git log 2ec8f8738..ddf5e2bb9 --date=short --no-merges --format='%ad %ae %s'
2021-08-31 dneto Remove .travis.yml

Created with:
  roll-dep external/effcee

* Roll external/googletest/ 955c7f837..bf0701daa (32 commits)

955c7f837e...bf0701daa9

$ git log 955c7f837..bf0701daa --date=short --no-merges --format='%ad %ae %s'
2021-11-03 absl-team Googletest export
2021-10-28 dmauro Googletest export
2021-10-27 dmauro Googletest export
2021-10-26 absl-team Googletest export
2021-10-26 absl-team Googletest export
2021-10-25 dmauro Googletest export
2021-10-25 dmauro Googletest export
2021-10-30 dartme18 Re #3637 Show Disabled Tests in testing output
2021-10-11 absl-team Googletest export
2021-10-11 absl-team Googletest export
2021-10-11 absl-team Googletest export
2021-10-08 yesudeep Fix linker errors on FreeBSD.
2021-09-30 absl-team Googletest export
2021-09-28 absl-team Googletest export
2021-09-24 cclauss Fix remaining typos discovered by codespell
2021-09-20 absl-team Googletest export
2021-09-20 absl-team Internal change
2021-09-17 julian.amann Remove bazelbuild/rules_cc dependency
2021-09-16 cclauss Fix typos discovered by codespell
2021-09-16 cclauss Fix typos discovered by codespell
2021-09-16 cclauss Fix typo discovered by codespell
2021-09-15 absl-team Googletest export
2021-09-15 dmauro Googletest export
2021-09-15 absl-team Googletest export
2021-09-14 dmauro Googletest export
2021-09-14 dmauro Googletest export
2021-09-14 absl-team Googletest export
2021-09-15 761129+derekmauro Revert grammatically incorrect change
2021-09-10 absl-team Googletest export
2021-08-10 akashkumarsingh11032001 add a missing 'a'
2021-08-10 akashkumarsingh11032001 Create CONTRIBUTING.md
2020-12-29 julien.jemine Using auto instead of container::const_iterator

Created with:
  roll-dep external/googletest

* Roll external/spirv-headers/ 19e835041..29817199b (3 commits)

19e8350415...29817199b7

$ git log 19e835041..29817199b --date=short --no-merges --format='%ad %ae %s'
2021-07-24 kpet Add SpecConstantSubgroupMaxSize to the clspv reflection non-semantic instruction set
2021-05-24 pmistry Implement header definitions for SPV_NV_bindless_texture
2021-10-12 ben.ashbaugh reserve SPIR-V enum block for Intel extensions

Created with:
  roll-dep external/spirv-headers
2021-11-09 09:43:45 -05:00
Jakub Kuderski
2bd46c5c55 Update CHANGES 2021-11-08 21:41:56 -05: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
David Neto
6b073f8992
Run the wasm build on push and pull_request (#4614) 2021-11-03 13:13:15 -04:00
David Neto
66ef7cb68e
Remove publish-to-npm step for Wasm build (#4610)
The JS-Tools/npm-publish flow requires a `token` attribute, even
in dry-run mode.
There is no token, so remove the step for now.
2021-11-03 11:04:04 -04:00
David Neto
d645ea2705
Update CHANGES, README for WebAssembly build (#4609) 2021-11-02 08:56:06 -04:00
Pelle Johnsen
0d0013002a
Add Wasm build (#3752)
* Add wasm build

* Run wasm ci on push

* Add copyright notice to wasm files

* [wasm] Update Emscripten

* [wasm] Change global lambda to regular function

* [wasm] Show detected core count during build

* [wasm] Set JS version from CHANGES, GITHUB_RUN_ID

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

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

* [wasm] Us docker-compose up for CI

* [wasm] pass GITHUB_RUN_ID to docker

* [wasm] Change GITHUB_RUN_ID to GITHUB_RUN_NUMBER

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

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

This change reworks the relevant code so that both arguments to the
logical && are evaluated into temporaries.
2021-10-29 15:36:51 -04:00
Ralf Habacker
e3c7098104
In generated cmake config file for SPIRV-Tools only access cmake target, if present (#4590)
Fixes #4582
2021-10-29 14:05:45 -04:00
timlyeee
e3a373f2b7
Make cxx exceptions controllable (#4591)
* Make cxx exceptions controllable 

Found a possible link error if we compile spirv-tools by using VS2019 and link with VS2017 for another project, unresolved symbols as _CxxFrameHandler4 and __GSHandlerCheck_EH4 will be thrown. As Visual Studio updated its c++ exceptions libs.

https://devblogs.microsoft.com/cppblog/making-cpp-exception-handling-smaller-x64/

So we are making cxx exceptions controllable via a CMake option `ENABLE_EXCEPTIONS_ON_MSVC`.
2021-10-29 14:04:59 -04:00
sfricke-samsung
c194bb2a7f
spirv-val Update LocalSizeId VUID (#4602) 2021-10-29 11:58:02 -04:00
Steven Perron
6c7885dbde
Change branch handling in ADCE to fix errors (#4596)
Consider the new test case.  The conditional branch in the continue
block is never marked as live.  However, `IsDead` will say it is not
dead, so it does not get deleted.  Because it was never marked as live,
`%false` was not mark as live either, but it gets deleted.  This results
in invalid code.

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

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

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

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

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

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

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

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

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

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

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

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

Before:
```
%descriptor = OpVariable %_ptr_array_Image Uniform
...
%ac = OpAccessChain %_ptr_Image %descriptor %variable_index
(some image instructions using %ac)
```
After:
```
%descriptor = OpVariable %_ptr_array_Image Uniform
...
OpSwitch %variable_index 0 %case0 1 %case1 ...
...
%case0 = OpLabel
%ac = OpAccessChain %_ptr_Image %descriptor %uint_0
...
%case1 = OpLabel
%ac = OpAccessChain %_ptr_Image %descriptor %uint_1
...
(use OpPhi for value with concrete type)
```
2021-10-26 17:20:58 -04:00
Steven Perron
d78c1c4cd3
Make IsLocalVar in ADCE work at any time. (NFC) (#4595)
Having IsLocalVar work only sometimes is something that could easily
lead to an error.  This change refactors the code so that the function
can be called at any point.  The current implementation was used because
we did not want to do multiple searches to see if a function was an
entry point or if it had a call.  This was maintained by added a cache
that will store of a given function is an entry point with no calls.
2021-10-26 13:24:29 -04:00
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
David Neto
7a7a69037e
README: Remove appveyor build badge. (#4584)
Bot failures are unrelated.
2021-10-19 17:17:56 -04:00
David Neto
4578db3c41
README: Update tested versions of compilers (#4579)
I checked this against the Kokoro output.
2021-10-18 15:34:06 -04: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