gl_shader_gen: Eliminate unnecessary std::string construction in AppendProcTexCombineAndMap()

We can make use of a std::string_view here, since only string literals
are used within the switch.
This commit is contained in:
Lioncash 2020-06-08 06:37:39 -04:00
parent edb5977fba
commit 9645c1e1b2

View file

@ -1018,43 +1018,34 @@ void AppendProcTexClamp(std::string& out, std::string_view var, ProcTexClamp mod
void AppendProcTexCombineAndMap(std::string& out, ProcTexCombiner combiner, void AppendProcTexCombineAndMap(std::string& out, ProcTexCombiner combiner,
std::string_view offset) { std::string_view offset) {
std::string combined; const auto combined = [combiner]() -> std::string_view {
switch (combiner) { switch (combiner) {
case ProcTexCombiner::U: case ProcTexCombiner::U:
combined = "u"; return "u";
break;
case ProcTexCombiner::U2: case ProcTexCombiner::U2:
combined = "(u * u)"; return "(u * u)";
break;
case TexturingRegs::ProcTexCombiner::V: case TexturingRegs::ProcTexCombiner::V:
combined = "v"; return "v";
break;
case TexturingRegs::ProcTexCombiner::V2: case TexturingRegs::ProcTexCombiner::V2:
combined = "(v * v)"; return "(v * v)";
break;
case TexturingRegs::ProcTexCombiner::Add: case TexturingRegs::ProcTexCombiner::Add:
combined = "((u + v) * 0.5)"; return "((u + v) * 0.5)";
break;
case TexturingRegs::ProcTexCombiner::Add2: case TexturingRegs::ProcTexCombiner::Add2:
combined = "((u * u + v * v) * 0.5)"; return "((u * u + v * v) * 0.5)";
break;
case TexturingRegs::ProcTexCombiner::SqrtAdd2: case TexturingRegs::ProcTexCombiner::SqrtAdd2:
combined = "min(sqrt(u * u + v * v), 1.0)"; return "min(sqrt(u * u + v * v), 1.0)";
break;
case TexturingRegs::ProcTexCombiner::Min: case TexturingRegs::ProcTexCombiner::Min:
combined = "min(u, v)"; return "min(u, v)";
break;
case TexturingRegs::ProcTexCombiner::Max: case TexturingRegs::ProcTexCombiner::Max:
combined = "max(u, v)"; return "max(u, v)";
break;
case TexturingRegs::ProcTexCombiner::RMax: case TexturingRegs::ProcTexCombiner::RMax:
combined = "min(((u + v) * 0.5 + sqrt(u * u + v * v)) * 0.5, 1.0)"; return "min(((u + v) * 0.5 + sqrt(u * u + v * v)) * 0.5, 1.0)";
break;
default: default:
LOG_CRITICAL(HW_GPU, "Unknown combiner {}", static_cast<u32>(combiner)); LOG_CRITICAL(HW_GPU, "Unknown combiner {}", static_cast<u32>(combiner));
combined = "0.0"; return "0.0";
break;
} }
}();
out += fmt::format("ProcTexLookupLUT({}, {})", offset, combined); out += fmt::format("ProcTexLookupLUT({}, {})", offset, combined);
} }