diff --git a/Source/Core/VideoCommon/VertexLoaderBase.cpp b/Source/Core/VideoCommon/VertexLoaderBase.cpp index 678246783d..bf4e364147 100644 --- a/Source/Core/VideoCommon/VertexLoaderBase.cpp +++ b/Source/Core/VideoCommon/VertexLoaderBase.cpp @@ -12,6 +12,7 @@ #include #include "Common/Assert.h" +#include "Common/BitSet.h" #include "Common/CommonTypes.h" #include "Common/Logging/Log.h" #include "Common/MsgHandler.h" @@ -96,45 +97,33 @@ private: std::vector buffer_b; }; -template -static void GetComponentSizes(const TVtxDesc& vtx_desc, const VAT& vtx_attr, Function f) +u32 VertexLoaderBase::GetVertexSize(const TVtxDesc& vtx_desc, const VAT& vtx_attr) { - if (vtx_desc.low.PosMatIdx) - f(1); - for (auto texmtxidx : vtx_desc.low.TexMatIdx) - { - if (texmtxidx) - f(1); - } + u32 size = 0; + + // Each enabled TexMatIdx adds one byte, as does PosMatIdx + size += Common::CountSetBits(vtx_desc.low.Hex & 0x1FF); + const u32 pos_size = VertexLoader_Position::GetSize(vtx_desc.low.Position, vtx_attr.g0.PosFormat, vtx_attr.g0.PosElements); - if (pos_size != 0) - f(pos_size); + size += pos_size; const u32 norm_size = VertexLoader_Normal::GetSize(vtx_desc.low.Normal, vtx_attr.g0.NormalFormat, vtx_attr.g0.NormalElements, vtx_attr.g0.NormalIndex3); - if (norm_size != 0) - f(norm_size); + size += norm_size; for (u32 i = 0; i < vtx_desc.low.Color.Size(); i++) { const u32 color_size = VertexLoader_Color::GetSize(vtx_desc.low.Color[i], vtx_attr.GetColorFormat(i)); - if (color_size != 0) - f(color_size); + size += color_size; } for (u32 i = 0; i < vtx_desc.high.TexCoord.Size(); i++) { const u32 tc_size = VertexLoader_TextCoord::GetSize( vtx_desc.high.TexCoord[i], vtx_attr.GetTexFormat(i), vtx_attr.GetTexElements(i)); - if (tc_size != 0) - f(tc_size); + size += tc_size; } -} -u32 VertexLoaderBase::GetVertexSize(const TVtxDesc& vtx_desc, const VAT& vtx_attr) -{ - u32 size = 0; - GetComponentSizes(vtx_desc, vtx_attr, [&size](u32 s) { size += s; }); return size; } @@ -168,14 +157,6 @@ u32 VertexLoaderBase::GetVertexComponents(const TVtxDesc& vtx_desc, const VAT& v return components; } -std::vector VertexLoaderBase::GetVertexComponentSizes(const TVtxDesc& vtx_desc, - const VAT& vtx_attr) -{ - std::vector sizes; - GetComponentSizes(vtx_desc, vtx_attr, [&sizes](u32 s) { sizes.push_back(s); }); - return sizes; -} - std::unique_ptr VertexLoaderBase::CreateVertexLoader(const TVtxDesc& vtx_desc, const VAT& vtx_attr) { diff --git a/Source/Core/VideoCommon/VertexLoaderBase.h b/Source/Core/VideoCommon/VertexLoaderBase.h index 26ec5c6026..11e9136251 100644 --- a/Source/Core/VideoCommon/VertexLoaderBase.h +++ b/Source/Core/VideoCommon/VertexLoaderBase.h @@ -62,7 +62,6 @@ class VertexLoaderBase public: static u32 GetVertexSize(const TVtxDesc& vtx_desc, const VAT& vtx_attr); static u32 GetVertexComponents(const TVtxDesc& vtx_desc, const VAT& vtx_attr); - static std::vector GetVertexComponentSizes(const TVtxDesc& vtx_desc, const VAT& vtx_attr); static std::unique_ptr CreateVertexLoader(const TVtxDesc& vtx_desc, const VAT& vtx_attr); virtual ~VertexLoaderBase() {} diff --git a/Source/Core/VideoCommon/VertexLoader_Color.cpp b/Source/Core/VideoCommon/VertexLoader_Color.cpp index b41272cbf1..05a50d9660 100644 --- a/Source/Core/VideoCommon/VertexLoader_Color.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Color.cpp @@ -205,24 +205,8 @@ constexpr Table s_table_read_color = { Color_ReadIndex_32b_8888}), }; -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 -u32 VertexLoader_Color::GetSize(VertexComponentFormat type, ColorFormat format) -{ - if (format > ColorFormat::RGBA8888) - { - PanicAlertFmt("Invalid color format {}", format); - return 0; - } - return s_table_read_color_vertex_size[type][format]; -} - TPipelineFunction VertexLoader_Color::GetFunction(VertexComponentFormat type, ColorFormat format) { if (format > ColorFormat::RGBA8888) diff --git a/Source/Core/VideoCommon/VertexLoader_Color.h b/Source/Core/VideoCommon/VertexLoader_Color.h index a3c631ff1f..0e66bfbf86 100644 --- a/Source/Core/VideoCommon/VertexLoader_Color.h +++ b/Source/Core/VideoCommon/VertexLoader_Color.h @@ -4,14 +4,44 @@ #pragma once #include "Common/CommonTypes.h" -#include "VideoCommon/VertexLoader.h" +#include "Common/EnumMap.h" +#include "Common/Inline.h" -enum class VertexComponentFormat; -enum class ColorFormat; +#include "VideoCommon/CPMemory.h" +#include "VideoCommon/VertexLoader.h" class VertexLoader_Color { public: - static u32 GetSize(VertexComponentFormat type, ColorFormat format); + static DOLPHIN_FORCE_INLINE u32 GetSize(VertexComponentFormat type, ColorFormat format) + { + if (format > ColorFormat::RGBA8888) + { + PanicAlertFmt("Invalid color format {}", format); + return 0; + } + return s_table_size[type][format]; + } + static TPipelineFunction GetFunction(VertexComponentFormat type, ColorFormat format); + +private: + template + using EnumMap = typename Common::EnumMap; + + using SizeTable = EnumMap, VertexComponentFormat::Index16>; + + static constexpr SizeTable s_table_size = []() consteval + { + SizeTable table{}; + + using VCF = VertexComponentFormat; + + table[VCF::Direct] = {2u, 3u, 4u, 2u, 3u, 4u}; + table[VCF::Index8] = {1u, 1u, 1u, 1u, 1u, 1u}; + table[VCF::Index16] = {2u, 2u, 2u, 2u, 2u, 2u}; + + return table; + } + (); }; diff --git a/Source/Core/VideoCommon/VertexLoader_Normal.cpp b/Source/Core/VideoCommon/VertexLoader_Normal.cpp index 6813e4128c..3b685e0ca4 100644 --- a/Source/Core/VideoCommon/VertexLoader_Normal.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Normal.cpp @@ -63,20 +63,15 @@ void ReadIndirect(VertexLoader* loader, const T* data) } template -struct Normal_Direct +void Normal_ReadDirect(VertexLoader* loader) { - static void function(VertexLoader* loader) - { - const auto source = reinterpret_cast(DataGetPosition()); - ReadIndirect(loader, source); - DataSkip(); - } - - static constexpr u32 size = sizeof(T) * N * 3; -}; + const auto source = reinterpret_cast(DataGetPosition()); + ReadIndirect(loader, source); + DataSkip(); +} template -void Normal_Index_Offset(VertexLoader* loader) +void Normal_ReadIndex_Offset(VertexLoader* loader) { static_assert(std::is_unsigned_v, "Only unsigned I is sane!"); @@ -88,46 +83,26 @@ void Normal_Index_Offset(VertexLoader* loader) } template -struct Normal_Index +void Normal_ReadIndex(VertexLoader* loader) { - static void function(VertexLoader* loader) { Normal_Index_Offset(loader); } - static constexpr u32 size = sizeof(I); -}; + Normal_ReadIndex_Offset(loader); +} template -struct Normal_Index_Indices3 +void Normal_ReadIndex_Indices3(VertexLoader* loader) { - static void function(VertexLoader* loader) - { - Normal_Index_Offset(loader); - Normal_Index_Offset(loader); - Normal_Index_Offset(loader); - } - - static constexpr u32 size = sizeof(I) * 3; -}; - -struct Set -{ - template - constexpr Set& operator=(const T&) - { - gc_size = T::size; - function = T::function; - return *this; - } - - u32 gc_size; - TPipelineFunction function; -}; + Normal_ReadIndex_Offset(loader); + Normal_ReadIndex_Offset(loader); + Normal_ReadIndex_Offset(loader); +} using Common::EnumMap; -using Formats = EnumMap; +using Formats = EnumMap; using Elements = EnumMap; using Indices = std::array; using Types = EnumMap; -constexpr Types InitializeTable() +consteval Types InitializeTable() { Types table{}; @@ -135,90 +110,84 @@ constexpr Types InitializeTable() 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::NTB][FMT::UByte] = Normal_Direct(); - table[VCF::Direct][false][NCC::NTB][FMT::Byte] = Normal_Direct(); - table[VCF::Direct][false][NCC::NTB][FMT::UShort] = Normal_Direct(); - table[VCF::Direct][false][NCC::NTB][FMT::Short] = Normal_Direct(); - table[VCF::Direct][false][NCC::NTB][FMT::Float] = Normal_Direct(); + table[VCF::Direct][false][NCC::N][FMT::UByte] = Normal_ReadDirect; + table[VCF::Direct][false][NCC::N][FMT::Byte] = Normal_ReadDirect; + table[VCF::Direct][false][NCC::N][FMT::UShort] = Normal_ReadDirect; + table[VCF::Direct][false][NCC::N][FMT::Short] = Normal_ReadDirect; + table[VCF::Direct][false][NCC::N][FMT::Float] = Normal_ReadDirect; + table[VCF::Direct][false][NCC::NTB][FMT::UByte] = Normal_ReadDirect; + table[VCF::Direct][false][NCC::NTB][FMT::Byte] = Normal_ReadDirect; + table[VCF::Direct][false][NCC::NTB][FMT::UShort] = Normal_ReadDirect; + table[VCF::Direct][false][NCC::NTB][FMT::Short] = Normal_ReadDirect; + table[VCF::Direct][false][NCC::NTB][FMT::Float] = Normal_ReadDirect; // 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::NTB][FMT::UByte] = Normal_Direct(); - table[VCF::Direct][true][NCC::NTB][FMT::Byte] = Normal_Direct(); - table[VCF::Direct][true][NCC::NTB][FMT::UShort] = Normal_Direct(); - table[VCF::Direct][true][NCC::NTB][FMT::Short] = Normal_Direct(); - table[VCF::Direct][true][NCC::NTB][FMT::Float] = Normal_Direct(); + table[VCF::Direct][true][NCC::N][FMT::UByte] = Normal_ReadDirect; + table[VCF::Direct][true][NCC::N][FMT::Byte] = Normal_ReadDirect; + table[VCF::Direct][true][NCC::N][FMT::UShort] = Normal_ReadDirect; + table[VCF::Direct][true][NCC::N][FMT::Short] = Normal_ReadDirect; + table[VCF::Direct][true][NCC::N][FMT::Float] = Normal_ReadDirect; + table[VCF::Direct][true][NCC::NTB][FMT::UByte] = Normal_ReadDirect; + table[VCF::Direct][true][NCC::NTB][FMT::Byte] = Normal_ReadDirect; + table[VCF::Direct][true][NCC::NTB][FMT::UShort] = Normal_ReadDirect; + table[VCF::Direct][true][NCC::NTB][FMT::Short] = Normal_ReadDirect; + table[VCF::Direct][true][NCC::NTB][FMT::Float] = Normal_ReadDirect; - 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::NTB][FMT::UByte] = Normal_Index(); - table[VCF::Index8][false][NCC::NTB][FMT::Byte] = Normal_Index(); - table[VCF::Index8][false][NCC::NTB][FMT::UShort] = Normal_Index(); - table[VCF::Index8][false][NCC::NTB][FMT::Short] = Normal_Index(); - table[VCF::Index8][false][NCC::NTB][FMT::Float] = Normal_Index(); + table[VCF::Index8][false][NCC::N][FMT::UByte] = Normal_ReadIndex; + table[VCF::Index8][false][NCC::N][FMT::Byte] = Normal_ReadIndex; + table[VCF::Index8][false][NCC::N][FMT::UShort] = Normal_ReadIndex; + table[VCF::Index8][false][NCC::N][FMT::Short] = Normal_ReadIndex; + table[VCF::Index8][false][NCC::N][FMT::Float] = Normal_ReadIndex; + table[VCF::Index8][false][NCC::NTB][FMT::UByte] = Normal_ReadIndex; + table[VCF::Index8][false][NCC::NTB][FMT::Byte] = Normal_ReadIndex; + table[VCF::Index8][false][NCC::NTB][FMT::UShort] = Normal_ReadIndex; + table[VCF::Index8][false][NCC::NTB][FMT::Short] = Normal_ReadIndex; + table[VCF::Index8][false][NCC::NTB][FMT::Float] = Normal_ReadIndex; // Same for NormalComponentCount::N; differs for NTB - 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::NTB][FMT::UByte] = Normal_Index_Indices3(); - table[VCF::Index8][true][NCC::NTB][FMT::Byte] = Normal_Index_Indices3(); - table[VCF::Index8][true][NCC::NTB][FMT::UShort] = Normal_Index_Indices3(); - table[VCF::Index8][true][NCC::NTB][FMT::Short] = Normal_Index_Indices3(); - table[VCF::Index8][true][NCC::NTB][FMT::Float] = Normal_Index_Indices3(); + table[VCF::Index8][true][NCC::N][FMT::UByte] = Normal_ReadIndex; + table[VCF::Index8][true][NCC::N][FMT::Byte] = Normal_ReadIndex; + table[VCF::Index8][true][NCC::N][FMT::UShort] = Normal_ReadIndex; + table[VCF::Index8][true][NCC::N][FMT::Short] = Normal_ReadIndex; + table[VCF::Index8][true][NCC::N][FMT::Float] = Normal_ReadIndex; + table[VCF::Index8][true][NCC::NTB][FMT::UByte] = Normal_ReadIndex_Indices3; + table[VCF::Index8][true][NCC::NTB][FMT::Byte] = Normal_ReadIndex_Indices3; + table[VCF::Index8][true][NCC::NTB][FMT::UShort] = Normal_ReadIndex_Indices3; + table[VCF::Index8][true][NCC::NTB][FMT::Short] = Normal_ReadIndex_Indices3; + table[VCF::Index8][true][NCC::NTB][FMT::Float] = Normal_ReadIndex_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::NTB][FMT::UByte] = Normal_Index(); - table[VCF::Index16][false][NCC::NTB][FMT::Byte] = Normal_Index(); - table[VCF::Index16][false][NCC::NTB][FMT::UShort] = Normal_Index(); - table[VCF::Index16][false][NCC::NTB][FMT::Short] = Normal_Index(); - table[VCF::Index16][false][NCC::NTB][FMT::Float] = Normal_Index(); + table[VCF::Index16][false][NCC::N][FMT::UByte] = Normal_ReadIndex; + table[VCF::Index16][false][NCC::N][FMT::Byte] = Normal_ReadIndex; + table[VCF::Index16][false][NCC::N][FMT::UShort] = Normal_ReadIndex; + table[VCF::Index16][false][NCC::N][FMT::Short] = Normal_ReadIndex; + table[VCF::Index16][false][NCC::N][FMT::Float] = Normal_ReadIndex; + table[VCF::Index16][false][NCC::NTB][FMT::UByte] = Normal_ReadIndex; + table[VCF::Index16][false][NCC::NTB][FMT::Byte] = Normal_ReadIndex; + table[VCF::Index16][false][NCC::NTB][FMT::UShort] = Normal_ReadIndex; + table[VCF::Index16][false][NCC::NTB][FMT::Short] = Normal_ReadIndex; + table[VCF::Index16][false][NCC::NTB][FMT::Float] = Normal_ReadIndex; // Same for NormalComponentCount::N; differs for NTB - 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::NTB][FMT::UByte] = Normal_Index_Indices3(); - table[VCF::Index16][true][NCC::NTB][FMT::Byte] = Normal_Index_Indices3(); - table[VCF::Index16][true][NCC::NTB][FMT::UShort] = Normal_Index_Indices3(); - table[VCF::Index16][true][NCC::NTB][FMT::Short] = Normal_Index_Indices3(); - table[VCF::Index16][true][NCC::NTB][FMT::Float] = Normal_Index_Indices3(); + table[VCF::Index16][true][NCC::N][FMT::UByte] = Normal_ReadIndex; + table[VCF::Index16][true][NCC::N][FMT::Byte] = Normal_ReadIndex; + table[VCF::Index16][true][NCC::N][FMT::UShort] = Normal_ReadIndex; + table[VCF::Index16][true][NCC::N][FMT::Short] = Normal_ReadIndex; + table[VCF::Index16][true][NCC::N][FMT::Float] = Normal_ReadIndex; + table[VCF::Index16][true][NCC::NTB][FMT::UByte] = Normal_ReadIndex_Indices3; + table[VCF::Index16][true][NCC::NTB][FMT::Byte] = Normal_ReadIndex_Indices3; + table[VCF::Index16][true][NCC::NTB][FMT::UShort] = Normal_ReadIndex_Indices3; + table[VCF::Index16][true][NCC::NTB][FMT::Short] = Normal_ReadIndex_Indices3; + table[VCF::Index16][true][NCC::NTB][FMT::Float] = Normal_ReadIndex_Indices3; return table; } -constexpr Types s_table = InitializeTable(); +constexpr Types s_table_read_normal = InitializeTable(); } // Anonymous namespace -u32 VertexLoader_Normal::GetSize(VertexComponentFormat type, ComponentFormat format, - NormalComponentCount elements, bool index3) -{ - return s_table[type][index3][elements][format].gc_size; -} - TPipelineFunction VertexLoader_Normal::GetFunction(VertexComponentFormat type, ComponentFormat format, NormalComponentCount elements, bool index3) { - return s_table[type][index3][elements][format].function; + return s_table_read_normal[type][index3][elements][format]; } diff --git a/Source/Core/VideoCommon/VertexLoader_Normal.h b/Source/Core/VideoCommon/VertexLoader_Normal.h index 30674159fb..b5200dc875 100644 --- a/Source/Core/VideoCommon/VertexLoader_Normal.h +++ b/Source/Core/VideoCommon/VertexLoader_Normal.h @@ -4,18 +4,110 @@ #pragma once #include "Common/CommonTypes.h" -#include "VideoCommon/VertexLoader.h" +#include "Common/EnumMap.h" +#include "Common/Inline.h" -enum class VertexComponentFormat; -enum class ComponentFormat; -enum class NormalComponentCount; +#include "VideoCommon/CPMemory.h" +#include "VideoCommon/VertexLoader.h" class VertexLoader_Normal { public: - static u32 GetSize(VertexComponentFormat type, ComponentFormat format, - NormalComponentCount elements, bool index3); + static DOLPHIN_FORCE_INLINE u32 GetSize(VertexComponentFormat type, ComponentFormat format, + NormalComponentCount elements, bool index3) + { + return s_table_size[type][index3][elements][format]; + } static TPipelineFunction GetFunction(VertexComponentFormat type, ComponentFormat format, NormalComponentCount elements, bool index3); + +private: + template + using EnumMap = typename Common::EnumMap; + + using SizeTable = EnumMap< + std::array, NormalComponentCount::NTB>, 2>, + VertexComponentFormat::Index16>; + + static constexpr SizeTable s_table_size = []() consteval + { + SizeTable table{}; + + using VCF = VertexComponentFormat; + using NCC = NormalComponentCount; + using FMT = ComponentFormat; + + table[VCF::Direct][false][NCC::N][FMT::UByte] = 3; + table[VCF::Direct][false][NCC::N][FMT::Byte] = 3; + table[VCF::Direct][false][NCC::N][FMT::UShort] = 6; + table[VCF::Direct][false][NCC::N][FMT::Short] = 6; + table[VCF::Direct][false][NCC::N][FMT::Float] = 12; + table[VCF::Direct][false][NCC::NTB][FMT::UByte] = 9; + table[VCF::Direct][false][NCC::NTB][FMT::Byte] = 9; + table[VCF::Direct][false][NCC::NTB][FMT::UShort] = 18; + table[VCF::Direct][false][NCC::NTB][FMT::Short] = 18; + table[VCF::Direct][false][NCC::NTB][FMT::Float] = 36; + + // Same as above, since there are no indices + table[VCF::Direct][true][NCC::N][FMT::UByte] = 3; + table[VCF::Direct][true][NCC::N][FMT::Byte] = 3; + table[VCF::Direct][true][NCC::N][FMT::UShort] = 6; + table[VCF::Direct][true][NCC::N][FMT::Short] = 6; + table[VCF::Direct][true][NCC::N][FMT::Float] = 12; + table[VCF::Direct][true][NCC::NTB][FMT::UByte] = 9; + table[VCF::Direct][true][NCC::NTB][FMT::Byte] = 9; + table[VCF::Direct][true][NCC::NTB][FMT::UShort] = 18; + table[VCF::Direct][true][NCC::NTB][FMT::Short] = 18; + table[VCF::Direct][true][NCC::NTB][FMT::Float] = 36; + + table[VCF::Index8][false][NCC::N][FMT::UByte] = 1; + table[VCF::Index8][false][NCC::N][FMT::Byte] = 1; + table[VCF::Index8][false][NCC::N][FMT::UShort] = 1; + table[VCF::Index8][false][NCC::N][FMT::Short] = 1; + table[VCF::Index8][false][NCC::N][FMT::Float] = 1; + table[VCF::Index8][false][NCC::NTB][FMT::UByte] = 1; + table[VCF::Index8][false][NCC::NTB][FMT::Byte] = 1; + table[VCF::Index8][false][NCC::NTB][FMT::UShort] = 1; + table[VCF::Index8][false][NCC::NTB][FMT::Short] = 1; + table[VCF::Index8][false][NCC::NTB][FMT::Float] = 1; + + // Same for NormalComponentCount::N; differs for NTB + table[VCF::Index8][true][NCC::N][FMT::UByte] = 1; + table[VCF::Index8][true][NCC::N][FMT::Byte] = 1; + table[VCF::Index8][true][NCC::N][FMT::UShort] = 1; + table[VCF::Index8][true][NCC::N][FMT::Short] = 1; + table[VCF::Index8][true][NCC::N][FMT::Float] = 1; + table[VCF::Index8][true][NCC::NTB][FMT::UByte] = 3; + table[VCF::Index8][true][NCC::NTB][FMT::Byte] = 3; + table[VCF::Index8][true][NCC::NTB][FMT::UShort] = 3; + table[VCF::Index8][true][NCC::NTB][FMT::Short] = 3; + table[VCF::Index8][true][NCC::NTB][FMT::Float] = 3; + + table[VCF::Index16][false][NCC::N][FMT::UByte] = 2; + table[VCF::Index16][false][NCC::N][FMT::Byte] = 2; + table[VCF::Index16][false][NCC::N][FMT::UShort] = 2; + table[VCF::Index16][false][NCC::N][FMT::Short] = 2; + table[VCF::Index16][false][NCC::N][FMT::Float] = 2; + table[VCF::Index16][false][NCC::NTB][FMT::UByte] = 2; + table[VCF::Index16][false][NCC::NTB][FMT::Byte] = 2; + table[VCF::Index16][false][NCC::NTB][FMT::UShort] = 2; + table[VCF::Index16][false][NCC::NTB][FMT::Short] = 2; + table[VCF::Index16][false][NCC::NTB][FMT::Float] = 2; + + // Same for NormalComponentCount::N; differs for NTB + table[VCF::Index16][true][NCC::N][FMT::UByte] = 2; + table[VCF::Index16][true][NCC::N][FMT::Byte] = 2; + table[VCF::Index16][true][NCC::N][FMT::UShort] = 2; + table[VCF::Index16][true][NCC::N][FMT::Short] = 2; + table[VCF::Index16][true][NCC::N][FMT::Float] = 2; + table[VCF::Index16][true][NCC::NTB][FMT::UByte] = 6; + table[VCF::Index16][true][NCC::NTB][FMT::Byte] = 6; + table[VCF::Index16][true][NCC::NTB][FMT::UShort] = 6; + table[VCF::Index16][true][NCC::NTB][FMT::Short] = 6; + table[VCF::Index16][true][NCC::NTB][FMT::Float] = 6; + + return table; + } + (); }; diff --git a/Source/Core/VideoCommon/VertexLoader_Position.cpp b/Source/Core/VideoCommon/VertexLoader_Position.cpp index 15d2f6d94e..a568518798 100644 --- a/Source/Core/VideoCommon/VertexLoader_Position.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Position.cpp @@ -138,45 +138,8 @@ constexpr Table s_table_read_position = { e(Pos_ReadIndex, Pos_ReadIndex), }), }; - -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[type][format][elements]; -} - TPipelineFunction VertexLoader_Position::GetFunction(VertexComponentFormat type, ComponentFormat format, CoordComponentCount elements) diff --git a/Source/Core/VideoCommon/VertexLoader_Position.h b/Source/Core/VideoCommon/VertexLoader_Position.h index 59bfe99da4..da095419fd 100644 --- a/Source/Core/VideoCommon/VertexLoader_Position.h +++ b/Source/Core/VideoCommon/VertexLoader_Position.h @@ -4,18 +4,57 @@ #pragma once #include "Common/CommonTypes.h" -#include "VideoCommon/VertexLoader.h" +#include "Common/EnumMap.h" +#include "Common/Inline.h" -enum class VertexComponentFormat; -enum class ComponentFormat; -enum class CoordComponentCount; +#include "VideoCommon/CPMemory.h" +#include "VideoCommon/VertexLoader.h" class VertexLoader_Position { public: - static u32 GetSize(VertexComponentFormat type, ComponentFormat format, - CoordComponentCount elements); + static DOLPHIN_FORCE_INLINE u32 GetSize(VertexComponentFormat type, ComponentFormat format, + CoordComponentCount elements) + { + return s_table_size[type][format][elements]; + } static TPipelineFunction GetFunction(VertexComponentFormat type, ComponentFormat format, CoordComponentCount elements); + +private: + template + using EnumMap = typename Common::EnumMap; + + using SizeTable = EnumMap, ComponentFormat::Float>, + VertexComponentFormat::Index16>; + + static constexpr SizeTable s_table_size = []() consteval + { + SizeTable table{}; + + using VCF = VertexComponentFormat; + using FMT = ComponentFormat; + + table[VCF::Direct][FMT::UByte] = {2, 3}; + table[VCF::Direct][FMT::Byte] = {2, 3}; + table[VCF::Direct][FMT::UShort] = {4, 6}; + table[VCF::Direct][FMT::Short] = {4, 6}; + table[VCF::Direct][FMT::Float] = {8, 12}; + + table[VCF::Index8][FMT::UByte] = {1, 1}; + table[VCF::Index8][FMT::Byte] = {1, 1}; + table[VCF::Index8][FMT::UShort] = {1, 1}; + table[VCF::Index8][FMT::Short] = {1, 1}; + table[VCF::Index8][FMT::Float] = {1, 1}; + + table[VCF::Index16][FMT::UByte] = {2, 2}; + table[VCF::Index16][FMT::Byte] = {2, 2}; + table[VCF::Index16][FMT::UShort] = {2, 2}; + table[VCF::Index16][FMT::Short] = {2, 2}; + table[VCF::Index16][FMT::Float] = {2, 2}; + + return table; + } + (); }; diff --git a/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp b/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp index 89891df5a8..8b2bbf5560 100644 --- a/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp +++ b/Source/Core/VideoCommon/VertexLoader_TextCoord.cpp @@ -127,45 +127,8 @@ constexpr Table s_table_read_tex_coord = { e(TexCoord_ReadIndex, TexCoord_ReadIndex), }), }; - -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[type][format][elements]; -} - TPipelineFunction VertexLoader_TextCoord::GetFunction(VertexComponentFormat type, ComponentFormat format, TexComponentCount elements) diff --git a/Source/Core/VideoCommon/VertexLoader_TextCoord.h b/Source/Core/VideoCommon/VertexLoader_TextCoord.h index e2dac72021..9041185490 100644 --- a/Source/Core/VideoCommon/VertexLoader_TextCoord.h +++ b/Source/Core/VideoCommon/VertexLoader_TextCoord.h @@ -4,21 +4,60 @@ #pragma once #include "Common/CommonTypes.h" -#include "VideoCommon/VertexLoader.h" +#include "Common/EnumMap.h" +#include "Common/Inline.h" -enum class VertexComponentFormat; -enum class ComponentFormat; -enum class TexComponentCount; +#include "VideoCommon/CPMemory.h" +#include "VideoCommon/VertexLoader.h" class VertexLoader_TextCoord { public: - static u32 GetSize(VertexComponentFormat type, ComponentFormat format, - TexComponentCount elements); + static DOLPHIN_FORCE_INLINE u32 GetSize(VertexComponentFormat type, ComponentFormat format, + TexComponentCount elements) + { + return s_table_size[type][format][elements]; + } static TPipelineFunction GetFunction(VertexComponentFormat type, ComponentFormat format, TexComponentCount elements); // It is important to synchronize tcIndex. static TPipelineFunction GetDummyFunction(); + +private: + template + using EnumMap = typename Common::EnumMap; + + using SizeTable = EnumMap, ComponentFormat::Float>, + VertexComponentFormat::Index16>; + + static constexpr SizeTable s_table_size = []() consteval + { + SizeTable table{}; + + using VCF = VertexComponentFormat; + using FMT = ComponentFormat; + + table[VCF::Direct][FMT::UByte] = {1, 2}; + table[VCF::Direct][FMT::Byte] = {1, 2}; + table[VCF::Direct][FMT::UShort] = {2, 4}; + table[VCF::Direct][FMT::Short] = {2, 4}; + table[VCF::Direct][FMT::Float] = {4, 8}; + + table[VCF::Index8][FMT::UByte] = {1, 1}; + table[VCF::Index8][FMT::Byte] = {1, 1}; + table[VCF::Index8][FMT::UShort] = {1, 1}; + table[VCF::Index8][FMT::Short] = {1, 1}; + table[VCF::Index8][FMT::Float] = {1, 1}; + + table[VCF::Index16][FMT::UByte] = {2, 2}; + table[VCF::Index16][FMT::Byte] = {2, 2}; + table[VCF::Index16][FMT::UShort] = {2, 2}; + table[VCF::Index16][FMT::Short] = {2, 2}; + table[VCF::Index16][FMT::Float] = {2, 2}; + + return table; + } + (); };