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

Function FindVec4OutputVariable

source/fuzz/force_render_red.cpp:85–122  ·  view source on GitHub ↗

Helper method to check that there is a single vec4 output variable and get a pointer to it.

Source from the content-addressed store, hash-verified

83// Helper method to check that there is a single vec4 output variable and get a
84// pointer to it.
85opt::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.

Callers 1

ForceRenderRedFunction · 0.85

Calls 12

AsVectorMethod · 0.80
pointee_typeMethod · 0.80
AsPointerMethod · 0.80
get_type_mgrMethod · 0.80
AsFloatMethod · 0.80
types_valuesMethod · 0.45
opcodeMethod · 0.45
GetTypeMethod · 0.45
type_idMethod · 0.45
element_countMethod · 0.45
element_typeMethod · 0.45

Tested by

no test coverage detected