Helper method to check that there is a single vec4 output variable and get a pointer to it.
| 83 | // Helper method to check that there is a single vec4 output variable and get a |
| 84 | // pointer to it. |
| 85 | opt::Instruction* FindVec4OutputVariable(opt::IRContext* ir_context, |
| 86 | MessageConsumer message_consumer) { |
| 87 | opt::Instruction* output_variable = nullptr; |
| 88 | for (auto& inst : ir_context->types_values()) { |
| 89 | if (inst.opcode() == spv::Op::OpVariable && |
| 90 | spv::StorageClass(inst.GetSingleWordInOperand(0)) == |
| 91 | spv::StorageClass::Output) { |
| 92 | if (output_variable != nullptr) { |
| 93 | message_consumer(SPV_MSG_ERROR, nullptr, {}, |
| 94 | "Only one output variable can be handled at present; " |
| 95 | "found multiple."); |
| 96 | return nullptr; |
| 97 | } |
| 98 | output_variable = &inst; |
| 99 | // Do not break, as we want to check for multiple output variables. |
| 100 | } |
| 101 | } |
| 102 | if (output_variable == nullptr) { |
| 103 | message_consumer(SPV_MSG_ERROR, nullptr, {}, |
| 104 | "No output variable to which to write red was found."); |
| 105 | return nullptr; |
| 106 | } |
| 107 | |
| 108 | auto output_variable_base_type = ir_context->get_type_mgr() |
| 109 | ->GetType(output_variable->type_id()) |
| 110 | ->AsPointer() |
| 111 | ->pointee_type() |
| 112 | ->AsVector(); |
| 113 | if (!output_variable_base_type || |
| 114 | output_variable_base_type->element_count() != 4 || |
| 115 | !output_variable_base_type->element_type()->AsFloat()) { |
| 116 | message_consumer(SPV_MSG_ERROR, nullptr, {}, |
| 117 | "The output variable must have type vec4."); |
| 118 | return nullptr; |
| 119 | } |
| 120 | |
| 121 | return output_variable; |
| 122 | } |
| 123 | |
| 124 | // Helper to get the ids of float constants 0.0 and 1.0, creating them if |
| 125 | // necessary. |
no test coverage detected