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 "Common/CommonTypes.h"
#include "Common/EnumMap.h"
#include "Common/MsgHandler.h"
#include "Common/Swap.h"
@ -175,21 +176,40 @@ void Color_ReadDirect_32b_8888(VertexLoader* loader)
SetCol(loader, DataReadU32Unswapped());
}
constexpr TPipelineFunction s_table_read_color[4][6] = {
{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr},
{Color_ReadDirect_16b_565, Color_ReadDirect_24b_888, Color_ReadDirect_32b_888x,
Color_ReadDirect_16b_4444, Color_ReadDirect_24b_6666, Color_ReadDirect_32b_8888},
{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>},
{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>},
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}}
// (although it does allow std::array<std::array<u32, 2>, 2> b = {1, 2, 3, 4})
constexpr EnumMap<TPipelineFunction, ColorFormat::RGBA8888>
f(EnumMap<TPipelineFunction, ColorFormat::RGBA8888> in)
{
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] = {
{0, 0, 0, 0, 0, 0},
{2, 3, 4, 2, 3, 4},
{1, 1, 1, 1, 1, 1},
{2, 2, 2, 2, 2, 2},
constexpr Table<u32> 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
@ -200,7 +220,7 @@ u32 VertexLoader_Color::GetSize(VertexComponentFormat type, ColorFormat format)
PanicAlertFmt("Invalid color format {}", format);
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)
@ -210,5 +230,5 @@ TPipelineFunction VertexLoader_Color::GetFunction(VertexComponentFormat type, Co
PanicAlertFmt("Invalid color format {}", format);
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 "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 <typename T>
@ -145,83 +113,88 @@ struct Set
TPipelineFunction function;
};
using Formats = std::array<Set, NUM_NRM_FORMAT>;
using Elements = std::array<Formats, NUM_NRM_ELEMENTS>;
using Indices = std::array<Elements, NUM_NRM_INDICES>;
using Types = std::array<Indices, NUM_NRM_TYPE>;
using Common::EnumMap;
using Formats = EnumMap<Set, ComponentFormat::Float>;
using Elements = EnumMap<Formats, NormalComponentCount::NBT>;
using Indices = std::array<Elements, 2>;
using Types = EnumMap<Indices, VertexComponentFormat::Index16>;
constexpr Types InitializeTable()
{
Types table{};
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_UBYTE] = Normal_Direct<u8, 1>();
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_BYTE] = Normal_Direct<s8, 1>();
table[NRM_DIRECT][NRM_INDICES1][NRM_NBT][FORMAT_USHORT] = Normal_Direct<u16, 1>();
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>();
using VCF = VertexComponentFormat;
using NCC = NormalComponentCount;
using FMT = ComponentFormat;
// Same as above
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_UBYTE] = Normal_Direct<u8, 1>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_BYTE] = Normal_Direct<s8, 1>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_USHORT] = Normal_Direct<u16, 1>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_SHORT] = Normal_Direct<s16, 1>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT][FORMAT_FLOAT] = Normal_Direct<float, 1>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_UBYTE] = Normal_Direct<u8, 3>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_BYTE] = Normal_Direct<s8, 3>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_USHORT] = Normal_Direct<u16, 3>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_SHORT] = Normal_Direct<s16, 3>();
table[NRM_DIRECT][NRM_INDICES3][NRM_NBT3][FORMAT_FLOAT] = Normal_Direct<float, 3>();
table[VCF::Direct][false][NCC::N][FMT::UByte] = Normal_Direct<u8, 1>();
table[VCF::Direct][false][NCC::N][FMT::Byte] = Normal_Direct<s8, 1>();
table[VCF::Direct][false][NCC::N][FMT::UShort] = Normal_Direct<u16, 1>();
table[VCF::Direct][false][NCC::N][FMT::Short] = Normal_Direct<s16, 1>();
table[VCF::Direct][false][NCC::N][FMT::Float] = Normal_Direct<float, 1>();
table[VCF::Direct][false][NCC::NBT][FMT::UByte] = Normal_Direct<u8, 3>();
table[VCF::Direct][false][NCC::NBT][FMT::Byte] = Normal_Direct<s8, 3>();
table[VCF::Direct][false][NCC::NBT][FMT::UShort] = Normal_Direct<u16, 3>();
table[VCF::Direct][false][NCC::NBT][FMT::Short] = Normal_Direct<s16, 3>();
table[VCF::Direct][false][NCC::NBT][FMT::Float] = Normal_Direct<float, 3>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_UBYTE] = Normal_Index<u8, u8, 1>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_BYTE] = Normal_Index<u8, s8, 1>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_USHORT] = Normal_Index<u8, u16, 1>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_SHORT] = Normal_Index<u8, s16, 1>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT][FORMAT_FLOAT] = Normal_Index<u8, float, 1>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_UBYTE] = Normal_Index<u8, u8, 3>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_BYTE] = Normal_Index<u8, s8, 3>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_USHORT] = Normal_Index<u8, u16, 3>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_SHORT] = Normal_Index<u8, s16, 3>();
table[NRM_INDEX8][NRM_INDICES1][NRM_NBT3][FORMAT_FLOAT] = Normal_Index<u8, float, 3>();
// Same as above, since there are no indices
table[VCF::Direct][true][NCC::N][FMT::UByte] = Normal_Direct<u8, 1>();
table[VCF::Direct][true][NCC::N][FMT::Byte] = Normal_Direct<s8, 1>();
table[VCF::Direct][true][NCC::N][FMT::UShort] = Normal_Direct<u16, 1>();
table[VCF::Direct][true][NCC::N][FMT::Short] = Normal_Direct<s16, 1>();
table[VCF::Direct][true][NCC::N][FMT::Float] = Normal_Direct<float, 1>();
table[VCF::Direct][true][NCC::NBT][FMT::UByte] = Normal_Direct<u8, 3>();
table[VCF::Direct][true][NCC::NBT][FMT::Byte] = Normal_Direct<s8, 3>();
table[VCF::Direct][true][NCC::NBT][FMT::UShort] = Normal_Direct<u16, 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[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_UBYTE] = Normal_Index<u8, u8, 1>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_BYTE] = Normal_Index<u8, s8, 1>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_USHORT] = Normal_Index<u8, u16, 1>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_SHORT] = Normal_Index<u8, s16, 1>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT][FORMAT_FLOAT] = Normal_Index<u8, float, 1>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_UBYTE] = Normal_Index_Indices3<u8, u8>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_BYTE] = Normal_Index_Indices3<u8, s8>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_USHORT] = Normal_Index_Indices3<u8, u16>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_SHORT] = Normal_Index_Indices3<u8, s16>();
table[NRM_INDEX8][NRM_INDICES3][NRM_NBT3][FORMAT_FLOAT] = Normal_Index_Indices3<u8, float>();
table[VCF::Index8][false][NCC::N][FMT::UByte] = Normal_Index<u8, u8, 1>();
table[VCF::Index8][false][NCC::N][FMT::Byte] = Normal_Index<u8, s8, 1>();
table[VCF::Index8][false][NCC::N][FMT::UShort] = Normal_Index<u8, u16, 1>();
table[VCF::Index8][false][NCC::N][FMT::Short] = Normal_Index<u8, s16, 1>();
table[VCF::Index8][false][NCC::N][FMT::Float] = Normal_Index<u8, float, 1>();
table[VCF::Index8][false][NCC::NBT][FMT::UByte] = Normal_Index<u8, u8, 3>();
table[VCF::Index8][false][NCC::NBT][FMT::Byte] = Normal_Index<u8, s8, 3>();
table[VCF::Index8][false][NCC::NBT][FMT::UShort] = Normal_Index<u8, u16, 3>();
table[VCF::Index8][false][NCC::NBT][FMT::Short] = Normal_Index<u8, s16, 3>();
table[VCF::Index8][false][NCC::NBT][FMT::Float] = Normal_Index<u8, float, 3>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_UBYTE] = Normal_Index<u16, u8, 1>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_BYTE] = Normal_Index<u16, s8, 1>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_USHORT] = Normal_Index<u16, u16, 1>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_SHORT] = Normal_Index<u16, s16, 1>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT][FORMAT_FLOAT] = Normal_Index<u16, float, 1>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_UBYTE] = Normal_Index<u16, u8, 3>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_BYTE] = Normal_Index<u16, s8, 3>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_USHORT] = Normal_Index<u16, u16, 3>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_SHORT] = Normal_Index<u16, s16, 3>();
table[NRM_INDEX16][NRM_INDICES1][NRM_NBT3][FORMAT_FLOAT] = Normal_Index<u16, float, 3>();
// Same for NormalComponentCount::N; differs for NBT
table[VCF::Index8][true][NCC::N][FMT::UByte] = Normal_Index<u8, u8, 1>();
table[VCF::Index8][true][NCC::N][FMT::Byte] = Normal_Index<u8, s8, 1>();
table[VCF::Index8][true][NCC::N][FMT::UShort] = Normal_Index<u8, u16, 1>();
table[VCF::Index8][true][NCC::N][FMT::Short] = Normal_Index<u8, s16, 1>();
table[VCF::Index8][true][NCC::N][FMT::Float] = Normal_Index<u8, float, 1>();
table[VCF::Index8][true][NCC::NBT][FMT::UByte] = Normal_Index_Indices3<u8, u8>();
table[VCF::Index8][true][NCC::NBT][FMT::Byte] = Normal_Index_Indices3<u8, s8>();
table[VCF::Index8][true][NCC::NBT][FMT::UShort] = Normal_Index_Indices3<u8, u16>();
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[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_UBYTE] = Normal_Index<u16, u8, 1>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_BYTE] = Normal_Index<u16, s8, 1>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_USHORT] = Normal_Index<u16, u16, 1>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_SHORT] = Normal_Index<u16, s16, 1>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT][FORMAT_FLOAT] = Normal_Index<u16, float, 1>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_UBYTE] = Normal_Index_Indices3<u16, u8>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_BYTE] = Normal_Index_Indices3<u16, s8>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_USHORT] = Normal_Index_Indices3<u16, u16>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_SHORT] = Normal_Index_Indices3<u16, s16>();
table[NRM_INDEX16][NRM_INDICES3][NRM_NBT3][FORMAT_FLOAT] = Normal_Index_Indices3<u16, float>();
table[VCF::Index16][false][NCC::N][FMT::UByte] = Normal_Index<u16, u8, 1>();
table[VCF::Index16][false][NCC::N][FMT::Byte] = Normal_Index<u16, s8, 1>();
table[VCF::Index16][false][NCC::N][FMT::UShort] = Normal_Index<u16, u16, 1>();
table[VCF::Index16][false][NCC::N][FMT::Short] = Normal_Index<u16, s16, 1>();
table[VCF::Index16][false][NCC::N][FMT::Float] = Normal_Index<u16, float, 1>();
table[VCF::Index16][false][NCC::NBT][FMT::UByte] = Normal_Index<u16, u8, 3>();
table[VCF::Index16][false][NCC::NBT][FMT::Byte] = Normal_Index<u16, s8, 3>();
table[VCF::Index16][false][NCC::NBT][FMT::UShort] = Normal_Index<u16, u16, 3>();
table[VCF::Index16][false][NCC::NBT][FMT::Short] = Normal_Index<u16, s16, 3>();
table[VCF::Index16][false][NCC::NBT][FMT::Float] = Normal_Index<u16, float, 3>();
// 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;
}
@ -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;
}

View File

@ -14,8 +14,8 @@ class VertexLoader_Normal
{
public:
static u32 GetSize(VertexComponentFormat type, ComponentFormat format,
NormalComponentCount elements, u32 index3);
NormalComponentCount elements, bool index3);
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 "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<u8, 2>,
Pos_ReadDirect<u8, 3>,
},
{
Pos_ReadDirect<s8, 2>,
Pos_ReadDirect<s8, 3>,
},
{
Pos_ReadDirect<u16, 2>,
Pos_ReadDirect<u16, 3>,
},
{
Pos_ReadDirect<s16, 2>,
Pos_ReadDirect<s16, 3>,
},
{
Pos_ReadDirect<float, 2>,
Pos_ReadDirect<float, 3>,
},
},
{
{
Pos_ReadIndex<u8, u8, 2>,
Pos_ReadIndex<u8, u8, 3>,
},
{
Pos_ReadIndex<u8, s8, 2>,
Pos_ReadIndex<u8, s8, 3>,
},
{
Pos_ReadIndex<u8, u16, 2>,
Pos_ReadIndex<u8, u16, 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>,
},
},
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}}
// (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)
{
return {xy, xyz};
}
constexpr EnumMap<u32, CoordComponentCount::XYZ> e(u32 xy, u32 xyz)
{
return {xy, xyz};
}
constexpr EnumMap<EnumMap<TPipelineFunction, CoordComponentCount::XYZ>, ComponentFormat::Float>
f(EnumMap<EnumMap<TPipelineFunction, CoordComponentCount::XYZ>, ComponentFormat::Float> in)
{
return in;
}
constexpr EnumMap<EnumMap<u32, CoordComponentCount::XYZ>, ComponentFormat::Float>
g(EnumMap<EnumMap<u32, CoordComponentCount::XYZ>, ComponentFormat::Float> in)
{
return in;
}
template <typename T>
using Table = EnumMap<EnumMap<EnumMap<T, CoordComponentCount::XYZ>, ComponentFormat::Float>,
VertexComponentFormat::Index16>;
constexpr Table<TPipelineFunction> s_table_read_position = {
f({
e(nullptr, nullptr),
e(nullptr, nullptr),
e(nullptr, nullptr),
e(nullptr, nullptr),
e(nullptr, nullptr),
}),
f({
e(Pos_ReadDirect<u8, 2>, Pos_ReadDirect<u8, 3>),
e(Pos_ReadDirect<s8, 2>, Pos_ReadDirect<s8, 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({
e(Pos_ReadIndex<u8, u8, 2>, 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>),
e(Pos_ReadIndex<u8, float, 2>, Pos_ReadIndex<u8, float, 3>),
}),
f({
e(Pos_ReadIndex<u16, u8, 2>, Pos_ReadIndex<u16, u8, 3>),
e(Pos_ReadIndex<u16, s8, 2>, Pos_ReadIndex<u16, s8, 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>),
}),
};
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<u32> 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];
}

View File

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