From 2b1d1038a6acf0acf75b03ca93c85de6fe6cdf18 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Sun, 25 Apr 2021 16:04:13 -0700 Subject: VertexLoader: Convert to EnumMap --- Source/Core/VideoCommon/VertexLoader_Position.cpp | 212 ++++++++++------------ 1 file changed, 92 insertions(+), 120 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoader_Position.cpp') 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]; } -- cgit v1.2.3