From c9936f8c1cd061c6b045c2223d4bb83c5eb9b6e0 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Tue, 21 Dec 2021 18:15:25 -0800 Subject: [PATCH] SW/Tev: Use EnumMap for scale/bias tables --- Source/Core/VideoBackends/Software/Tev.cpp | 30 +++++----------------- Source/Core/VideoBackends/Software/Tev.h | 6 ++--- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/Source/Core/VideoBackends/Software/Tev.cpp b/Source/Core/VideoBackends/Software/Tev.cpp index 4bd54b5a8e..52a2ecebd0 100644 --- a/Source/Core/VideoBackends/Software/Tev.cpp +++ b/Source/Core/VideoBackends/Software/Tev.cpp @@ -29,20 +29,6 @@ void Tev::Init() { - m_BiasLUT[0] = 0; - m_BiasLUT[1] = 128; - m_BiasLUT[2] = -128; - m_BiasLUT[3] = 0; - - m_ScaleLShiftLUT[0] = 0; - m_ScaleLShiftLUT[1] = 1; - m_ScaleLShiftLUT[2] = 2; - m_ScaleLShiftLUT[3] = 0; - - m_ScaleRShiftLUT[0] = 0; - m_ScaleRShiftLUT[1] = 0; - m_ScaleRShiftLUT[2] = 0; - m_ScaleRShiftLUT[3] = 1; } static inline s16 Clamp255(s16 in) @@ -110,15 +96,13 @@ void Tev::DrawColorRegular(const TevStageCombiner::ColorCombiner& cc, const Inpu const u16 c = InputReg.c + (InputReg.c >> 7); s32 temp = InputReg.a * (256 - c) + (InputReg.b * c); - temp <<= m_ScaleLShiftLUT[u32(cc.scale.Value())]; + temp <<= s_ScaleLShiftLUT[cc.scale]; temp += (cc.scale == TevScale::Divide2) ? 0 : (cc.op == TevOp::Sub) ? 127 : 128; temp >>= 8; temp = cc.op == TevOp::Sub ? -temp : temp; - s32 result = ((InputReg.d + m_BiasLUT[u32(cc.bias.Value())]) - << m_ScaleLShiftLUT[u32(cc.scale.Value())]) + - temp; - result = result >> m_ScaleRShiftLUT[u32(cc.scale.Value())]; + s32 result = ((InputReg.d + s_BiasLUT[cc.bias]) << s_ScaleLShiftLUT[cc.scale]) + temp; + result = result >> s_ScaleRShiftLUT[cc.scale]; Reg[cc.dest][i] = result; } @@ -170,14 +154,12 @@ void Tev::DrawAlphaRegular(const TevStageCombiner::AlphaCombiner& ac, const Inpu const u16 c = InputReg.c + (InputReg.c >> 7); s32 temp = InputReg.a * (256 - c) + (InputReg.b * c); - temp <<= m_ScaleLShiftLUT[u32(ac.scale.Value())]; + temp <<= s_ScaleLShiftLUT[ac.scale]; temp += (ac.scale == TevScale::Divide2) ? 0 : (ac.op == TevOp::Sub) ? 127 : 128; temp = ac.op == TevOp::Sub ? (-temp >> 8) : (temp >> 8); - s32 result = - ((InputReg.d + m_BiasLUT[u32(ac.bias.Value())]) << m_ScaleLShiftLUT[u32(ac.scale.Value())]) + - temp; - result = result >> m_ScaleRShiftLUT[u32(ac.scale.Value())]; + s32 result = ((InputReg.d + s_BiasLUT[ac.bias]) << s_ScaleLShiftLUT[ac.scale]) + temp; + result = result >> s_ScaleRShiftLUT[ac.scale]; Reg[ac.dest].a = result; } diff --git a/Source/Core/VideoBackends/Software/Tev.h b/Source/Core/VideoBackends/Software/Tev.h index da94f05172..a9c54e8dd4 100644 --- a/Source/Core/VideoBackends/Software/Tev.h +++ b/Source/Core/VideoBackends/Software/Tev.h @@ -189,9 +189,9 @@ class Tev TevKonstRef::Value(KonstantColors[2].a), // Konst 2 Alpha TevKonstRef::Value(KonstantColors[3].a), // Konst 3 Alpha }; - s16 m_BiasLUT[4]; - u8 m_ScaleLShiftLUT[4]; - u8 m_ScaleRShiftLUT[4]; + static constexpr Common::EnumMap s_BiasLUT{0, 128, -128, 0}; + static constexpr Common::EnumMap s_ScaleLShiftLUT{0, 1, 2, 0}; + static constexpr Common::EnumMap s_ScaleRShiftLUT{0, 0, 0, 1}; enum BufferBase {