For now, it is used only for checks of 16bit int and float types.
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 {
/// 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
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&);
/// 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
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)
<< "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)