2016-01-07 18:44:22 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
2015-05-22 17:26:19 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2015-05-22 17:26:19 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-05-22 17:26:19 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2018-07-11 14:27:34 +00:00
|
|
|
#ifndef SOURCE_VAL_VALIDATE_H_
|
|
|
|
#define SOURCE_VAL_VALIDATE_H_
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2016-06-04 01:24:24 +00:00
|
|
|
#include <functional>
|
2018-08-03 19:06:09 +00:00
|
|
|
#include <memory>
|
2016-01-15 16:25:11 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-07-11 14:27:34 +00:00
|
|
|
#include "source/instruction.h"
|
|
|
|
#include "source/table.h"
|
2016-02-17 19:44:00 +00:00
|
|
|
#include "spirv-tools/libspirv.h"
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2018-07-07 13:38:00 +00:00
|
|
|
namespace spvtools {
|
2018-07-10 03:18:44 +00:00
|
|
|
namespace val {
|
2016-01-15 16:25:11 +00:00
|
|
|
|
|
|
|
class ValidationState_t;
|
2016-08-06 17:25:02 +00:00
|
|
|
class BasicBlock;
|
2018-07-03 19:06:54 +00:00
|
|
|
class Instruction;
|
2016-01-15 16:25:11 +00:00
|
|
|
|
2016-03-16 21:20:02 +00:00
|
|
|
/// @brief Performs the Control Flow Graph checks
|
|
|
|
///
|
|
|
|
/// @param[in] _ the validation state of the module
|
|
|
|
///
|
|
|
|
/// @return SPV_SUCCESS if no errors are found. SPV_ERROR_INVALID_CFG otherwise
|
|
|
|
spv_result_t PerformCfgChecks(ValidationState_t& _);
|
2016-01-15 16:25:11 +00:00
|
|
|
|
2016-08-06 17:29:33 +00:00
|
|
|
/// @brief Updates the use vectors of all instructions that can be referenced
|
|
|
|
///
|
|
|
|
/// This function will update the vector which define where an instruction was
|
|
|
|
/// referenced in the binary.
|
|
|
|
///
|
|
|
|
/// @param[in] _ the validation state of the module
|
|
|
|
///
|
|
|
|
/// @return SPV_SUCCESS if no errors are found.
|
2018-08-02 14:00:52 +00:00
|
|
|
spv_result_t UpdateIdUse(ValidationState_t& _, const Instruction* inst);
|
2016-08-06 17:29:33 +00:00
|
|
|
|
2016-07-13 22:57:52 +00:00
|
|
|
/// @brief This function checks all ID definitions dominate their use in the
|
|
|
|
/// CFG.
|
|
|
|
///
|
|
|
|
/// This function will iterate over all ID definitions that are defined in the
|
|
|
|
/// functions of a module and make sure that the definitions appear in a
|
|
|
|
/// block that dominates their use.
|
|
|
|
///
|
|
|
|
/// @param[in] _ the validation state of the module
|
|
|
|
///
|
|
|
|
/// @return SPV_SUCCESS if no errors are found. SPV_ERROR_INVALID_ID otherwise
|
2018-10-03 19:59:40 +00:00
|
|
|
spv_result_t CheckIdDefinitionDominateUse(ValidationState_t& _);
|
2016-07-13 22:57:52 +00:00
|
|
|
|
2018-01-25 23:32:01 +00:00
|
|
|
/// @brief This function checks for preconditions involving the adjacent
|
|
|
|
/// instructions.
|
|
|
|
///
|
|
|
|
/// This function will iterate over all instructions and check for any required
|
2022-11-04 21:27:10 +00:00
|
|
|
/// predecessor and/or successor instructions. e.g. spv::Op::OpPhi must only be
|
|
|
|
/// preceded by spv::Op::OpLabel, spv::Op::OpPhi, or spv::Op::OpLine.
|
2018-01-25 23:32:01 +00:00
|
|
|
///
|
|
|
|
/// @param[in] _ the validation state of the module
|
|
|
|
///
|
|
|
|
/// @return SPV_SUCCESS if no errors are found. SPV_ERROR_INVALID_DATA otherwise
|
2018-09-27 15:09:47 +00:00
|
|
|
spv_result_t ValidateAdjacency(ValidationState_t& _);
|
2018-01-25 23:32:01 +00:00
|
|
|
|
2018-05-31 13:07:09 +00:00
|
|
|
/// @brief Validates static uses of input and output variables
|
|
|
|
///
|
|
|
|
/// Checks that any entry point that uses a input or output variable lists that
|
|
|
|
/// variable in its interface.
|
|
|
|
///
|
|
|
|
/// @param[in] _ the validation state of the module
|
|
|
|
///
|
|
|
|
/// @return SPV_SUCCESS if no errors are found.
|
|
|
|
spv_result_t ValidateInterfaces(ValidationState_t& _);
|
|
|
|
|
2024-01-25 15:22:09 +00:00
|
|
|
/// @brief Validates entry point call tree requirements of
|
|
|
|
/// SPV_KHR_float_controls2
|
|
|
|
///
|
|
|
|
/// Checks that no entry point using FPFastMathDefault uses:
|
|
|
|
/// * FPFastMathMode Fast
|
|
|
|
/// * NoContraction
|
|
|
|
///
|
|
|
|
/// @param[in] _ the validation state of the module
|
|
|
|
///
|
|
|
|
/// @return SPV_SUCCESS if no errors are found.
|
|
|
|
spv_result_t ValidateFloatControls2(ValidationState_t& _);
|
|
|
|
|
2024-04-12 12:51:41 +00:00
|
|
|
/// @brief Validates duplicated execution modes for each entry point.
|
|
|
|
///
|
|
|
|
/// @param[in] _ the validation state of the module
|
|
|
|
///
|
|
|
|
/// @return SPV_SUCCESS if no errors are found.
|
|
|
|
spv_result_t ValidateDuplicateExecutionModes(ValidationState_t& _);
|
|
|
|
|
2018-08-01 18:44:56 +00:00
|
|
|
/// @brief Validates memory instructions
|
|
|
|
///
|
|
|
|
/// @param[in] _ the validation state of the module
|
|
|
|
/// @return SPV_SUCCESS if no errors are found.
|
2018-09-27 16:34:14 +00:00
|
|
|
spv_result_t MemoryPass(ValidationState_t& _, const Instruction* inst);
|
2018-08-01 18:44:56 +00:00
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
/// @brief Updates the immediate dominator for each of the block edges
|
|
|
|
///
|
|
|
|
/// Updates the immediate dominator of the blocks for each of the edges
|
|
|
|
/// provided by the @p dom_edges parameter
|
|
|
|
///
|
|
|
|
/// @param[in,out] dom_edges The edges of the dominator tree
|
2016-06-04 01:24:24 +00:00
|
|
|
/// @param[in] set_func This function will be called to updated the Immediate
|
|
|
|
/// dominator
|
2016-03-16 21:20:02 +00:00
|
|
|
void UpdateImmediateDominators(
|
2016-06-04 01:24:24 +00:00
|
|
|
const std::vector<std::pair<BasicBlock*, BasicBlock*>>& dom_edges,
|
|
|
|
std::function<void(BasicBlock*, BasicBlock*)> set_func);
|
2016-03-16 21:20:02 +00:00
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
/// @brief Prints all of the dominators of a BasicBlock
|
|
|
|
///
|
|
|
|
/// @param[in] block The dominators of this block will be printed
|
2016-03-16 21:20:02 +00:00
|
|
|
void printDominatorList(BasicBlock& block);
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
/// Performs logical layout validation as described in section 2.4 of the SPIR-V
|
|
|
|
/// spec.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t ModuleLayoutPass(ValidationState_t& _, const Instruction* inst);
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2018-08-10 16:49:26 +00:00
|
|
|
/// Performs Control Flow Graph validation and construction.
|
2018-07-03 19:06:54 +00:00
|
|
|
spv_result_t CfgPass(ValidationState_t& _, const Instruction* inst);
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2018-08-10 16:49:26 +00:00
|
|
|
/// Validates Control Flow Graph instructions.
|
|
|
|
spv_result_t ControlFlowPass(ValidationState_t& _, const Instruction* inst);
|
|
|
|
|
2016-07-08 13:44:10 +00:00
|
|
|
/// Performs Id and SSA validation of a module
|
2018-07-31 13:54:25 +00:00
|
|
|
spv_result_t IdPass(ValidationState_t& _, Instruction* inst);
|
2016-06-02 22:51:05 +00:00
|
|
|
|
|
|
|
/// Performs instruction validation.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t InstructionPass(ValidationState_t& _, const Instruction* inst);
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2018-12-07 14:32:57 +00:00
|
|
|
/// Performs decoration validation. Assumes each decoration on a group
|
|
|
|
/// has been propagated down to the group members.
|
2017-01-13 16:46:21 +00:00
|
|
|
spv_result_t ValidateDecorations(ValidationState_t& _);
|
|
|
|
|
2018-02-07 16:50:26 +00:00
|
|
|
/// Performs validation of built-in variables.
|
2018-10-03 19:59:40 +00:00
|
|
|
spv_result_t ValidateBuiltIns(ValidationState_t& _);
|
2018-02-07 16:50:26 +00:00
|
|
|
|
2018-08-03 15:38:51 +00:00
|
|
|
/// Validates type instructions.
|
|
|
|
spv_result_t TypePass(ValidationState_t& _, const Instruction* inst);
|
2017-03-06 22:21:25 +00:00
|
|
|
|
2018-08-17 15:20:55 +00:00
|
|
|
/// Validates constant instructions.
|
|
|
|
spv_result_t ConstantPass(ValidationState_t& _, const Instruction* inst);
|
|
|
|
|
2017-08-30 14:13:10 +00:00
|
|
|
/// Validates correctness of arithmetic instructions.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t ArithmeticsPass(ValidationState_t& _, const Instruction* inst);
|
2017-08-30 14:13:10 +00:00
|
|
|
|
2017-12-05 15:15:51 +00:00
|
|
|
/// Validates correctness of composite instructions.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t CompositesPass(ValidationState_t& _, const Instruction* inst);
|
2017-12-05 15:15:51 +00:00
|
|
|
|
2017-09-28 18:53:24 +00:00
|
|
|
/// Validates correctness of conversion instructions.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t ConversionPass(ValidationState_t& _, const Instruction* inst);
|
2017-09-28 18:53:24 +00:00
|
|
|
|
2017-11-22 17:07:23 +00:00
|
|
|
/// Validates correctness of derivative instructions.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t DerivativesPass(ValidationState_t& _, const Instruction* inst);
|
2017-11-22 17:07:23 +00:00
|
|
|
|
2017-09-07 21:27:57 +00:00
|
|
|
/// Validates correctness of logical instructions.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t LogicalsPass(ValidationState_t& _, const Instruction* inst);
|
2017-09-07 21:27:57 +00:00
|
|
|
|
2017-09-18 20:49:11 +00:00
|
|
|
/// Validates correctness of bitwise instructions.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t BitwisePass(ValidationState_t& _, const Instruction* inst);
|
2017-09-18 20:49:11 +00:00
|
|
|
|
2017-10-26 19:30:23 +00:00
|
|
|
/// Validates correctness of image instructions.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t ImagePass(ValidationState_t& _, const Instruction* inst);
|
2017-10-26 19:30:23 +00:00
|
|
|
|
2017-11-30 16:29:05 +00:00
|
|
|
/// Validates correctness of atomic instructions.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t AtomicsPass(ValidationState_t& _, const Instruction* inst);
|
2017-10-18 09:00:02 +00:00
|
|
|
|
2018-01-31 21:29:54 +00:00
|
|
|
/// Validates correctness of barrier instructions.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t BarriersPass(ValidationState_t& _, const Instruction* inst);
|
2018-01-31 21:29:54 +00:00
|
|
|
|
2017-10-18 09:00:02 +00:00
|
|
|
/// Validates correctness of literal numbers.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t LiteralsPass(ValidationState_t& _, const Instruction* inst);
|
2017-12-13 16:56:09 +00:00
|
|
|
|
2018-11-27 22:05:54 +00:00
|
|
|
/// Validates correctness of extension instructions.
|
2018-11-27 21:20:01 +00:00
|
|
|
spv_result_t ExtensionPass(ValidationState_t& _, const Instruction* inst);
|
|
|
|
|
2018-08-08 18:21:27 +00:00
|
|
|
/// Validates correctness of annotation instructions.
|
|
|
|
spv_result_t AnnotationPass(ValidationState_t& _, const Instruction* inst);
|
|
|
|
|
2018-04-17 14:18:59 +00:00
|
|
|
/// Validates correctness of non-uniform group instructions.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t NonUniformPass(ValidationState_t& _, const Instruction* inst);
|
2018-08-08 17:47:09 +00:00
|
|
|
|
|
|
|
/// Validates correctness of debug instructions.
|
|
|
|
spv_result_t DebugPass(ValidationState_t& _, const Instruction* inst);
|
2018-04-17 14:18:59 +00:00
|
|
|
|
2017-03-06 22:21:25 +00:00
|
|
|
// Validates that capability declarations use operands allowed in the current
|
|
|
|
// context.
|
2018-07-31 13:54:25 +00:00
|
|
|
spv_result_t CapabilityPass(ValidationState_t& _, const Instruction* inst);
|
2017-03-06 22:21:25 +00:00
|
|
|
|
2017-12-14 22:29:37 +00:00
|
|
|
/// Validates correctness of primitive instructions.
|
2018-07-10 14:57:52 +00:00
|
|
|
spv_result_t PrimitivesPass(ValidationState_t& _, const Instruction* inst);
|
2017-12-14 22:29:37 +00:00
|
|
|
|
2018-08-08 18:49:59 +00:00
|
|
|
/// Validates correctness of mode setting instructions.
|
|
|
|
spv_result_t ModeSettingPass(ValidationState_t& _, const Instruction* inst);
|
|
|
|
|
2018-08-10 13:53:17 +00:00
|
|
|
/// Validates correctness of function instructions.
|
|
|
|
spv_result_t FunctionPass(ValidationState_t& _, const Instruction* inst);
|
|
|
|
|
2019-06-03 14:55:07 +00:00
|
|
|
/// Validates correctness of miscellaneous instructions.
|
|
|
|
spv_result_t MiscPass(ValidationState_t& _, const Instruction* inst);
|
|
|
|
|
2022-07-20 14:12:58 +00:00
|
|
|
/// Validates correctness of ray query instructions.
|
|
|
|
spv_result_t RayQueryPass(ValidationState_t& _, const Instruction* inst);
|
|
|
|
|
2022-08-08 18:45:04 +00:00
|
|
|
/// Validates correctness of ray tracing instructions.
|
|
|
|
spv_result_t RayTracingPass(ValidationState_t& _, const Instruction* inst);
|
|
|
|
|
2022-11-24 14:50:45 +00:00
|
|
|
/// Validates correctness of shader execution reorder instructions.
|
|
|
|
spv_result_t RayReorderNVPass(ValidationState_t& _, const Instruction* inst);
|
|
|
|
|
2022-09-23 15:06:46 +00:00
|
|
|
/// Validates correctness of mesh shading instructions.
|
|
|
|
spv_result_t MeshShadingPass(ValidationState_t& _, const Instruction* inst);
|
|
|
|
|
2020-07-16 01:27:03 +00:00
|
|
|
/// Calculates the reachability of basic blocks.
|
|
|
|
void ReachabilityPass(ValidationState_t& _);
|
|
|
|
|
2024-10-24 17:55:04 +00:00
|
|
|
/// Validates tensor layout and view instructions.
|
|
|
|
spv_result_t TensorLayoutPass(ValidationState_t& _, const Instruction* inst);
|
|
|
|
|
2018-08-10 13:53:17 +00:00
|
|
|
/// Validates execution limitations.
|
|
|
|
///
|
|
|
|
/// Verifies execution models are allowed for all functionality they contain.
|
|
|
|
spv_result_t ValidateExecutionLimitations(ValidationState_t& _,
|
|
|
|
const Instruction* inst);
|
|
|
|
|
2019-09-16 23:13:30 +00:00
|
|
|
/// Validates restricted uses of 8- and 16-bit types.
|
2019-07-11 17:05:14 +00:00
|
|
|
///
|
|
|
|
/// Validates shaders that uses 8- or 16-bit storage capabilities, but not full
|
|
|
|
/// capabilities only have appropriate uses of those types.
|
|
|
|
spv_result_t ValidateSmallTypeUses(ValidationState_t& _,
|
|
|
|
const Instruction* inst);
|
|
|
|
|
2023-08-15 19:15:21 +00:00
|
|
|
/// Validates restricted uses of QCOM decorated textures
|
|
|
|
///
|
|
|
|
/// The textures that are decorated with some of QCOM image processing
|
|
|
|
/// decorations must be used in the specified QCOM image processing built-in
|
|
|
|
/// functions and not used in any other image functions.
|
|
|
|
spv_result_t ValidateQCOMImageProcessingTextureUsages(ValidationState_t& _,
|
|
|
|
const Instruction* inst);
|
|
|
|
|
2015-05-22 17:26:19 +00:00
|
|
|
/// @brief Validate the ID's within a SPIR-V binary
|
|
|
|
///
|
|
|
|
/// @param[in] pInstructions array of instructions
|
|
|
|
/// @param[in] count number of elements in instruction array
|
|
|
|
/// @param[in] bound the binary header
|
|
|
|
/// @param[in,out] position current word in the binary
|
2016-09-02 22:06:18 +00:00
|
|
|
/// @param[in] consumer message consumer callback
|
2015-05-22 17:26:19 +00:00
|
|
|
///
|
|
|
|
/// @return result code
|
2015-11-02 14:41:20 +00:00
|
|
|
spv_result_t spvValidateIDs(const spv_instruction_t* pInstructions,
|
2015-05-22 17:26:19 +00:00
|
|
|
const uint64_t count, const uint32_t bound,
|
2016-09-02 22:06:18 +00:00
|
|
|
spv_position position,
|
2018-07-10 03:18:44 +00:00
|
|
|
const MessageConsumer& consumer);
|
2015-05-22 17:26:19 +00:00
|
|
|
|
2017-01-11 20:03:53 +00:00
|
|
|
// Performs validation for the SPIRV-V module binary.
|
|
|
|
// The main difference between this API and spvValidateBinary is that the
|
|
|
|
// "Validation State" is not destroyed upon function return; it lives on and is
|
|
|
|
// pointed to by the vstate unique_ptr.
|
|
|
|
spv_result_t ValidateBinaryAndKeepValidationState(
|
2017-02-15 18:29:33 +00:00
|
|
|
const spv_const_context context, spv_const_validator_options options,
|
|
|
|
const uint32_t* words, const size_t num_words, spv_diagnostic* pDiagnostic,
|
2018-07-10 03:18:44 +00:00
|
|
|
std::unique_ptr<ValidationState_t>* vstate);
|
2017-05-03 19:26:39 +00:00
|
|
|
|
2018-07-10 03:18:44 +00:00
|
|
|
} // namespace val
|
2017-01-11 20:03:53 +00:00
|
|
|
} // namespace spvtools
|
|
|
|
|
2018-07-11 14:27:34 +00:00
|
|
|
#endif // SOURCE_VAL_VALIDATE_H_
|