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: return "(u * u)";
combined = "(u * u)"; case TexturingRegs::ProcTexCombiner::V:
break; return "v";
case TexturingRegs::ProcTexCombiner::V: case TexturingRegs::ProcTexCombiner::V2:
combined = "v"; return "(v * v)";
break; case TexturingRegs::ProcTexCombiner::Add:
case TexturingRegs::ProcTexCombiner::V2: return "((u + v) * 0.5)";
combined = "(v * v)"; case TexturingRegs::ProcTexCombiner::Add2:
break; return "((u * u + v * v) * 0.5)";
case TexturingRegs::ProcTexCombiner::Add: case TexturingRegs::ProcTexCombiner::SqrtAdd2:
combined = "((u + v) * 0.5)"; return "min(sqrt(u * u + v * v), 1.0)";
break; case TexturingRegs::ProcTexCombiner::Min:
case TexturingRegs::ProcTexCombiner::Add2: return "min(u, v)";
combined = "((u * u + v * v) * 0.5)"; case TexturingRegs::ProcTexCombiner::Max:
break; return "max(u, v)";
case TexturingRegs::ProcTexCombiner::SqrtAdd2: case TexturingRegs::ProcTexCombiner::RMax:
combined = "min(sqrt(u * u + v * v), 1.0)"; return "min(((u + v) * 0.5 + sqrt(u * u + v * v)) * 0.5, 1.0)";
break; default:
case TexturingRegs::ProcTexCombiner::Min: LOG_CRITICAL(HW_GPU, "Unknown combiner {}", static_cast<u32>(combiner));
combined = "min(u, v)"; return "0.0";
break; }
case TexturingRegs::ProcTexCombiner::Max: }();
combined = "max(u, v)";
break;
case TexturingRegs::ProcTexCombiner::RMax:
combined = "min(((u + v) * 0.5 + sqrt(u * u + v * v)) * 0.5, 1.0)";
break;
default:
LOG_CRITICAL(HW_GPU, "Unknown combiner {}", static_cast<u32>(combiner));
combined = "0.0";
break;
}
out += fmt::format("ProcTexLookupLUT({}, {})", offset, combined); out += fmt::format("ProcTexLookupLUT({}, {})", offset, combined);
} }