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

Function GetConstantUniformValue

source/opt/const_folding_rules.cpp:1079–1118  ·  view source on GitHub ↗

Get a singular uniform value, which is repeated when the |type| is a vector.

Source from the content-addressed store, hash-verified

1077
1078// Get a singular uniform value, which is repeated when the |type| is a vector.
1079const analysis::Constant* GetConstantUniformValue(
1080 analysis::ConstantManager* const_mgr, const analysis::Type* type,
1081 std::optional<double> f = {}, std::optional<uint64_t> i = {}) {
1082 const analysis::Constant* uniform = nullptr;
1083 bool is_vector = false;
1084 const analysis::Type* base_type = type;
1085
1086 if (base_type->AsVector()) {
1087 is_vector = true;
1088 base_type = base_type->AsVector()->element_type();
1089 }
1090
1091 if (f && base_type->AsFloat()) {
1092 if (base_type->AsFloat()->width() == 32) {
1093 uniform = const_mgr->GetConstant(
1094 base_type, utils::FloatProxy<float>((float)f.value()).GetWords());
1095 } else if (base_type->AsFloat()->width() == 64) {
1096 uniform = const_mgr->GetConstant(
1097 base_type, utils::FloatProxy<double>(f.value()).GetWords());
1098 }
1099 } else if (i && base_type->AsInteger()) {
1100 uniform =
1101 const_mgr->GenerateIntegerConstant(base_type->AsInteger(), i.value());
1102 }
1103
1104 if (!uniform) {
1105 return nullptr;
1106 }
1107
1108 if (is_vector) {
1109 Instruction* uniform_inst = const_mgr->GetDefiningInstruction(uniform);
1110 if (!uniform_inst) return nullptr;
1111
1112 uint32_t uniform_id = uniform_inst->result_id();
1113 uniform =
1114 const_mgr->GetConstant(type, std::vector<uint32_t>(4, uniform_id));
1115 }
1116
1117 return uniform;
1118}
1119
1120// x / x = 1
1121// -x / x = -1

Callers 1

FoldRedundantDivFunction · 0.85

Calls 11

AsVectorMethod · 0.80
AsFloatMethod · 0.80
GetWordsMethod · 0.80
AsIntegerMethod · 0.80
element_typeMethod · 0.45
widthMethod · 0.45
GetConstantMethod · 0.45
valueMethod · 0.45
result_idMethod · 0.45

Tested by

no test coverage detected