From: David Neto Date: Wed, 22 Feb 2017 22:53:08 +0000 (-0500) Subject: Add a Feature struct to validation state. X-Git-Tag: upstream/2018.6~959 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c6099ad242c2df138fedd713fdb98f576f7961c5;p=platform%2Fupstream%2FSPIRV-Tools.git Add a Feature struct to validation state. For now, it is used only for checks of 16bit int and float types. --- diff --git a/source/val/validation_state.cpp b/source/val/validation_state.cpp index 4f1dd7a..5b01b15 100644 --- a/source/val/validation_state.cpp +++ b/source/val/validation_state.cpp @@ -332,6 +332,18 @@ void ValidationState_t::RegisterCapability(SpvCapability cap) { desc->capabilities.ForEach( [this](SpvCapability c) { RegisterCapability(c); }); } + + switch (cap) { + case SpvCapabilityInt16: + features_.declare_int16_type = true; + break; + case SpvCapabilityFloat16: + case SpvCapabilityFloat16Buffer: + features_.declare_float16_type = true; + break; + default: + break; + } } bool ValidationState_t::HasAnyOf(const CapabilitySet& capabilities) const { diff --git a/source/val/validation_state.h b/source/val/validation_state.h index 3900487..97f4e7f 100644 --- a/source/val/validation_state.h +++ b/source/val/validation_state.h @@ -54,6 +54,12 @@ enum ModuleLayoutSection { /// This class manages the state of the SPIR-V validation as it is being parsed. class ValidationState_t { public: + // Features that can optionally be turned on by a capability. + struct Feature { + bool declare_int16_type = false; // Allow OpTypeInt with 16 bit width? + bool declare_float16_type = false; // Allow OpTypeFloat with 16 bit width? + }; + ValidationState_t(const spv_const_context context); /// Returns the context @@ -290,6 +296,10 @@ class ValidationState_t { bool IsStructTypeWithBuiltInMember(uint32_t id) const { return (builtin_structs_.find(id) != builtin_structs_.end()); } + + // Returns the state of optional features. + const Feature& features() const { return features_; } + private: ValidationState_t(const ValidationState_t&); @@ -361,6 +371,10 @@ class ValidationState_t { /// NOTE: See correspoding getter functions bool in_function_; + + // The state of optional features. These are determined by capabilities + // declared by the module. + Feature features_; }; } /// namespace libspirv diff --git a/source/validate_datarules.cpp b/source/validate_datarules.cpp index 3d50328..3927ab5 100644 --- a/source/validate_datarules.cpp +++ b/source/validate_datarules.cpp @@ -69,8 +69,7 @@ spv_result_t ValidateFloatSize(ValidationState_t& _, return SPV_SUCCESS; } if (num_bits == 16) { - if (_.HasCapability(SpvCapabilityFloat16) || - _.HasCapability(SpvCapabilityFloat16Buffer)) { + if (_.features().declare_float16_type) { return SPV_SUCCESS; } return _.diag(SPV_ERROR_INVALID_DATA) @@ -108,7 +107,7 @@ spv_result_t ValidateIntSize(ValidationState_t& _, << "Using an 8-bit integer type requires the Int8 capability."; } if (num_bits == 16) { - if (_.HasCapability(SpvCapabilityInt16)) { + if (_.features().declare_int16_type) { return SPV_SUCCESS; } return _.diag(SPV_ERROR_INVALID_DATA)