diff --git a/Source/Core/VideoCommon/VertexLoader_Color.cpp b/Source/Core/VideoCommon/VertexLoader_Color.cpp index 4f2e04b0b4..4e71889bbd 100644 --- a/Source/Core/VideoCommon/VertexLoader_Color.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Color.cpp @@ -6,6 +6,7 @@ #include #include "Common/CommonTypes.h" +#include "Common/EnumMap.h" #include "Common/MsgHandler.h" #include "Common/Swap.h" @@ -175,21 +176,40 @@ void Color_ReadDirect_32b_8888(VertexLoader* loader) SetCol(loader, DataReadU32Unswapped()); } -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}, +using Common::EnumMap; + +// These functions are to work around a "too many initializer values" error with nested brackets +// C++ does not let you write std::array, 2> a = {{1, 2}, {3, 4}} +// (although it does allow std::array, 2> b = {1, 2, 3, 4}) +constexpr EnumMap +f(EnumMap in) +{ + return in; +} +constexpr EnumMap g(EnumMap in) +{ + return in; +} + +template +using Table = EnumMap, VertexComponentFormat::Index16>; + +constexpr Table s_table_read_color = { + f({nullptr, nullptr, nullptr, nullptr, nullptr, nullptr}), + f({Color_ReadDirect_16b_565, Color_ReadDirect_24b_888, Color_ReadDirect_32b_888x, + Color_ReadDirect_16b_4444, Color_ReadDirect_24b_6666, Color_ReadDirect_32b_8888}), + f({Color_ReadIndex_16b_565, Color_ReadIndex_24b_888, Color_ReadIndex_32b_888x, + Color_ReadIndex_16b_4444, Color_ReadIndex_24b_6666, Color_ReadIndex_32b_8888}), + f({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}, +constexpr Table s_table_read_color_vertex_size = { + g({0u, 0u, 0u, 0u, 0u, 0u}), + g({2u, 3u, 4u, 2u, 3u, 4u}), + g({1u, 1u, 1u, 1u, 1u, 1u}), + g({2u, 2u, 2u, 2u, 2u, 2u}), }; } // Anonymous namespace @@ -200,7 +220,7 @@ u32 VertexLoader_Color::GetSize(VertexComponentFormat type, ColorFormat format) PanicAlertFmt("Invalid color format {}", format); return 0; } - return s_table_read_color_vertex_size[u32(type)][u32(format)]; + return s_table_read_color_vertex_size[type][format]; } TPipelineFunction VertexLoader_Color::GetFunction(VertexComponentFormat type, ColorFormat format) @@ -210,5 +230,5 @@ TPipelineFunction VertexLoader_Color::GetFunction(VertexComponentFormat type, Co PanicAlertFmt("Invalid color format {}", format); return nullptr; } - return s_table_read_color[u32(type)][u32(format)]; + return s_table_read_color[type][format]; } diff --git a/Source/Core/VideoCommon/VertexLoader_Normal.cpp b/Source/Core/VideoCommon/VertexLoader_Normal.cpp index a69f78c887..f19f27eda3 100644 --- a/Source/Core/VideoCommon/VertexLoader_Normal.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Normal.cpp @@ -7,6 +7,7 @@ #include #include "Common/CommonTypes.h" +#include "Common/EnumMap.h" #include "VideoCommon/DataReader.h" #include "VideoCommon/VertexLoader.h" @@ -98,39 +99,6 @@ struct Normal_Index_Indices3 static constexpr u32 size = sizeof(I) * 3; }; -enum NormalType -{ - NRM_NOT_PRESENT = 0, - NRM_DIRECT = 1, - NRM_INDEX8 = 2, - NRM_INDEX16 = 3, - NUM_NRM_TYPE -}; - -enum NormalFormat -{ - FORMAT_UBYTE = 0, - FORMAT_BYTE = 1, - FORMAT_USHORT = 2, - FORMAT_SHORT = 3, - FORMAT_FLOAT = 4, - NUM_NRM_FORMAT -}; - -enum NormalElements -{ - NRM_NBT = 0, - NRM_NBT3 = 1, - NUM_NRM_ELEMENTS -}; - -enum NormalIndices -{ - NRM_INDICES1 = 0, - NRM_INDICES3 = 1, - NUM_NRM_INDICES -}; - struct Set { template @@ -145,83 +113,88 @@ struct Set TPipelineFunction function; }; -using Formats = std::array; -using Elements = std::array; -using Indices = std::array; -using Types = std::array; +using Common::EnumMap; +using Formats = EnumMap; +using Elements = EnumMap; +using Indices = std::array; +using Types = EnumMap; constexpr Types InitializeTable() { Types table{}; - table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_UBYTE] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_BYTE] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_USHORT] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_SHORT] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_FLOAT] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES1][NRM_NBT3][FORMAT_UBYTE] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES1][NRM_NBT3][FORMAT_BYTE] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES1][NRM_NBT3][FORMAT_USHORT] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES1][NRM_NBT3][FORMAT_SHORT] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES1][NRM_NBT3][FORMAT_FLOAT] = Normal_Direct(); + using VCF = VertexComponentFormat; + using NCC = NormalComponentCount; + using FMT = ComponentFormat; - // Same as above - table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_UBYTE] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_BYTE] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_USHORT] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_SHORT] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_FLOAT] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_UBYTE] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_BYTE] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_USHORT] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_SHORT] = Normal_Direct(); - table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_FLOAT] = Normal_Direct(); + table[VCF::Direct][false][NCC::N][FMT::UByte] = Normal_Direct(); + table[VCF::Direct][false][NCC::N][FMT::Byte] = Normal_Direct(); + table[VCF::Direct][false][NCC::N][FMT::UShort] = Normal_Direct(); + table[VCF::Direct][false][NCC::N][FMT::Short] = Normal_Direct(); + table[VCF::Direct][false][NCC::N][FMT::Float] = Normal_Direct(); + table[VCF::Direct][false][NCC::NBT][FMT::UByte] = Normal_Direct(); + table[VCF::Direct][false][NCC::NBT][FMT::Byte] = Normal_Direct(); + table[VCF::Direct][false][NCC::NBT][FMT::UShort] = Normal_Direct(); + table[VCF::Direct][false][NCC::NBT][FMT::Short] = Normal_Direct(); + table[VCF::Direct][false][NCC::NBT][FMT::Float] = Normal_Direct(); - table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_UBYTE] = Normal_Index(); - table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_BYTE] = Normal_Index(); - table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_USHORT] = Normal_Index(); - table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_SHORT] = Normal_Index(); - table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_FLOAT] = Normal_Index(); - table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_UBYTE] = Normal_Index(); - table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_BYTE] = Normal_Index(); - table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_USHORT] = Normal_Index(); - table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_SHORT] = Normal_Index(); - table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_FLOAT] = Normal_Index(); + // Same as above, since there are no indices + table[VCF::Direct][true][NCC::N][FMT::UByte] = Normal_Direct(); + table[VCF::Direct][true][NCC::N][FMT::Byte] = Normal_Direct(); + table[VCF::Direct][true][NCC::N][FMT::UShort] = Normal_Direct(); + table[VCF::Direct][true][NCC::N][FMT::Short] = Normal_Direct(); + table[VCF::Direct][true][NCC::N][FMT::Float] = Normal_Direct(); + table[VCF::Direct][true][NCC::NBT][FMT::UByte] = Normal_Direct(); + table[VCF::Direct][true][NCC::NBT][FMT::Byte] = Normal_Direct(); + table[VCF::Direct][true][NCC::NBT][FMT::UShort] = Normal_Direct(); + table[VCF::Direct][true][NCC::NBT][FMT::Short] = Normal_Direct(); + table[VCF::Direct][true][NCC::NBT][FMT::Float] = Normal_Direct(); - // Same as above for NRM_NBT - table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_UBYTE] = Normal_Index(); - table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_BYTE] = Normal_Index(); - table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_USHORT] = Normal_Index(); - table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_SHORT] = Normal_Index(); - table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_FLOAT] = Normal_Index(); - table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_UBYTE] = Normal_Index_Indices3(); - table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_BYTE] = Normal_Index_Indices3(); - table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_USHORT] = Normal_Index_Indices3(); - table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_SHORT] = Normal_Index_Indices3(); - table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_FLOAT] = Normal_Index_Indices3(); + table[VCF::Index8][false][NCC::N][FMT::UByte] = Normal_Index(); + table[VCF::Index8][false][NCC::N][FMT::Byte] = Normal_Index(); + table[VCF::Index8][false][NCC::N][FMT::UShort] = Normal_Index(); + table[VCF::Index8][false][NCC::N][FMT::Short] = Normal_Index(); + table[VCF::Index8][false][NCC::N][FMT::Float] = Normal_Index(); + table[VCF::Index8][false][NCC::NBT][FMT::UByte] = Normal_Index(); + table[VCF::Index8][false][NCC::NBT][FMT::Byte] = Normal_Index(); + table[VCF::Index8][false][NCC::NBT][FMT::UShort] = Normal_Index(); + table[VCF::Index8][false][NCC::NBT][FMT::Short] = Normal_Index(); + table[VCF::Index8][false][NCC::NBT][FMT::Float] = Normal_Index(); - table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_UBYTE] = Normal_Index(); - table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_BYTE] = Normal_Index(); - table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_USHORT] = Normal_Index(); - table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_SHORT] = Normal_Index(); - table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_FLOAT] = Normal_Index(); - table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_UBYTE] = Normal_Index(); - table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_BYTE] = Normal_Index(); - table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_USHORT] = Normal_Index(); - table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_SHORT] = Normal_Index(); - table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_FLOAT] = Normal_Index(); + // Same for NormalComponentCount::N; differs for NBT + table[VCF::Index8][true][NCC::N][FMT::UByte] = Normal_Index(); + table[VCF::Index8][true][NCC::N][FMT::Byte] = Normal_Index(); + table[VCF::Index8][true][NCC::N][FMT::UShort] = Normal_Index(); + table[VCF::Index8][true][NCC::N][FMT::Short] = Normal_Index(); + table[VCF::Index8][true][NCC::N][FMT::Float] = Normal_Index(); + table[VCF::Index8][true][NCC::NBT][FMT::UByte] = Normal_Index_Indices3(); + table[VCF::Index8][true][NCC::NBT][FMT::Byte] = Normal_Index_Indices3(); + table[VCF::Index8][true][NCC::NBT][FMT::UShort] = Normal_Index_Indices3(); + table[VCF::Index8][true][NCC::NBT][FMT::Short] = Normal_Index_Indices3(); + table[VCF::Index8][true][NCC::NBT][FMT::Float] = Normal_Index_Indices3(); - // Same as above for NRM_NBT - table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_UBYTE] = Normal_Index(); - table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_BYTE] = Normal_Index(); - table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_USHORT] = Normal_Index(); - table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_SHORT] = Normal_Index(); - table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_FLOAT] = Normal_Index(); - table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_UBYTE] = Normal_Index_Indices3(); - table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_BYTE] = Normal_Index_Indices3(); - table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_USHORT] = Normal_Index_Indices3(); - table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_SHORT] = Normal_Index_Indices3(); - table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_FLOAT] = Normal_Index_Indices3(); + table[VCF::Index16][false][NCC::N][FMT::UByte] = Normal_Index(); + table[VCF::Index16][false][NCC::N][FMT::Byte] = Normal_Index(); + table[VCF::Index16][false][NCC::N][FMT::UShort] = Normal_Index(); + table[VCF::Index16][false][NCC::N][FMT::Short] = Normal_Index(); + table[VCF::Index16][false][NCC::N][FMT::Float] = Normal_Index(); + table[VCF::Index16][false][NCC::NBT][FMT::UByte] = Normal_Index(); + table[VCF::Index16][false][NCC::NBT][FMT::Byte] = Normal_Index(); + table[VCF::Index16][false][NCC::NBT][FMT::UShort] = Normal_Index(); + table[VCF::Index16][false][NCC::NBT][FMT::Short] = Normal_Index(); + table[VCF::Index16][false][NCC::NBT][FMT::Float] = Normal_Index(); + + // Same for NormalComponentCount::N; differs for NBT + table[VCF::Index16][true][NCC::N][FMT::UByte] = Normal_Index(); + table[VCF::Index16][true][NCC::N][FMT::Byte] = Normal_Index(); + table[VCF::Index16][true][NCC::N][FMT::UShort] = Normal_Index(); + table[VCF::Index16][true][NCC::N][FMT::Short] = Normal_Index(); + table[VCF::Index16][true][NCC::N][FMT::Float] = Normal_Index(); + table[VCF::Index16][true][NCC::NBT][FMT::UByte] = Normal_Index_Indices3(); + table[VCF::Index16][true][NCC::NBT][FMT::Byte] = Normal_Index_Indices3(); + table[VCF::Index16][true][NCC::NBT][FMT::UShort] = Normal_Index_Indices3(); + table[VCF::Index16][true][NCC::NBT][FMT::Short] = Normal_Index_Indices3(); + table[VCF::Index16][true][NCC::NBT][FMT::Float] = Normal_Index_Indices3(); return table; } @@ -230,14 +203,14 @@ constexpr Types s_table = InitializeTable(); } // Anonymous namespace u32 VertexLoader_Normal::GetSize(VertexComponentFormat type, ComponentFormat format, - NormalComponentCount elements, u32 index3) + NormalComponentCount elements, bool index3) { - return s_table[u32(type)][index3][u32(elements)][u32(format)].gc_size; + return s_table[type][index3][elements][format].gc_size; } TPipelineFunction VertexLoader_Normal::GetFunction(VertexComponentFormat type, ComponentFormat format, - NormalComponentCount elements, u32 index3) + NormalComponentCount elements, bool index3) { - return s_table[u32(type)][index3][u32(elements)][u32(format)].function; + return s_table[type][index3][elements][format].function; } diff --git a/Source/Core/VideoCommon/VertexLoader_Normal.h b/Source/Core/VideoCommon/VertexLoader_Normal.h index f416c590c9..30674159fb 100644 --- a/Source/Core/VideoCommon/VertexLoader_Normal.h +++ b/Source/Core/VideoCommon/VertexLoader_Normal.h @@ -14,8 +14,8 @@ class VertexLoader_Normal { public: static u32 GetSize(VertexComponentFormat type, ComponentFormat format, - NormalComponentCount elements, u32 index3); + NormalComponentCount elements, bool index3); static TPipelineFunction GetFunction(VertexComponentFormat type, ComponentFormat format, - NormalComponentCount elements, u32 index3); + NormalComponentCount elements, bool index3); }; diff --git a/Source/Core/VideoCommon/VertexLoader_Position.cpp b/Source/Core/VideoCommon/VertexLoader_Position.cpp index 273cccebc3..37b15de53c 100644 --- a/Source/Core/VideoCommon/VertexLoader_Position.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Position.cpp @@ -7,6 +7,7 @@ #include #include "Common/CommonTypes.h" +#include "Common/EnumMap.h" #include "Common/Swap.h" #include "VideoCommon/DataReader.h" @@ -76,138 +77,109 @@ void Pos_ReadIndex(VertexLoader* loader) LOG_VTX(); } -constexpr TPipelineFunction s_table_read_position[4][8][2] = { - { - { - nullptr, - nullptr, - }, - { - nullptr, - nullptr, - }, - { - nullptr, - nullptr, - }, - { - nullptr, - nullptr, - }, - { - nullptr, - nullptr, - }, - }, - { - { - Pos_ReadDirect, - Pos_ReadDirect, - }, - { - Pos_ReadDirect, - Pos_ReadDirect, - }, - { - Pos_ReadDirect, - Pos_ReadDirect, - }, - { - Pos_ReadDirect, - Pos_ReadDirect, - }, - { - Pos_ReadDirect, - Pos_ReadDirect, - }, - }, - { - { - Pos_ReadIndex, - Pos_ReadIndex, - }, - { - Pos_ReadIndex, - Pos_ReadIndex, - }, - { - Pos_ReadIndex, - Pos_ReadIndex, - }, - { - Pos_ReadIndex, - Pos_ReadIndex, - }, - { - Pos_ReadIndex, - Pos_ReadIndex, - }, - }, - { - { - Pos_ReadIndex, - Pos_ReadIndex, - }, - { - Pos_ReadIndex, - Pos_ReadIndex, - }, - { - Pos_ReadIndex, - Pos_ReadIndex, - }, - { - Pos_ReadIndex, - Pos_ReadIndex, - }, - { - Pos_ReadIndex, - Pos_ReadIndex, - }, - }, +using Common::EnumMap; + +// These functions are to work around a "too many initializer values" error with nested brackets +// C++ does not let you write std::array, 2> a = {{1, 2}, {3, 4}} +// (although it does allow std::array, 2> b = {1, 2, 3, 4}) +constexpr EnumMap e(TPipelineFunction xy, + TPipelineFunction xyz) +{ + return {xy, xyz}; +} +constexpr EnumMap e(u32 xy, u32 xyz) +{ + return {xy, xyz}; +} + +constexpr EnumMap, ComponentFormat::Float> +f(EnumMap, ComponentFormat::Float> in) +{ + return in; +} + +constexpr EnumMap, ComponentFormat::Float> +g(EnumMap, ComponentFormat::Float> in) +{ + return in; +} + +template +using Table = EnumMap, ComponentFormat::Float>, + VertexComponentFormat::Index16>; + +constexpr Table s_table_read_position = { + f({ + e(nullptr, nullptr), + e(nullptr, nullptr), + e(nullptr, nullptr), + e(nullptr, nullptr), + e(nullptr, nullptr), + }), + f({ + e(Pos_ReadDirect, Pos_ReadDirect), + e(Pos_ReadDirect, Pos_ReadDirect), + e(Pos_ReadDirect, Pos_ReadDirect), + e(Pos_ReadDirect, Pos_ReadDirect), + e(Pos_ReadDirect, Pos_ReadDirect), + }), + f({ + e(Pos_ReadIndex, Pos_ReadIndex), + e(Pos_ReadIndex, Pos_ReadIndex), + e(Pos_ReadIndex, Pos_ReadIndex), + e(Pos_ReadIndex, Pos_ReadIndex), + e(Pos_ReadIndex, Pos_ReadIndex), + }), + f({ + e(Pos_ReadIndex, Pos_ReadIndex), + e(Pos_ReadIndex, Pos_ReadIndex), + e(Pos_ReadIndex, Pos_ReadIndex), + e(Pos_ReadIndex, Pos_ReadIndex), + e(Pos_ReadIndex, Pos_ReadIndex), + }), }; -constexpr u32 s_table_read_position_vertex_size[4][8][2] = { - { - {0, 0}, - {0, 0}, - {0, 0}, - {0, 0}, - {0, 0}, - }, - { - {2, 3}, - {2, 3}, - {4, 6}, - {4, 6}, - {8, 12}, - }, - { - {1, 1}, - {1, 1}, - {1, 1}, - {1, 1}, - {1, 1}, - }, - { - {2, 2}, - {2, 2}, - {2, 2}, - {2, 2}, - {2, 2}, - }, +constexpr Table s_table_read_position_vertex_size = { + g({ + e(0u, 0u), + e(0u, 0u), + e(0u, 0u), + e(0u, 0u), + e(0u, 0u), + }), + g({ + e(2, 3), + e(2, 3), + e(4, 6), + e(4, 6), + e(8, 12), + }), + g({ + e(1, 1), + e(1, 1), + e(1, 1), + e(1, 1), + e(1, 1), + }), + g({ + e(2, 2), + e(2, 2), + e(2, 2), + e(2, 2), + e(2, 2), + }), }; } // Anonymous namespace u32 VertexLoader_Position::GetSize(VertexComponentFormat type, ComponentFormat format, CoordComponentCount elements) { - return s_table_read_position_vertex_size[u32(type)][u32(format)][u32(elements)]; + return s_table_read_position_vertex_size[type][format][elements]; } TPipelineFunction VertexLoader_Position::GetFunction(VertexComponentFormat type, ComponentFormat format, CoordComponentCount elements) { - return s_table_read_position[u32(type)][u32(format)][u32(elements)]; + return s_table_read_position[type][format][elements]; } diff --git a/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp b/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp index aa01ab0bf3..f5741f6423 100644 --- a/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp +++ b/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp @@ -67,140 +67,110 @@ void TexCoord_ReadIndex(VertexLoader* loader) ++loader->m_tcIndex; } -constexpr TPipelineFunction s_table_read_tex_coord[4][8][2] = { - { - { - nullptr, - nullptr, - }, - { - nullptr, - nullptr, - }, - { - nullptr, - nullptr, - }, - { - nullptr, - nullptr, - }, - { - nullptr, - nullptr, - }, - }, - { - { - TexCoord_ReadDirect, - TexCoord_ReadDirect, - }, - { - TexCoord_ReadDirect, - TexCoord_ReadDirect, - }, - { - TexCoord_ReadDirect, - TexCoord_ReadDirect, - }, - { - TexCoord_ReadDirect, - TexCoord_ReadDirect, - }, - { - TexCoord_ReadDirect, - TexCoord_ReadDirect, - }, - }, - { - { - TexCoord_ReadIndex, - TexCoord_ReadIndex, - }, - { - TexCoord_ReadIndex, - TexCoord_ReadIndex, - }, - { - TexCoord_ReadIndex, - TexCoord_ReadIndex, - }, - { - TexCoord_ReadIndex, - TexCoord_ReadIndex, - }, - { - TexCoord_ReadIndex, - TexCoord_ReadIndex, - }, - }, - { - { - TexCoord_ReadIndex, - TexCoord_ReadIndex, - }, - { - TexCoord_ReadIndex, - TexCoord_ReadIndex, - }, - { - TexCoord_ReadIndex, - TexCoord_ReadIndex, - }, - { - TexCoord_ReadIndex, - TexCoord_ReadIndex, - }, - { - TexCoord_ReadIndex, - TexCoord_ReadIndex, - }, - }, +using Common::EnumMap; +// These functions are to work around a "too many initializer values" error with nested brackets +// C++ does not let you write std::array, 2> a = {{1, 2}, {3, 4}} +// (although it does allow std::array, 2> b = {1, 2, 3, 4}) +constexpr EnumMap e(TPipelineFunction s, + TPipelineFunction st) +{ + return {s, st}; +} +constexpr EnumMap e(u32 s, u32 st) +{ + return {s, st}; +} + +constexpr EnumMap, ComponentFormat::Float> +f(EnumMap, ComponentFormat::Float> in) +{ + return in; +} + +constexpr EnumMap, ComponentFormat::Float> +g(EnumMap, ComponentFormat::Float> in) +{ + return in; +} + +template +using Table = EnumMap, ComponentFormat::Float>, + VertexComponentFormat::Index16>; + +constexpr Table s_table_read_tex_coord = { + f({ + e(nullptr, nullptr), + e(nullptr, nullptr), + e(nullptr, nullptr), + e(nullptr, nullptr), + e(nullptr, nullptr), + }), + f({ + e(TexCoord_ReadDirect, TexCoord_ReadDirect), + e(TexCoord_ReadDirect, TexCoord_ReadDirect), + e(TexCoord_ReadDirect, TexCoord_ReadDirect), + e(TexCoord_ReadDirect, TexCoord_ReadDirect), + e(TexCoord_ReadDirect, TexCoord_ReadDirect), + }), + f({ + e(TexCoord_ReadIndex, TexCoord_ReadIndex), + e(TexCoord_ReadIndex, TexCoord_ReadIndex), + e(TexCoord_ReadIndex, TexCoord_ReadIndex), + e(TexCoord_ReadIndex, TexCoord_ReadIndex), + e(TexCoord_ReadIndex, TexCoord_ReadIndex), + }), + f({ + e(TexCoord_ReadIndex, TexCoord_ReadIndex), + e(TexCoord_ReadIndex, TexCoord_ReadIndex), + e(TexCoord_ReadIndex, TexCoord_ReadIndex), + e(TexCoord_ReadIndex, TexCoord_ReadIndex), + e(TexCoord_ReadIndex, TexCoord_ReadIndex), + }), }; -constexpr u32 s_table_read_tex_coord_vertex_size[4][8][2] = { - { - {0, 0}, - {0, 0}, - {0, 0}, - {0, 0}, - {0, 0}, - }, - { - {1, 2}, - {1, 2}, - {2, 4}, - {2, 4}, - {4, 8}, - }, - { - {1, 1}, - {1, 1}, - {1, 1}, - {1, 1}, - {1, 1}, - }, - { - {2, 2}, - {2, 2}, - {2, 2}, - {2, 2}, - {2, 2}, - }, +constexpr Table s_table_read_tex_coord_vertex_size = { + g({ + e(0u, 0u), + e(0u, 0u), + e(0u, 0u), + e(0u, 0u), + e(0u, 0u), + }), + g({ + e(1, 2), + e(1, 2), + e(2, 4), + e(2, 4), + e(4, 8), + }), + g({ + e(1, 1), + e(1, 1), + e(1, 1), + e(1, 1), + e(1, 1), + }), + g({ + e(2, 2), + e(2, 2), + e(2, 2), + e(2, 2), + e(2, 2), + }), }; } // Anonymous namespace u32 VertexLoader_TextCoord::GetSize(VertexComponentFormat type, ComponentFormat format, TexComponentCount elements) { - return s_table_read_tex_coord_vertex_size[u32(type)][u32(format)][u32(elements)]; + return s_table_read_tex_coord_vertex_size[type][format][elements]; } TPipelineFunction VertexLoader_TextCoord::GetFunction(VertexComponentFormat type, ComponentFormat format, TexComponentCount elements) { - return s_table_read_tex_coord[u32(type)][u32(format)][u32(elements)]; + return s_table_read_tex_coord[type][format][elements]; } TPipelineFunction VertexLoader_TextCoord::GetDummyFunction()