Merge pull request #8143 from lioncash/loader

VertexLoader_*: Minor cleanup
This commit is contained in:
Léo Lam 2019-05-31 14:18:16 +02:00 committed by GitHub
commit a4837a5c5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 154 additions and 273 deletions

View File

@ -12,9 +12,11 @@
#include "VideoCommon/VertexLoaderUtils.h" #include "VideoCommon/VertexLoaderUtils.h"
#include "VideoCommon/VertexLoader_Color.h" #include "VideoCommon/VertexLoader_Color.h"
#define AMASK 0xFF000000 namespace
{
constexpr u32 alpha_mask = 0xFF000000;
static void SetCol(VertexLoader* loader, u32 val) void SetCol(VertexLoader* loader, u32 val)
{ {
DataWrite(val); DataWrite(val);
loader->m_colIndex++; loader->m_colIndex++;
@ -22,7 +24,7 @@ static void SetCol(VertexLoader* loader, u32 val)
// Color comes in format BARG in 16 bits // Color comes in format BARG in 16 bits
// BARG -> AABBGGRR // BARG -> AABBGGRR
static void SetCol4444(VertexLoader* loader, u16 val_) void SetCol4444(VertexLoader* loader, u16 val_)
{ {
u32 col, val = val_; u32 col, val = val_;
col = val & 0x00F0; // col = 000000R0; col = val & 0x00F0; // col = 000000R0;
@ -35,7 +37,7 @@ static void SetCol4444(VertexLoader* loader, u16 val_)
// Color comes in format RGBA // Color comes in format RGBA
// RRRRRRGG GGGGBBBB BBAAAAAA // RRRRRRGG GGGGBBBB BBAAAAAA
static void SetCol6666(VertexLoader* loader, u32 val) void SetCol6666(VertexLoader* loader, u32 val)
{ {
u32 col = (val >> 16) & 0x000000FC; u32 col = (val >> 16) & 0x000000FC;
col |= (val >> 2) & 0x0000FC00; col |= (val >> 2) & 0x0000FC00;
@ -47,7 +49,7 @@ static void SetCol6666(VertexLoader* loader, u32 val)
// Color comes in RGB // Color comes in RGB
// RRRRRGGG GGGBBBBB // RRRRRGGG GGGBBBBB
static void SetCol565(VertexLoader* loader, u16 val_) void SetCol565(VertexLoader* loader, u16 val_)
{ {
u32 col, val = val_; u32 col, val = val_;
col = (val >> 8) & 0x0000F8; col = (val >> 8) & 0x0000F8;
@ -55,21 +57,87 @@ static void SetCol565(VertexLoader* loader, u16 val_)
col |= (val << 19) & 0xF80000; col |= (val << 19) & 0xF80000;
col |= (col >> 5) & 0x070007; col |= (col >> 5) & 0x070007;
col |= (col >> 6) & 0x000300; col |= (col >> 6) & 0x000300;
SetCol(loader, col | AMASK); SetCol(loader, col | alpha_mask);
} }
static u32 Read32(const u8* addr) u32 Read32(const u8* addr)
{ {
u32 value; u32 value;
std::memcpy(&value, addr, sizeof(u32)); std::memcpy(&value, addr, sizeof(u32));
return value; return value;
} }
static u32 Read24(const u8* addr) u32 Read24(const u8* addr)
{ {
return Read32(addr) | AMASK; return Read32(addr) | alpha_mask;
} }
template <typename I>
void Color_ReadIndex_16b_565(VertexLoader* loader)
{
const auto index = DataRead<I>();
const u8* const address =
VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
u16 value;
std::memcpy(&value, address, sizeof(u16));
SetCol565(loader, Common::swap16(value));
}
template <typename I>
void Color_ReadIndex_24b_888(VertexLoader* loader)
{
const auto index = DataRead<I>();
const u8* address = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
SetCol(loader, Read24(address));
}
template <typename I>
void Color_ReadIndex_32b_888x(VertexLoader* loader)
{
const auto index = DataRead<I>();
const u8* address = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
SetCol(loader, Read24(address));
}
template <typename I>
void Color_ReadIndex_16b_4444(VertexLoader* loader)
{
auto const index = DataRead<I>();
const u8* const address =
VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
u16 value;
std::memcpy(&value, address, sizeof(u16));
SetCol4444(loader, value);
}
template <typename I>
void Color_ReadIndex_24b_6666(VertexLoader* loader)
{
const auto index = DataRead<I>();
const u8* data = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]) - 1;
const u32 val = Common::swap32(data);
SetCol6666(loader, val);
}
template <typename I>
void Color_ReadIndex_32b_8888(VertexLoader* loader)
{
const auto index = DataRead<I>();
const u8* address = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
SetCol(loader, Read32(address));
}
} // Anonymous namespace
void Color_ReadDirect_24b_888(VertexLoader* loader) void Color_ReadDirect_24b_888(VertexLoader* loader)
{ {
SetCol(loader, Read24(DataGetPosition())); SetCol(loader, Read24(DataGetPosition()));
@ -103,71 +171,6 @@ void Color_ReadDirect_32b_8888(VertexLoader* loader)
SetCol(loader, DataReadU32Unswapped()); SetCol(loader, DataReadU32Unswapped());
} }
template <typename I>
void Color_ReadIndex_16b_565(VertexLoader* loader)
{
auto const Index = DataRead<I>();
const u8* const address =
VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(Index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
u16 value;
std::memcpy(&value, address, sizeof(u16));
SetCol565(loader, Common::swap16(value));
}
template <typename I>
void Color_ReadIndex_24b_888(VertexLoader* loader)
{
auto const Index = DataRead<I>();
const u8* iAddress = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(Index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
SetCol(loader, Read24(iAddress));
}
template <typename I>
void Color_ReadIndex_32b_888x(VertexLoader* loader)
{
auto const Index = DataRead<I>();
const u8* iAddress = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(Index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
SetCol(loader, Read24(iAddress));
}
template <typename I>
void Color_ReadIndex_16b_4444(VertexLoader* loader)
{
auto const Index = DataRead<I>();
const u8* const address =
VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(Index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
u16 value;
std::memcpy(&value, address, sizeof(u16));
SetCol4444(loader, value);
}
template <typename I>
void Color_ReadIndex_24b_6666(VertexLoader* loader)
{
auto const Index = DataRead<I>();
const u8* pData = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(Index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]) - 1;
u32 val = Common::swap32(pData);
SetCol6666(loader, val);
}
template <typename I>
void Color_ReadIndex_32b_8888(VertexLoader* loader)
{
auto const Index = DataRead<I>();
const u8* iAddress = VertexLoaderManager::cached_arraybases[ARRAY_COLOR + loader->m_colIndex] +
(Index * g_main_cp_state.array_strides[ARRAY_COLOR + loader->m_colIndex]);
SetCol(loader, Read32(iAddress));
}
void Color_ReadIndex8_16b_565(VertexLoader* loader) void Color_ReadIndex8_16b_565(VertexLoader* loader)
{ {
Color_ReadIndex_16b_565<u8>(loader); Color_ReadIndex_16b_565<u8>(loader);

View File

@ -16,14 +16,16 @@
#include "VideoCommon/VertexLoaderUtils.h" #include "VideoCommon/VertexLoaderUtils.h"
#include "VideoCommon/VideoCommon.h" #include "VideoCommon/VideoCommon.h"
namespace
{
template <typename T> template <typename T>
float PosScale(T val, float scale) constexpr float PosScale(T val, float scale)
{ {
return val * scale; return val * scale;
} }
template <> template <>
float PosScale(float val, float scale) constexpr float PosScale(float val, [[maybe_unused]] float scale)
{ {
return val; return val;
} }
@ -32,13 +34,13 @@ template <typename T, int N>
void Pos_ReadDirect(VertexLoader* loader) void Pos_ReadDirect(VertexLoader* loader)
{ {
static_assert(N <= 3, "N > 3 is not sane!"); static_assert(N <= 3, "N > 3 is not sane!");
auto const scale = loader->m_posScale; const auto scale = loader->m_posScale;
DataReader dst(g_vertex_manager_write_ptr, nullptr); DataReader dst(g_vertex_manager_write_ptr, nullptr);
DataReader src(g_video_buffer_read_ptr, nullptr); DataReader src(g_video_buffer_read_ptr, nullptr);
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
float value = PosScale(src.Read<T>(), scale); const float value = PosScale(src.Read<T>(), scale);
if (loader->m_counter < 3) if (loader->m_counter < 3)
VertexLoaderManager::position_cache[loader->m_counter][i] = value; VertexLoaderManager::position_cache[loader->m_counter][i] = value;
dst.Write(value); dst.Write(value);
@ -55,17 +57,17 @@ void Pos_ReadIndex(VertexLoader* loader)
static_assert(std::is_unsigned<I>::value, "Only unsigned I is sane!"); static_assert(std::is_unsigned<I>::value, "Only unsigned I is sane!");
static_assert(N <= 3, "N > 3 is not sane!"); static_assert(N <= 3, "N > 3 is not sane!");
auto const index = DataRead<I>(); const auto index = DataRead<I>();
loader->m_vertexSkip = index == std::numeric_limits<I>::max(); loader->m_vertexSkip = index == std::numeric_limits<I>::max();
auto const data = const auto data =
reinterpret_cast<const T*>(VertexLoaderManager::cached_arraybases[ARRAY_POSITION] + reinterpret_cast<const T*>(VertexLoaderManager::cached_arraybases[ARRAY_POSITION] +
(index * g_main_cp_state.array_strides[ARRAY_POSITION])); (index * g_main_cp_state.array_strides[ARRAY_POSITION]));
auto const scale = loader->m_posScale; const auto scale = loader->m_posScale;
DataReader dst(g_vertex_manager_write_ptr, nullptr); DataReader dst(g_vertex_manager_write_ptr, nullptr);
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
{ {
float value = PosScale(Common::FromBigEndian(data[i]), scale); const float value = PosScale(Common::FromBigEndian(data[i]), scale);
if (loader->m_counter < 3) if (loader->m_counter < 3)
VertexLoaderManager::position_cache[loader->m_counter][i] = value; VertexLoaderManager::position_cache[loader->m_counter][i] = value;
dst.Write(value); dst.Write(value);
@ -75,7 +77,7 @@ void Pos_ReadIndex(VertexLoader* loader)
LOG_VTX(); LOG_VTX();
} }
static TPipelineFunction tableReadPosition[4][8][2] = { constexpr TPipelineFunction s_table_read_position[4][8][2] = {
{ {
{ {
nullptr, nullptr,
@ -166,104 +168,44 @@ static TPipelineFunction tableReadPosition[4][8][2] = {
}, },
}; };
static int tableReadPositionVertexSize[4][8][2] = { constexpr u32 s_table_read_position_vertex_size[4][8][2] = {
{ {
{ {0, 0},
0, {0, 0},
0, {0, 0},
{0, 0},
{0, 0},
}, },
{ {
0, {2, 3},
0, {2, 3},
{4, 6},
{4, 6},
{8, 12},
}, },
{ {
0, {1, 1},
0, {1, 1},
{1, 1},
{1, 1},
{1, 1},
}, },
{ {
0, {2, 2},
0, {2, 2},
}, {2, 2},
{ {2, 2},
0, {2, 2},
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,
},
}, },
}; };
} // Anonymous namespace
unsigned int VertexLoader_Position::GetSize(u64 _type, unsigned int _format, unsigned int _elements) u32 VertexLoader_Position::GetSize(u64 type, u32 format, u32 elements)
{ {
return tableReadPositionVertexSize[_type][_format][_elements]; return s_table_read_position_vertex_size[type][format][elements];
} }
TPipelineFunction VertexLoader_Position::GetFunction(u64 _type, unsigned int _format, TPipelineFunction VertexLoader_Position::GetFunction(u64 type, u32 format, u32 elements)
unsigned int _elements)
{ {
return tableReadPosition[_type][_format][_elements]; return s_table_read_position[type][format][elements];
} }

View File

@ -10,9 +10,7 @@
class VertexLoader_Position class VertexLoader_Position
{ {
public: public:
// GetSize static u32 GetSize(u64 type, u32 format, u32 elements);
static unsigned int GetSize(u64 _type, unsigned int _format, unsigned int _elements);
// GetFunction static TPipelineFunction GetFunction(u64 type, u32 format, u32 elements);
static TPipelineFunction GetFunction(u64 _type, unsigned int _format, unsigned int _elements);
}; };

View File

@ -14,6 +14,8 @@
#include "VideoCommon/VertexLoaderManager.h" #include "VideoCommon/VertexLoaderManager.h"
#include "VideoCommon/VertexLoaderUtils.h" #include "VideoCommon/VertexLoaderUtils.h"
namespace
{
template <int N> template <int N>
void LOG_TEX(); void LOG_TEX();
@ -32,19 +34,19 @@ void LOG_TEX<2>()
// ((float*)g_vertex_manager_write_ptr)[-1]); // ((float*)g_vertex_manager_write_ptr)[-1]);
} }
static void TexCoord_Read_Dummy(VertexLoader* loader) void TexCoord_Read_Dummy(VertexLoader* loader)
{ {
loader->m_tcIndex++; loader->m_tcIndex++;
} }
template <typename T> template <typename T>
float TCScale(T val, float scale) constexpr float TCScale(T val, float scale)
{ {
return val * scale; return val * scale;
} }
template <> template <>
float TCScale(float val, float scale) constexpr float TCScale(float val, [[maybe_unused]] float scale)
{ {
return val; return val;
} }
@ -52,7 +54,7 @@ float TCScale(float val, float scale)
template <typename T, int N> template <typename T, int N>
void TexCoord_ReadDirect(VertexLoader* loader) void TexCoord_ReadDirect(VertexLoader* loader)
{ {
auto const scale = loader->m_tcScale[loader->m_tcIndex]; const auto scale = loader->m_tcScale[loader->m_tcIndex];
DataReader dst(g_vertex_manager_write_ptr, nullptr); DataReader dst(g_vertex_manager_write_ptr, nullptr);
DataReader src(g_video_buffer_read_ptr, nullptr); DataReader src(g_video_buffer_read_ptr, nullptr);
@ -71,11 +73,11 @@ void TexCoord_ReadIndex(VertexLoader* loader)
{ {
static_assert(std::is_unsigned<I>::value, "Only unsigned I is sane!"); static_assert(std::is_unsigned<I>::value, "Only unsigned I is sane!");
auto const index = DataRead<I>(); const auto index = DataRead<I>();
auto const data = reinterpret_cast<const T*>( const auto data = reinterpret_cast<const T*>(
VertexLoaderManager::cached_arraybases[ARRAY_TEXCOORD0 + loader->m_tcIndex] + VertexLoaderManager::cached_arraybases[ARRAY_TEXCOORD0 + loader->m_tcIndex] +
(index * g_main_cp_state.array_strides[ARRAY_TEXCOORD0 + loader->m_tcIndex])); (index * g_main_cp_state.array_strides[ARRAY_TEXCOORD0 + loader->m_tcIndex]));
auto const scale = loader->m_tcScale[loader->m_tcIndex]; const auto scale = loader->m_tcScale[loader->m_tcIndex];
DataReader dst(g_vertex_manager_write_ptr, nullptr); DataReader dst(g_vertex_manager_write_ptr, nullptr);
for (int i = 0; i != N; ++i) for (int i = 0; i != N; ++i)
@ -86,7 +88,7 @@ void TexCoord_ReadIndex(VertexLoader* loader)
++loader->m_tcIndex; ++loader->m_tcIndex;
} }
static TPipelineFunction tableReadTexCoord[4][8][2] = { constexpr TPipelineFunction s_table_read_tex_coord[4][8][2] = {
{ {
{ {
nullptr, nullptr,
@ -177,107 +179,46 @@ static TPipelineFunction tableReadTexCoord[4][8][2] = {
}, },
}; };
static int tableReadTexCoordVertexSize[4][8][2] = { constexpr u32 s_table_read_tex_coord_vertex_size[4][8][2] = {
{ {
{ {0, 0},
0, {0, 0},
0, {0, 0},
{0, 0},
{0, 0},
}, },
{ {
0, {1, 2},
0, {1, 2},
{2, 4},
{2, 4},
{4, 8},
}, },
{ {
0, {1, 1},
0, {1, 1},
{1, 1},
{1, 1},
{1, 1},
}, },
{ {
0, {2, 2},
0, {2, 2},
}, {2, 2},
{ {2, 2},
0, {2, 2},
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,
},
}, },
}; };
} // Anonymous namespace
unsigned int VertexLoader_TextCoord::GetSize(u64 _type, unsigned int _format, u32 VertexLoader_TextCoord::GetSize(u64 type, u32 format, u32 elements)
unsigned int _elements)
{ {
return tableReadTexCoordVertexSize[_type][_format][_elements]; return s_table_read_tex_coord_vertex_size[type][format][elements];
} }
TPipelineFunction VertexLoader_TextCoord::GetFunction(u64 _type, unsigned int _format, TPipelineFunction VertexLoader_TextCoord::GetFunction(u64 type, u32 format, u32 elements)
unsigned int _elements)
{ {
return tableReadTexCoord[_type][_format][_elements]; return s_table_read_tex_coord[type][format][elements];
} }
TPipelineFunction VertexLoader_TextCoord::GetDummyFunction() TPipelineFunction VertexLoader_TextCoord::GetDummyFunction()

View File

@ -10,13 +10,10 @@
class VertexLoader_TextCoord class VertexLoader_TextCoord
{ {
public: public:
// GetSize static u32 GetSize(u64 type, u32 format, u32 elements);
static unsigned int GetSize(u64 _type, unsigned int _format, unsigned int _elements);
// GetFunction static TPipelineFunction GetFunction(u64 type, u32 format, u32 elements);
static TPipelineFunction GetFunction(u64 _type, unsigned int _format, unsigned int _elements);
// GetDummyFunction
// It is important to synchronize tcIndex. // It is important to synchronize tcIndex.
static TPipelineFunction GetDummyFunction(); static TPipelineFunction GetDummyFunction();
}; };