@@ -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 <typename T, auto last_member>
using EnumMap = typename Common::EnumMap<T, last_member>;

using SizeTable = EnumMap<
std::array<EnumMap<EnumMap<u32, ComponentFormat::Float>, 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;
}
();
};
@@ -138,45 +138,8 @@ constexpr Table<TPipelineFunction> s_table_read_position = {
e(Pos_ReadIndex<u16, float, 2>, Pos_ReadIndex<u16, float, 3>),
}),
};

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[type][format][elements];
}

TPipelineFunction VertexLoader_Position::GetFunction(VertexComponentFormat type,
ComponentFormat format,
CoordComponentCount elements)
@@ -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 <typename T, auto last_member>
using EnumMap = typename Common::EnumMap<T, last_member>;

using SizeTable = EnumMap<EnumMap<EnumMap<u32, CoordComponentCount::XYZ>, 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;
}
();
};
@@ -127,45 +127,8 @@ constexpr Table<TPipelineFunction> s_table_read_tex_coord = {
e(TexCoord_ReadIndex<u16, float, 1>, TexCoord_ReadIndex<u16, float, 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[type][format][elements];
}

TPipelineFunction VertexLoader_TextCoord::GetFunction(VertexComponentFormat type,
ComponentFormat format,
TexComponentCount elements)
@@ -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 <typename T, auto last_member>
using EnumMap = typename Common::EnumMap<T, last_member>;

using SizeTable = EnumMap<EnumMap<EnumMap<u32, TexComponentCount::ST>, 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;
}
();
};