Update spirv-tools to 025ea89 (#6393)

This commit is contained in:
Ben Doherty
2022-12-19 15:42:42 -08:00
committed by GitHub
parent 9ff4a311ef
commit 1d5ce4d1c2
654 changed files with 40839 additions and 26083 deletions

View File

@@ -28,7 +28,8 @@ namespace {
// of the decorations that apply to |a|.
bool DoPointeesLogicallyMatch(val::Instruction* a, val::Instruction* b,
ValidationState_t& _) {
if (a->opcode() != SpvOpTypePointer || b->opcode() != SpvOpTypePointer) {
if (a->opcode() != spv::Op::OpTypePointer ||
b->opcode() != spv::Op::OpTypePointer) {
return false;
}
@@ -56,35 +57,35 @@ bool DoPointeesLogicallyMatch(val::Instruction* a, val::Instruction* b,
spv_result_t ValidateFunction(ValidationState_t& _, const Instruction* inst) {
const auto function_type_id = inst->GetOperandAs<uint32_t>(3);
const auto function_type = _.FindDef(function_type_id);
if (!function_type || SpvOpTypeFunction != function_type->opcode()) {
if (!function_type || spv::Op::OpTypeFunction != function_type->opcode()) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpFunction Function Type <id> '" << _.getIdName(function_type_id)
<< "' is not a function type.";
<< "OpFunction Function Type <id> " << _.getIdName(function_type_id)
<< " is not a function type.";
}
const auto return_id = function_type->GetOperandAs<uint32_t>(1);
if (return_id != inst->type_id()) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpFunction Result Type <id> '" << _.getIdName(inst->type_id())
<< "' does not match the Function Type's return type <id> '"
<< _.getIdName(return_id) << "'.";
<< "OpFunction Result Type <id> " << _.getIdName(inst->type_id())
<< " does not match the Function Type's return type <id> "
<< _.getIdName(return_id) << ".";
}
const std::vector<SpvOp> acceptable = {
SpvOpGroupDecorate,
SpvOpDecorate,
SpvOpEnqueueKernel,
SpvOpEntryPoint,
SpvOpExecutionMode,
SpvOpExecutionModeId,
SpvOpFunctionCall,
SpvOpGetKernelNDrangeSubGroupCount,
SpvOpGetKernelNDrangeMaxSubGroupSize,
SpvOpGetKernelWorkGroupSize,
SpvOpGetKernelPreferredWorkGroupSizeMultiple,
SpvOpGetKernelLocalSizeForSubgroupCount,
SpvOpGetKernelMaxNumSubgroups,
SpvOpName};
const std::vector<spv::Op> acceptable = {
spv::Op::OpGroupDecorate,
spv::Op::OpDecorate,
spv::Op::OpEnqueueKernel,
spv::Op::OpEntryPoint,
spv::Op::OpExecutionMode,
spv::Op::OpExecutionModeId,
spv::Op::OpFunctionCall,
spv::Op::OpGetKernelNDrangeSubGroupCount,
spv::Op::OpGetKernelNDrangeMaxSubGroupSize,
spv::Op::OpGetKernelWorkGroupSize,
spv::Op::OpGetKernelPreferredWorkGroupSizeMultiple,
spv::Op::OpGetKernelLocalSizeForSubgroupCount,
spv::Op::OpGetKernelMaxNumSubgroups,
spv::Op::OpName};
for (auto& pair : inst->uses()) {
const auto* use = pair.first;
if (std::find(acceptable.begin(), acceptable.end(), use->opcode()) ==
@@ -112,14 +113,14 @@ spv_result_t ValidateFunctionParameter(ValidationState_t& _,
auto func_inst = &_.ordered_instructions()[inst_num];
while (--inst_num) {
func_inst = &_.ordered_instructions()[inst_num];
if (func_inst->opcode() == SpvOpFunction) {
if (func_inst->opcode() == spv::Op::OpFunction) {
break;
} else if (func_inst->opcode() == SpvOpFunctionParameter) {
} else if (func_inst->opcode() == spv::Op::OpFunctionParameter) {
++param_index;
}
}
if (func_inst->opcode() != SpvOpFunction) {
if (func_inst->opcode() != spv::Op::OpFunction) {
return _.diag(SPV_ERROR_INVALID_LAYOUT, inst)
<< "Function parameter must be preceded by a function.";
}
@@ -141,34 +142,34 @@ spv_result_t ValidateFunctionParameter(ValidationState_t& _,
_.FindDef(function_type->GetOperandAs<uint32_t>(param_index + 2));
if (!param_type || inst->type_id() != param_type->id()) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpFunctionParameter Result Type <id> '"
<< "OpFunctionParameter Result Type <id> "
<< _.getIdName(inst->type_id())
<< "' does not match the OpTypeFunction parameter "
<< " does not match the OpTypeFunction parameter "
"type of the same index.";
}
// Validate that PhysicalStorageBuffer have one of Restrict, Aliased,
// RestrictPointer, or AliasedPointer.
auto param_nonarray_type_id = param_type->id();
while (_.GetIdOpcode(param_nonarray_type_id) == SpvOpTypeArray) {
while (_.GetIdOpcode(param_nonarray_type_id) == spv::Op::OpTypeArray) {
param_nonarray_type_id =
_.FindDef(param_nonarray_type_id)->GetOperandAs<uint32_t>(1u);
}
if (_.GetIdOpcode(param_nonarray_type_id) == SpvOpTypePointer) {
if (_.GetIdOpcode(param_nonarray_type_id) == spv::Op::OpTypePointer) {
auto param_nonarray_type = _.FindDef(param_nonarray_type_id);
if (param_nonarray_type->GetOperandAs<uint32_t>(1u) ==
SpvStorageClassPhysicalStorageBuffer) {
if (param_nonarray_type->GetOperandAs<spv::StorageClass>(1u) ==
spv::StorageClass::PhysicalStorageBuffer) {
// check for Aliased or Restrict
const auto& decorations = _.id_decorations(inst->id());
bool foundAliased = std::any_of(
decorations.begin(), decorations.end(), [](const Decoration& d) {
return SpvDecorationAliased == d.dec_type();
return spv::Decoration::Aliased == d.dec_type();
});
bool foundRestrict = std::any_of(
decorations.begin(), decorations.end(), [](const Decoration& d) {
return SpvDecorationRestrict == d.dec_type();
return spv::Decoration::Restrict == d.dec_type();
});
if (!foundAliased && !foundRestrict) {
@@ -187,20 +188,20 @@ spv_result_t ValidateFunctionParameter(ValidationState_t& _,
const auto pointee_type_id =
param_nonarray_type->GetOperandAs<uint32_t>(2);
const auto pointee_type = _.FindDef(pointee_type_id);
if (SpvOpTypePointer == pointee_type->opcode() &&
pointee_type->GetOperandAs<uint32_t>(1u) ==
SpvStorageClassPhysicalStorageBuffer) {
if (spv::Op::OpTypePointer == pointee_type->opcode() &&
pointee_type->GetOperandAs<spv::StorageClass>(1u) ==
spv::StorageClass::PhysicalStorageBuffer) {
// check for AliasedPointer/RestrictPointer
const auto& decorations = _.id_decorations(inst->id());
bool foundAliased = std::any_of(
decorations.begin(), decorations.end(), [](const Decoration& d) {
return SpvDecorationAliasedPointer == d.dec_type();
return spv::Decoration::AliasedPointer == d.dec_type();
});
bool foundRestrict = std::any_of(
decorations.begin(), decorations.end(), [](const Decoration& d) {
return SpvDecorationRestrictPointer == d.dec_type();
return spv::Decoration::RestrictPointer == d.dec_type();
});
if (!foundAliased && !foundRestrict) {
@@ -226,24 +227,23 @@ spv_result_t ValidateFunctionCall(ValidationState_t& _,
const Instruction* inst) {
const auto function_id = inst->GetOperandAs<uint32_t>(2);
const auto function = _.FindDef(function_id);
if (!function || SpvOpFunction != function->opcode()) {
if (!function || spv::Op::OpFunction != function->opcode()) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpFunctionCall Function <id> '" << _.getIdName(function_id)
<< "' is not a function.";
<< "OpFunctionCall Function <id> " << _.getIdName(function_id)
<< " is not a function.";
}
auto return_type = _.FindDef(function->type_id());
if (!return_type || return_type->id() != inst->type_id()) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpFunctionCall Result Type <id> '"
<< _.getIdName(inst->type_id())
<< "'s type does not match Function <id> '"
<< _.getIdName(return_type->id()) << "'s return type.";
<< "OpFunctionCall Result Type <id> " << _.getIdName(inst->type_id())
<< "s type does not match Function <id> "
<< _.getIdName(return_type->id()) << "s return type.";
}
const auto function_type_id = function->GetOperandAs<uint32_t>(3);
const auto function_type = _.FindDef(function_type_id);
if (!function_type || function_type->opcode() != SpvOpTypeFunction) {
if (!function_type || function_type->opcode() != spv::Op::OpTypeFunction) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "Missing function type definition.";
}
@@ -280,26 +280,27 @@ spv_result_t ValidateFunctionCall(ValidationState_t& _,
if (!_.options()->before_hlsl_legalization ||
!DoPointeesLogicallyMatch(argument_type, parameter_type, _)) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpFunctionCall Argument <id> '" << _.getIdName(argument_id)
<< "'s type does not match Function <id> '"
<< _.getIdName(parameter_type_id) << "'s parameter type.";
<< "OpFunctionCall Argument <id> " << _.getIdName(argument_id)
<< "s type does not match Function <id> "
<< _.getIdName(parameter_type_id) << "s parameter type.";
}
}
if (_.addressing_model() == SpvAddressingModelLogical) {
if (parameter_type->opcode() == SpvOpTypePointer &&
if (_.addressing_model() == spv::AddressingModel::Logical) {
if (parameter_type->opcode() == spv::Op::OpTypePointer &&
!_.options()->relax_logical_pointer) {
SpvStorageClass sc = parameter_type->GetOperandAs<SpvStorageClass>(1u);
spv::StorageClass sc =
parameter_type->GetOperandAs<spv::StorageClass>(1u);
// Validate which storage classes can be pointer operands.
switch (sc) {
case SpvStorageClassUniformConstant:
case SpvStorageClassFunction:
case SpvStorageClassPrivate:
case SpvStorageClassWorkgroup:
case SpvStorageClassAtomicCounter:
case spv::StorageClass::UniformConstant:
case spv::StorageClass::Function:
case spv::StorageClass::Private:
case spv::StorageClass::Workgroup:
case spv::StorageClass::AtomicCounter:
// These are always allowed.
break;
case SpvStorageClassStorageBuffer:
case spv::StorageClass::StorageBuffer:
if (!_.features().variable_pointers) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "StorageBuffer pointer operand "
@@ -314,13 +315,14 @@ spv_result_t ValidateFunctionCall(ValidationState_t& _,
}
// Validate memory object declaration requirements.
if (argument->opcode() != SpvOpVariable &&
argument->opcode() != SpvOpFunctionParameter) {
if (argument->opcode() != spv::Op::OpVariable &&
argument->opcode() != spv::Op::OpFunctionParameter) {
const bool ssbo_vptr = _.features().variable_pointers &&
sc == SpvStorageClassStorageBuffer;
const bool wg_vptr = _.HasCapability(SpvCapabilityVariablePointers) &&
sc == SpvStorageClassWorkgroup;
const bool uc_ptr = sc == SpvStorageClassUniformConstant;
sc == spv::StorageClass::StorageBuffer;
const bool wg_vptr =
_.HasCapability(spv::Capability::VariablePointers) &&
sc == spv::StorageClass::Workgroup;
const bool uc_ptr = sc == spv::StorageClass::UniformConstant;
if (!ssbo_vptr && !wg_vptr && !uc_ptr) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "Pointer operand " << _.getIdName(argument_id)
@@ -337,13 +339,13 @@ spv_result_t ValidateFunctionCall(ValidationState_t& _,
spv_result_t FunctionPass(ValidationState_t& _, const Instruction* inst) {
switch (inst->opcode()) {
case SpvOpFunction:
case spv::Op::OpFunction:
if (auto error = ValidateFunction(_, inst)) return error;
break;
case SpvOpFunctionParameter:
case spv::Op::OpFunctionParameter:
if (auto error = ValidateFunctionParameter(_, inst)) return error;
break;
case SpvOpFunctionCall:
case spv::Op::OpFunctionCall:
if (auto error = ValidateFunctionCall(_, inst)) return error;
break;
default: