mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-18 04:53:06 +01:00
Updated spirv-tools.
This commit is contained in:
@@ -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,7 +57,7 @@ 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.";
|
||||
@@ -70,21 +71,21 @@ spv_result_t ValidateFunction(ValidationState_t& _, const Instruction* inst) {
|
||||
<< _.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.";
|
||||
}
|
||||
@@ -150,25 +151,25 @@ spv_result_t ValidateFunctionParameter(ValidationState_t& _,
|
||||
// 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,7 +227,7 @@ 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.";
|
||||
@@ -242,7 +243,7 @@ spv_result_t ValidateFunctionCall(ValidationState_t& _,
|
||||
|
||||
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.";
|
||||
}
|
||||
@@ -285,20 +286,21 @@ spv_result_t ValidateFunctionCall(ValidationState_t& _,
|
||||
}
|
||||
}
|
||||
|
||||
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 "
|
||||
@@ -313,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)
|
||||
@@ -336,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:
|
||||
|
||||
Reference in New Issue
Block a user