MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / ValidateExtractSubArrayQCOM

Function ValidateExtractSubArrayQCOM

source/val/validate_composites.cpp:1102–1144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1100}
1101
1102spv_result_t ValidateExtractSubArrayQCOM(ValidationState_t& _,
1103 const Instruction* inst) {
1104 const auto result_type_inst = _.FindDef(inst->type_id());
1105 const auto source = _.FindDef(inst->GetOperandAs<uint32_t>(2u));
1106 const auto source_type_inst = _.FindDef(source->type_id());
1107
1108 // Are the input and the result arrays?
1109 if (result_type_inst->opcode() != spv::Op::OpTypeArray ||
1110 source_type_inst->opcode() != spv::Op::OpTypeArray) {
1111 return _.diag(SPV_ERROR_INVALID_DATA, inst)
1112 << "Opcode " << spvOpcodeString(inst->opcode())
1113 << " requires OpTypeArray operands for the input and the result.";
1114 }
1115
1116 const auto source_elt_type = _.GetComponentType(source_type_inst->id());
1117 const auto result_elt_type = _.GetComponentType(result_type_inst->id());
1118
1119 // Do the input and result element types match?
1120 if (source_elt_type != result_elt_type) {
1121 return _.diag(SPV_ERROR_INVALID_DATA, inst)
1122 << "Opcode " << spvOpcodeString(inst->opcode())
1123 << " requires the input and result element types match.";
1124 }
1125
1126 // Elt type must be one of int32_t/uint32_t/float32/float16
1127 if (!_.IsIntNOrFP32OrFP16<32>(source_elt_type)) {
1128 return _.diag(SPV_ERROR_INVALID_DATA, inst)
1129 << "Opcode " << spvOpcodeString(inst->opcode())
1130 << " requires the element type be one of 32-bit OpTypeInt "
1131 "(signed/unsigned), 32-bit OpTypeFloat and 16-bit OpTypeFloat";
1132 }
1133
1134 const auto start_index = _.FindDef(inst->GetOperandAs<uint32_t>(3u));
1135 if (!start_index || !_.ContainsSizedIntOrFloatType(start_index->type_id(),
1136 spv::Op::OpTypeInt, 32)) {
1137 return _.diag(SPV_ERROR_INVALID_DATA, inst)
1138 << "Opcode " << spvOpcodeString(inst->opcode())
1139 << " requires the type of the start index operand be 32-bit "
1140 "OpTypeInt";
1141 }
1142
1143 return SPV_SUCCESS;
1144}
1145
1146} // anonymous namespace
1147// Validates correctness of composite instructions.

Callers 1

CompositesPassFunction · 0.85

Calls 8

spvOpcodeStringFunction · 0.85
FindDefMethod · 0.80
diagMethod · 0.80
type_idMethod · 0.45
opcodeMethod · 0.45
GetComponentTypeMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected