Helper method to find the fragment shader entry point, complaining if there is no shader or if there is no fragment entry point.
| 32 | // Helper method to find the fragment shader entry point, complaining if there |
| 33 | // is no shader or if there is no fragment entry point. |
| 34 | opt::Function* FindFragmentShaderEntryPoint(opt::IRContext* ir_context, |
| 35 | MessageConsumer message_consumer) { |
| 36 | // Check that this is a fragment shader |
| 37 | bool found_capability_shader = false; |
| 38 | for (auto& capability : ir_context->capabilities()) { |
| 39 | assert(capability.opcode() == spv::Op::OpCapability || |
| 40 | capability.opcode() == spv::Op::OpConditionalCapabilityINTEL); |
| 41 | const uint32_t i_cap = |
| 42 | capability.opcode() == spv::Op::OpConditionalCapabilityINTEL ? 1 : 0; |
| 43 | if (spv::Capability(capability.GetSingleWordInOperand(i_cap)) == |
| 44 | spv::Capability::Shader) { |
| 45 | found_capability_shader = true; |
| 46 | break; |
| 47 | } |
| 48 | } |
| 49 | if (!found_capability_shader) { |
| 50 | message_consumer( |
| 51 | SPV_MSG_ERROR, nullptr, {}, |
| 52 | "Forcing of red rendering requires the Shader capability."); |
| 53 | return nullptr; |
| 54 | } |
| 55 | |
| 56 | opt::Instruction* fragment_entry_point = nullptr; |
| 57 | for (auto& entry_point : ir_context->module()->entry_points()) { |
| 58 | if (spv::ExecutionModel(entry_point.GetSingleWordInOperand(0)) == |
| 59 | spv::ExecutionModel::Fragment) { |
| 60 | fragment_entry_point = &entry_point; |
| 61 | break; |
| 62 | } |
| 63 | } |
| 64 | if (fragment_entry_point == nullptr) { |
| 65 | message_consumer(SPV_MSG_ERROR, nullptr, {}, |
| 66 | "Forcing of red rendering requires an entry point with " |
| 67 | "the Fragment execution model."); |
| 68 | return nullptr; |
| 69 | } |
| 70 | |
| 71 | for (auto& function : *ir_context->module()) { |
| 72 | if (function.result_id() == |
| 73 | fragment_entry_point->GetSingleWordInOperand(1)) { |
| 74 | return &function; |
| 75 | } |
| 76 | } |
| 77 | assert( |
| 78 | false && |
| 79 | "A valid module must have a function associate with each entry point."); |
| 80 | return nullptr; |
| 81 | } |
| 82 | |
| 83 | // Helper method to check that there is a single vec4 output variable and get a |
| 84 | // pointer to it. |
no test coverage detected