Add a Feature struct to validation state.

For now, it is used only for checks of 16bit int and float types.
This commit is contained in:
David Neto 2017-02-22 17:53:08 -05:00
parent c0949703b1
commit c6099ad242
3 changed files with 28 additions and 3 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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)