VertexLoader: Convert to EnumMap

This commit is contained in:
Pokechu22 2021-04-25 16:04:13 -07:00
parent 327126d1e8
commit 2b1d1038a6
5 changed files with 296 additions and 361 deletions

View File

@ -6,6 +6,7 @@
#include <cstring> #include <cstring>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/EnumMap.h"
#include "Common/MsgHandler.h" #include "Common/MsgHandler.h"
#include "Common/Swap.h" #include "Common/Swap.h"
@ -175,21 +176,40 @@ void Color_ReadDirect_32b_8888(VertexLoader* loader)
SetCol(loader, DataReadU32Unswapped()); SetCol(loader, DataReadU32Unswapped());
} }
constexpr TPipelineFunction s_table_read_color[4][6] = { using Common::EnumMap;
{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
{Color_ReadDirect_16b_565, Color_ReadDirect_24b_888, Color_ReadDirect_32b_888x, // These functions are to work around a "too many initializer values" error with nested brackets
Color_ReadDirect_16b_4444, Color_ReadDirect_24b_6666, Color_ReadDirect_32b_8888}, // C++ does not let you write std::array<std::array<u32, 2>, 2> a = {{1, 2}, {3, 4}}
{Color_ReadIndex_16b_565<u8>, Color_ReadIndex_24b_888<u8>, Color_ReadIndex_32b_888x<u8>, // (although it does allow std::array<std::array<u32, 2>, 2> b = {1, 2, 3, 4})
Color_ReadIndex_16b_4444<u8>, Color_ReadIndex_24b_6666<u8>, Color_ReadIndex_32b_8888<u8>}, constexpr EnumMap<TPipelineFunction, ColorFormat::RGBA8888>
{Color_ReadIndex_16b_565<u16>, Color_ReadIndex_24b_888<u16>, Color_ReadIndex_32b_888x<u16>, f(EnumMap<TPipelineFunction, ColorFormat::RGBA8888> in)
Color_ReadIndex_16b_4444<u16>, Color_ReadIndex_24b_6666<u16>, Color_ReadIndex_32b_8888<u16>}, {
return in;
}
constexpr EnumMap<u32, ColorFormat::RGBA8888> g(EnumMap<u32, ColorFormat::RGBA8888> in)
{
return in;
}
template <typename T>
using Table = EnumMap<EnumMap<T, ColorFormat::RGBA8888>, VertexComponentFormat::Index16>;
constexpr Table<TPipelineFunction> 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<u8>, Color_ReadIndex_24b_888<u8>, Color_ReadIndex_32b_888x<u8>,
Color_ReadIndex_16b_4444<u8>, Color_ReadIndex_24b_6666<u8>, Color_ReadIndex_32b_8888<u8>}),
f({Color_ReadIndex_16b_565<u16>, Color_ReadIndex_24b_888<u16>, Color_ReadIndex_32b_888x<u16>,
Color_ReadIndex_16b_4444<u16>, Color_ReadIndex_24b_6666<u16>,
Color_ReadIndex_32b_8888<u16>}),
}; };
constexpr u32 s_table_read_color_vertex_size[4][6] = { constexpr Table<u32> s_table_read_color_vertex_size = {
{0, 0, 0, 0, 0, 0}, g({0u, 0u, 0u, 0u, 0u, 0u}),
{2, 3, 4, 2, 3, 4}, g({2u, 3u, 4u, 2u, 3u, 4u}),
{1, 1, 1, 1, 1, 1}, g({1u, 1u, 1u, 1u, 1u, 1u}),
{2, 2, 2, 2, 2, 2}, g({2u, 2u, 2u, 2u, 2u, 2u}),
}; };
} // Anonymous namespace } // Anonymous namespace
@ -200,7 +220,7 @@ u32 VertexLoader_Color::GetSize(VertexComponentFormat type, ColorFormat format)
PanicAlertFmt("Invalid color format {}", format); PanicAlertFmt("Invalid color format {}", format);
return 0; 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) TPipelineFunction VertexLoader_Color::GetFunction(VertexComponentFormat type, ColorFormat format)
@ -210,5 +230,5 @@ TPipelineFunction VertexLoader_Color::GetFunction(VertexComponentFormat type, Co
PanicAlertFmt("Invalid color format {}", format); PanicAlertFmt("Invalid color format {}", format);
return nullptr; return nullptr;
} }
return s_table_read_color[u32(type)][u32(format)]; return s_table_read_color[type][format];
} }

View File

@ -7,6 +7,7 @@
#include <type_traits> #include <type_traits>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/EnumMap.h"
#include "VideoCommon/DataReader.h" #include "VideoCommon/DataReader.h"
#include "VideoCommon/VertexLoader.h" #include "VideoCommon/VertexLoader.h"
@ -98,39 +99,6 @@ struct Normal_Index_Indices3
static constexpr u32 size = sizeof(I) * 3; 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 struct Set
{ {
template <typename T> template <typename T>
@ -145,83 +113,88 @@ struct Set
TPipelineFunction function; TPipelineFunction function;
}; };
using Formats = std::array<Set, NUM_NRM_FORMAT>; using Common::EnumMap;
using Elements = std::array<Formats, NUM_NRM_ELEMENTS>; using Formats = EnumMap<Set, ComponentFormat::Float>;
using Indices = std::array<Elements, NUM_NRM_INDICES>; using Elements = EnumMap<Formats, NormalComponentCount::NBT>;
using Types = std::array<Indices, NUM_NRM_TYPE>; using Indices = std::array<Elements, 2>;
using Types = EnumMap<Indices, VertexComponentFormat::Index16>;
constexpr Types InitializeTable() constexpr Types InitializeTable()
{ {
Types table{}; Types table{};
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_UBYTE] = Normal_Direct<u8, 1>(); using VCF = VertexComponentFormat;
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_BYTE] = Normal_Direct<s8, 1>(); using NCC = NormalComponentCount;
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_USHORT] = Normal_Direct<u16, 1>(); using FMT = ComponentFormat;
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_SHORT] = Normal_Direct<s16, 1>();
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_FLOAT] = Normal_Direct<float, 1>();
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT3][FORMAT_UBYTE] = Normal_Direct<u8, 3>();
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT3][FORMAT_BYTE] = Normal_Direct<s8, 3>();
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT3][FORMAT_USHORT] = Normal_Direct<u16, 3>();
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT3][FORMAT_SHORT] = Normal_Direct<s16, 3>();
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT3][FORMAT_FLOAT] = Normal_Direct<float, 3>();
// Same as above table[VCF::Direct][false][NCC::N][FMT::UByte] = Normal_Direct<u8, 1>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_UBYTE] = Normal_Direct<u8, 1>(); table[VCF::Direct][false][NCC::N][FMT::Byte] = Normal_Direct<s8, 1>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_BYTE] = Normal_Direct<s8, 1>(); table[VCF::Direct][false][NCC::N][FMT::UShort] = Normal_Direct<u16, 1>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_USHORT] = Normal_Direct<u16, 1>(); table[VCF::Direct][false][NCC::N][FMT::Short] = Normal_Direct<s16, 1>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_SHORT] = Normal_Direct<s16, 1>(); table[VCF::Direct][false][NCC::N][FMT::Float] = Normal_Direct<float, 1>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_FLOAT] = Normal_Direct<float, 1>(); table[VCF::Direct][false][NCC::NBT][FMT::UByte] = Normal_Direct<u8, 3>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_UBYTE] = Normal_Direct<u8, 3>(); table[VCF::Direct][false][NCC::NBT][FMT::Byte] = Normal_Direct<s8, 3>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_BYTE] = Normal_Direct<s8, 3>(); table[VCF::Direct][false][NCC::NBT][FMT::UShort] = Normal_Direct<u16, 3>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_USHORT] = Normal_Direct<u16, 3>(); table[VCF::Direct][false][NCC::NBT][FMT::Short] = Normal_Direct<s16, 3>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_SHORT] = Normal_Direct<s16, 3>(); table[VCF::Direct][false][NCC::NBT][FMT::Float] = Normal_Direct<float, 3>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_FLOAT] = Normal_Direct<float, 3>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_UBYTE] = Normal_Index<u8, u8, 1>(); // Same as above, since there are no indices
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_BYTE] = Normal_Index<u8, s8, 1>(); table[VCF::Direct][true][NCC::N][FMT::UByte] = Normal_Direct<u8, 1>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_USHORT] = Normal_Index<u8, u16, 1>(); table[VCF::Direct][true][NCC::N][FMT::Byte] = Normal_Direct<s8, 1>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_SHORT] = Normal_Index<u8, s16, 1>(); table[VCF::Direct][true][NCC::N][FMT::UShort] = Normal_Direct<u16, 1>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_FLOAT] = Normal_Index<u8, float, 1>(); table[VCF::Direct][true][NCC::N][FMT::Short] = Normal_Direct<s16, 1>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_UBYTE] = Normal_Index<u8, u8, 3>(); table[VCF::Direct][true][NCC::N][FMT::Float] = Normal_Direct<float, 1>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_BYTE] = Normal_Index<u8, s8, 3>(); table[VCF::Direct][true][NCC::NBT][FMT::UByte] = Normal_Direct<u8, 3>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_USHORT] = Normal_Index<u8, u16, 3>(); table[VCF::Direct][true][NCC::NBT][FMT::Byte] = Normal_Direct<s8, 3>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_SHORT] = Normal_Index<u8, s16, 3>(); table[VCF::Direct][true][NCC::NBT][FMT::UShort] = Normal_Direct<u16, 3>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_FLOAT] = Normal_Index<u8, float, 3>(); table[VCF::Direct][true][NCC::NBT][FMT::Short] = Normal_Direct<s16, 3>();
table[VCF::Direct][true][NCC::NBT][FMT::Float] = Normal_Direct<float, 3>();
// Same as above for NRM_NBT table[VCF::Index8][false][NCC::N][FMT::UByte] = Normal_Index<u8, u8, 1>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_UBYTE] = Normal_Index<u8, u8, 1>(); table[VCF::Index8][false][NCC::N][FMT::Byte] = Normal_Index<u8, s8, 1>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_BYTE] = Normal_Index<u8, s8, 1>(); table[VCF::Index8][false][NCC::N][FMT::UShort] = Normal_Index<u8, u16, 1>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_USHORT] = Normal_Index<u8, u16, 1>(); table[VCF::Index8][false][NCC::N][FMT::Short] = Normal_Index<u8, s16, 1>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_SHORT] = Normal_Index<u8, s16, 1>(); table[VCF::Index8][false][NCC::N][FMT::Float] = Normal_Index<u8, float, 1>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_FLOAT] = Normal_Index<u8, float, 1>(); table[VCF::Index8][false][NCC::NBT][FMT::UByte] = Normal_Index<u8, u8, 3>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_UBYTE] = Normal_Index_Indices3<u8, u8>(); table[VCF::Index8][false][NCC::NBT][FMT::Byte] = Normal_Index<u8, s8, 3>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_BYTE] = Normal_Index_Indices3<u8, s8>(); table[VCF::Index8][false][NCC::NBT][FMT::UShort] = Normal_Index<u8, u16, 3>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_USHORT] = Normal_Index_Indices3<u8, u16>(); table[VCF::Index8][false][NCC::NBT][FMT::Short] = Normal_Index<u8, s16, 3>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_SHORT] = Normal_Index_Indices3<u8, s16>(); table[VCF::Index8][false][NCC::NBT][FMT::Float] = Normal_Index<u8, float, 3>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_FLOAT] = Normal_Index_Indices3<u8, float>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_UBYTE] = Normal_Index<u16, u8, 1>(); // Same for NormalComponentCount::N; differs for NBT
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_BYTE] = Normal_Index<u16, s8, 1>(); table[VCF::Index8][true][NCC::N][FMT::UByte] = Normal_Index<u8, u8, 1>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_USHORT] = Normal_Index<u16, u16, 1>(); table[VCF::Index8][true][NCC::N][FMT::Byte] = Normal_Index<u8, s8, 1>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_SHORT] = Normal_Index<u16, s16, 1>(); table[VCF::Index8][true][NCC::N][FMT::UShort] = Normal_Index<u8, u16, 1>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_FLOAT] = Normal_Index<u16, float, 1>(); table[VCF::Index8][true][NCC::N][FMT::Short] = Normal_Index<u8, s16, 1>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_UBYTE] = Normal_Index<u16, u8, 3>(); table[VCF::Index8][true][NCC::N][FMT::Float] = Normal_Index<u8, float, 1>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_BYTE] = Normal_Index<u16, s8, 3>(); table[VCF::Index8][true][NCC::NBT][FMT::UByte] = Normal_Index_Indices3<u8, u8>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_USHORT] = Normal_Index<u16, u16, 3>(); table[VCF::Index8][true][NCC::NBT][FMT::Byte] = Normal_Index_Indices3<u8, s8>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_SHORT] = Normal_Index<u16, s16, 3>(); table[VCF::Index8][true][NCC::NBT][FMT::UShort] = Normal_Index_Indices3<u8, u16>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_FLOAT] = Normal_Index<u16, float, 3>(); table[VCF::Index8][true][NCC::NBT][FMT::Short] = Normal_Index_Indices3<u8, s16>();
table[VCF::Index8][true][NCC::NBT][FMT::Float] = Normal_Index_Indices3<u8, float>();
// Same as above for NRM_NBT table[VCF::Index16][false][NCC::N][FMT::UByte] = Normal_Index<u16, u8, 1>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_UBYTE] = Normal_Index<u16, u8, 1>(); table[VCF::Index16][false][NCC::N][FMT::Byte] = Normal_Index<u16, s8, 1>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_BYTE] = Normal_Index<u16, s8, 1>(); table[VCF::Index16][false][NCC::N][FMT::UShort] = Normal_Index<u16, u16, 1>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_USHORT] = Normal_Index<u16, u16, 1>(); table[VCF::Index16][false][NCC::N][FMT::Short] = Normal_Index<u16, s16, 1>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_SHORT] = Normal_Index<u16, s16, 1>(); table[VCF::Index16][false][NCC::N][FMT::Float] = Normal_Index<u16, float, 1>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_FLOAT] = Normal_Index<u16, float, 1>(); table[VCF::Index16][false][NCC::NBT][FMT::UByte] = Normal_Index<u16, u8, 3>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_UBYTE] = Normal_Index_Indices3<u16, u8>(); table[VCF::Index16][false][NCC::NBT][FMT::Byte] = Normal_Index<u16, s8, 3>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_BYTE] = Normal_Index_Indices3<u16, s8>(); table[VCF::Index16][false][NCC::NBT][FMT::UShort] = Normal_Index<u16, u16, 3>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_USHORT] = Normal_Index_Indices3<u16, u16>(); table[VCF::Index16][false][NCC::NBT][FMT::Short] = Normal_Index<u16, s16, 3>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_SHORT] = Normal_Index_Indices3<u16, s16>(); table[VCF::Index16][false][NCC::NBT][FMT::Float] = Normal_Index<u16, float, 3>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_FLOAT] = Normal_Index_Indices3<u16, float>();
// Same for NormalComponentCount::N; differs for NBT
table[VCF::Index16][true][NCC::N][FMT::UByte] = Normal_Index<u16, u8, 1>();
table[VCF::Index16][true][NCC::N][FMT::Byte] = Normal_Index<u16, s8, 1>();
table[VCF::Index16][true][NCC::N][FMT::UShort] = Normal_Index<u16, u16, 1>();
table[VCF::Index16][true][NCC::N][FMT::Short] = Normal_Index<u16, s16, 1>();
table[VCF::Index16][true][NCC::N][FMT::Float] = Normal_Index<u16, float, 1>();
table[VCF::Index16][true][NCC::NBT][FMT::UByte] = Normal_Index_Indices3<u16, u8>();
table[VCF::Index16][true][NCC::NBT][FMT::Byte] = Normal_Index_Indices3<u16, s8>();
table[VCF::Index16][true][NCC::NBT][FMT::UShort] = Normal_Index_Indices3<u16, u16>();
table[VCF::Index16][true][NCC::NBT][FMT::Short] = Normal_Index_Indices3<u16, s16>();
table[VCF::Index16][true][NCC::NBT][FMT::Float] = Normal_Index_Indices3<u16, float>();
return table; return table;
} }
@ -230,14 +203,14 @@ constexpr Types s_table = InitializeTable();
} // Anonymous namespace } // Anonymous namespace
u32 VertexLoader_Normal::GetSize(VertexComponentFormat type, ComponentFormat format, 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, TPipelineFunction VertexLoader_Normal::GetFunction(VertexComponentFormat type,
ComponentFormat format, 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;
} }

View File

@ -14,8 +14,8 @@ class VertexLoader_Normal
{ {
public: public:
static u32 GetSize(VertexComponentFormat type, ComponentFormat format, static u32 GetSize(VertexComponentFormat type, ComponentFormat format,
NormalComponentCount elements, u32 index3); NormalComponentCount elements, bool index3);
static TPipelineFunction GetFunction(VertexComponentFormat type, ComponentFormat format, static TPipelineFunction GetFunction(VertexComponentFormat type, ComponentFormat format,
NormalComponentCount elements, u32 index3); NormalComponentCount elements, bool index3);
}; };

View File

@ -7,6 +7,7 @@
#include <type_traits> #include <type_traits>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/EnumMap.h"
#include "Common/Swap.h" #include "Common/Swap.h"
#include "VideoCommon/DataReader.h" #include "VideoCommon/DataReader.h"
@ -76,138 +77,109 @@ void Pos_ReadIndex(VertexLoader* loader)
LOG_VTX(); LOG_VTX();
} }
constexpr TPipelineFunction s_table_read_position[4][8][2] = { using Common::EnumMap;
{
{ // These functions are to work around a "too many initializer values" error with nested brackets
nullptr, // C++ does not let you write std::array<std::array<u32, 2>, 2> a = {{1, 2}, {3, 4}}
nullptr, // (although it does allow std::array<std::array<u32, 2>, 2> b = {1, 2, 3, 4})
}, constexpr EnumMap<TPipelineFunction, CoordComponentCount::XYZ> e(TPipelineFunction xy,
{ TPipelineFunction xyz)
nullptr, {
nullptr, return {xy, xyz};
}, }
{ constexpr EnumMap<u32, CoordComponentCount::XYZ> e(u32 xy, u32 xyz)
nullptr, {
nullptr, return {xy, xyz};
}, }
{
nullptr, constexpr EnumMap<EnumMap<TPipelineFunction, CoordComponentCount::XYZ>, ComponentFormat::Float>
nullptr, f(EnumMap<EnumMap<TPipelineFunction, CoordComponentCount::XYZ>, ComponentFormat::Float> in)
}, {
{ return in;
nullptr, }
nullptr,
}, constexpr EnumMap<EnumMap<u32, CoordComponentCount::XYZ>, ComponentFormat::Float>
}, g(EnumMap<EnumMap<u32, CoordComponentCount::XYZ>, ComponentFormat::Float> in)
{ {
{ return in;
Pos_ReadDirect<u8, 2>, }
Pos_ReadDirect<u8, 3>,
}, template <typename T>
{ using Table = EnumMap<EnumMap<EnumMap<T, CoordComponentCount::XYZ>, ComponentFormat::Float>,
Pos_ReadDirect<s8, 2>, VertexComponentFormat::Index16>;
Pos_ReadDirect<s8, 3>,
}, constexpr Table<TPipelineFunction> s_table_read_position = {
{ f({
Pos_ReadDirect<u16, 2>, e(nullptr, nullptr),
Pos_ReadDirect<u16, 3>, e(nullptr, nullptr),
}, e(nullptr, nullptr),
{ e(nullptr, nullptr),
Pos_ReadDirect<s16, 2>, e(nullptr, nullptr),
Pos_ReadDirect<s16, 3>, }),
}, f({
{ e(Pos_ReadDirect<u8, 2>, Pos_ReadDirect<u8, 3>),
Pos_ReadDirect<float, 2>, e(Pos_ReadDirect<s8, 2>, Pos_ReadDirect<s8, 3>),
Pos_ReadDirect<float, 3>, e(Pos_ReadDirect<u16, 2>, Pos_ReadDirect<u16, 3>),
}, e(Pos_ReadDirect<s16, 2>, Pos_ReadDirect<s16, 3>),
}, e(Pos_ReadDirect<float, 2>, Pos_ReadDirect<float, 3>),
{ }),
{ f({
Pos_ReadIndex<u8, u8, 2>, e(Pos_ReadIndex<u8, u8, 2>, Pos_ReadIndex<u8, u8, 3>),
Pos_ReadIndex<u8, u8, 3>, e(Pos_ReadIndex<u8, s8, 2>, Pos_ReadIndex<u8, s8, 3>),
}, e(Pos_ReadIndex<u8, u16, 2>, Pos_ReadIndex<u8, u16, 3>),
{ e(Pos_ReadIndex<u8, s16, 2>, Pos_ReadIndex<u8, s16, 3>),
Pos_ReadIndex<u8, s8, 2>, e(Pos_ReadIndex<u8, float, 2>, Pos_ReadIndex<u8, float, 3>),
Pos_ReadIndex<u8, s8, 3>, }),
}, f({
{ e(Pos_ReadIndex<u16, u8, 2>, Pos_ReadIndex<u16, u8, 3>),
Pos_ReadIndex<u8, u16, 2>, e(Pos_ReadIndex<u16, s8, 2>, Pos_ReadIndex<u16, s8, 3>),
Pos_ReadIndex<u8, u16, 3>, e(Pos_ReadIndex<u16, u16, 2>, Pos_ReadIndex<u16, u16, 3>),
}, e(Pos_ReadIndex<u16, s16, 2>, Pos_ReadIndex<u16, s16, 3>),
{ e(Pos_ReadIndex<u16, float, 2>, Pos_ReadIndex<u16, float, 3>),
Pos_ReadIndex<u8, s16, 2>, }),
Pos_ReadIndex<u8, s16, 3>,
},
{
Pos_ReadIndex<u8, float, 2>,
Pos_ReadIndex<u8, float, 3>,
},
},
{
{
Pos_ReadIndex<u16, u8, 2>,
Pos_ReadIndex<u16, u8, 3>,
},
{
Pos_ReadIndex<u16, s8, 2>,
Pos_ReadIndex<u16, s8, 3>,
},
{
Pos_ReadIndex<u16, u16, 2>,
Pos_ReadIndex<u16, u16, 3>,
},
{
Pos_ReadIndex<u16, s16, 2>,
Pos_ReadIndex<u16, s16, 3>,
},
{
Pos_ReadIndex<u16, float, 2>,
Pos_ReadIndex<u16, float, 3>,
},
},
}; };
constexpr u32 s_table_read_position_vertex_size[4][8][2] = { constexpr Table<u32> s_table_read_position_vertex_size = {
{ g({
{0, 0}, e(0u, 0u),
{0, 0}, e(0u, 0u),
{0, 0}, e(0u, 0u),
{0, 0}, e(0u, 0u),
{0, 0}, e(0u, 0u),
}, }),
{ g({
{2, 3}, e(2, 3),
{2, 3}, e(2, 3),
{4, 6}, e(4, 6),
{4, 6}, e(4, 6),
{8, 12}, e(8, 12),
}, }),
{ g({
{1, 1}, e(1, 1),
{1, 1}, e(1, 1),
{1, 1}, e(1, 1),
{1, 1}, e(1, 1),
{1, 1}, e(1, 1),
}, }),
{ g({
{2, 2}, e(2, 2),
{2, 2}, e(2, 2),
{2, 2}, e(2, 2),
{2, 2}, e(2, 2),
{2, 2}, e(2, 2),
}, }),
}; };
} // Anonymous namespace } // Anonymous namespace
u32 VertexLoader_Position::GetSize(VertexComponentFormat type, ComponentFormat format, u32 VertexLoader_Position::GetSize(VertexComponentFormat type, ComponentFormat format,
CoordComponentCount elements) 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, TPipelineFunction VertexLoader_Position::GetFunction(VertexComponentFormat type,
ComponentFormat format, ComponentFormat format,
CoordComponentCount elements) CoordComponentCount elements)
{ {
return s_table_read_position[u32(type)][u32(format)][u32(elements)]; return s_table_read_position[type][format][elements];
} }

View File

@ -67,140 +67,110 @@ void TexCoord_ReadIndex(VertexLoader* loader)
++loader->m_tcIndex; ++loader->m_tcIndex;
} }
constexpr TPipelineFunction s_table_read_tex_coord[4][8][2] = { 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<std::array<u32, 2>, 2> a = {{1, 2}, {3, 4}}
nullptr, // (although it does allow std::array<std::array<u32, 2>, 2> b = {1, 2, 3, 4})
nullptr, constexpr EnumMap<TPipelineFunction, TexComponentCount::ST> e(TPipelineFunction s,
}, TPipelineFunction st)
{ {
nullptr, return {s, st};
nullptr, }
}, constexpr EnumMap<u32, TexComponentCount::ST> e(u32 s, u32 st)
{ {
nullptr, return {s, st};
nullptr, }
},
{ constexpr EnumMap<EnumMap<TPipelineFunction, TexComponentCount::ST>, ComponentFormat::Float>
nullptr, f(EnumMap<EnumMap<TPipelineFunction, TexComponentCount::ST>, ComponentFormat::Float> in)
nullptr, {
}, return in;
{ }
nullptr,
nullptr, constexpr EnumMap<EnumMap<u32, TexComponentCount::ST>, ComponentFormat::Float>
}, g(EnumMap<EnumMap<u32, TexComponentCount::ST>, ComponentFormat::Float> in)
}, {
{ return in;
{ }
TexCoord_ReadDirect<u8, 1>,
TexCoord_ReadDirect<u8, 2>, template <typename T>
}, using Table = EnumMap<EnumMap<EnumMap<T, TexComponentCount::ST>, ComponentFormat::Float>,
{ VertexComponentFormat::Index16>;
TexCoord_ReadDirect<s8, 1>,
TexCoord_ReadDirect<s8, 2>, constexpr Table<TPipelineFunction> s_table_read_tex_coord = {
}, f({
{ e(nullptr, nullptr),
TexCoord_ReadDirect<u16, 1>, e(nullptr, nullptr),
TexCoord_ReadDirect<u16, 2>, e(nullptr, nullptr),
}, e(nullptr, nullptr),
{ e(nullptr, nullptr),
TexCoord_ReadDirect<s16, 1>, }),
TexCoord_ReadDirect<s16, 2>, f({
}, e(TexCoord_ReadDirect<u8, 1>, TexCoord_ReadDirect<u8, 2>),
{ e(TexCoord_ReadDirect<s8, 1>, TexCoord_ReadDirect<s8, 2>),
TexCoord_ReadDirect<float, 1>, e(TexCoord_ReadDirect<u16, 1>, TexCoord_ReadDirect<u16, 2>),
TexCoord_ReadDirect<float, 2>, e(TexCoord_ReadDirect<s16, 1>, TexCoord_ReadDirect<s16, 2>),
}, e(TexCoord_ReadDirect<float, 1>, TexCoord_ReadDirect<float, 2>),
}, }),
{ f({
{ e(TexCoord_ReadIndex<u8, u8, 1>, TexCoord_ReadIndex<u8, u8, 2>),
TexCoord_ReadIndex<u8, u8, 1>, e(TexCoord_ReadIndex<u8, s8, 1>, TexCoord_ReadIndex<u8, s8, 2>),
TexCoord_ReadIndex<u8, u8, 2>, e(TexCoord_ReadIndex<u8, u16, 1>, TexCoord_ReadIndex<u8, u16, 2>),
}, e(TexCoord_ReadIndex<u8, s16, 1>, TexCoord_ReadIndex<u8, s16, 2>),
{ e(TexCoord_ReadIndex<u8, float, 1>, TexCoord_ReadIndex<u8, float, 2>),
TexCoord_ReadIndex<u8, s8, 1>, }),
TexCoord_ReadIndex<u8, s8, 2>, f({
}, e(TexCoord_ReadIndex<u16, u8, 1>, TexCoord_ReadIndex<u16, u8, 2>),
{ e(TexCoord_ReadIndex<u16, s8, 1>, TexCoord_ReadIndex<u16, s8, 2>),
TexCoord_ReadIndex<u8, u16, 1>, e(TexCoord_ReadIndex<u16, u16, 1>, TexCoord_ReadIndex<u16, u16, 2>),
TexCoord_ReadIndex<u8, u16, 2>, e(TexCoord_ReadIndex<u16, s16, 1>, TexCoord_ReadIndex<u16, s16, 2>),
}, e(TexCoord_ReadIndex<u16, float, 1>, TexCoord_ReadIndex<u16, float, 2>),
{ }),
TexCoord_ReadIndex<u8, s16, 1>,
TexCoord_ReadIndex<u8, s16, 2>,
},
{
TexCoord_ReadIndex<u8, float, 1>,
TexCoord_ReadIndex<u8, float, 2>,
},
},
{
{
TexCoord_ReadIndex<u16, u8, 1>,
TexCoord_ReadIndex<u16, u8, 2>,
},
{
TexCoord_ReadIndex<u16, s8, 1>,
TexCoord_ReadIndex<u16, s8, 2>,
},
{
TexCoord_ReadIndex<u16, u16, 1>,
TexCoord_ReadIndex<u16, u16, 2>,
},
{
TexCoord_ReadIndex<u16, s16, 1>,
TexCoord_ReadIndex<u16, s16, 2>,
},
{
TexCoord_ReadIndex<u16, float, 1>,
TexCoord_ReadIndex<u16, float, 2>,
},
},
}; };
constexpr u32 s_table_read_tex_coord_vertex_size[4][8][2] = { constexpr Table<u32> s_table_read_tex_coord_vertex_size = {
{ g({
{0, 0}, e(0u, 0u),
{0, 0}, e(0u, 0u),
{0, 0}, e(0u, 0u),
{0, 0}, e(0u, 0u),
{0, 0}, e(0u, 0u),
}, }),
{ g({
{1, 2}, e(1, 2),
{1, 2}, e(1, 2),
{2, 4}, e(2, 4),
{2, 4}, e(2, 4),
{4, 8}, e(4, 8),
}, }),
{ g({
{1, 1}, e(1, 1),
{1, 1}, e(1, 1),
{1, 1}, e(1, 1),
{1, 1}, e(1, 1),
{1, 1}, e(1, 1),
}, }),
{ g({
{2, 2}, e(2, 2),
{2, 2}, e(2, 2),
{2, 2}, e(2, 2),
{2, 2}, e(2, 2),
{2, 2}, e(2, 2),
}, }),
}; };
} // Anonymous namespace } // Anonymous namespace
u32 VertexLoader_TextCoord::GetSize(VertexComponentFormat type, ComponentFormat format, u32 VertexLoader_TextCoord::GetSize(VertexComponentFormat type, ComponentFormat format,
TexComponentCount elements) 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, TPipelineFunction VertexLoader_TextCoord::GetFunction(VertexComponentFormat type,
ComponentFormat format, ComponentFormat format,
TexComponentCount elements) 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() TPipelineFunction VertexLoader_TextCoord::GetDummyFunction()