From 581a575042c76f6b88509f6b57d14ae6d10081c4 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Tue, 11 Oct 2022 15:41:52 -0700 Subject: [PATCH] VertexLoader: Remove "too many initializer values" workaround functions I originally added these in 2b1d1038a6acf0acf75b03ca93c85de6fe6cdf18, for both the TPipelineFunction and the size. The size was moved into the header in fdcd2b7d009cece6ad090143ce954aed713bb11c (making the size functions obsolete), but it seems that the functions themselves are no longer needed now. I think I didn't use this approach before because it would have required ComponentFormatTable and ComponentCountRow to be templated, which would end up resulting in lines that were too long and thus wrapped in awkward places. (I *think* they didn't get inferred properly.) Now that we only need TPipelineFunction, the templating is not needed, and this ends up being a more readable version of the version with the wrapper functions. --- .../Core/VideoCommon/VertexLoader_Color.cpp | 37 +++------ .../VideoCommon/VertexLoader_Position.cpp | 83 +++++++------------ .../VideoCommon/VertexLoader_TextCoord.cpp | 82 +++++++----------- 3 files changed, 67 insertions(+), 135 deletions(-) diff --git a/Source/Core/VideoCommon/VertexLoader_Color.cpp b/Source/Core/VideoCommon/VertexLoader_Color.cpp index 05a50d9660..fab4177fca 100644 --- a/Source/Core/VideoCommon/VertexLoader_Color.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Color.cpp @@ -176,33 +176,18 @@ void Color_ReadDirect_32b_8888(VertexLoader* loader) SetCol(loader, DataReadU32Unswapped()); } -using Common::EnumMap; +using Row = Common::EnumMap; +using Table = 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 Table s_table_read_color = { + Row(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr), + Row(Color_ReadDirect_16b_565, Color_ReadDirect_24b_888, Color_ReadDirect_32b_888x, + Color_ReadDirect_16b_4444, Color_ReadDirect_24b_6666, Color_ReadDirect_32b_8888), + Row(Color_ReadIndex_16b_565, Color_ReadIndex_24b_888, Color_ReadIndex_32b_888x, + Color_ReadIndex_16b_4444, Color_ReadIndex_24b_6666, Color_ReadIndex_32b_8888), + Row(Color_ReadIndex_16b_565, Color_ReadIndex_24b_888, Color_ReadIndex_32b_888x, + Color_ReadIndex_16b_4444, Color_ReadIndex_24b_6666, + Color_ReadIndex_32b_8888), }; } // Anonymous namespace diff --git a/Source/Core/VideoCommon/VertexLoader_Position.cpp b/Source/Core/VideoCommon/VertexLoader_Position.cpp index a568518798..92583e0726 100644 --- a/Source/Core/VideoCommon/VertexLoader_Position.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Position.cpp @@ -77,65 +77,38 @@ void Pos_ReadIndex(VertexLoader* loader) LOG_VTX(); } -using Common::EnumMap; +using ComponentCountRow = Common::EnumMap; +using ComponentFormatTable = Common::EnumMap; +using Table = 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), +constexpr Table s_table_read_position = { + ComponentFormatTable({ + ComponentCountRow(nullptr, nullptr), + ComponentCountRow(nullptr, nullptr), + ComponentCountRow(nullptr, nullptr), + ComponentCountRow(nullptr, nullptr), + ComponentCountRow(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), + ComponentFormatTable({ + ComponentCountRow(Pos_ReadDirect, Pos_ReadDirect), + ComponentCountRow(Pos_ReadDirect, Pos_ReadDirect), + ComponentCountRow(Pos_ReadDirect, Pos_ReadDirect), + ComponentCountRow(Pos_ReadDirect, Pos_ReadDirect), + ComponentCountRow(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), + ComponentFormatTable({ + ComponentCountRow(Pos_ReadIndex, Pos_ReadIndex), + ComponentCountRow(Pos_ReadIndex, Pos_ReadIndex), + ComponentCountRow(Pos_ReadIndex, Pos_ReadIndex), + ComponentCountRow(Pos_ReadIndex, Pos_ReadIndex), + ComponentCountRow(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), + ComponentFormatTable({ + ComponentCountRow(Pos_ReadIndex, Pos_ReadIndex), + ComponentCountRow(Pos_ReadIndex, Pos_ReadIndex), + ComponentCountRow(Pos_ReadIndex, Pos_ReadIndex), + ComponentCountRow(Pos_ReadIndex, Pos_ReadIndex), + ComponentCountRow(Pos_ReadIndex, Pos_ReadIndex), }), }; } // Anonymous namespace diff --git a/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp b/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp index 8b2bbf5560..abe8d36fc4 100644 --- a/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp +++ b/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp @@ -67,64 +67,38 @@ void TexCoord_ReadIndex(VertexLoader* loader) ++loader->m_tcIndex; } -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}; -} +using ComponentCountRow = Common::EnumMap; +using ComponentFormatTable = Common::EnumMap; +using Table = Common::EnumMap; -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), +constexpr Table s_table_read_tex_coord = { + ComponentFormatTable({ + ComponentCountRow(nullptr, nullptr), + ComponentCountRow(nullptr, nullptr), + ComponentCountRow(nullptr, nullptr), + ComponentCountRow(nullptr, nullptr), + ComponentCountRow(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), + ComponentFormatTable({ + ComponentCountRow(TexCoord_ReadDirect, TexCoord_ReadDirect), + ComponentCountRow(TexCoord_ReadDirect, TexCoord_ReadDirect), + ComponentCountRow(TexCoord_ReadDirect, TexCoord_ReadDirect), + ComponentCountRow(TexCoord_ReadDirect, TexCoord_ReadDirect), + ComponentCountRow(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), + ComponentFormatTable({ + ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), + ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), + ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), + ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), + ComponentCountRow(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), + ComponentFormatTable({ + ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), + ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), + ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), + ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), + ComponentCountRow(TexCoord_ReadIndex, TexCoord_ReadIndex), }), }; } // Anonymous namespace