Commit Graph

1040 Commits

Author SHA1 Message Date
Nathan Gauër
bf03d40922
opt: change Get* functions to return const& (#5331)
GetCapabilities returned a const*, and GetExtensions did not exist.
This commit adds GetExtensions, and changes the return value to
be a const&.

This commit also removes the overload to GetCapabilities which returns
a mutable set, as it is unused.

Signed-off-by: Nathan Gauër <brioche@google.com>
2023-07-20 10:18:19 -04:00
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
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
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
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
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
Steven Perron
5ed21eb1e2
Add folding rule for OpTranspose (#5241) 2023-06-01 12:09:08 -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
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
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
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
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
Steven Perron
a0fcd06f8f
Add Vulkan memory model to allow lists (#5173)
Fixes #5086
2023-03-28 16:57:45 -04:00
Spencer Fricke
fa69b09cff
spirv-opt: Remove unused includes and code (#5177) 2023-03-28 12:40:30 -04:00
Steven Perron
d24a39a7f0
Do not remove control barrier after spv1.3 (#5174)
The control barrier instruction was allowed in a limiteted set of shader types.
Part of the HLSL legalization, we use to remove the instructions when it was is
a shader in which it was not allowed. As of spv1.3 that restriction is not long
there.

This change modifies replaced invalid opc to no longer remove it.

Fixes #4999.
2023-03-27 11:04:40 -04:00
Jeremy Hayes
b4e0850ef7
Ignore NonSemanticInstructions (#5171)
Fix #5163.

Ignore NonSemanticInstructions in DoDeadOutputStoresElimination and
ComputeLiveness.
2023-03-24 10:46:52 -06:00
Laura Hermanns
bd83b772c3
Fix operand index out of bounds when folding OpCompositeExtract. (#5107)
GetExtractOperandsForElementOfCompositeConstruct() states "Returns the
empty vector if |result_index| is out-of-bounds", but violates that
contract for non-vector result types.
2023-03-03 15:52:49 +00:00
alan-baker
b955c468b1
Add missing header include (#5124)
* Found during an internal build
2023-02-24 13:21:53 -05:00
alan-baker
5d2bc6f064
Fix removal of dependent non-semantic instructions (#5122)
Fixes #5121

* If the non-semantic info instructions depended on other moved
  instructions the def/use manager would get corrupted.
2023-02-24 01:10:35 +00:00
Dave Airlie
956114df28
opt: fix spirv ABI on Linux again. (#5113)
Breaking the ABI for this API isn't worth it when the fix is so simple.
2023-02-15 20:11:30 +00:00
Kévin Petit
f4343515ad
Remove duplicate lists of constant and type opcodes (#5106)
Adding a new type instruction required making the same change in two
places.

Also remove IsCompileTimeConstantInst that was used in a single place
and replace its use by an expression that better conveys the intent.

Change-Id: I49330b74bd34a35db6369c438c053224805c18e0

Signed-off-by: Kevin Petit <kevin.petit@arm.com>
2023-02-15 20:09:55 +00:00
Laura Hermanns
cac9a5a3ee
Fix null pointer in FoldInsertWithConstants. (#5093)
* Fix null pointer in FoldInsertWithConstants.

Struct types are not supported in constant folding yet.

* Added 'Test case 16' to fold_test.

Tests OpCompositeInsert not to be folded on a struct type.
2023-02-03 15:03:15 +00:00
Jeremy Gebben
5890763734
instrument: Clean up generation code (#5090)
-Make more use of InstructionBuilder instruction helper methods
-Use MakeUnique<>() rather than new
-Add InstrumentPass::GenReadFunctionCall() which optimizes function
calls in a loop with constant arguments and no side effects.

This is a prepatory change for future work on the instrumentation
code which will add more generated functions.
2023-02-03 00:39:09 +00:00
Daniel Story
0994ca45b6
Add C interface for Optimizer (#5030) 2023-02-01 13:58:52 +00:00
Jeremy Gebben
ba4c9fe534
Instrument: Fix bindless checking for BufferDeviceAddress (#5049)
Avoid using OpConstantNull with types that do not allow it.

Update existing tests for slight changes in code generation.

Add new tests based on the Vulkan Validation layer test case
that exposed this problem.
2023-01-16 20:57:37 +00:00
Juan Ramos
1dad991441
cmake: Modernize install(TARGET) usage (#5056) 2023-01-16 10:55:35 -05:00
Jeremy Gebben
025ea891fa
Optimize allocation of spvtools::opt::Instruction::operands_ (#5024)
Reserve space for the entire operand list rather than adding them
one a time.
2022-12-19 13:08:01 -05:00
Greg Fischer
f64a4b64b7
[spirv-opt] Clone names for new struct in EliminateIODeadComponents (#5016) 2022-12-19 10:20:44 -07:00
alan-baker
235182cfee
Fix use of invalid analysis (#5013)
Fixes https://crbug.com/1395415

* Block merging needed to invalid structured cfg analysis
2022-12-12 10:49:59 -05:00
Spencer Fricke
7b8f00f00a
spirv-opt: Fix OpCompositeInsert with Null Constant (#5008)
* spirv-opt: Unify GetConstId function names

* spirv-opt: Fix OpCompositeInsert with Null Constant

* spirv-opt: Improve GetNullCompositeConstant description
2022-12-06 09:00:10 -05:00
Greg Fischer
00018e58af
Change EliminateDeadInputComponentsPass to EliminateDeadIOComponentsPass (#4997)
To reflect processing of both Input and Output variables.

Also renamed files as needed.
2022-11-25 16:48:13 -07:00
alelenv
f33d152400
Add validation support for SPV_NV_shader_invocation_reorder. (#4979)
Co-authored-by: Pankaj Mistry <pmistry@nvidia.com>
2022-11-24 09:50:45 -05:00
Spencer Fricke
597631b693
spirv-opt: Handle null CompositeInsert (#4998)
Fixes #4996
2022-11-24 08:38:12 -05:00
Greg Fischer
81ec2aaa0e
Add option to ADCE to remove output variables from interface. (#4994)
This can cause interface incompatibility and should only be done
if ADCE has been applied to the following shader in the pipeline.
For this reason this capability is not available through the CLI
but rather only non-default through the API. This functionality is
intended as part of a larger cross-shader dead code elimination
sequence.
2022-11-23 10:48:58 -07:00
Greg Fischer
46ca66e699
Add support for tesc, tese and geom to EliminateDead*Components (#4990) 2022-11-18 15:08:18 -07:00
Nathan Gauër
1a7f71afb4
clean: constexpr-ify and unify anon namespace use (#4991)
Constexpr guaranteed no runtime init in addition to const semantics.
Moving all opt/ to constexpr.
Moving all compile-unit statics to anonymous namespaces to uniformize
the method used (anonymous namespace vs static has the same behavior
here AFAIK).

Signed-off-by: Nathan Gauër <brioche@google.com>
2022-11-17 19:02:50 +01:00
Greg Fischer
8ea3ae6be2
Split EliminateDeadInputComponents into safe and unsafe versions. (#4984)
Safe version will only optimize vertex shaders. All other shaders will
succeed without change.

Change --eliminate-dead-input-components to use new safe version.

Unsafe version (allowing non-vertex shaders) currently only available
through API. Should only be used in combination with other optimizations
to keep interfaces consistent. See optimizer.hpp for more details.
2022-11-14 11:44:26 -07:00
Jeremy Gebben
68e8327f29
Instrument: Change output buffer offset definitions (#4961)
Add a flags field at the first offset within this buffer.
Define flags to allow buffer OOB checking to be enabled or
disabled at run time. This is to support VK_EXT_pipeline_robustnes.
2022-11-10 12:35:18 -05:00