Commit Graph

2612 Commits

Author SHA1 Message Date
ncesario-lunarg
7dd5f95d25
[spirv-opt] Handle OpFunction in GetPtr (#5316)
When using PhysicalStorageBuffer it is possible for a function to
return a pointer type. This was not being handled correctly in
`GetLoadedVariablesFromFunctionCall` in the DCE pass because
`IsPtr` returns the wrong result.

Fixes #5270.
2023-07-17 19:16:25 +00:00
asudarsa
6add9ccf07
Add support for LiteralFloat type (#5323)
Signed-off-by: Arvind Sudarsanam <arvind.sudarsanam@intel.com>
2023-07-17 11:16:01 -04:00
Nathan Gauër
85a4482131
NFC: makes the FeatureManager immutable for users (#5329)
* NFC: makes the FeatureManager immutable for users

The FeatureManager contains some internal state, like
a set of capabilities and extensions. Those are derived
from the module.

Before this commit, the FeatureManager exposed Remove* functions
which could unsync the reported extensions/capabilities from
the truth: the module.

The only valid usecase to remove items directly from the FeatureManager
is by the context itself, when an instruction is killed:
instead of running the whole an analysis, we remove the single outdated
item.

The was 2 users who mutated its state:
 - one to invalidate the manager. Moved to call a reset function.
 - one who removed an extension from the feature manager after removing
   it from the module. This logic has been moved to the context, who
   now handles the extension removal itself.

Signed-off-by: Nathan Gauër <brioche@google.com>

* clang-format

* add RemoveCapability since the fuzztests are using it

* add tests

---------

Signed-off-by: Nathan Gauër <brioche@google.com>
2023-07-17 11:15:08 -04:00
Nathan Gauër
29431859f5
NFC: replace EnumSet::ForEach with range-based-for (#5322)
EnumSet now supports iterators, meaning we can remove the custom
ForEach.

Signed-off-by: Nathan Gauër <brioche@google.com>
2023-07-13 14:40:47 -04:00
Nathan Gauër
5b4fb072eb
enumset: fix bug in the new iterator class (#5321)
The iterator class was initialized by setting the offset
and bucket to 0. Big oversight: what if the first enum is
not valid? Then `*iterator->begin()` would return the wrong
value.

Because the first capacity is Matrix, this bug was not visible by
any SPIRV test.
And this specific case wasn't tested correctly in the new enumset tests.

Signed-off-by: Nathan Gauër <brioche@google.com>

---------

Signed-off-by: Nathan Gauër <brioche@google.com>
2023-07-13 09:55:24 -04:00
Nathan Gauër
9ab811a125
NFC: fix missing comments on functions (#5318)
Signed-off-by: Nathan Gauër <brioche@google.com>
2023-07-13 11:16:54 +02:00
Jeremy Gebben
9266197c37
instrument: Cast gl_VertexIndex and InstanceIndex to uint (#5319)
This avoids errors like this from instrumenting vertex shaders:

error: 165: Expected Constituents to be scalars or vectors of the
  same type as Result Type components
  %195 = OpCompositeConstruct %v4uint %uint_0 %191 %194 %uint_0
2023-07-12 15:12:26 -06:00
Nathan Gauër
3424b16c10
enumset: STL-ize container (#5311)
This commit adds forward iterator, and renames functions to
it matches the std::unordered_set/std::set better.
This goes against the SPIR-V coding style, but might be better in
the long run, especially when this set is used along real STL
sets.
(Right now, they are not compatible, and requires 2 syntaxes).

This container could in theory handle bidirectional
iterator, but for now, only forward seemed required for
our use-cases.

Signed-off-by: Nathan Gauër <brioche@google.com>
2023-07-12 11:34:44 -04:00
Spencer Fricke
7ff331af66
source: Give better message if using new Source Language (#5314) 2023-07-11 11:50:41 -04:00
alan-baker
0530a532fc
Validate GroupNonUniform instructions (#5296)
Fixes #5283

* Validate group non-uniform instructions
2023-07-11 08:40:40 -04:00
Nathan Gauër
0f3bea06ef
NFC: rewrite EnumSet to handle larger enums. (#5289)
The current EnumSet implementation is only efficient for enums with
values < than 64. The reason is the first 63 values are stored as a
bitmask in a 64 bit unsigned integer, and the other values are stored
in a std::set.
For small enums, this is fine (most SPIR-V enums have IDs < than 64),
but performance starts to drop with larger enums (Capabilities,
opcodes).

Design considerations:
----------------------

This PR changes the internal behavior of the EnumSet to handle enums
with arbitrary values while staying performant.
The idea is to extend the 64-bits buckets sparsely:
 - each bucket can store 64 value, starting from a multiplier of 64.
This could be considered as a hashset with linear probing.

- For small enums, there is a slight memory overhead due to the bucket
storage, but lookup is still constant.
- For linearly distributed values, lookup is constant.
- Worse case for storage are for enums with values which are multiples of 64.
But lookup is constant.
- Worse case for lookup are enums with a lot of small ranges scattered in
the space (requires linear probing).

For enums like capabilities/opcodes, this bucketing is useful as values
are usually scatters in distinct, but almost contiguous blocks.
(vendors usually have allocated ranges, like [5000;5500], while [1000;5000]
is mostly unused).

Benchmarking:
-------------

Benchmarking was done in 2 ways:
 - a benchmark built for the occasion, which only measure the EnumSet
   performance.
 - SPIRV-Tools tests, to measure a more realist scenario.

Running SPIR-V tests with both implementations shows the same
performance (delta < noise). So seems like we have no regressions.
This method is noisy by nature (I/O, etc), but the most representative
of a real-life scenario.

Protocol:
 - run spirv-tests with no stdout using perf, multiple times.
Result:
 - measure noise is larger than the observed difference.

The custom benchmark was testing EnumSet interfaces using SPIRV enums.
Doing thousand of insertion/deletion/lookup, with 2 kind of scenarios:
 - add once, lookup many times.
 - add/delete/loopkup many time.

For small enums, results are similar (delta < noise). Seems relevant
with the previously observed results as most SPIRV enums are small, and
SPIRV-Tools is not doing that many intensive operations on EnumSets.

Performance on large enums (opcode/capabilities) shows an improvement:

+-----------------------------+---------+---------+---------+
| Metric                      |  Old    |   New   | Delta % |
+-----------------------------+---------+---------+---------+
| Execution time              |   27s   |   7s    |  -72%   |
| Instruction count           |  174b   |  129b   |  -25%   |
| Branch count                |   28b   |   33b   |  +17%   |
| Branch miss                 |  490m   |   26m   |  -94%   |
| Cache-misses                |  149k   |   26k   |  -82%   |
+-----------------------------+---------+---------+---------+

Future work
-----------

This was by-design an NFC change to compare apples-to-apples.
The next PR aims to add STL-like iterators to the EnumSet to allow
using it with STL algorithms, and range-based for loops.

Signed-off-by: Nathan Gauër <brioche@google.com>
2023-07-07 10:41:52 -04:00
Spencer Fricke
870fd1e17a
spirv-val: Label SPV_KHR_cooperative_matrix VUID (#5301) 2023-07-04 09:01:04 -04:00
Nathan Gauër
7520bfa6b1
build: remove last references of c++11 (#5295)
Figured I forgot some references. Naive sed this time, so we should be
done.

Signed-off-by: Nathan Gauër <brioche@google.com>
2023-06-28 05:37:55 -07:00
alan-baker
310a67020a
Validate layouts for PhysicalStorageBuffer pointers (#5291)
* Validate layouts for PhysicalStorageBuffer pointers

Fixes #5282

* These pointers may not orginate from a variable so standard layout
  validation misses them
* Now checks every instructions that results in a physical storage
  buffer pointer
  * May not start from a Block-decorated struct so that part is fudged
    with a valid layout

* formatting
2023-06-23 19:17:55 +00:00
archimedus
04cdb2d344
SPV_KHR_cooperative_matrix (#5286)
* SPV_KHR_cooperative_matrix

* Update DEPS with headers

* Update according to review recommendations

* Bugfix and formatting

* Formatting missed or damaged by VS2022
2023-06-22 18:33:36 -04:00
Jeremy Gebben
daee1e7d34
instrument: Combine descriptor length and init state checking (#5274)
Simplify what we add to user code by moving most of it into a function
that checks both that the descriptor index is in bounds and the
initialization state. Move error logging into this function as
well.

Remove many options to turn off parts of the instrumentation,
because there were far too many permutations to keep working and
test properly.

Combine Buffer and TexBuffer error checking. This requires that VVL
set the length of TexBuffers in the descriptor input state, rather
than relying on the instrumentation code to call OpImageQuerySize.
Since the error log includes the descriptor set and binding numbers
we can use a single OOB error code rather than having 4 per-type
error codes.

Since the error codes are getting renumbered, make them start at 1
rather than 0 so it is easier to determine if the error code was
actually set by the instrumentation.
2023-06-22 09:39:49 -06:00
Juan Ramos
a63ac9f73d
cmake: Use modern Python3 CMake support (#5277)
From the 3.27 release notes:
The FindPythonInterp and FindPythonLibs modules, which have been
deprecated since CMake 3.12, have been removed by policy CMP0148.
Port projects to FindPython3, FindPython2, or FindPython.

closes #4145
2023-06-19 15:02:41 -04:00
Laura Hermanns
951980e5ac
Enable vector constant folding (#4913) (#5272)
- Add test case 6 to UIntVectorInstructionFoldingTest
- Add test case 3 to IntVectorInstructionFoldingTest
2023-06-19 15:01:51 -04:00
Steven Perron
6b9fc79330
Fold negation of integer vectors (#5269) 2023-06-16 10:37:21 -04:00
Jeremy Gebben
d33bea5847
instrument: Fix buffer address length calculations (#5257)
The length of a uvec3 was assumed to be 16 bytes, but it is 12.
Sometimes the stride might be 16 bytes though, which is probably the
source of the confusion.

Redo structure length to be the offset + length of the last member.

Add tests to cover arrays of uvec3s and uvec3 struct members.

Fixes https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/5691
2023-06-14 16:14:46 -06:00
Eugene Kozlov
b4f352e54f
Expose preserve_interface in Optimizer::Register*Passes. (#5268)
Fixes #5266
2023-06-14 10:00:26 -04:00
Jim Blandy
ae1843b67c
spirv-diff: Leave undefined ids unpaired. (#5262)
If an id in one module is not defined by any instruction, don't bother
matching it with an id in the other module, as this disturbs the
reported id bound, resulting in spurious differences.

Fixes #5260.
2023-06-09 15:00:46 -04:00
Jim Blandy
93c13345e1
spirv-diff: Properly match SPV_KHR_ray_query types. (#5259)
Fixes #5258.
2023-06-08 10:42:45 -04:00
alan-baker
59b4febd81
Allow OpTypeBool in UniformConstant (#5237)
See https://github.com/KhronosGroup/SPIRV-Registry/issues/72

* OpenGL allowed uniforms to be declared with boolean types, but the
  validator was overly strict in disallowing it
2023-06-06 18:05:04 -04:00
Steven Perron
5ed21eb1e2
Add folding rule for OpTranspose (#5241) 2023-06-01 12:09:08 -04:00
alan-baker
182fd9ebce
Allow physical storage buffer pointer in IO (#5251)
Follow up to #5249

* glslang tests that physical storage buffer pointers can be used as
  varyings in shaders
  * Allow physical storage buffer pointers in IO interfaces as a 64-bit
    type
2023-05-30 20:07:58 -04:00
Jim Blandy
9ed2ac257d
Fix pairing of function parameters. (#5225)
- Consider prior type pairings when attempting to pair function
parameters by type.
- Pair all parameters that have matching types, not just the first.
- Update diff tests.

Fixes #5218.
2023-05-30 09:30:01 -04:00
alan-baker
cf62673e42
Error for invalid location type (#5249)
Fixes https://crbug.com/oss-fuzz/56754

* When checking locations, produce an error if the type cannot be
  assigned a location
2023-05-30 09:08:09 -04:00
Spencer Fricke
23cb9b96cc
spirv-val: Remove VUID from 1.3.251 spec (#5244) 2023-05-29 09:20:07 -04:00
Steven Perron
af27ece750
Check if const is zero before getting components. (#5217)
* Check if const is zero before getting components.

Two folding rules try to cast a constant to a MatrixConstant before
checking if it is a Null constant. This leads to the null pointer being
dereferneced. The solution is to move the check for zero earlier.

Fixes https://github.com/microsoft/DirectXShaderCompiler/issues/5063
2023-05-25 09:07:22 -04:00
Jim Blandy
f29e11dcb6
diff: Don't give up entry point matching too early. (#5224)
Addresses one case mentioned in #5218.
2023-05-24 15:28:45 -04:00
Pankaj Mistry
82b1a87b21
Add SPV_NV_bindless_texture to spirv optimizations (#5231) 2023-05-24 11:01:11 -04:00
Steve Urquhart
44c9da6fee
Remove const zero image operands (#5232) 2023-05-24 10:30:10 -04:00
Kévin Petit
17a26b45ff
Improve an error message in the assembler (#5219)
Signed-off-by: Kevin Petit <kevin.petit@arm.com>
2023-05-15 09:56:48 -04:00
Spencer Fricke
7c39951f6e
spirv-val: Label Interface Location/Component VUIDs (#5221) 2023-05-15 09:53:37 -04:00
Steven Perron
51892874ba
Run ADCE when the printf extension is used. (#5215)
This is for
https://github.com/microsoft/DirectXShaderCompiler/issues/5136.
2023-05-10 10:03:40 +02:00
Chris Oattes
e803fe6717
Don't convert struct members to half (#5201) 2023-05-08 12:14:42 -04:00
Steven Perron
8993f9f52f
Apply scalar replacement on vars with Pointer decorations (#5208)
We want to be able to apply scalar replacement on variables that have
the AliasPointer and RestrictPointer decorations.

This exposed a bug that needs to be fixed as well.

Scalar replacement sometimes uses the type manager to get the type id for the
variables it is creating. The variable type is a pointer to a pointee
type. Currently, scalar replacement uses the type manager when only if
the pointee type has to be unique in the module. This is done to try to avoid the case where two type hash to the same
value in the type manager, and it returns the wrong one.

However, this check is not the correct check. Pointer types still have to be
unique in the spir-v module. However, two unique pointer types can hash
to the same value if their pointee types are isomorphic. For example,

%s1 = OpTypeStruct %int
%s2 = OpTypeStruct %int
; %p1 and %p2 will hash to the same value even though they are still
; considered "unique".
%p1 = OpTypePointer Function %s1
%p2 = OpTypePointer Function %s2
To fix this, we now use FindPointerToType, and we modified TypeManager::IsUnique to refer to the whether or not a type will hash to a unique value and say that pointers are not unique.

Fixes #5196
2023-05-08 09:39:14 -04:00
Jeremy Gebben
0ce36ad785
instrument: Add set and binding to bindless error records (#5204)
Add set and binding fields to the error records so that it is
easier for users to figure out which descriptor caused an error.
2023-05-01 14:23:30 -04:00
Jeremy Gebben
d4c0abdcad
instrument: Change descriptor state storage format (#5178)
Split per-DescriptorSet state into separate memory blocks
which are accessed via an array of buffer device addresses.
This is being done to make it easier to update state for a
single DescriptorSet without rebuilding the old giant flat
buffer.

The new data format is documented as comments in
include/spirv-tools/instrument.hpp
2023-04-26 14:28:01 -06:00
Steven Perron
25ad5e19f1
Do not define GOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL_INLINE if it is already defined. (#5200) 2023-04-18 15:47:10 -04:00
Ben Clayton
bec566a32b
opt: Fix null deref in OpMatrixTimesVector and OpVectorTimesMatrix (#5199)
When some (not all) of the matrix columns are OpConstantNull
2023-04-18 14:58:12 -04:00
alan-baker
d5f69dba55
Remove dead code (#5195)
* Execution model limitation was never executed and the check actually
  belongs with other opcodes
2023-04-14 10:59:01 -04:00
janharaldfredriksen-arm
6f276e05cc
Add support for SPV_EXT_shader_tile_image (#5188)
* Update DEPS file to pull in header changes for SPV_EXT_shader_tile_image
2023-04-13 16:58:00 -04:00
James Price
1877a7f909
Fix vector OpConstantComposite type validation (#5191)
The constituent types much fully match, not just the opcode.
2023-04-13 12:50:16 -04:00
Corentin Wallez
f449fb4ad9
Add default case for spv::Dim for TileImageEXT (#5194)
Without this the switch statement must be updated at the same time as
the SPIR-V headers, which makes rolls impossible.
2023-04-13 16:10:02 +01:00
Steven Perron
9a4e7a1eb5
Update protobuf to v21.12 (#5189)
* Update protobuf to v21.12

We need to update because the current version was not buliding with gcc 12.2. I
could not move upda to v22.x because there was an odd use of some defines that
were causing failures.

* Disable clang warnings for protobuf headers
2023-04-12 19:37:07 +02:00
Steven Perron
048faf2e53
Remove use of deprecated std::aligned_storage (#5183)
* Remove use of deprecated std::aligned_storage

Fixes #4806.
2023-04-06 17:22:28 +02:00
LDeakin
dd03c1fca4
Fix LICMPass (#5087)
Do not move loads out of the loop unless the memory is readonly.

Fixes https://github.com/KhronosGroup/SPIRV-Tools/issues/5075
2023-04-05 11:48:14 -04:00
Steven Perron
6b72fe20c5
Add missing header guard (#5181)
Fixes #5018
2023-03-29 15:52:47 -04:00