Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/KhronosGroup/SPIRV-Tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/val/validate_instruction.cpp')
-rw-r--r--source/val/validate_instruction.cpp99
1 files changed, 50 insertions, 49 deletions
diff --git a/source/val/validate_instruction.cpp b/source/val/validate_instruction.cpp
index 767c0cee1..1b7847cac 100644
--- a/source/val/validate_instruction.cpp
+++ b/source/val/validate_instruction.cpp
@@ -44,13 +44,13 @@ namespace {
std::string ToString(const CapabilitySet& capabilities,
const AssemblyGrammar& grammar) {
std::stringstream ss;
- capabilities.ForEach([&grammar, &ss](SpvCapability cap) {
+ capabilities.ForEach([&grammar, &ss](spv::Capability cap) {
spv_operand_desc desc;
- if (SPV_SUCCESS ==
- grammar.lookupOperand(SPV_OPERAND_TYPE_CAPABILITY, cap, &desc))
+ if (SPV_SUCCESS == grammar.lookupOperand(SPV_OPERAND_TYPE_CAPABILITY,
+ uint32_t(cap), &desc))
ss << desc->name << " ";
else
- ss << cap << " ";
+ ss << uint32_t(cap) << " ";
});
return ss.str();
}
@@ -60,18 +60,18 @@ std::string ToString(const CapabilitySet& capabilities,
// the opcode may only be used if at least one of the capabilities is specified
// by the module.
CapabilitySet EnablingCapabilitiesForOp(const ValidationState_t& state,
- SpvOp opcode) {
+ spv::Op opcode) {
// Exceptions for SPV_AMD_shader_ballot
switch (opcode) {
// Normally these would require Group capability
- case SpvOpGroupIAddNonUniformAMD:
- case SpvOpGroupFAddNonUniformAMD:
- case SpvOpGroupFMinNonUniformAMD:
- case SpvOpGroupUMinNonUniformAMD:
- case SpvOpGroupSMinNonUniformAMD:
- case SpvOpGroupFMaxNonUniformAMD:
- case SpvOpGroupUMaxNonUniformAMD:
- case SpvOpGroupSMaxNonUniformAMD:
+ case spv::Op::OpGroupIAddNonUniformAMD:
+ case spv::Op::OpGroupFAddNonUniformAMD:
+ case spv::Op::OpGroupFMinNonUniformAMD:
+ case spv::Op::OpGroupUMinNonUniformAMD:
+ case spv::Op::OpGroupSMinNonUniformAMD:
+ case spv::Op::OpGroupFMaxNonUniformAMD:
+ case spv::Op::OpGroupUMaxNonUniformAMD:
+ case spv::Op::OpGroupSMaxNonUniformAMD:
if (state.HasExtension(kSPV_AMD_shader_ballot)) return CapabilitySet();
break;
default:
@@ -151,10 +151,10 @@ spv_result_t CheckRequiredCapabilities(ValidationState_t& state,
// not implemented yet. This rule is independent of target environment.
// See https://github.com/KhronosGroup/SPIRV-Tools/issues/365
if (operand.type == SPV_OPERAND_TYPE_BUILT_IN) {
- switch (word) {
- case SpvBuiltInPointSize:
- case SpvBuiltInClipDistance:
- case SpvBuiltInCullDistance:
+ switch (spv::BuiltIn(word)) {
+ case spv::BuiltIn::PointSize:
+ case spv::BuiltIn::ClipDistance:
+ case spv::BuiltIn::CullDistance:
return SPV_SUCCESS;
default:
break;
@@ -166,7 +166,7 @@ spv_result_t CheckRequiredCapabilities(ValidationState_t& state,
}
} else if (operand.type == SPV_OPERAND_TYPE_GROUP_OPERATION &&
state.features().group_ops_reduce_and_scans &&
- (word <= uint32_t(SpvGroupOperationExclusiveScan))) {
+ (word <= uint32_t(spv::GroupOperation::ExclusiveScan))) {
// Allow certain group operations if requested.
return SPV_SUCCESS;
}
@@ -178,15 +178,16 @@ spv_result_t CheckRequiredCapabilities(ValidationState_t& state,
if (lookup_result == SPV_SUCCESS) {
// Allow FPRoundingMode decoration if requested.
if (operand.type == SPV_OPERAND_TYPE_DECORATION &&
- operand_desc->value == SpvDecorationFPRoundingMode) {
+ spv::Decoration(operand_desc->value) ==
+ spv::Decoration::FPRoundingMode) {
if (state.features().free_fp_rounding_mode) return SPV_SUCCESS;
// Vulkan API requires more capabilities on rounding mode.
if (spvIsVulkanEnv(state.context()->target_env)) {
- enabling_capabilities.Add(SpvCapabilityStorageUniformBufferBlock16);
- enabling_capabilities.Add(SpvCapabilityStorageUniform16);
- enabling_capabilities.Add(SpvCapabilityStoragePushConstant16);
- enabling_capabilities.Add(SpvCapabilityStorageInputOutput16);
+ enabling_capabilities.Add(spv::Capability::StorageUniformBufferBlock16);
+ enabling_capabilities.Add(spv::Capability::StorageUniform16);
+ enabling_capabilities.Add(spv::Capability::StoragePushConstant16);
+ enabling_capabilities.Add(spv::Capability::StorageInputOutput16);
}
} else {
enabling_capabilities = state.grammar().filterCapsAgainstTargetEnv(
@@ -197,7 +198,7 @@ spv_result_t CheckRequiredCapabilities(ValidationState_t& state,
// registers a capability with the module *before* checking capabilities.
// So in the case of an OpCapability instruction, don't bother checking
// enablement by another capability.
- if (inst->opcode() != SpvOpCapability) {
+ if (inst->opcode() != spv::Op::OpCapability) {
const bool enabled_by_cap =
state.HasAnyOfCapabilities(enabling_capabilities);
if (!enabling_capabilities.IsEmpty() && !enabled_by_cap) {
@@ -218,14 +219,14 @@ spv_result_t CheckRequiredCapabilities(ValidationState_t& state,
// is explicitly reserved in the SPIR-V core spec. Otherwise return
// SPV_SUCCESS.
spv_result_t ReservedCheck(ValidationState_t& _, const Instruction* inst) {
- const SpvOp opcode = inst->opcode();
+ const spv::Op opcode = inst->opcode();
switch (opcode) {
// These instructions are enabled by a capability, but should never
// be used anyway.
- case SpvOpImageSparseSampleProjImplicitLod:
- case SpvOpImageSparseSampleProjExplicitLod:
- case SpvOpImageSparseSampleProjDrefImplicitLod:
- case SpvOpImageSparseSampleProjDrefExplicitLod: {
+ case spv::Op::OpImageSparseSampleProjImplicitLod:
+ case spv::Op::OpImageSparseSampleProjExplicitLod:
+ case spv::Op::OpImageSparseSampleProjDrefImplicitLod:
+ case spv::Op::OpImageSparseSampleProjDrefExplicitLod: {
spv_opcode_desc inst_desc;
_.grammar().lookupOpcode(opcode, &inst_desc);
return _.diag(SPV_ERROR_INVALID_BINARY, inst)
@@ -241,7 +242,7 @@ spv_result_t ReservedCheck(ValidationState_t& _, const Instruction* inst) {
// instruction is invalid because the required capability isn't declared
// in the module.
spv_result_t CapabilityCheck(ValidationState_t& _, const Instruction* inst) {
- const SpvOp opcode = inst->opcode();
+ const spv::Op opcode = inst->opcode();
CapabilitySet opcode_caps = EnablingCapabilitiesForOp(_, opcode);
if (!_.HasAnyOfCapabilities(opcode_caps)) {
return _.diag(SPV_ERROR_INVALID_CAPABILITY, inst)
@@ -299,7 +300,7 @@ spv_result_t VersionCheck(ValidationState_t& _, const Instruction* inst) {
// OpTerminateInvocation is special because it is enabled by Shader
// capability, but also requires an extension and/or version check.
const bool capability_check_is_sufficient =
- inst->opcode() != SpvOpTerminateInvocation;
+ inst->opcode() != spv::Op::OpTerminateInvocation;
if (capability_check_is_sufficient && (inst_desc->numCapabilities > 0u)) {
// We already checked that the direct capability dependency has been
@@ -357,7 +358,7 @@ spv_result_t LimitCheckIdBound(ValidationState_t& _, const Instruction* inst) {
// Checks that the number of OpTypeStruct members is within the limit.
spv_result_t LimitCheckStruct(ValidationState_t& _, const Instruction* inst) {
- if (SpvOpTypeStruct != inst->opcode()) {
+ if (spv::Op::OpTypeStruct != inst->opcode()) {
return SPV_SUCCESS;
}
@@ -382,7 +383,7 @@ spv_result_t LimitCheckStruct(ValidationState_t& _, const Instruction* inst) {
for (size_t word_i = 2; word_i < inst->words().size(); ++word_i) {
auto member = inst->word(word_i);
auto memberTypeInstr = _.FindDef(member);
- if (memberTypeInstr && SpvOpTypeStruct == memberTypeInstr->opcode()) {
+ if (memberTypeInstr && spv::Op::OpTypeStruct == memberTypeInstr->opcode()) {
max_member_depth = std::max(
max_member_depth, _.struct_nesting_depth(memberTypeInstr->id()));
}
@@ -402,7 +403,7 @@ spv_result_t LimitCheckStruct(ValidationState_t& _, const Instruction* inst) {
// Checks that the number of (literal, label) pairs in OpSwitch is within
// the limit.
spv_result_t LimitCheckSwitch(ValidationState_t& _, const Instruction* inst) {
- if (SpvOpSwitch == inst->opcode()) {
+ if (spv::Op::OpSwitch == inst->opcode()) {
// The instruction syntax is as follows:
// OpSwitch <selector ID> <Default ID> literal label literal label ...
// literal,label pairs come after the first 2 operands.
@@ -422,8 +423,8 @@ spv_result_t LimitCheckSwitch(ValidationState_t& _, const Instruction* inst) {
// Ensure the number of variables of the given class does not exceed the
// limit.
spv_result_t LimitCheckNumVars(ValidationState_t& _, const uint32_t var_id,
- const SpvStorageClass storage_class) {
- if (SpvStorageClassFunction == storage_class) {
+ const spv::StorageClass storage_class) {
+ if (spv::StorageClass::Function == storage_class) {
_.registerLocalVariable(var_id);
const uint32_t num_local_vars_limit =
_.options()->universal_limits_.max_local_variables;
@@ -462,29 +463,29 @@ spv_result_t CheckIfKnownExtension(ValidationState_t& _,
} // namespace
spv_result_t InstructionPass(ValidationState_t& _, const Instruction* inst) {
- const SpvOp opcode = inst->opcode();
- if (opcode == SpvOpExtension) {
+ const spv::Op opcode = inst->opcode();
+ if (opcode == spv::Op::OpExtension) {
CheckIfKnownExtension(_, inst);
- } else if (opcode == SpvOpCapability) {
- _.RegisterCapability(inst->GetOperandAs<SpvCapability>(0));
- } else if (opcode == SpvOpMemoryModel) {
+ } else if (opcode == spv::Op::OpCapability) {
+ _.RegisterCapability(inst->GetOperandAs<spv::Capability>(0));
+ } else if (opcode == spv::Op::OpMemoryModel) {
if (_.has_memory_model_specified()) {
return _.diag(SPV_ERROR_INVALID_LAYOUT, inst)
<< "OpMemoryModel should only be provided once.";
}
- _.set_addressing_model(inst->GetOperandAs<SpvAddressingModel>(0));
- _.set_memory_model(inst->GetOperandAs<SpvMemoryModel>(1));
- } else if (opcode == SpvOpExecutionMode) {
+ _.set_addressing_model(inst->GetOperandAs<spv::AddressingModel>(0));
+ _.set_memory_model(inst->GetOperandAs<spv::MemoryModel>(1));
+ } else if (opcode == spv::Op::OpExecutionMode) {
const uint32_t entry_point = inst->word(1);
_.RegisterExecutionModeForEntryPoint(entry_point,
- SpvExecutionMode(inst->word(2)));
- } else if (opcode == SpvOpVariable) {
- const auto storage_class = inst->GetOperandAs<SpvStorageClass>(2);
+ spv::ExecutionMode(inst->word(2)));
+ } else if (opcode == spv::Op::OpVariable) {
+ const auto storage_class = inst->GetOperandAs<spv::StorageClass>(2);
if (auto error = LimitCheckNumVars(_, inst->id(), storage_class)) {
return error;
}
- } else if (opcode == SpvOpSamplerImageAddressingModeNV) {
- if (!_.HasCapability(SpvCapabilityBindlessTextureNV)) {
+ } else if (opcode == spv::Op::OpSamplerImageAddressingModeNV) {
+ if (!_.HasCapability(spv::Capability::BindlessTextureNV)) {
return _.diag(SPV_ERROR_MISSING_EXTENSION, inst)
<< "OpSamplerImageAddressingModeNV supported only with extension "
"SPV_NV_bindless_texture";