2016-06-02 22:51:05 +00:00
|
|
|
// Copyright (c) 2015-2016 The Khronos Group Inc.
|
|
|
|
//
|
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
|
2016-06-02 22:51:05 +00:00
|
|
|
//
|
2016-09-01 19:33:59 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2016-06-02 22:51:05 +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.
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2018-08-03 12:05:33 +00:00
|
|
|
#ifndef SOURCE_VAL_VALIDATION_STATE_H_
|
|
|
|
#define SOURCE_VAL_VALIDATION_STATE_H_
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2019-01-14 21:44:44 +00:00
|
|
|
#include <algorithm>
|
2018-08-03 19:06:09 +00:00
|
|
|
#include <map>
|
2017-02-23 21:07:52 +00:00
|
|
|
#include <set>
|
2016-06-02 22:51:05 +00:00
|
|
|
#include <string>
|
2018-02-06 17:10:11 +00:00
|
|
|
#include <tuple>
|
2016-06-02 22:51:05 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <unordered_set>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-08-03 19:06:09 +00:00
|
|
|
#include "source/assembly_grammar.h"
|
|
|
|
#include "source/diagnostic.h"
|
|
|
|
#include "source/disassemble.h"
|
|
|
|
#include "source/enum_set.h"
|
|
|
|
#include "source/latest_version_spirv_header.h"
|
2018-12-03 22:01:30 +00:00
|
|
|
#include "source/name_mapper.h"
|
2018-08-03 19:06:09 +00:00
|
|
|
#include "source/spirv_definition.h"
|
|
|
|
#include "source/spirv_validator_options.h"
|
|
|
|
#include "source/val/decoration.h"
|
|
|
|
#include "source/val/function.h"
|
|
|
|
#include "source/val/instruction.h"
|
2016-06-02 22:51:05 +00:00
|
|
|
#include "spirv-tools/libspirv.h"
|
|
|
|
|
2018-07-07 13:38:00 +00:00
|
|
|
namespace spvtools {
|
2018-07-10 03:18:44 +00:00
|
|
|
namespace val {
|
2016-06-02 22:51:05 +00:00
|
|
|
|
|
|
|
/// This enum represents the sections of a SPIRV module. See section 2.4
|
|
|
|
/// of the SPIRV spec for additional details of the order. The enumerant values
|
|
|
|
/// are in the same order as the vector returned by GetModuleOrder
|
|
|
|
enum ModuleLayoutSection {
|
|
|
|
kLayoutCapabilities, /// < Section 2.4 #1
|
|
|
|
kLayoutExtensions, /// < Section 2.4 #2
|
|
|
|
kLayoutExtInstImport, /// < Section 2.4 #3
|
|
|
|
kLayoutMemoryModel, /// < Section 2.4 #4
|
|
|
|
kLayoutEntryPoint, /// < Section 2.4 #5
|
|
|
|
kLayoutExecutionMode, /// < Section 2.4 #6
|
|
|
|
kLayoutDebug1, /// < Section 2.4 #7 > 1
|
|
|
|
kLayoutDebug2, /// < Section 2.4 #7 > 2
|
2017-09-07 21:38:31 +00:00
|
|
|
kLayoutDebug3, /// < Section 2.4 #7 > 3
|
2016-06-02 22:51:05 +00:00
|
|
|
kLayoutAnnotations, /// < Section 2.4 #8
|
|
|
|
kLayoutTypes, /// < Section 2.4 #9
|
|
|
|
kLayoutFunctionDeclarations, /// < Section 2.4 #10
|
|
|
|
kLayoutFunctionDefinitions /// < Section 2.4 #11
|
|
|
|
};
|
|
|
|
|
|
|
|
/// This class manages the state of the SPIR-V validation as it is being parsed.
|
|
|
|
class ValidationState_t {
|
|
|
|
public:
|
2018-06-20 17:29:38 +00:00
|
|
|
// Features that can optionally be turned on by a capability or environment.
|
2017-02-22 22:53:08 +00:00
|
|
|
struct Feature {
|
2017-03-01 20:51:44 +00:00
|
|
|
bool declare_int16_type = false; // Allow OpTypeInt with 16 bit width?
|
|
|
|
bool declare_float16_type = false; // Allow OpTypeFloat with 16 bit width?
|
|
|
|
bool free_fp_rounding_mode = false; // Allow the FPRoundingMode decoration
|
|
|
|
// and its vaules to be used without
|
|
|
|
// requiring any capability
|
2017-02-01 20:37:39 +00:00
|
|
|
|
|
|
|
// Allow functionalities enabled by VariablePointers capability.
|
|
|
|
bool variable_pointers = false;
|
2017-03-26 01:12:22 +00:00
|
|
|
// Allow functionalities enabled by VariablePointersStorageBuffer
|
2017-02-01 20:37:39 +00:00
|
|
|
// capability.
|
2017-03-26 01:12:22 +00:00
|
|
|
bool variable_pointers_storage_buffer = false;
|
2017-11-24 19:18:17 +00:00
|
|
|
|
|
|
|
// Permit group oerations Reduce, InclusiveScan, ExclusiveScan
|
|
|
|
bool group_ops_reduce_and_scans = false;
|
2018-06-20 17:29:38 +00:00
|
|
|
|
2018-06-01 19:19:11 +00:00
|
|
|
// Allow OpTypeInt with 8 bit width?
|
|
|
|
bool declare_int8_type = false;
|
2018-07-09 21:19:34 +00:00
|
|
|
|
2018-07-10 21:01:06 +00:00
|
|
|
// Target environment uses relaxed block layout.
|
|
|
|
// This is true for Vulkan 1.1 or later.
|
|
|
|
bool env_relaxed_block_layout = false;
|
2018-10-19 17:45:26 +00:00
|
|
|
|
|
|
|
// Allow an OpTypeInt with 8 bit width to be used in more than just int
|
|
|
|
// conversion opcodes
|
|
|
|
bool use_int8_type = false;
|
2018-10-10 00:43:09 +00:00
|
|
|
|
2019-05-07 16:27:18 +00:00
|
|
|
// SPIR-V 1.4 allows us to select between any two composite values
|
|
|
|
// of the same type.
|
|
|
|
bool select_between_composites = false;
|
|
|
|
|
|
|
|
// SPIR-V 1.4 allows two memory access operands for OpCopyMemory and
|
|
|
|
// OpCopyMemorySized.
|
|
|
|
bool copy_memory_permits_two_memory_accesses = false;
|
|
|
|
|
|
|
|
// SPIR-V 1.4 allows UConvert as a spec constant op in any environment.
|
2019-01-09 00:00:18 +00:00
|
|
|
// The Kernel capability already enables it, separately from this flag.
|
|
|
|
bool uconvert_spec_constant_op = false;
|
2019-05-07 16:27:18 +00:00
|
|
|
|
|
|
|
// SPIR-V 1.4 allows Function and Private variables to be NonWritable
|
|
|
|
bool nonwritable_var_in_function_or_private = false;
|
2021-08-26 18:33:19 +00:00
|
|
|
|
|
|
|
// Whether LocalSizeId execution mode is allowed by the environment.
|
|
|
|
bool env_allow_localsizeid = false;
|
2017-02-22 22:53:08 +00:00
|
|
|
};
|
|
|
|
|
2017-02-15 18:29:33 +00:00
|
|
|
ValidationState_t(const spv_const_context context,
|
2018-06-19 20:02:44 +00:00
|
|
|
const spv_const_validator_options opt,
|
2018-10-03 19:59:40 +00:00
|
|
|
const uint32_t* words, const size_t num_words,
|
|
|
|
const uint32_t max_warnings);
|
2016-09-02 22:06:18 +00:00
|
|
|
|
|
|
|
/// Returns the context
|
|
|
|
spv_const_context context() const { return context_; }
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2017-02-15 18:29:33 +00:00
|
|
|
/// Returns the command line options
|
|
|
|
spv_const_validator_options options() const { return options_; }
|
|
|
|
|
2018-08-02 16:01:26 +00:00
|
|
|
/// Sets the ID of the generator for this module.
|
|
|
|
void setGenerator(uint32_t gen) { generator_ = gen; }
|
|
|
|
|
|
|
|
/// Returns the ID of the generator for this module.
|
|
|
|
uint32_t generator() const { return generator_; }
|
|
|
|
|
|
|
|
/// Sets the SPIR-V version of this module.
|
|
|
|
void setVersion(uint32_t ver) { version_ = ver; }
|
|
|
|
|
|
|
|
/// Gets the SPIR-V version of this module.
|
|
|
|
uint32_t version() const { return version_; }
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
/// Forward declares the id in the module
|
2016-06-25 03:45:25 +00:00
|
|
|
spv_result_t ForwardDeclareId(uint32_t id);
|
2016-06-02 22:51:05 +00:00
|
|
|
|
|
|
|
/// Removes a forward declared ID if it has been defined
|
2016-06-25 03:45:25 +00:00
|
|
|
spv_result_t RemoveIfForwardDeclared(uint32_t id);
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2016-11-10 20:12:26 +00:00
|
|
|
/// Registers an ID as a forward pointer
|
|
|
|
spv_result_t RegisterForwardPointer(uint32_t id);
|
|
|
|
|
|
|
|
/// Returns whether or not an ID is a forward pointer
|
|
|
|
bool IsForwardPointer(uint32_t id) const;
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
/// Assigns a name to an ID
|
2016-06-25 03:45:25 +00:00
|
|
|
void AssignNameToId(uint32_t id, std::string name);
|
2016-06-02 22:51:05 +00:00
|
|
|
|
|
|
|
/// Returns a string representation of the ID in the format <id>[Name] where
|
|
|
|
/// the <id> is the numeric valid of the id and the Name is a name assigned by
|
|
|
|
/// the OpName instruction
|
|
|
|
std::string getIdName(uint32_t id) const;
|
|
|
|
|
2016-11-24 20:37:22 +00:00
|
|
|
/// Accessor function for ID bound.
|
|
|
|
uint32_t getIdBound() const;
|
|
|
|
|
|
|
|
/// Mutator function for ID bound.
|
|
|
|
void setIdBound(uint32_t bound);
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
/// Returns the number of ID which have been forward referenced but not
|
|
|
|
/// defined
|
2016-06-25 03:45:25 +00:00
|
|
|
size_t unresolved_forward_id_count() const;
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2016-08-09 18:05:03 +00:00
|
|
|
/// Returns a vector of unresolved forward ids.
|
2016-06-25 03:45:25 +00:00
|
|
|
std::vector<uint32_t> UnresolvedForwardIds() const;
|
2016-06-02 22:51:05 +00:00
|
|
|
|
|
|
|
/// Returns true if the id has been defined
|
2016-06-25 03:45:25 +00:00
|
|
|
bool IsDefinedId(uint32_t id) const;
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2018-08-01 14:37:36 +00:00
|
|
|
/// Increments the total number of instructions in the file.
|
|
|
|
void increment_total_instructions() { total_instructions_++; }
|
|
|
|
|
|
|
|
/// Increments the total number of functions in the file.
|
|
|
|
void increment_total_functions() { total_functions_++; }
|
|
|
|
|
|
|
|
/// Allocates internal storage. Note, calling this will invalidate any
|
|
|
|
/// pointers to |ordered_instructions_| or |module_functions_| and, hence,
|
|
|
|
/// should only be called at the beginning of validation.
|
|
|
|
void preallocateStorage();
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
/// Returns the current layout section which is being processed
|
2016-06-25 03:45:25 +00:00
|
|
|
ModuleLayoutSection current_layout_section() const;
|
2016-06-02 22:51:05 +00:00
|
|
|
|
|
|
|
/// Increments the module_layout_order_section_
|
2016-06-25 03:45:25 +00:00
|
|
|
void ProgressToNextLayoutSectionOrder();
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2020-10-08 17:10:12 +00:00
|
|
|
/// Determines if the op instruction is in a previous layout section
|
|
|
|
bool IsOpcodeInPreviousLayoutSection(SpvOp op);
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
/// Determines if the op instruction is part of the current section
|
2016-06-25 03:45:25 +00:00
|
|
|
bool IsOpcodeInCurrentLayoutSection(SpvOp op);
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2018-10-03 19:59:40 +00:00
|
|
|
DiagnosticStream diag(spv_result_t error_code, const Instruction* inst);
|
2016-06-02 22:51:05 +00:00
|
|
|
|
|
|
|
/// Returns the function states
|
2018-08-01 14:37:36 +00:00
|
|
|
std::vector<Function>& functions();
|
2016-06-02 22:51:05 +00:00
|
|
|
|
|
|
|
/// Returns the function states
|
2016-06-25 03:45:25 +00:00
|
|
|
Function& current_function();
|
2017-10-11 22:13:21 +00:00
|
|
|
const Function& current_function() const;
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2017-11-23 17:11:15 +00:00
|
|
|
/// Returns function state with the given id, or nullptr if no such function.
|
|
|
|
const Function* function(uint32_t id) const;
|
2018-08-03 16:57:11 +00:00
|
|
|
Function* function(uint32_t id);
|
2017-11-23 17:11:15 +00:00
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
/// Returns true if the called after a function instruction but before the
|
|
|
|
/// function end instruction
|
|
|
|
bool in_function_body() const;
|
|
|
|
|
|
|
|
/// Returns true if called after a label instruction but before a branch
|
|
|
|
/// instruction
|
|
|
|
bool in_block() const;
|
|
|
|
|
2018-05-31 13:07:09 +00:00
|
|
|
struct EntryPointDescription {
|
|
|
|
std::string name;
|
|
|
|
std::vector<uint32_t> interfaces;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Registers |id| as an entry point with |execution_model| and |interfaces|.
|
|
|
|
void RegisterEntryPoint(const uint32_t id, SpvExecutionModel execution_model,
|
|
|
|
EntryPointDescription&& desc) {
|
2017-01-16 17:54:15 +00:00
|
|
|
entry_points_.push_back(id);
|
2018-03-27 15:13:39 +00:00
|
|
|
entry_point_to_execution_models_[id].insert(execution_model);
|
2018-05-31 13:07:09 +00:00
|
|
|
entry_point_descriptions_[id].emplace_back(desc);
|
2017-01-16 17:54:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
/// Returns a list of entry point function ids
|
|
|
|
const std::vector<uint32_t>& entry_points() const { return entry_points_; }
|
|
|
|
|
2018-12-05 18:58:43 +00:00
|
|
|
/// Returns the set of entry points that root call graphs that contain
|
|
|
|
/// recursion.
|
|
|
|
const std::set<uint32_t>& recursive_entry_points() const {
|
|
|
|
return recursive_entry_points_;
|
|
|
|
}
|
|
|
|
|
2018-03-27 15:13:39 +00:00
|
|
|
/// Registers execution mode for the given entry point.
|
|
|
|
void RegisterExecutionModeForEntryPoint(uint32_t entry_point,
|
|
|
|
SpvExecutionMode execution_mode) {
|
|
|
|
entry_point_to_execution_modes_[entry_point].insert(execution_mode);
|
|
|
|
}
|
|
|
|
|
2018-05-31 13:07:09 +00:00
|
|
|
/// Returns the interface descriptions of a given entry point.
|
|
|
|
const std::vector<EntryPointDescription>& entry_point_descriptions(
|
|
|
|
uint32_t entry_point) {
|
|
|
|
return entry_point_descriptions_.at(entry_point);
|
2017-01-16 17:54:15 +00:00
|
|
|
}
|
|
|
|
|
2018-03-27 15:13:39 +00:00
|
|
|
/// Returns Execution Models for the given Entry Point.
|
|
|
|
/// Returns nullptr if none found (would trigger assertion).
|
|
|
|
const std::set<SpvExecutionModel>* GetExecutionModels(
|
|
|
|
uint32_t entry_point) const {
|
|
|
|
const auto it = entry_point_to_execution_models_.find(entry_point);
|
|
|
|
if (it == entry_point_to_execution_models_.end()) {
|
|
|
|
assert(0);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return &it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns Execution Modes for the given Entry Point.
|
|
|
|
/// Returns nullptr if none found.
|
|
|
|
const std::set<SpvExecutionMode>* GetExecutionModes(
|
|
|
|
uint32_t entry_point) const {
|
|
|
|
const auto it = entry_point_to_execution_modes_.find(entry_point);
|
|
|
|
if (it == entry_point_to_execution_modes_.end()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return &it->second;
|
|
|
|
}
|
|
|
|
|
2018-04-16 17:58:11 +00:00
|
|
|
/// Traverses call tree and computes function_to_entry_points_.
|
|
|
|
/// Note: called after fully parsing the binary.
|
|
|
|
void ComputeFunctionToEntryPointMapping();
|
|
|
|
|
2018-12-05 18:58:43 +00:00
|
|
|
/// Traverse call tree and computes recursive_entry_points_.
|
|
|
|
/// Note: called after fully parsing the binary and calling
|
|
|
|
/// ComputeFunctionToEntryPointMapping.
|
|
|
|
void ComputeRecursiveEntryPoints();
|
|
|
|
|
2018-04-16 17:58:11 +00:00
|
|
|
/// Returns all the entry points that can call |func|.
|
|
|
|
const std::vector<uint32_t>& FunctionEntryPoints(uint32_t func) const;
|
|
|
|
|
2018-12-05 13:10:02 +00:00
|
|
|
/// Returns all the entry points that statically use |id|.
|
|
|
|
///
|
|
|
|
/// Note: requires ComputeFunctionToEntryPointMapping to have been called.
|
|
|
|
std::set<uint32_t> EntryPointReferences(uint32_t id) const;
|
|
|
|
|
2017-01-09 16:10:52 +00:00
|
|
|
/// Inserts an <id> to the set of functions that are target of OpFunctionCall.
|
|
|
|
void AddFunctionCallTarget(const uint32_t id) {
|
|
|
|
function_call_targets_.insert(id);
|
2017-11-23 17:11:15 +00:00
|
|
|
current_function().AddFunctionCallTarget(id);
|
2017-01-09 16:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns whether or not a function<id> is the target of OpFunctionCall.
|
|
|
|
bool IsFunctionCallTarget(const uint32_t id) {
|
|
|
|
return (function_call_targets_.find(id) != function_call_targets_.end());
|
|
|
|
}
|
|
|
|
|
2018-12-05 16:47:24 +00:00
|
|
|
bool IsFunctionCallDefined(const uint32_t id) {
|
|
|
|
return (id_to_function_.find(id) != id_to_function_.end());
|
|
|
|
}
|
2016-06-02 22:51:05 +00:00
|
|
|
/// Registers the capability and its dependent capabilities
|
|
|
|
void RegisterCapability(SpvCapability cap);
|
|
|
|
|
2017-03-08 18:59:01 +00:00
|
|
|
/// Registers the extension.
|
|
|
|
void RegisterExtension(Extension ext);
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
/// Registers the function in the module. Subsequent instructions will be
|
|
|
|
/// called against this function
|
|
|
|
spv_result_t RegisterFunction(uint32_t id, uint32_t ret_type_id,
|
|
|
|
SpvFunctionControlMask function_control,
|
|
|
|
uint32_t function_type_id);
|
|
|
|
|
|
|
|
/// Register a function end instruction
|
|
|
|
spv_result_t RegisterFunctionEnd();
|
|
|
|
|
|
|
|
/// Returns true if the capability is enabled in the module.
|
2016-08-29 18:49:00 +00:00
|
|
|
bool HasCapability(SpvCapability cap) const {
|
|
|
|
return module_capabilities_.Contains(cap);
|
|
|
|
}
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2019-09-13 18:59:02 +00:00
|
|
|
/// Returns a reference to the set of capabilities in the module.
|
|
|
|
/// This is provided for debuggability.
|
|
|
|
const CapabilitySet& module_capabilities() const {
|
|
|
|
return module_capabilities_;
|
|
|
|
}
|
|
|
|
|
2017-03-10 20:58:15 +00:00
|
|
|
/// Returns true if the extension is enabled in the module.
|
|
|
|
bool HasExtension(Extension ext) const {
|
|
|
|
return module_extensions_.Contains(ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if any of the capabilities is enabled, or if |capabilities|
|
|
|
|
/// is an empty set.
|
2018-07-07 13:38:00 +00:00
|
|
|
bool HasAnyOfCapabilities(const CapabilitySet& capabilities) const;
|
2017-03-10 20:58:15 +00:00
|
|
|
|
|
|
|
/// Returns true if any of the extensions is enabled, or if |extensions|
|
|
|
|
/// is an empty set.
|
2018-07-07 13:38:00 +00:00
|
|
|
bool HasAnyOfExtensions(const ExtensionSet& extensions) const;
|
2016-06-02 22:51:05 +00:00
|
|
|
|
|
|
|
/// Sets the addressing model of this module (logical/physical).
|
2016-06-25 03:45:25 +00:00
|
|
|
void set_addressing_model(SpvAddressingModel am);
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2018-05-22 17:09:50 +00:00
|
|
|
/// Returns true if the OpMemoryModel was found.
|
|
|
|
bool has_memory_model_specified() const {
|
|
|
|
return addressing_model_ != SpvAddressingModelMax &&
|
|
|
|
memory_model_ != SpvMemoryModelMax;
|
|
|
|
}
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
/// Returns the addressing model of this module, or Logical if uninitialized.
|
2016-06-25 03:45:25 +00:00
|
|
|
SpvAddressingModel addressing_model() const;
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2019-01-07 18:19:24 +00:00
|
|
|
/// Returns the addressing model of this module, or Logical if uninitialized.
|
|
|
|
uint32_t pointer_size_and_alignment() const {
|
|
|
|
return pointer_size_and_alignment_;
|
|
|
|
}
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
/// Sets the memory model of this module.
|
2016-06-25 03:45:25 +00:00
|
|
|
void set_memory_model(SpvMemoryModel mm);
|
2016-06-02 22:51:05 +00:00
|
|
|
|
|
|
|
/// Returns the memory model of this module, or Simple if uninitialized.
|
2016-06-25 03:45:25 +00:00
|
|
|
SpvMemoryModel memory_model() const;
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2017-03-01 20:51:44 +00:00
|
|
|
const AssemblyGrammar& grammar() const { return grammar_; }
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2018-07-31 13:54:25 +00:00
|
|
|
/// Inserts the instruction into the list of ordered instructions in the file.
|
|
|
|
Instruction* AddOrderedInstruction(const spv_parsed_instruction_t* inst);
|
|
|
|
|
|
|
|
/// Registers the instruction. This will add the instruction to the list of
|
|
|
|
/// definitions and register sampled image consumers.
|
|
|
|
void RegisterInstruction(Instruction* inst);
|
|
|
|
|
|
|
|
/// Registers the debug instruction information.
|
|
|
|
void RegisterDebugInstruction(const Instruction* inst);
|
2016-07-08 13:44:10 +00:00
|
|
|
|
2017-01-11 15:51:23 +00:00
|
|
|
/// Registers the decoration for the given <id>
|
|
|
|
void RegisterDecorationForId(uint32_t id, const Decoration& dec) {
|
2019-09-09 16:55:44 +00:00
|
|
|
auto& dec_list = id_decorations_[id];
|
|
|
|
auto lb = std::find(dec_list.begin(), dec_list.end(), dec);
|
|
|
|
if (lb == dec_list.end()) {
|
|
|
|
dec_list.push_back(dec);
|
|
|
|
}
|
2017-01-11 15:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Registers the list of decorations for the given <id>
|
|
|
|
template <class InputIt>
|
|
|
|
void RegisterDecorationsForId(uint32_t id, InputIt begin, InputIt end) {
|
|
|
|
std::vector<Decoration>& cur_decs = id_decorations_[id];
|
|
|
|
cur_decs.insert(cur_decs.end(), begin, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Registers the list of decorations for the given member of the given
|
|
|
|
/// structure.
|
|
|
|
template <class InputIt>
|
|
|
|
void RegisterDecorationsForStructMember(uint32_t struct_id,
|
|
|
|
uint32_t member_index, InputIt begin,
|
|
|
|
InputIt end) {
|
|
|
|
RegisterDecorationsForId(struct_id, begin, end);
|
|
|
|
for (auto& decoration : id_decorations_[struct_id]) {
|
|
|
|
decoration.set_struct_member_index(member_index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns all the decorations for the given <id>. If no decorations exist
|
|
|
|
/// for the <id>, it registers an empty vector for it in the map and
|
|
|
|
/// returns the empty vector.
|
|
|
|
std::vector<Decoration>& id_decorations(uint32_t id) {
|
|
|
|
return id_decorations_[id];
|
|
|
|
}
|
|
|
|
|
2018-02-07 16:50:26 +00:00
|
|
|
// Returns const pointer to the internal decoration container.
|
2018-04-03 20:07:55 +00:00
|
|
|
const std::map<uint32_t, std::vector<Decoration>>& id_decorations() const {
|
2018-02-07 16:50:26 +00:00
|
|
|
return id_decorations_;
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:44:44 +00:00
|
|
|
/// Returns true if the given id <id> has the given decoration <dec>,
|
|
|
|
/// otherwise returns false.
|
|
|
|
bool HasDecoration(uint32_t id, SpvDecoration dec) {
|
|
|
|
const auto& decorations = id_decorations_.find(id);
|
|
|
|
if (decorations == id_decorations_.end()) return false;
|
|
|
|
|
|
|
|
return std::any_of(
|
|
|
|
decorations->second.begin(), decorations->second.end(),
|
|
|
|
[dec](const Decoration& d) { return dec == d.dec_type(); });
|
|
|
|
}
|
|
|
|
|
2016-08-06 17:29:33 +00:00
|
|
|
/// Finds id's def, if it exists. If found, returns the definition otherwise
|
|
|
|
/// nullptr
|
|
|
|
const Instruction* FindDef(uint32_t id) const;
|
2016-07-08 13:44:10 +00:00
|
|
|
|
|
|
|
/// Finds id's def, if it exists. If found, returns the definition otherwise
|
|
|
|
/// nullptr
|
2016-08-06 17:29:33 +00:00
|
|
|
Instruction* FindDef(uint32_t id);
|
2016-07-08 13:44:10 +00:00
|
|
|
|
2018-08-01 14:37:36 +00:00
|
|
|
/// Returns the instructions in the order they appear in the binary
|
|
|
|
const std::vector<Instruction>& ordered_instructions() const {
|
2016-08-06 17:29:33 +00:00
|
|
|
return ordered_instructions_;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns a map of instructions mapped by their result id
|
|
|
|
const std::unordered_map<uint32_t, Instruction*>& all_definitions() const {
|
2016-07-08 13:44:10 +00:00
|
|
|
return all_definitions_;
|
|
|
|
}
|
|
|
|
|
2019-03-19 16:39:37 +00:00
|
|
|
/// Returns a vector containing the instructions that consume the given
|
2016-11-22 23:06:55 +00:00
|
|
|
/// SampledImage id.
|
2019-03-19 16:39:37 +00:00
|
|
|
std::vector<Instruction*> getSampledImageConsumers(uint32_t id) const;
|
2016-11-22 23:06:55 +00:00
|
|
|
|
|
|
|
/// Records cons_id as a consumer of sampled_image_id.
|
|
|
|
void RegisterSampledImageConsumer(uint32_t sampled_image_id,
|
2019-03-19 16:39:37 +00:00
|
|
|
Instruction* consumer);
|
2016-11-22 23:06:55 +00:00
|
|
|
|
2021-06-10 12:38:23 +00:00
|
|
|
// Record a function's storage class consumer instruction
|
|
|
|
void RegisterStorageClassConsumer(SpvStorageClass storage_class,
|
|
|
|
Instruction* consumer);
|
|
|
|
|
2017-01-13 16:46:21 +00:00
|
|
|
/// Returns the set of Global Variables.
|
|
|
|
std::unordered_set<uint32_t>& global_vars() { return global_vars_; }
|
2016-11-29 20:50:34 +00:00
|
|
|
|
2017-01-13 16:46:21 +00:00
|
|
|
/// Returns the set of Local Variables.
|
|
|
|
std::unordered_set<uint32_t>& local_vars() { return local_vars_; }
|
2016-11-29 20:50:34 +00:00
|
|
|
|
2017-01-13 16:46:21 +00:00
|
|
|
/// Returns the number of Global Variables.
|
|
|
|
size_t num_global_vars() { return global_vars_.size(); }
|
2016-11-29 20:50:34 +00:00
|
|
|
|
2017-01-13 16:46:21 +00:00
|
|
|
/// Returns the number of Local Variables.
|
|
|
|
size_t num_local_vars() { return local_vars_.size(); }
|
|
|
|
|
|
|
|
/// Inserts a new <id> to the set of Global Variables.
|
|
|
|
void registerGlobalVariable(const uint32_t id) { global_vars_.insert(id); }
|
|
|
|
|
|
|
|
/// Inserts a new <id> to the set of Local Variables.
|
|
|
|
void registerLocalVariable(const uint32_t id) { local_vars_.insert(id); }
|
2016-11-29 20:50:34 +00:00
|
|
|
|
2018-07-10 21:01:06 +00:00
|
|
|
// Returns true if using relaxed block layout, equivalent to
|
|
|
|
// VK_KHR_relaxed_block_layout.
|
|
|
|
bool IsRelaxedBlockLayout() const {
|
|
|
|
return features_.env_relaxed_block_layout || options()->relax_block_layout;
|
|
|
|
}
|
|
|
|
|
2021-08-26 18:33:19 +00:00
|
|
|
// Returns true if allowing localsizeid, either because the environment always
|
|
|
|
// allows it, or because it is enabled from the command-line.
|
|
|
|
bool IsLocalSizeIdAllowed() const {
|
|
|
|
return features_.env_allow_localsizeid || options()->allow_localsizeid;
|
|
|
|
}
|
|
|
|
|
2016-12-04 15:48:26 +00:00
|
|
|
/// Sets the struct nesting depth for a given struct ID
|
|
|
|
void set_struct_nesting_depth(uint32_t id, uint32_t depth) {
|
|
|
|
struct_nesting_depth_[id] = depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the nesting depth of a given structure ID
|
|
|
|
uint32_t struct_nesting_depth(uint32_t id) {
|
|
|
|
return struct_nesting_depth_[id];
|
|
|
|
}
|
|
|
|
|
2019-02-25 15:37:43 +00:00
|
|
|
/// Records the has a nested block/bufferblock decorated struct for a given
|
|
|
|
/// struct ID
|
|
|
|
void SetHasNestedBlockOrBufferBlockStruct(uint32_t id, bool has) {
|
|
|
|
struct_has_nested_blockorbufferblock_struct_[id] = has;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// For a given struct ID returns true if it has a nested block/bufferblock
|
|
|
|
/// decorated struct
|
|
|
|
bool GetHasNestedBlockOrBufferBlockStruct(uint32_t id) {
|
|
|
|
return struct_has_nested_blockorbufferblock_struct_[id];
|
|
|
|
}
|
|
|
|
|
2017-01-16 17:54:15 +00:00
|
|
|
/// Records that the structure type has a member decorated with a built-in.
|
|
|
|
void RegisterStructTypeWithBuiltInMember(uint32_t id) {
|
|
|
|
builtin_structs_.insert(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if the struct type with the given Id has a BuiltIn member.
|
|
|
|
bool IsStructTypeWithBuiltInMember(uint32_t id) const {
|
|
|
|
return (builtin_structs_.find(id) != builtin_structs_.end());
|
|
|
|
}
|
2017-02-22 22:53:08 +00:00
|
|
|
|
|
|
|
// Returns the state of optional features.
|
|
|
|
const Feature& features() const { return features_; }
|
|
|
|
|
2017-02-23 21:07:52 +00:00
|
|
|
/// Adds the instruction data to unique_type_declarations_.
|
|
|
|
/// Returns false if an identical type declaration already exists.
|
2018-07-10 14:57:52 +00:00
|
|
|
bool RegisterUniqueTypeDeclaration(const Instruction* inst);
|
2017-02-23 21:07:52 +00:00
|
|
|
|
2017-08-30 14:13:10 +00:00
|
|
|
// Returns type_id of the scalar component of |id|.
|
|
|
|
// |id| can be either
|
2017-09-06 18:30:27 +00:00
|
|
|
// - scalar, vector or matrix type
|
|
|
|
// - object of either scalar, vector or matrix type
|
2017-08-30 14:13:10 +00:00
|
|
|
uint32_t GetComponentType(uint32_t id) const;
|
|
|
|
|
2017-09-06 18:30:27 +00:00
|
|
|
// Returns
|
|
|
|
// - 1 for scalar types or objects
|
|
|
|
// - vector size for vector types or objects
|
|
|
|
// - num columns for matrix types or objects
|
|
|
|
// Should not be called with any other arguments (will return zero and invoke
|
|
|
|
// assertion).
|
2017-08-30 14:13:10 +00:00
|
|
|
uint32_t GetDimension(uint32_t id) const;
|
|
|
|
|
|
|
|
// Returns bit width of scalar or component.
|
|
|
|
// |id| can be
|
2017-09-06 18:30:27 +00:00
|
|
|
// - scalar, vector or matrix type
|
|
|
|
// - object of either scalar, vector or matrix type
|
2017-08-30 14:13:10 +00:00
|
|
|
// Will invoke assertion and return 0 if |id| is none of the above.
|
|
|
|
uint32_t GetBitWidth(uint32_t id) const;
|
|
|
|
|
2017-09-06 18:30:27 +00:00
|
|
|
// Provides detailed information on matrix type.
|
|
|
|
// Returns false iff |id| is not matrix type.
|
2017-11-08 17:40:02 +00:00
|
|
|
bool GetMatrixTypeInfo(uint32_t id, uint32_t* num_rows, uint32_t* num_cols,
|
|
|
|
uint32_t* column_type, uint32_t* component_type) const;
|
2017-09-06 18:30:27 +00:00
|
|
|
|
2017-09-18 17:06:40 +00:00
|
|
|
// Collects struct member types into |member_types|.
|
|
|
|
// Returns false iff not struct type or has no members.
|
|
|
|
// Deletes prior contents of |member_types|.
|
2017-11-08 17:40:02 +00:00
|
|
|
bool GetStructMemberTypes(uint32_t struct_type_id,
|
|
|
|
std::vector<uint32_t>* member_types) const;
|
2017-09-18 17:06:40 +00:00
|
|
|
|
2017-08-30 14:13:10 +00:00
|
|
|
// Returns true iff |id| is a type corresponding to the name of the function.
|
|
|
|
// Only works for types not for objects.
|
2019-05-21 13:17:50 +00:00
|
|
|
bool IsVoidType(uint32_t id) const;
|
2017-08-30 14:13:10 +00:00
|
|
|
bool IsFloatScalarType(uint32_t id) const;
|
|
|
|
bool IsFloatVectorType(uint32_t id) const;
|
2017-10-26 19:30:23 +00:00
|
|
|
bool IsFloatScalarOrVectorType(uint32_t id) const;
|
2017-09-06 18:30:27 +00:00
|
|
|
bool IsFloatMatrixType(uint32_t id) const;
|
2017-08-30 14:13:10 +00:00
|
|
|
bool IsIntScalarType(uint32_t id) const;
|
|
|
|
bool IsIntVectorType(uint32_t id) const;
|
2017-10-26 19:30:23 +00:00
|
|
|
bool IsIntScalarOrVectorType(uint32_t id) const;
|
2017-08-30 14:13:10 +00:00
|
|
|
bool IsUnsignedIntScalarType(uint32_t id) const;
|
|
|
|
bool IsUnsignedIntVectorType(uint32_t id) const;
|
|
|
|
bool IsSignedIntScalarType(uint32_t id) const;
|
|
|
|
bool IsSignedIntVectorType(uint32_t id) const;
|
|
|
|
bool IsBoolScalarType(uint32_t id) const;
|
|
|
|
bool IsBoolVectorType(uint32_t id) const;
|
2017-10-26 19:30:23 +00:00
|
|
|
bool IsBoolScalarOrVectorType(uint32_t id) const;
|
2017-09-28 18:53:24 +00:00
|
|
|
bool IsPointerType(uint32_t id) const;
|
2019-02-25 22:43:11 +00:00
|
|
|
bool IsCooperativeMatrixType(uint32_t id) const;
|
|
|
|
bool IsFloatCooperativeMatrixType(uint32_t id) const;
|
|
|
|
bool IsIntCooperativeMatrixType(uint32_t id) const;
|
|
|
|
bool IsUnsignedIntCooperativeMatrixType(uint32_t id) const;
|
2017-08-30 14:13:10 +00:00
|
|
|
|
2019-07-08 18:10:13 +00:00
|
|
|
// Returns true if |id| is a type id that contains |type| (or integer or
|
|
|
|
// floating point type) of |width| bits.
|
|
|
|
bool ContainsSizedIntOrFloatType(uint32_t id, SpvOp type,
|
|
|
|
uint32_t width) const;
|
|
|
|
// Returns true if |id| is a type id that contains a 8- or 16-bit int or
|
|
|
|
// 16-bit float that is not generally enabled for use.
|
|
|
|
bool ContainsLimitedUseIntOrFloatType(uint32_t id) const;
|
|
|
|
|
2021-08-16 22:23:10 +00:00
|
|
|
// Returns true if |id| is a type that contains a runtime-sized array.
|
|
|
|
// Does not consider a pointers as contains the array.
|
|
|
|
bool ContainsRuntimeArray(uint32_t id) const;
|
|
|
|
|
|
|
|
// Generic type traversal.
|
|
|
|
// Only traverse pointers and functions if |traverse_all_types| is true.
|
|
|
|
// Recursively tests |f| against the type hierarchy headed by |id|.
|
|
|
|
bool ContainsType(uint32_t id,
|
|
|
|
const std::function<bool(const Instruction*)>& f,
|
|
|
|
bool traverse_all_types = true) const;
|
|
|
|
|
2017-10-26 19:30:23 +00:00
|
|
|
// Gets value from OpConstant and OpSpecConstant as uint64.
|
|
|
|
// Returns false on failure (no instruction, wrong instruction, not int).
|
|
|
|
bool GetConstantValUint64(uint32_t id, uint64_t* val) const;
|
|
|
|
|
2017-08-30 14:13:10 +00:00
|
|
|
// Returns type_id if id has type or zero otherwise.
|
|
|
|
uint32_t GetTypeId(uint32_t id) const;
|
|
|
|
|
2017-10-26 19:30:23 +00:00
|
|
|
// Returns opcode of the instruction which issued the id or OpNop if the
|
|
|
|
// instruction is not registered.
|
|
|
|
SpvOp GetIdOpcode(uint32_t id) const;
|
|
|
|
|
2017-09-28 18:53:24 +00:00
|
|
|
// Returns type_id for given id operand if it has a type or zero otherwise.
|
|
|
|
// |operand_index| is expected to be pointing towards an operand which is an
|
|
|
|
// id.
|
2018-07-10 14:57:52 +00:00
|
|
|
uint32_t GetOperandTypeId(const Instruction* inst,
|
2017-09-28 18:53:24 +00:00
|
|
|
size_t operand_index) const;
|
|
|
|
|
|
|
|
// Provides information on pointer type. Returns false iff not pointer type.
|
2017-11-08 17:40:02 +00:00
|
|
|
bool GetPointerTypeInfo(uint32_t id, uint32_t* data_type,
|
|
|
|
uint32_t* storage_class) const;
|
2017-09-28 18:53:24 +00:00
|
|
|
|
2019-01-28 20:44:13 +00:00
|
|
|
// Is the ID the type of a pointer to a uniform block: Block-decorated struct
|
|
|
|
// in uniform storage class? The result is only valid after internal method
|
|
|
|
// CheckDecorationsOfBuffers has been called.
|
|
|
|
bool IsPointerToUniformBlock(uint32_t type_id) const {
|
|
|
|
return pointer_to_uniform_block_.find(type_id) !=
|
|
|
|
pointer_to_uniform_block_.cend();
|
|
|
|
}
|
|
|
|
// Save the ID of a pointer to uniform block.
|
|
|
|
void RegisterPointerToUniformBlock(uint32_t type_id) {
|
|
|
|
pointer_to_uniform_block_.insert(type_id);
|
|
|
|
}
|
|
|
|
// Is the ID the type of a struct used as a uniform block?
|
|
|
|
// The result is only valid after internal method CheckDecorationsOfBuffers
|
|
|
|
// has been called.
|
|
|
|
bool IsStructForUniformBlock(uint32_t type_id) const {
|
|
|
|
return struct_for_uniform_block_.find(type_id) !=
|
|
|
|
struct_for_uniform_block_.cend();
|
|
|
|
}
|
|
|
|
// Save the ID of a struct of a uniform block.
|
|
|
|
void RegisterStructForUniformBlock(uint32_t type_id) {
|
|
|
|
struct_for_uniform_block_.insert(type_id);
|
|
|
|
}
|
|
|
|
// Is the ID the type of a pointer to a storage buffer: BufferBlock-decorated
|
|
|
|
// struct in uniform storage class, or Block-decorated struct in StorageBuffer
|
|
|
|
// storage class? The result is only valid after internal method
|
|
|
|
// CheckDecorationsOfBuffers has been called.
|
|
|
|
bool IsPointerToStorageBuffer(uint32_t type_id) const {
|
|
|
|
return pointer_to_storage_buffer_.find(type_id) !=
|
|
|
|
pointer_to_storage_buffer_.cend();
|
|
|
|
}
|
|
|
|
// Save the ID of a pointer to a storage buffer.
|
|
|
|
void RegisterPointerToStorageBuffer(uint32_t type_id) {
|
|
|
|
pointer_to_storage_buffer_.insert(type_id);
|
|
|
|
}
|
|
|
|
// Is the ID the type of a struct for storage buffer?
|
|
|
|
// The result is only valid after internal method CheckDecorationsOfBuffers
|
|
|
|
// has been called.
|
|
|
|
bool IsStructForStorageBuffer(uint32_t type_id) const {
|
|
|
|
return struct_for_storage_buffer_.find(type_id) !=
|
|
|
|
struct_for_storage_buffer_.cend();
|
|
|
|
}
|
|
|
|
// Save the ID of a struct of a storage buffer.
|
|
|
|
void RegisterStructForStorageBuffer(uint32_t type_id) {
|
|
|
|
struct_for_storage_buffer_.insert(type_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Is the ID the type of a pointer to a storage image? That is, the pointee
|
|
|
|
// type is an image type which is known to not use a sampler.
|
|
|
|
bool IsPointerToStorageImage(uint32_t type_id) const {
|
|
|
|
return pointer_to_storage_image_.find(type_id) !=
|
|
|
|
pointer_to_storage_image_.cend();
|
|
|
|
}
|
|
|
|
// Save the ID of a pointer to a storage image.
|
|
|
|
void RegisterPointerToStorageImage(uint32_t type_id) {
|
|
|
|
pointer_to_storage_image_.insert(type_id);
|
|
|
|
}
|
|
|
|
|
2018-02-06 17:10:11 +00:00
|
|
|
// Tries to evaluate a 32-bit signed or unsigned scalar integer constant.
|
|
|
|
// Returns tuple <is_int32, is_const_int32, value>.
|
2018-11-30 19:00:56 +00:00
|
|
|
// OpSpecConstant* return |is_const_int32| as false since their values cannot
|
|
|
|
// be relied upon during validation.
|
2019-02-25 22:43:11 +00:00
|
|
|
std::tuple<bool, bool, uint32_t> EvalInt32IfConst(uint32_t id) const;
|
2018-02-06 17:10:11 +00:00
|
|
|
|
2018-06-19 20:02:44 +00:00
|
|
|
// Returns the disassembly string for the given instruction.
|
|
|
|
std::string Disassemble(const Instruction& inst) const;
|
|
|
|
|
|
|
|
// Returns the disassembly string for the given instruction.
|
|
|
|
std::string Disassemble(const uint32_t* words, uint16_t num_words) const;
|
|
|
|
|
2019-02-25 22:43:11 +00:00
|
|
|
// Returns whether type m1 and type m2 are cooperative matrices with
|
|
|
|
// the same "shape" (matching scope, rows, cols). If any are specialization
|
|
|
|
// constants, we assume they can match because we can't prove they don't.
|
|
|
|
spv_result_t CooperativeMatrixShapesMatch(const Instruction* inst,
|
|
|
|
uint32_t m1, uint32_t m2);
|
|
|
|
|
2019-05-13 17:48:17 +00:00
|
|
|
// Returns true if |lhs| and |rhs| logically match and, if the decorations of
|
|
|
|
// |rhs| are a subset of |lhs|.
|
|
|
|
//
|
|
|
|
// 1. Must both be either OpTypeArray or OpTypeStruct
|
|
|
|
// 2. If OpTypeArray, then
|
|
|
|
// * Length must be the same
|
|
|
|
// * Element type must match or logically match
|
|
|
|
// 3. If OpTypeStruct, then
|
|
|
|
// * Both have same number of elements
|
|
|
|
// * Element N for both structs must match or logically match
|
|
|
|
//
|
|
|
|
// If |check_decorations| is false, then the decorations are not checked.
|
|
|
|
bool LogicallyMatch(const Instruction* lhs, const Instruction* rhs,
|
|
|
|
bool check_decorations);
|
|
|
|
|
2019-06-17 17:13:07 +00:00
|
|
|
// Traces |inst| to find a single base pointer. Returns the base pointer.
|
|
|
|
// Will trace through the following instructions:
|
|
|
|
// * OpAccessChain
|
|
|
|
// * OpInBoundsAccessChain
|
|
|
|
// * OpPtrAccessChain
|
|
|
|
// * OpInBoundsPtrAccessChain
|
|
|
|
// * OpCopyObject
|
|
|
|
const Instruction* TracePointer(const Instruction* inst) const;
|
|
|
|
|
2019-09-27 04:06:36 +00:00
|
|
|
// Validates the storage class for the target environment.
|
|
|
|
bool IsValidStorageClass(SpvStorageClass storage_class) const;
|
|
|
|
|
2020-09-02 18:02:13 +00:00
|
|
|
// Takes a Vulkan Valid Usage ID (VUID) as |id| and optional |reference| and
|
|
|
|
// will return a non-empty string only if ID is known and targeting Vulkan.
|
|
|
|
// VUIDs are found in the Vulkan-Docs repo in the form "[[VUID-ref-ref-id]]"
|
|
|
|
// where "id" is always an 5 char long number (with zeros padding) and matches
|
|
|
|
// to |id|. |reference| is used if there is a "common validity" and the VUID
|
|
|
|
// shares the same |id| value.
|
|
|
|
//
|
|
|
|
// More details about Vulkan validation can be found in Vulkan Guide:
|
|
|
|
// https://github.com/KhronosGroup/Vulkan-Guide/blob/master/chapters/validation_overview.md
|
|
|
|
std::string VkErrorID(uint32_t id, const char* reference = nullptr) const;
|
|
|
|
|
2020-10-08 17:10:12 +00:00
|
|
|
// Testing method to allow setting the current layout section.
|
|
|
|
void SetCurrentLayoutSectionForTesting(ModuleLayoutSection section) {
|
|
|
|
current_layout_section_ = section;
|
|
|
|
}
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
private:
|
2016-08-06 16:24:19 +00:00
|
|
|
ValidationState_t(const ValidationState_t&);
|
|
|
|
|
2016-09-02 22:06:18 +00:00
|
|
|
const spv_const_context context_;
|
|
|
|
|
2017-02-15 18:29:33 +00:00
|
|
|
/// Stores the Validator command line options. Must be a valid options object.
|
|
|
|
const spv_const_validator_options options_;
|
|
|
|
|
2018-06-19 20:02:44 +00:00
|
|
|
/// The SPIR-V binary module we're validating.
|
|
|
|
const uint32_t* words_;
|
|
|
|
const size_t num_words_;
|
|
|
|
|
2018-08-02 16:01:26 +00:00
|
|
|
/// The generator of the SPIR-V.
|
|
|
|
uint32_t generator_ = 0;
|
|
|
|
|
|
|
|
/// The version of the SPIR-V.
|
|
|
|
uint32_t version_ = 0;
|
|
|
|
|
2018-08-01 14:37:36 +00:00
|
|
|
/// The total number of instructions in the binary.
|
|
|
|
size_t total_instructions_ = 0;
|
|
|
|
/// The total number of functions in the binary.
|
|
|
|
size_t total_functions_ = 0;
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
/// IDs which have been forward declared but have not been defined
|
|
|
|
std::unordered_set<uint32_t> unresolved_forward_ids_;
|
|
|
|
|
2016-11-10 20:12:26 +00:00
|
|
|
/// IDs that have been declared as forward pointers.
|
|
|
|
std::unordered_set<uint32_t> forward_pointer_ids_;
|
|
|
|
|
2016-11-22 23:06:55 +00:00
|
|
|
/// Stores a vector of instructions that use the result of a given
|
|
|
|
/// OpSampledImage instruction.
|
2019-03-19 16:39:37 +00:00
|
|
|
std::unordered_map<uint32_t, std::vector<Instruction*>>
|
|
|
|
sampled_image_consumers_;
|
2016-11-22 23:06:55 +00:00
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
/// A map of operand IDs and their names defined by the OpName instruction
|
2016-08-06 17:29:33 +00:00
|
|
|
std::unordered_map<uint32_t, std::string> operand_names_;
|
2016-06-02 22:51:05 +00:00
|
|
|
|
|
|
|
/// The section of the code being processed
|
|
|
|
ModuleLayoutSection current_layout_section_;
|
|
|
|
|
2017-11-23 17:11:15 +00:00
|
|
|
/// A list of functions in the module.
|
|
|
|
/// Pointers to objects in this container are guaranteed to be stable and
|
|
|
|
/// valid until the end of lifetime of the validation state.
|
2018-08-01 14:37:36 +00:00
|
|
|
std::vector<Function> module_functions_;
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2017-03-08 18:59:01 +00:00
|
|
|
/// Capabilities declared in the module
|
2018-07-07 13:38:00 +00:00
|
|
|
CapabilitySet module_capabilities_;
|
2017-03-08 18:59:01 +00:00
|
|
|
|
|
|
|
/// Extensions declared in the module
|
2018-07-07 13:38:00 +00:00
|
|
|
ExtensionSet module_extensions_;
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2016-08-06 17:29:33 +00:00
|
|
|
/// List of all instructions in the order they appear in the binary
|
2018-08-01 14:37:36 +00:00
|
|
|
std::vector<Instruction> ordered_instructions_;
|
2016-08-06 17:29:33 +00:00
|
|
|
|
|
|
|
/// Instructions that can be referenced by Ids
|
|
|
|
std::unordered_map<uint32_t, Instruction*> all_definitions_;
|
2016-06-02 22:51:05 +00:00
|
|
|
|
|
|
|
/// IDs that are entry points, ie, arguments to OpEntryPoint.
|
|
|
|
std::vector<uint32_t> entry_points_;
|
|
|
|
|
2018-05-31 13:07:09 +00:00
|
|
|
/// Maps an entry point id to its desciptions.
|
|
|
|
std::unordered_map<uint32_t, std::vector<EntryPointDescription>>
|
|
|
|
entry_point_descriptions_;
|
2017-01-16 17:54:15 +00:00
|
|
|
|
2018-12-05 18:58:43 +00:00
|
|
|
/// IDs that are entry points, ie, arguments to OpEntryPoint, and root a call
|
|
|
|
/// graph that recurses.
|
|
|
|
std::set<uint32_t> recursive_entry_points_;
|
|
|
|
|
2017-01-09 16:10:52 +00:00
|
|
|
/// Functions IDs that are target of OpFunctionCall.
|
|
|
|
std::unordered_set<uint32_t> function_call_targets_;
|
|
|
|
|
2016-11-24 20:37:22 +00:00
|
|
|
/// ID Bound from the Header
|
|
|
|
uint32_t id_bound_;
|
|
|
|
|
2017-01-13 16:46:21 +00:00
|
|
|
/// Set of Global Variable IDs (Storage Class other than 'Function')
|
|
|
|
std::unordered_set<uint32_t> global_vars_;
|
2016-11-29 20:50:34 +00:00
|
|
|
|
2017-01-13 16:46:21 +00:00
|
|
|
/// Set of Local Variable IDs ('Function' Storage Class)
|
|
|
|
std::unordered_set<uint32_t> local_vars_;
|
2016-11-29 20:50:34 +00:00
|
|
|
|
2017-01-16 17:54:15 +00:00
|
|
|
/// Set of struct types that have members with a BuiltIn decoration.
|
|
|
|
std::unordered_set<uint32_t> builtin_structs_;
|
|
|
|
|
2016-12-04 15:48:26 +00:00
|
|
|
/// Structure Nesting Depth
|
|
|
|
std::unordered_map<uint32_t, uint32_t> struct_nesting_depth_;
|
|
|
|
|
2019-02-25 15:37:43 +00:00
|
|
|
/// Structure has nested blockorbufferblock struct
|
|
|
|
std::unordered_map<uint32_t, bool>
|
|
|
|
struct_has_nested_blockorbufferblock_struct_;
|
|
|
|
|
2017-01-11 15:51:23 +00:00
|
|
|
/// Stores the list of decorations for a given <id>
|
2018-04-03 20:07:55 +00:00
|
|
|
std::map<uint32_t, std::vector<Decoration>> id_decorations_;
|
2017-01-11 15:51:23 +00:00
|
|
|
|
2017-02-23 21:07:52 +00:00
|
|
|
/// Stores type declarations which need to be unique (i.e. non-aggregates),
|
|
|
|
/// in the form [opcode, operand words], result_id is not stored.
|
|
|
|
/// Using ordered set to avoid the need for a vector hash function.
|
|
|
|
/// The size of this container is expected not to exceed double-digits.
|
|
|
|
std::set<std::vector<uint32_t>> unique_type_declarations_;
|
|
|
|
|
2016-06-02 22:51:05 +00:00
|
|
|
AssemblyGrammar grammar_;
|
|
|
|
|
|
|
|
SpvAddressingModel addressing_model_;
|
|
|
|
SpvMemoryModel memory_model_;
|
2019-01-07 18:19:24 +00:00
|
|
|
// pointer size derived from addressing model. Assumes all storage classes
|
|
|
|
// have the same pointer size (for physical pointer types).
|
|
|
|
uint32_t pointer_size_and_alignment_;
|
2016-06-02 22:51:05 +00:00
|
|
|
|
|
|
|
/// NOTE: See correspoding getter functions
|
|
|
|
bool in_function_;
|
2017-02-22 22:53:08 +00:00
|
|
|
|
2017-11-23 17:11:15 +00:00
|
|
|
/// The state of optional features. These are determined by capabilities
|
2018-06-20 17:29:38 +00:00
|
|
|
/// declared by the module and the environment.
|
2017-02-22 22:53:08 +00:00
|
|
|
Feature features_;
|
2017-11-23 17:11:15 +00:00
|
|
|
|
|
|
|
/// Maps function ids to function stat objects.
|
|
|
|
std::unordered_map<uint32_t, Function*> id_to_function_;
|
2018-03-27 15:13:39 +00:00
|
|
|
|
|
|
|
/// Mapping entry point -> execution models. It is presumed that the same
|
|
|
|
/// function could theoretically be used as 'main' by multiple OpEntryPoint
|
|
|
|
/// instructions.
|
|
|
|
std::unordered_map<uint32_t, std::set<SpvExecutionModel>>
|
|
|
|
entry_point_to_execution_models_;
|
|
|
|
|
|
|
|
/// Mapping entry point -> execution modes.
|
|
|
|
std::unordered_map<uint32_t, std::set<SpvExecutionMode>>
|
|
|
|
entry_point_to_execution_modes_;
|
2018-04-16 17:58:11 +00:00
|
|
|
|
|
|
|
/// Mapping function -> array of entry points inside this
|
|
|
|
/// module which can (indirectly) call the function.
|
|
|
|
std::unordered_map<uint32_t, std::vector<uint32_t>> function_to_entry_points_;
|
|
|
|
const std::vector<uint32_t> empty_ids_;
|
2018-10-03 19:59:40 +00:00
|
|
|
|
2019-01-28 20:44:13 +00:00
|
|
|
// The IDs of types of pointers to Block-decorated structs in Uniform storage
|
|
|
|
// class. This is populated at the start of ValidateDecorations.
|
|
|
|
std::unordered_set<uint32_t> pointer_to_uniform_block_;
|
|
|
|
// The IDs of struct types for uniform blocks.
|
|
|
|
// This is populated at the start of ValidateDecorations.
|
|
|
|
std::unordered_set<uint32_t> struct_for_uniform_block_;
|
|
|
|
// The IDs of types of pointers to BufferBlock-decorated structs in Uniform
|
|
|
|
// storage class, or Block-decorated structs in StorageBuffer storage class.
|
|
|
|
// This is populated at the start of ValidateDecorations.
|
|
|
|
std::unordered_set<uint32_t> pointer_to_storage_buffer_;
|
|
|
|
// The IDs of struct types for storage buffers.
|
|
|
|
// This is populated at the start of ValidateDecorations.
|
|
|
|
std::unordered_set<uint32_t> struct_for_storage_buffer_;
|
|
|
|
// The IDs of types of pointers to storage images. This is populated in the
|
|
|
|
// TypePass.
|
|
|
|
std::unordered_set<uint32_t> pointer_to_storage_image_;
|
|
|
|
|
2018-12-03 22:01:30 +00:00
|
|
|
/// Maps ids to friendly names.
|
|
|
|
std::unique_ptr<spvtools::FriendlyNameMapper> friendly_mapper_;
|
|
|
|
spvtools::NameMapper name_mapper_;
|
|
|
|
|
2018-10-03 19:59:40 +00:00
|
|
|
/// Variables used to reduce the number of diagnostic messages.
|
|
|
|
uint32_t num_of_warnings_;
|
|
|
|
uint32_t max_num_of_warnings_;
|
2016-06-02 22:51:05 +00:00
|
|
|
};
|
|
|
|
|
2018-07-10 03:18:44 +00:00
|
|
|
} // namespace val
|
2018-07-07 13:38:00 +00:00
|
|
|
} // namespace spvtools
|
2016-06-02 22:51:05 +00:00
|
|
|
|
2018-08-03 12:05:33 +00:00
|
|
|
#endif // SOURCE_VAL_VALIDATION_STATE_H_
|