aboutsummaryrefslogtreecommitdiff
path: root/source/val/validation_state.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/val/validation_state.h')
-rw-r--r--source/val/validation_state.h112
1 files changed, 80 insertions, 32 deletions
diff --git a/source/val/validation_state.h b/source/val/validation_state.h
index 89834a0d..1b599ff3 100644
--- a/source/val/validation_state.h
+++ b/source/val/validation_state.h
@@ -44,19 +44,20 @@ namespace val {
/// 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
- kLayoutDebug3, /// < Section 2.4 #7 > 3
- kLayoutAnnotations, /// < Section 2.4 #8
- kLayoutTypes, /// < Section 2.4 #9
- kLayoutFunctionDeclarations, /// < Section 2.4 #10
- kLayoutFunctionDefinitions /// < Section 2.4 #11
+ kLayoutCapabilities, /// < Section 2.4 #1
+ kLayoutExtensions, /// < Section 2.4 #2
+ kLayoutExtInstImport, /// < Section 2.4 #3
+ kLayoutMemoryModel, /// < Section 2.4 #4
+ kLayoutSamplerImageAddressMode, /// < Section 2.4 #5
+ kLayoutEntryPoint, /// < Section 2.4 #6
+ kLayoutExecutionMode, /// < Section 2.4 #7
+ kLayoutDebug1, /// < Section 2.4 #8 > 1
+ kLayoutDebug2, /// < Section 2.4 #8 > 2
+ kLayoutDebug3, /// < Section 2.4 #8 > 3
+ kLayoutAnnotations, /// < Section 2.4 #9
+ kLayoutTypes, /// < Section 2.4 #10
+ kLayoutFunctionDeclarations, /// < Section 2.4 #11
+ kLayoutFunctionDefinitions /// < Section 2.4 #12
};
/// This class manages the state of the SPIR-V validation as it is being parsed.
@@ -70,11 +71,9 @@ class ValidationState_t {
// and its values to be used without
// requiring any capability
- // Allow functionalities enabled by VariablePointers capability.
+ // Allow functionalities enabled by VariablePointers or
+ // VariablePointersStorageBuffer capability.
bool variable_pointers = false;
- // Allow functionalities enabled by VariablePointersStorageBuffer
- // capability.
- bool variable_pointers_storage_buffer = false;
// Permit group oerations Reduce, InclusiveScan, ExclusiveScan
bool group_ops_reduce_and_scans = false;
@@ -362,6 +361,20 @@ class ValidationState_t {
/// Returns the memory model of this module, or Simple if uninitialized.
SpvMemoryModel memory_model() const;
+ /// Sets the bit width for sampler/image type variables. If not set, they are
+ /// considered opaque
+ void set_samplerimage_variable_address_mode(uint32_t bit_width);
+
+ /// Get the addressing mode currently set. If 0, it means addressing mode is
+ /// invalid Sampler/Image type variables must be considered opaque This mode
+ /// is only valid after the instruction has been read
+ uint32_t samplerimage_variable_address_mode() const;
+
+ /// Returns true if the OpSamplerImageAddressingModeNV was found.
+ bool has_samplerimage_variable_address_mode_specified() const {
+ return sampler_image_addressing_mode_ != 0;
+ }
+
const AssemblyGrammar& grammar() const { return grammar_; }
/// Inserts the instruction into the list of ordered instructions in the file.
@@ -377,17 +390,14 @@ class ValidationState_t {
/// Registers the decoration for the given <id>
void RegisterDecorationForId(uint32_t id, const Decoration& dec) {
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);
- }
+ dec_list.insert(dec);
}
/// 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);
+ std::set<Decoration>& cur_decs = id_decorations_[id];
+ cur_decs.insert(begin, end);
}
/// Registers the list of decorations for the given member of the given
@@ -396,21 +406,44 @@ class ValidationState_t {
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);
+ std::set<Decoration>& cur_decs = id_decorations_[struct_id];
+ for (InputIt iter = begin; iter != end; ++iter) {
+ Decoration dec = *iter;
+ dec.set_struct_member_index(member_index);
+ cur_decs.insert(dec);
}
}
/// 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) {
+ /// for the <id>, it registers an empty set for it in the map and
+ /// returns the empty set.
+ std::set<Decoration>& id_decorations(uint32_t id) {
return id_decorations_[id];
}
+ /// Returns the range of decorations for the given field of the given <id>.
+ struct FieldDecorationsIter {
+ std::set<Decoration>::const_iterator begin;
+ std::set<Decoration>::const_iterator end;
+ };
+ FieldDecorationsIter id_member_decorations(uint32_t id,
+ uint32_t member_index) {
+ const auto& decorations = id_decorations_[id];
+
+ // The decorations are sorted by member_index, so this look up will give the
+ // exact range of decorations for this member index.
+ Decoration min_decoration((SpvDecoration)0, {}, member_index);
+ Decoration max_decoration(SpvDecorationMax, {}, member_index);
+
+ FieldDecorationsIter result;
+ result.begin = decorations.lower_bound(min_decoration);
+ result.end = decorations.upper_bound(max_decoration);
+
+ return result;
+ }
+
// Returns const pointer to the internal decoration container.
- const std::map<uint32_t, std::vector<Decoration>>& id_decorations() const {
+ const std::map<uint32_t, std::set<Decoration>>& id_decorations() const {
return id_decorations_;
}
@@ -574,10 +607,12 @@ class ValidationState_t {
bool IsBoolVectorType(uint32_t id) const;
bool IsBoolScalarOrVectorType(uint32_t id) const;
bool IsPointerType(uint32_t id) const;
+ bool IsAccelerationStructureType(uint32_t id) const;
bool IsCooperativeMatrixType(uint32_t id) const;
bool IsFloatCooperativeMatrixType(uint32_t id) const;
bool IsIntCooperativeMatrixType(uint32_t id) const;
bool IsUnsignedIntCooperativeMatrixType(uint32_t id) const;
+ bool IsUnsigned64BitHandle(uint32_t id) const;
// Returns true if |id| is a type id that contains |type| (or integer or
// floating point type) of |width| bits.
@@ -688,6 +723,16 @@ class ValidationState_t {
// Returns the disassembly string for the given instruction.
std::string Disassemble(const uint32_t* words, uint16_t num_words) const;
+ // Returns the string name for |decoration|.
+ std::string SpvDecorationString(uint32_t decoration) {
+ spv_operand_desc desc = nullptr;
+ if (grammar_.lookupOperand(SPV_OPERAND_TYPE_DECORATION, decoration,
+ &desc) != SPV_SUCCESS) {
+ return std::string("Unknown");
+ }
+ return std::string(desc->name);
+ }
+
// 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.
@@ -828,7 +873,7 @@ class ValidationState_t {
struct_has_nested_blockorbufferblock_struct_;
/// Stores the list of decorations for a given <id>
- std::map<uint32_t, std::vector<Decoration>> id_decorations_;
+ std::map<uint32_t, std::set<Decoration>> id_decorations_;
/// Stores type declarations which need to be unique (i.e. non-aggregates),
/// in the form [opcode, operand words], result_id is not stored.
@@ -844,7 +889,10 @@ class ValidationState_t {
// have the same pointer size (for physical pointer types).
uint32_t pointer_size_and_alignment_;
- /// NOTE: See corresponding getter functions
+ /// bit width of sampler/image type variables. Valid values are 32 and 64
+ uint32_t sampler_image_addressing_mode_;
+
+ /// NOTE: See correspoding getter functions
bool in_function_;
/// The state of optional features. These are determined by capabilities