Update SPIR-V Dependencies to match Dawn requirements

This commit is contained in:
bridgewaterrobbie
2025-02-19 17:24:15 -05:00
committed by bridgewaterrobbie
parent 17091df8dc
commit a937362ccc
1242 changed files with 95189 additions and 28682 deletions

View File

@@ -14,6 +14,7 @@
#include <algorithm>
#include "source/enum_string_mapping.h"
#include "source/opcode.h"
#include "source/val/instruction.h"
#include "source/val/validate.h"
@@ -85,7 +86,10 @@ spv_result_t ValidateFunction(ValidationState_t& _, const Instruction* inst) {
spv::Op::OpGetKernelPreferredWorkGroupSizeMultiple,
spv::Op::OpGetKernelLocalSizeForSubgroupCount,
spv::Op::OpGetKernelMaxNumSubgroups,
spv::Op::OpName};
spv::Op::OpName,
spv::Op::OpCooperativeMatrixPerElementOpNV,
spv::Op::OpCooperativeMatrixReduceNV,
spv::Op::OpCooperativeMatrixLoadTensorNV};
for (auto& pair : inst->uses()) {
const auto* use = pair.first;
if (std::find(acceptable.begin(), acceptable.end(), use->opcode()) ==
@@ -148,78 +152,6 @@ spv_result_t ValidateFunctionParameter(ValidationState_t& _,
"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) == spv::Op::OpTypeArray) {
param_nonarray_type_id =
_.FindDef(param_nonarray_type_id)->GetOperandAs<uint32_t>(1u);
}
if (_.GetIdOpcode(param_nonarray_type_id) == spv::Op::OpTypePointer) {
auto param_nonarray_type = _.FindDef(param_nonarray_type_id);
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 spv::Decoration::Aliased == d.dec_type();
});
bool foundRestrict = std::any_of(
decorations.begin(), decorations.end(), [](const Decoration& d) {
return spv::Decoration::Restrict == d.dec_type();
});
if (!foundAliased && !foundRestrict) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpFunctionParameter " << inst->id()
<< ": expected Aliased or Restrict for PhysicalStorageBuffer "
"pointer.";
}
if (foundAliased && foundRestrict) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpFunctionParameter " << inst->id()
<< ": can't specify both Aliased and Restrict for "
"PhysicalStorageBuffer pointer.";
}
} else {
const auto pointee_type_id =
param_nonarray_type->GetOperandAs<uint32_t>(2);
const auto pointee_type = _.FindDef(pointee_type_id);
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 spv::Decoration::AliasedPointer == d.dec_type();
});
bool foundRestrict = std::any_of(
decorations.begin(), decorations.end(), [](const Decoration& d) {
return spv::Decoration::RestrictPointer == d.dec_type();
});
if (!foundAliased && !foundRestrict) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpFunctionParameter " << inst->id()
<< ": expected AliasedPointer or RestrictPointer for "
"PhysicalStorageBuffer pointer.";
}
if (foundAliased && foundRestrict) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpFunctionParameter " << inst->id()
<< ": can't specify both AliasedPointer and "
"RestrictPointer for PhysicalStorageBuffer pointer.";
}
}
}
}
return SPV_SUCCESS;
}
@@ -277,7 +209,7 @@ spv_result_t ValidateFunctionCall(ValidationState_t& _,
function_type->GetOperandAs<uint32_t>(param_index);
const auto parameter_type = _.FindDef(parameter_type_id);
if (!parameter_type || argument_type->id() != parameter_type->id()) {
if (!_.options()->before_hlsl_legalization ||
if (!parameter_type || !_.options()->before_hlsl_legalization ||
!DoPointeesLogicallyMatch(argument_type, parameter_type, _)) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpFunctionCall Argument <id> " << _.getIdName(argument_id)
@@ -287,7 +219,8 @@ spv_result_t ValidateFunctionCall(ValidationState_t& _,
}
if (_.addressing_model() == spv::AddressingModel::Logical) {
if (parameter_type->opcode() == spv::Op::OpTypePointer &&
if ((parameter_type->opcode() == spv::Op::OpTypePointer ||
parameter_type->opcode() == spv::Op::OpTypeUntypedPointerKHR) &&
!_.options()->relax_logical_pointer) {
spv::StorageClass sc =
parameter_type->GetOperandAs<spv::StorageClass>(1u);
@@ -316,9 +249,11 @@ spv_result_t ValidateFunctionCall(ValidationState_t& _,
// Validate memory object declaration requirements.
if (argument->opcode() != spv::Op::OpVariable &&
argument->opcode() != spv::Op::OpUntypedVariableKHR &&
argument->opcode() != spv::Op::OpFunctionParameter) {
const bool ssbo_vptr = _.features().variable_pointers &&
sc == spv::StorageClass::StorageBuffer;
const bool ssbo_vptr =
_.HasCapability(spv::Capability::VariablePointersStorageBuffer) &&
sc == spv::StorageClass::StorageBuffer;
const bool wg_vptr =
_.HasCapability(spv::Capability::VariablePointers) &&
sc == spv::StorageClass::Workgroup;
@@ -335,6 +270,80 @@ spv_result_t ValidateFunctionCall(ValidationState_t& _,
return SPV_SUCCESS;
}
spv_result_t ValidateCooperativeMatrixPerElementOp(ValidationState_t& _,
const Instruction* inst) {
const auto function_id = inst->GetOperandAs<uint32_t>(3);
const auto function = _.FindDef(function_id);
if (!function || spv::Op::OpFunction != function->opcode()) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpCooperativeMatrixPerElementOpNV Function <id> "
<< _.getIdName(function_id) << " is not a function.";
}
const auto matrix_id = inst->GetOperandAs<uint32_t>(2);
const auto matrix = _.FindDef(matrix_id);
const auto matrix_type_id = matrix->type_id();
if (!_.IsCooperativeMatrixKHRType(matrix_type_id)) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpCooperativeMatrixPerElementOpNV Matrix <id> "
<< _.getIdName(matrix_id) << " is not a cooperative matrix.";
}
const auto result_type_id = inst->GetOperandAs<uint32_t>(0);
if (matrix_type_id != result_type_id) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpCooperativeMatrixPerElementOpNV Result Type <id> "
<< _.getIdName(result_type_id) << " must match matrix type <id> "
<< _.getIdName(matrix_type_id) << ".";
}
const auto matrix_comp_type_id =
_.FindDef(matrix_type_id)->GetOperandAs<uint32_t>(1);
const auto function_type_id = function->GetOperandAs<uint32_t>(3);
const auto function_type = _.FindDef(function_type_id);
auto return_type_id = function_type->GetOperandAs<uint32_t>(1);
if (return_type_id != matrix_comp_type_id) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpCooperativeMatrixPerElementOpNV function return type <id> "
<< _.getIdName(return_type_id)
<< " must match matrix component type <id> "
<< _.getIdName(matrix_comp_type_id) << ".";
}
if (function_type->operands().size() < 5) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpCooperativeMatrixPerElementOpNV function type <id> "
<< _.getIdName(function_type_id)
<< " must have a least three parameters.";
}
const auto param0_id = function_type->GetOperandAs<uint32_t>(2);
const auto param1_id = function_type->GetOperandAs<uint32_t>(3);
const auto param2_id = function_type->GetOperandAs<uint32_t>(4);
if (!_.IsIntScalarType(param0_id) || _.GetBitWidth(param0_id) != 32) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpCooperativeMatrixPerElementOpNV function type first parameter "
"type <id> "
<< _.getIdName(param0_id) << " must be a 32-bit integer.";
}
if (!_.IsIntScalarType(param1_id) || _.GetBitWidth(param1_id) != 32) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpCooperativeMatrixPerElementOpNV function type second "
"parameter type <id> "
<< _.getIdName(param1_id) << " must be a 32-bit integer.";
}
if (param2_id != matrix_comp_type_id) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "OpCooperativeMatrixPerElementOpNV function type third parameter "
"type <id> "
<< _.getIdName(param2_id) << " must match matrix component type.";
}
return SPV_SUCCESS;
}
} // namespace
spv_result_t FunctionPass(ValidationState_t& _, const Instruction* inst) {
@@ -348,6 +357,10 @@ spv_result_t FunctionPass(ValidationState_t& _, const Instruction* inst) {
case spv::Op::OpFunctionCall:
if (auto error = ValidateFunctionCall(_, inst)) return error;
break;
case spv::Op::OpCooperativeMatrixPerElementOpNV:
if (auto error = ValidateCooperativeMatrixPerElementOp(_, inst))
return error;
break;
default:
break;
}