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_composites.cpp')
-rw-r--r--source/val/validate_composites.cpp90
1 files changed, 46 insertions, 44 deletions
diff --git a/source/val/validate_composites.cpp b/source/val/validate_composites.cpp
index c3d948dc7..e777f1640 100644
--- a/source/val/validate_composites.cpp
+++ b/source/val/validate_composites.cpp
@@ -35,9 +35,10 @@ namespace {
spv_result_t GetExtractInsertValueType(ValidationState_t& _,
const Instruction* inst,
uint32_t* member_type) {
- const SpvOp opcode = inst->opcode();
- assert(opcode == SpvOpCompositeExtract || opcode == SpvOpCompositeInsert);
- uint32_t word_index = opcode == SpvOpCompositeExtract ? 4 : 5;
+ const spv::Op opcode = inst->opcode();
+ assert(opcode == spv::Op::OpCompositeExtract ||
+ opcode == spv::Op::OpCompositeInsert);
+ uint32_t word_index = opcode == spv::Op::OpCompositeExtract ? 4 : 5;
const uint32_t num_words = static_cast<uint32_t>(inst->words().size());
const uint32_t composite_id_index = word_index - 1;
const uint32_t num_indices = num_words - word_index;
@@ -66,7 +67,7 @@ spv_result_t GetExtractInsertValueType(ValidationState_t& _,
const Instruction* const type_inst = _.FindDef(*member_type);
assert(type_inst);
switch (type_inst->opcode()) {
- case SpvOpTypeVector: {
+ case spv::Op::OpTypeVector: {
*member_type = type_inst->word(2);
const uint32_t vector_size = type_inst->word(3);
if (component_index >= vector_size) {
@@ -76,7 +77,7 @@ spv_result_t GetExtractInsertValueType(ValidationState_t& _,
}
break;
}
- case SpvOpTypeMatrix: {
+ case spv::Op::OpTypeMatrix: {
*member_type = type_inst->word(2);
const uint32_t num_cols = type_inst->word(3);
if (component_index >= num_cols) {
@@ -86,7 +87,7 @@ spv_result_t GetExtractInsertValueType(ValidationState_t& _,
}
break;
}
- case SpvOpTypeArray: {
+ case spv::Op::OpTypeArray: {
uint64_t array_size = 0;
auto size = _.FindDef(type_inst->word(3));
*member_type = type_inst->word(2);
@@ -105,12 +106,12 @@ spv_result_t GetExtractInsertValueType(ValidationState_t& _,
}
break;
}
- case SpvOpTypeRuntimeArray: {
+ case spv::Op::OpTypeRuntimeArray: {
*member_type = type_inst->word(2);
// Array size is unknown.
break;
}
- case SpvOpTypeStruct: {
+ case spv::Op::OpTypeStruct: {
const size_t num_struct_members = type_inst->words().size() - 2;
if (component_index >= num_struct_members) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
@@ -123,7 +124,7 @@ spv_result_t GetExtractInsertValueType(ValidationState_t& _,
*member_type = type_inst->word(component_index + 2);
break;
}
- case SpvOpTypeCooperativeMatrixNV: {
+ case spv::Op::OpTypeCooperativeMatrixNV: {
*member_type = type_inst->word(2);
break;
}
@@ -140,15 +141,15 @@ spv_result_t GetExtractInsertValueType(ValidationState_t& _,
spv_result_t ValidateVectorExtractDynamic(ValidationState_t& _,
const Instruction* inst) {
const uint32_t result_type = inst->type_id();
- const SpvOp result_opcode = _.GetIdOpcode(result_type);
+ const spv::Op result_opcode = _.GetIdOpcode(result_type);
if (!spvOpcodeIsScalarType(result_opcode)) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Expected Result Type to be a scalar type";
}
const uint32_t vector_type = _.GetOperandTypeId(inst, 2);
- const SpvOp vector_opcode = _.GetIdOpcode(vector_type);
- if (vector_opcode != SpvOpTypeVector) {
+ const spv::Op vector_opcode = _.GetIdOpcode(vector_type);
+ if (vector_opcode != spv::Op::OpTypeVector) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Expected Vector type to be OpTypeVector";
}
@@ -164,7 +165,7 @@ spv_result_t ValidateVectorExtractDynamic(ValidationState_t& _,
<< "Expected Index to be int scalar";
}
- if (_.HasCapability(SpvCapabilityShader) &&
+ if (_.HasCapability(spv::Capability::Shader) &&
_.ContainsLimitedUseIntOrFloatType(inst->type_id())) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Cannot extract from a vector of 8- or 16-bit types";
@@ -175,8 +176,8 @@ spv_result_t ValidateVectorExtractDynamic(ValidationState_t& _,
spv_result_t ValidateVectorInsertDyanmic(ValidationState_t& _,
const Instruction* inst) {
const uint32_t result_type = inst->type_id();
- const SpvOp result_opcode = _.GetIdOpcode(result_type);
- if (result_opcode != SpvOpTypeVector) {
+ const spv::Op result_opcode = _.GetIdOpcode(result_type);
+ if (result_opcode != spv::Op::OpTypeVector) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Expected Result Type to be OpTypeVector";
}
@@ -200,7 +201,7 @@ spv_result_t ValidateVectorInsertDyanmic(ValidationState_t& _,
<< "Expected Index to be int scalar";
}
- if (_.HasCapability(SpvCapabilityShader) &&
+ if (_.HasCapability(spv::Capability::Shader) &&
_.ContainsLimitedUseIntOrFloatType(inst->type_id())) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Cannot insert into a vector of 8- or 16-bit types";
@@ -212,9 +213,9 @@ spv_result_t ValidateCompositeConstruct(ValidationState_t& _,
const Instruction* inst) {
const uint32_t num_operands = static_cast<uint32_t>(inst->operands().size());
const uint32_t result_type = inst->type_id();
- const SpvOp result_opcode = _.GetIdOpcode(result_type);
+ const spv::Op result_opcode = _.GetIdOpcode(result_type);
switch (result_opcode) {
- case SpvOpTypeVector: {
+ case spv::Op::OpTypeVector: {
const uint32_t num_result_components = _.GetDimension(result_type);
const uint32_t result_component_type = _.GetComponentType(result_type);
uint32_t given_component_count = 0;
@@ -230,7 +231,7 @@ spv_result_t ValidateCompositeConstruct(ValidationState_t& _,
if (operand_type == result_component_type) {
++given_component_count;
} else {
- if (_.GetIdOpcode(operand_type) != SpvOpTypeVector ||
+ if (_.GetIdOpcode(operand_type) != spv::Op::OpTypeVector ||
_.GetComponentType(operand_type) != result_component_type) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Expected Constituents to be scalars or vectors of"
@@ -249,7 +250,7 @@ spv_result_t ValidateCompositeConstruct(ValidationState_t& _,
break;
}
- case SpvOpTypeMatrix: {
+ case spv::Op::OpTypeMatrix: {
uint32_t result_num_rows = 0;
uint32_t result_num_cols = 0;
uint32_t result_col_type = 0;
@@ -277,10 +278,10 @@ spv_result_t ValidateCompositeConstruct(ValidationState_t& _,
break;
}
- case SpvOpTypeArray: {
+ case spv::Op::OpTypeArray: {
const Instruction* const array_inst = _.FindDef(result_type);
assert(array_inst);
- assert(array_inst->opcode() == SpvOpTypeArray);
+ assert(array_inst->opcode() == spv::Op::OpTypeArray);
auto size = _.FindDef(array_inst->word(3));
if (spvOpcodeIsSpecConstant(size->opcode())) {
@@ -312,10 +313,10 @@ spv_result_t ValidateCompositeConstruct(ValidationState_t& _,
break;
}
- case SpvOpTypeStruct: {
+ case spv::Op::OpTypeStruct: {
const Instruction* const struct_inst = _.FindDef(result_type);
assert(struct_inst);
- assert(struct_inst->opcode() == SpvOpTypeStruct);
+ assert(struct_inst->opcode() == spv::Op::OpTypeStruct);
if (struct_inst->operands().size() + 1 != num_operands) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
@@ -336,7 +337,7 @@ spv_result_t ValidateCompositeConstruct(ValidationState_t& _,
break;
}
- case SpvOpTypeCooperativeMatrixNV: {
+ case spv::Op::OpTypeCooperativeMatrixNV: {
const auto result_type_inst = _.FindDef(result_type);
assert(result_type_inst);
const auto component_type_id =
@@ -362,7 +363,7 @@ spv_result_t ValidateCompositeConstruct(ValidationState_t& _,
}
}
- if (_.HasCapability(SpvCapabilityShader) &&
+ if (_.HasCapability(spv::Capability::Shader) &&
_.ContainsLimitedUseIntOrFloatType(inst->type_id())) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Cannot create a composite containing 8- or 16-bit types";
@@ -386,7 +387,7 @@ spv_result_t ValidateCompositeExtract(ValidationState_t& _,
<< spvOpcodeString(_.GetIdOpcode(member_type)) << ").";
}
- if (_.HasCapability(SpvCapabilityShader) &&
+ if (_.HasCapability(spv::Capability::Shader) &&
_.ContainsLimitedUseIntOrFloatType(inst->type_id())) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Cannot extract from a composite of 8- or 16-bit types";
@@ -421,7 +422,7 @@ spv_result_t ValidateCompositeInsert(ValidationState_t& _,
<< spvOpcodeString(_.GetIdOpcode(member_type)) << ").";
}
- if (_.HasCapability(SpvCapabilityShader) &&
+ if (_.HasCapability(spv::Capability::Shader) &&
_.ContainsLimitedUseIntOrFloatType(inst->type_id())) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Cannot insert into a composite of 8- or 16-bit types";
@@ -480,7 +481,7 @@ spv_result_t ValidateTranspose(ValidationState_t& _, const Instruction* inst) {
<< "to be the reverse of those of Result Type";
}
- if (_.HasCapability(SpvCapabilityShader) &&
+ if (_.HasCapability(spv::Capability::Shader) &&
_.ContainsLimitedUseIntOrFloatType(inst->type_id())) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Cannot transpose matrices of 16-bit floats";
@@ -491,11 +492,12 @@ spv_result_t ValidateTranspose(ValidationState_t& _, const Instruction* inst) {
spv_result_t ValidateVectorShuffle(ValidationState_t& _,
const Instruction* inst) {
auto resultType = _.FindDef(inst->type_id());
- if (!resultType || resultType->opcode() != SpvOpTypeVector) {
+ if (!resultType || resultType->opcode() != spv::Op::OpTypeVector) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "The Result Type of OpVectorShuffle must be"
<< " OpTypeVector. Found Op"
- << spvOpcodeString(static_cast<SpvOp>(resultType->opcode())) << ".";
+ << spvOpcodeString(static_cast<spv::Op>(resultType->opcode()))
+ << ".";
}
// The number of components in Result Type must be the same as the number of
@@ -515,11 +517,11 @@ spv_result_t ValidateVectorShuffle(ValidationState_t& _,
auto vector1Type = _.FindDef(vector1Object->type_id());
auto vector2Object = _.FindDef(inst->GetOperandAs<uint32_t>(3));
auto vector2Type = _.FindDef(vector2Object->type_id());
- if (!vector1Type || vector1Type->opcode() != SpvOpTypeVector) {
+ if (!vector1Type || vector1Type->opcode() != spv::Op::OpTypeVector) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "The type of Vector 1 must be OpTypeVector.";
}
- if (!vector2Type || vector2Type->opcode() != SpvOpTypeVector) {
+ if (!vector2Type || vector2Type->opcode() != spv::Op::OpTypeVector) {
return _.diag(SPV_ERROR_INVALID_ID, inst)
<< "The type of Vector 2 must be OpTypeVector.";
}
@@ -548,7 +550,7 @@ spv_result_t ValidateVectorShuffle(ValidationState_t& _,
}
}
- if (_.HasCapability(SpvCapabilityShader) &&
+ if (_.HasCapability(spv::Capability::Shader) &&
_.ContainsLimitedUseIntOrFloatType(inst->type_id())) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Cannot shuffle a vector of 8- or 16-bit types";
@@ -572,7 +574,7 @@ spv_result_t ValidateCopyLogical(ValidationState_t& _,
<< "Result Type does not logically match the Operand type";
}
- if (_.HasCapability(SpvCapabilityShader) &&
+ if (_.HasCapability(spv::Capability::Shader) &&
_.ContainsLimitedUseIntOrFloatType(inst->type_id())) {
return _.diag(SPV_ERROR_INVALID_DATA, inst)
<< "Cannot copy composites of 8- or 16-bit types";
@@ -586,23 +588,23 @@ spv_result_t ValidateCopyLogical(ValidationState_t& _,
// Validates correctness of composite instructions.
spv_result_t CompositesPass(ValidationState_t& _, const Instruction* inst) {
switch (inst->opcode()) {
- case SpvOpVectorExtractDynamic:
+ case spv::Op::OpVectorExtractDynamic:
return ValidateVectorExtractDynamic(_, inst);
- case SpvOpVectorInsertDynamic:
+ case spv::Op::OpVectorInsertDynamic:
return ValidateVectorInsertDyanmic(_, inst);
- case SpvOpVectorShuffle:
+ case spv::Op::OpVectorShuffle:
return ValidateVectorShuffle(_, inst);
- case SpvOpCompositeConstruct:
+ case spv::Op::OpCompositeConstruct:
return ValidateCompositeConstruct(_, inst);
- case SpvOpCompositeExtract:
+ case spv::Op::OpCompositeExtract:
return ValidateCompositeExtract(_, inst);
- case SpvOpCompositeInsert:
+ case spv::Op::OpCompositeInsert:
return ValidateCompositeInsert(_, inst);
- case SpvOpCopyObject:
+ case spv::Op::OpCopyObject:
return ValidateCopyObject(_, inst);
- case SpvOpTranspose:
+ case spv::Op::OpTranspose:
return ValidateTranspose(_, inst);
- case SpvOpCopyLogical:
+ case spv::Op::OpCopyLogical:
return ValidateCopyLogical(_, inst);
default:
break;