diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp index f06b60a430..f51b27518f 100644 --- a/Source/Core/VideoCommon/VertexLoader.cpp +++ b/Source/Core/VideoCommon/VertexLoader.cpp @@ -205,98 +205,16 @@ void VertexLoader::CompileVertexTranslator() m_native_vtx_decl.colors[i].components = 4; m_native_vtx_decl.colors[i].type = VAR_UNSIGNED_BYTE; m_native_vtx_decl.colors[i].integer = false; - switch (m_VtxDesc.low.Color[i]) - { - case VertexComponentFormat::NotPresent: - break; - case VertexComponentFormat::Direct: - switch (m_VtxAttr.color[i].Comp) - { - case ColorFormat::RGB565: - m_VertexSize += 2; - WriteCall(Color_ReadDirect_16b_565); - break; - case ColorFormat::RGB888: - m_VertexSize += 3; - WriteCall(Color_ReadDirect_24b_888); - break; - case ColorFormat::RGB888x: - m_VertexSize += 4; - WriteCall(Color_ReadDirect_32b_888x); - break; - case ColorFormat::RGBA4444: - m_VertexSize += 2; - WriteCall(Color_ReadDirect_16b_4444); - break; - case ColorFormat::RGBA6666: - m_VertexSize += 3; - WriteCall(Color_ReadDirect_24b_6666); - break; - case ColorFormat::RGBA8888: - m_VertexSize += 4; - WriteCall(Color_ReadDirect_32b_8888); - break; - default: - ASSERT(0); - break; - } - break; - case VertexComponentFormat::Index8: - m_VertexSize += 1; - switch (m_VtxAttr.color[i].Comp) - { - case ColorFormat::RGB565: - WriteCall(Color_ReadIndex8_16b_565); - break; - case ColorFormat::RGB888: - WriteCall(Color_ReadIndex8_24b_888); - break; - case ColorFormat::RGB888x: - WriteCall(Color_ReadIndex8_32b_888x); - break; - case ColorFormat::RGBA4444: - WriteCall(Color_ReadIndex8_16b_4444); - break; - case ColorFormat::RGBA6666: - WriteCall(Color_ReadIndex8_24b_6666); - break; - case ColorFormat::RGBA8888: - WriteCall(Color_ReadIndex8_32b_8888); - break; - default: - ASSERT(0); - break; - } - break; - case VertexComponentFormat::Index16: - m_VertexSize += 2; - switch (m_VtxAttr.color[i].Comp) - { - case ColorFormat::RGB565: - WriteCall(Color_ReadIndex16_16b_565); - break; - case ColorFormat::RGB888: - WriteCall(Color_ReadIndex16_24b_888); - break; - case ColorFormat::RGB888x: - WriteCall(Color_ReadIndex16_32b_888x); - break; - case ColorFormat::RGBA4444: - WriteCall(Color_ReadIndex16_16b_4444); - break; - case ColorFormat::RGBA6666: - WriteCall(Color_ReadIndex16_24b_6666); - break; - case ColorFormat::RGBA8888: - WriteCall(Color_ReadIndex16_32b_8888); - break; - default: - ASSERT(0); - break; - } - break; - } - // Common for the three bottom cases + + m_VertexSize += VertexLoader_Color::GetSize(m_VtxDesc.low.Color[i], m_VtxAttr.color[i].Comp); + TPipelineFunction pFunc = + VertexLoader_Color::GetFunction(m_VtxDesc.low.Color[i], m_VtxAttr.color[i].Comp); + + if (pFunc != nullptr) + WriteCall(pFunc); + else + ASSERT(m_VtxDesc.low.Color[i] == VertexComponentFormat::NotPresent); + if (m_VtxDesc.low.Color[i] != VertexComponentFormat::NotPresent) { components |= VB_HAS_COL0 << i; diff --git a/Source/Core/VideoCommon/VertexLoader_Color.cpp b/Source/Core/VideoCommon/VertexLoader_Color.cpp index cef347346d..75d16ee458 100644 --- a/Source/Core/VideoCommon/VertexLoader_Color.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Color.cpp @@ -5,6 +5,7 @@ #include #include "Common/CommonTypes.h" +#include "Common/MsgHandler.h" #include "Common/Swap.h" #include "VideoCommon/VertexLoader.h" @@ -136,7 +137,6 @@ void Color_ReadIndex_32b_8888(VertexLoader* loader) (index * g_main_cp_state.array_strides[ARRAY_COLOR0 + loader->m_colIndex]); SetCol(loader, Read32(address)); } -} // Anonymous namespace void Color_ReadDirect_24b_888(VertexLoader* loader) { @@ -149,10 +149,12 @@ void Color_ReadDirect_32b_888x(VertexLoader* loader) SetCol(loader, Read24(DataGetPosition())); DataSkip(4); } + void Color_ReadDirect_16b_565(VertexLoader* loader) { SetCol565(loader, DataRead()); } + void Color_ReadDirect_16b_4444(VertexLoader* loader) { u16 value; @@ -161,62 +163,52 @@ void Color_ReadDirect_16b_4444(VertexLoader* loader) SetCol4444(loader, value); DataSkip(2); } + void Color_ReadDirect_24b_6666(VertexLoader* loader) { SetCol6666(loader, Common::swap32(DataGetPosition() - 1)); DataSkip(3); } + void Color_ReadDirect_32b_8888(VertexLoader* loader) { SetCol(loader, DataReadU32Unswapped()); } -void Color_ReadIndex8_16b_565(VertexLoader* loader) +constexpr TPipelineFunction s_table_read_color[4][6] = { + {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}, + {Color_ReadDirect_16b_565, Color_ReadDirect_24b_888, Color_ReadDirect_32b_888x, + Color_ReadDirect_16b_4444, Color_ReadDirect_24b_6666, Color_ReadDirect_32b_8888}, + {Color_ReadIndex_16b_565, Color_ReadIndex_24b_888, Color_ReadIndex_32b_888x, + Color_ReadIndex_16b_4444, Color_ReadIndex_24b_6666, Color_ReadIndex_32b_8888}, + {Color_ReadIndex_16b_565, Color_ReadIndex_24b_888, Color_ReadIndex_32b_888x, + Color_ReadIndex_16b_4444, Color_ReadIndex_24b_6666, Color_ReadIndex_32b_8888}, +}; + +constexpr u32 s_table_read_color_vertex_size[4][6] = { + {0, 0, 0, 0, 0, 0}, + {2, 3, 4, 2, 3, 4}, + {1, 1, 1, 1, 1, 1}, + {2, 2, 2, 2, 2, 2}, +}; +} // Anonymous namespace + +u32 VertexLoader_Color::GetSize(VertexComponentFormat type, ColorFormat format) { - Color_ReadIndex_16b_565(loader); -} -void Color_ReadIndex8_24b_888(VertexLoader* loader) -{ - Color_ReadIndex_24b_888(loader); -} -void Color_ReadIndex8_32b_888x(VertexLoader* loader) -{ - Color_ReadIndex_32b_888x(loader); -} -void Color_ReadIndex8_16b_4444(VertexLoader* loader) -{ - Color_ReadIndex_16b_4444(loader); -} -void Color_ReadIndex8_24b_6666(VertexLoader* loader) -{ - Color_ReadIndex_24b_6666(loader); -} -void Color_ReadIndex8_32b_8888(VertexLoader* loader) -{ - Color_ReadIndex_32b_8888(loader); + if (format > ColorFormat::RGBA8888) + { + PanicAlertFmt("Invalid color format {}", format); + return 0; + } + return s_table_read_color_vertex_size[u32(type)][u32(format)]; } -void Color_ReadIndex16_16b_565(VertexLoader* loader) +TPipelineFunction VertexLoader_Color::GetFunction(VertexComponentFormat type, ColorFormat format) { - Color_ReadIndex_16b_565(loader); -} -void Color_ReadIndex16_24b_888(VertexLoader* loader) -{ - Color_ReadIndex_24b_888(loader); -} -void Color_ReadIndex16_32b_888x(VertexLoader* loader) -{ - Color_ReadIndex_32b_888x(loader); -} -void Color_ReadIndex16_16b_4444(VertexLoader* loader) -{ - Color_ReadIndex_16b_4444(loader); -} -void Color_ReadIndex16_24b_6666(VertexLoader* loader) -{ - Color_ReadIndex_24b_6666(loader); -} -void Color_ReadIndex16_32b_8888(VertexLoader* loader) -{ - Color_ReadIndex_32b_8888(loader); + if (format > ColorFormat::RGBA8888) + { + PanicAlertFmt("Invalid color format {}", format); + return nullptr; + } + return s_table_read_color[u32(type)][u32(format)]; } diff --git a/Source/Core/VideoCommon/VertexLoader_Color.h b/Source/Core/VideoCommon/VertexLoader_Color.h index 0f83dc4b29..3fd8b078ea 100644 --- a/Source/Core/VideoCommon/VertexLoader_Color.h +++ b/Source/Core/VideoCommon/VertexLoader_Color.h @@ -4,25 +4,15 @@ #pragma once -class VertexLoader; +#include "Common/CommonTypes.h" +#include "VideoCommon/VertexLoader.h" -void Color_ReadDirect_24b_888(VertexLoader* loader); -void Color_ReadDirect_32b_888x(VertexLoader* loader); -void Color_ReadDirect_16b_565(VertexLoader* loader); -void Color_ReadDirect_16b_4444(VertexLoader* loader); -void Color_ReadDirect_24b_6666(VertexLoader* loader); -void Color_ReadDirect_32b_8888(VertexLoader* loader); +enum class VertexComponentFormat; +enum class ColorFormat; -void Color_ReadIndex8_16b_565(VertexLoader* loader); -void Color_ReadIndex8_24b_888(VertexLoader* loader); -void Color_ReadIndex8_32b_888x(VertexLoader* loader); -void Color_ReadIndex8_16b_4444(VertexLoader* loader); -void Color_ReadIndex8_24b_6666(VertexLoader* loader); -void Color_ReadIndex8_32b_8888(VertexLoader* loader); - -void Color_ReadIndex16_16b_565(VertexLoader* loader); -void Color_ReadIndex16_24b_888(VertexLoader* loader); -void Color_ReadIndex16_32b_888x(VertexLoader* loader); -void Color_ReadIndex16_16b_4444(VertexLoader* loader); -void Color_ReadIndex16_24b_6666(VertexLoader* loader); -void Color_ReadIndex16_32b_8888(VertexLoader* loader); +class VertexLoader_Color +{ +public: + static u32 GetSize(VertexComponentFormat type, ColorFormat format); + static TPipelineFunction GetFunction(VertexComponentFormat type, ColorFormat format); +};