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

Function ValidateGraphSetOutput

source/val/validate_graph.cpp:329–441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

327}
328
329spv_result_t ValidateGraphSetOutput(ValidationState_t& _,
330 const Instruction* inst) {
331 // Check type of OutputIndex
332 auto output_index_inst = _.FindDef(inst->GetOperandAs<uint32_t>(1));
333 if (!output_index_inst ||
334 !_.IsIntScalarType(output_index_inst->type_id(), 32)) {
335 return _.diag(SPV_ERROR_INVALID_DATA, inst)
336 << spvOpcodeString(inst->opcode())
337 << " OutputIndex must be a 32-bit integer.";
338 }
339
340 bool has_element_index = inst->operands().size() > 2;
341
342 // Check type of ElementIndex
343 if (has_element_index) {
344 auto element_index_inst = _.FindDef(inst->GetOperandAs<uint32_t>(2));
345 if (!element_index_inst ||
346 !_.IsIntScalarType(element_index_inst->type_id(), 32)) {
347 return _.diag(SPV_ERROR_INVALID_DATA, inst)
348 << spvOpcodeString(inst->opcode())
349 << " ElementIndex must be a 32-bit integer.";
350 }
351 }
352
353 // Find graph definition
354 size_t inst_num = inst->LineNum() - 1;
355 auto graph_inst = &_.ordered_instructions()[inst_num];
356 while (--inst_num) {
357 graph_inst = &_.ordered_instructions()[inst_num];
358 if (graph_inst->opcode() == spv::Op::OpGraphARM) {
359 break;
360 }
361 }
362
363 // Can the OutputIndex be evaluated?
364 // If not, there's nothing more we can validate here.
365 uint64_t output_index;
366 if (!_.EvalConstantValUint64(inst->GetOperandAs<uint32_t>(1),
367 &output_index)) {
368 return SPV_SUCCESS;
369 }
370
371 // Check that the OutputIndex is valid with respect to the graph type
372 auto graph_type_inst = _.FindDef(graph_inst->type_id());
373 size_t graph_type_num_outputs = GraphTypeInstNumOutputs(graph_type_inst);
374
375 if (output_index >= graph_type_num_outputs) {
376 return _.diag(SPV_ERROR_INVALID_DATA, inst)
377 << spvOpcodeString(inst->opcode()) << " setting OutputIndex "
378 << output_index << " but graph only has " << graph_type_num_outputs
379 << " outputs.";
380 }
381
382 uint32_t graph_type_output_type =
383 GraphTypeInstGetOutputAtIndex(graph_type_inst, output_index);
384
385 if (has_element_index) {
386 // Check ElementIndex is allowed

Callers 1

GraphPassFunction · 0.85

Calls 15

spvOpcodeStringFunction · 0.85
GraphTypeInstNumOutputsFunction · 0.85
IsTensorArrayFunction · 0.85
FindDefMethod · 0.80
IsIntScalarTypeMethod · 0.80
diagMethod · 0.80
operandsMethod · 0.80
LineNumMethod · 0.80
EvalConstantValUint64Method · 0.80
IsArrayTypeMethod · 0.80
getIdNameMethod · 0.80

Tested by

no test coverage detected