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

Function FindOrCreateFloatZeroAndOne

source/fuzz/force_render_red.cpp:126–144  ·  view source on GitHub ↗

Helper to get the ids of float constants 0.0 and 1.0, creating them if necessary.

Source from the content-addressed store, hash-verified

124// Helper to get the ids of float constants 0.0 and 1.0, creating them if
125// necessary.
126std::pair<uint32_t, uint32_t> FindOrCreateFloatZeroAndOne(
127 opt::IRContext* ir_context, opt::analysis::Float* float_type) {
128 float one = 1.0;
129 uint32_t one_as_uint;
130 memcpy(&one_as_uint, &one, sizeof(float));
131 std::vector<uint32_t> zero_bytes = {0};
132 std::vector<uint32_t> one_bytes = {one_as_uint};
133 auto constant_zero = ir_context->get_constant_mgr()->RegisterConstant(
134 MakeUnique<opt::analysis::FloatConstant>(float_type, zero_bytes));
135 auto constant_one = ir_context->get_constant_mgr()->RegisterConstant(
136 MakeUnique<opt::analysis::FloatConstant>(float_type, one_bytes));
137 auto constant_zero_id = ir_context->get_constant_mgr()
138 ->GetDefiningInstruction(constant_zero)
139 ->result_id();
140 auto constant_one_id = ir_context->get_constant_mgr()
141 ->GetDefiningInstruction(constant_one)
142 ->result_id();
143 return std::pair<uint32_t, uint32_t>(constant_zero_id, constant_one_id);
144}
145
146std::unique_ptr<TransformationReplaceConstantWithUniform>
147MakeConstantUniformReplacement(opt::IRContext* ir_context,

Callers 1

ForceRenderRedFunction · 0.85

Calls 4

RegisterConstantMethod · 0.80
get_constant_mgrMethod · 0.80
result_idMethod · 0.45

Tested by

no test coverage detected