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_Normal.cpp | 191 ++++++++++-------------- 1 file changed, 82 insertions(+), 109 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoader_Normal.cpp') 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(); - - // 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[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 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[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 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(); + using VCF = VertexComponentFormat; + using NCC = NormalComponentCount; + using FMT = ComponentFormat; + + 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(); + + // 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(); + + 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(); + + // 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(); + + 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; } -- cgit v1.2.3 From 1914087998bc296208355dc4b1b2553430b081b2 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Sun, 20 Jun 2021 13:47:57 -0700 Subject: Create and use CPArray enum class --- Source/Core/VideoCommon/VertexLoader_Normal.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Source/Core/VideoCommon/VertexLoader_Normal.cpp') diff --git a/Source/Core/VideoCommon/VertexLoader_Normal.cpp b/Source/Core/VideoCommon/VertexLoader_Normal.cpp index f19f27eda3..254bcacff3 100644 --- a/Source/Core/VideoCommon/VertexLoader_Normal.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Normal.cpp @@ -59,7 +59,7 @@ struct Normal_Direct { static void function([[maybe_unused]] VertexLoader* loader) { - auto const source = reinterpret_cast(DataGetPosition()); + const auto source = reinterpret_cast(DataGetPosition()); ReadIndirect(source); DataSkip(); } @@ -72,10 +72,10 @@ void Normal_Index_Offset() { static_assert(std::is_unsigned_v, "Only unsigned I is sane!"); - auto const index = DataRead(); - auto const data = reinterpret_cast( - VertexLoaderManager::cached_arraybases[ARRAY_NORMAL] + - (index * g_main_cp_state.array_strides[ARRAY_NORMAL]) + sizeof(T) * 3 * Offset); + const auto index = DataRead(); + const auto data = reinterpret_cast( + VertexLoaderManager::cached_arraybases[CPArray::Normal] + + (index * g_main_cp_state.array_strides[CPArray::Normal]) + sizeof(T) * 3 * Offset); ReadIndirect(data); } -- cgit v1.2.3