Refactored VertexLoader::CompileVertexTranslator(). Now the vertex position loader is selected from a function table. I will apply the same kind of refactoring to texture coordinates loader. This is a pre-preparation to optimize texture coordinates loaders.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5139 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
nodchip 2010-02-28 08:41:02 +00:00
parent ff8ce634e3
commit d348c33bf2
4 changed files with 88 additions and 113 deletions

View File

@ -263,44 +263,14 @@ void VertexLoader::CompileVertexTranslator()
if (m_VtxDesc.Tex6MatIdx) {m_VertexSize += 1; m_NativeFmt->m_components |= VB_HAS_TEXMTXIDX6; WriteCall(TexMtx_ReadDirect_UByte); }
if (m_VtxDesc.Tex7MatIdx) {m_VertexSize += 1; m_NativeFmt->m_components |= VB_HAS_TEXMTXIDX7; WriteCall(TexMtx_ReadDirect_UByte); }
switch (m_VtxDesc.Position) {
case NOT_PRESENT: {_assert_msg_(0, "Vertex descriptor without position!", "WTF?");} break;
case DIRECT:
switch (m_VtxAttr.PosFormat) {
case FORMAT_UBYTE: m_VertexSize += m_VtxAttr.PosElements?3:2; WriteCall(m_VtxAttr.PosElements?Pos_ReadDirect_UByte3:Pos_ReadDirect_UByte2); break;
case FORMAT_BYTE: m_VertexSize += m_VtxAttr.PosElements?3:2; WriteCall(m_VtxAttr.PosElements?Pos_ReadDirect_Byte3:Pos_ReadDirect_Byte2); break;
case FORMAT_USHORT: m_VertexSize += m_VtxAttr.PosElements?6:4; WriteCall(m_VtxAttr.PosElements?Pos_ReadDirect_UShort3:Pos_ReadDirect_UShort2); break;
case FORMAT_SHORT: m_VertexSize += m_VtxAttr.PosElements?6:4; WriteCall(m_VtxAttr.PosElements?Pos_ReadDirect_Short3:Pos_ReadDirect_Short2); break;
case FORMAT_FLOAT: m_VertexSize += m_VtxAttr.PosElements?12:8; WriteCall(m_VtxAttr.PosElements?Pos_ReadDirect_Float3:Pos_ReadDirect_Float2); break;
default: _assert_(0); break;
}
nat_offset += 12;
break;
case INDEX8:
switch (m_VtxAttr.PosFormat) {
case FORMAT_UBYTE: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex8_UByte3:Pos_ReadIndex8_UByte2); break; //WTF?
case FORMAT_BYTE: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex8_Byte3:Pos_ReadIndex8_Byte2); break;
case FORMAT_USHORT: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex8_UShort3:Pos_ReadIndex8_UShort2); break;
case FORMAT_SHORT: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex8_Short3:Pos_ReadIndex8_Short2); break;
case FORMAT_FLOAT: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex8_Float3:Pos_ReadIndex8_Float2); break;
default: _assert_(0); break;
}
m_VertexSize += 1;
nat_offset += 12;
break;
case INDEX16:
switch (m_VtxAttr.PosFormat) {
case FORMAT_UBYTE: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex16_UByte3:Pos_ReadIndex16_UByte2); break;
case FORMAT_BYTE: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex16_Byte3:Pos_ReadIndex16_Byte2); break;
case FORMAT_USHORT: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex16_UShort3:Pos_ReadIndex16_UShort2); break;
case FORMAT_SHORT: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex16_Short3:Pos_ReadIndex16_Short2); break;
case FORMAT_FLOAT: WriteCall(m_VtxAttr.PosElements?Pos_ReadIndex16_Float3:Pos_ReadIndex16_Float2); break;
default: _assert_(0); break;
}
m_VertexSize += 2;
nat_offset += 12;
break;
}
// Write vertex position loader
_assert_msg_(VIDEO, DIRECT <= m_VtxDesc.Position && m_VtxDesc.Position <= INDEX16, "Invalid vertex position!\n(m_VtxDesc.Position = %d)", m_VtxDesc.Position);
_assert_msg_(VIDEO, FORMAT_UBYTE <= m_VtxAttr.PosFormat && m_VtxAttr.PosFormat <= FORMAT_FLOAT, "Invalid vertex position format!\n(m_VtxAttr.PosFormat = %d)", m_VtxAttr.PosFormat);
_assert_msg_(VIDEO, 0 <= m_VtxAttr.PosElements && m_VtxAttr.PosElements <= 1, "Invalid number of vertex position elemnts!\n(m_VtxAttr.PosElements = %d)", m_VtxAttr.PosElements);
WriteCall(tableReadPosition[m_VtxDesc.Position][m_VtxAttr.PosFormat][m_VtxAttr.PosElements]);
m_VertexSize += tableVertexSize[m_VtxDesc.Position][m_VtxAttr.PosFormat][m_VtxAttr.PosElements];
nat_offset += 12;
// OK, so we just got a point. Let's go back and read it for the bounding box.

View File

@ -15,9 +15,6 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef VERTEXLOADER_POSITION_H
#define VERTEXLOADER_POSITION_H
#include "Common.h"
#include "VideoCommon.h"
#include "VertexLoader.h"
@ -191,4 +188,65 @@ void LOADERDECL Pos_ReadIndex16_UShort2() {Pos_ReadIndex_Short<u16, false>(DataR
void LOADERDECL Pos_ReadIndex16_Short2() {Pos_ReadIndex_Short<s16, false>(DataReadU16());}
void LOADERDECL Pos_ReadIndex16_Float2() {Pos_ReadIndex_Float<false> (DataReadU16());}
#endif
ReadPosision tableReadPosition[4][8][2] = {
{
{NULL, NULL,},
{NULL, NULL,},
{NULL, NULL,},
{NULL, NULL,},
{NULL, NULL,},
},
{
{Pos_ReadDirect_UByte2, Pos_ReadDirect_UByte3,},
{Pos_ReadDirect_Byte2, Pos_ReadDirect_Byte3,},
{Pos_ReadDirect_UShort2, Pos_ReadDirect_UShort3,},
{Pos_ReadDirect_Short2, Pos_ReadDirect_Short3,},
{Pos_ReadDirect_Float2, Pos_ReadDirect_Float3,},
},
{
{Pos_ReadIndex8_UByte2, Pos_ReadIndex8_UByte3,},
{Pos_ReadIndex8_Byte2, Pos_ReadIndex8_Byte3,},
{Pos_ReadIndex8_UShort2, Pos_ReadIndex8_UShort3,},
{Pos_ReadIndex8_Short2, Pos_ReadIndex8_Short3,},
{Pos_ReadIndex8_Float2, Pos_ReadIndex8_Float3,},
},
{
{Pos_ReadIndex16_UByte2, Pos_ReadIndex16_UByte3,},
{Pos_ReadIndex16_Byte2, Pos_ReadIndex16_Byte3,},
{Pos_ReadIndex16_UShort2, Pos_ReadIndex16_UShort3,},
{Pos_ReadIndex16_Short2, Pos_ReadIndex16_Short3,},
{Pos_ReadIndex16_Float2, Pos_ReadIndex16_Float3,},
},
};
int tableVertexSize[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,},
},
};

View File

@ -18,40 +18,17 @@
#ifndef VERTEXLOADER_POSITION_H
#define VERTEXLOADER_POSITION_H
void LOADERDECL Pos_ReadDirect_UByte3();
void LOADERDECL Pos_ReadDirect_Byte3();
void LOADERDECL Pos_ReadDirect_UShort3();
void LOADERDECL Pos_ReadDirect_Short3();
void LOADERDECL Pos_ReadDirect_Float3();
typedef void (LOADERDECL *ReadPosision)();
void LOADERDECL Pos_ReadIndex8_UByte3();
void LOADERDECL Pos_ReadIndex8_Byte3();
void LOADERDECL Pos_ReadIndex8_UShort3();
void LOADERDECL Pos_ReadIndex8_Short3();
void LOADERDECL Pos_ReadIndex8_Float3();
// Hold function pointers of vertex loaders.
// The first dimension corresponds to TVtxDesc.Position.
// The second dimension corresponds to TVtxAttr.PosFormat.
// The third dimension corresponds to TVtxAttr.PosElements.
// The dimensions are aligned to 2^n for speed up.
extern ReadPosision tableReadPosition[4][8][2];
void LOADERDECL Pos_ReadIndex16_UByte3();
void LOADERDECL Pos_ReadIndex16_Byte3();
void LOADERDECL Pos_ReadIndex16_UShort3();
void LOADERDECL Pos_ReadIndex16_Short3();
void LOADERDECL Pos_ReadIndex16_Float3();
void LOADERDECL Pos_ReadDirect_UByte2();
void LOADERDECL Pos_ReadDirect_Byte2();
void LOADERDECL Pos_ReadDirect_UShort2();
void LOADERDECL Pos_ReadDirect_Short2();
void LOADERDECL Pos_ReadDirect_Float2();
void LOADERDECL Pos_ReadIndex8_UByte2();
void LOADERDECL Pos_ReadIndex8_Byte2();
void LOADERDECL Pos_ReadIndex8_UShort2();
void LOADERDECL Pos_ReadIndex8_Short2();
void LOADERDECL Pos_ReadIndex8_Float2();
void LOADERDECL Pos_ReadIndex16_UByte2();
void LOADERDECL Pos_ReadIndex16_Byte2();
void LOADERDECL Pos_ReadIndex16_UShort2();
void LOADERDECL Pos_ReadIndex16_Short2();
void LOADERDECL Pos_ReadIndex16_Float2();
// Hold vertex size of each vertex format.
// The dimensions are same as tableReadPosition.
extern int tableVertexSize[4][8][2];
#endif

View File

@ -147,44 +147,14 @@ void VertexLoader::SetFormat(u8 attributeIndex, u8 primitiveType)
}
}
switch (g_VtxDesc.Position) {
case NOT_PRESENT: {_assert_msg_(VIDEO, 0, "Vertex descriptor without position!"); } break;
case DIRECT:
switch (m_CurrentVat->g0.PosFormat) {
case FORMAT_UBYTE: m_VertexSize += m_CurrentVat->g0.PosElements?3:2; m_positionLoader = (m_CurrentVat->g0.PosElements?Pos_ReadDirect_UByte3:Pos_ReadDirect_UByte2); break;
case FORMAT_BYTE: m_VertexSize += m_CurrentVat->g0.PosElements?3:2; m_positionLoader = (m_CurrentVat->g0.PosElements?Pos_ReadDirect_Byte3:Pos_ReadDirect_Byte2); break;
case FORMAT_USHORT: m_VertexSize += m_CurrentVat->g0.PosElements?6:4; m_positionLoader = (m_CurrentVat->g0.PosElements?Pos_ReadDirect_UShort3:Pos_ReadDirect_UShort2); break;
case FORMAT_SHORT: m_VertexSize += m_CurrentVat->g0.PosElements?6:4; m_positionLoader = (m_CurrentVat->g0.PosElements?Pos_ReadDirect_Short3:Pos_ReadDirect_Short2); break;
case FORMAT_FLOAT: m_VertexSize += m_CurrentVat->g0.PosElements?12:8; m_positionLoader = (m_CurrentVat->g0.PosElements?Pos_ReadDirect_Float3:Pos_ReadDirect_Float2); break;
default: _assert_(0); break;
}
AddAttributeLoader(LoadPosition);
break;
case INDEX8:
switch (m_CurrentVat->g0.PosFormat) {
case FORMAT_UBYTE: m_positionLoader = (m_CurrentVat->g0.PosElements?Pos_ReadIndex8_UByte3:Pos_ReadIndex8_UByte2); break;
case FORMAT_BYTE: m_positionLoader = (m_CurrentVat->g0.PosElements?Pos_ReadIndex8_Byte3:Pos_ReadIndex8_Byte2); break;
case FORMAT_USHORT: m_positionLoader = (m_CurrentVat->g0.PosElements?Pos_ReadIndex8_UShort3:Pos_ReadIndex8_UShort2); break;
case FORMAT_SHORT: m_positionLoader = (m_CurrentVat->g0.PosElements?Pos_ReadIndex8_Short3:Pos_ReadIndex8_Short2); break;
case FORMAT_FLOAT: m_positionLoader = (m_CurrentVat->g0.PosElements?Pos_ReadIndex8_Float3:Pos_ReadIndex8_Float2); break;
default: _assert_(0); break;
}
AddAttributeLoader(LoadPosition);
m_VertexSize += 1;
break;
case INDEX16:
switch (m_CurrentVat->g0.PosFormat) {
case FORMAT_UBYTE: m_positionLoader = (m_CurrentVat->g0.PosElements?Pos_ReadIndex16_UByte3:Pos_ReadIndex16_UByte2); break;
case FORMAT_BYTE: m_positionLoader = (m_CurrentVat->g0.PosElements?Pos_ReadIndex16_Byte3:Pos_ReadIndex16_Byte2); break;
case FORMAT_USHORT: m_positionLoader = (m_CurrentVat->g0.PosElements?Pos_ReadIndex16_UShort3:Pos_ReadIndex16_UShort2); break;
case FORMAT_SHORT: m_positionLoader = (m_CurrentVat->g0.PosElements?Pos_ReadIndex16_Short3:Pos_ReadIndex16_Short2); break;
case FORMAT_FLOAT: m_positionLoader = (m_CurrentVat->g0.PosElements?Pos_ReadIndex16_Float3:Pos_ReadIndex16_Float2); break;
default: _assert_(0); break;
}
AddAttributeLoader(LoadPosition);
m_VertexSize += 2;
break;
}
// Write vertex position loader
_assert_msg_(VIDEO, DIRECT <= g_VtxDesc.Position && g_VtxDesc.Position <= INDEX16, "Invalid vertex position!\n(m_VtxDesc.Position = %d)", g_VtxDesc.Position);
_assert_msg_(VIDEO, FORMAT_UBYTE <= m_CurrentVat->g0.PosFormat && m_CurrentVat->g0.PosFormat <= FORMAT_FLOAT, "Invalid vertex position format!\n(m_VtxAttr.PosFormat = %d)", m_CurrentVat->g0.PosFormat);
_assert_msg_(VIDEO, 0 <= m_CurrentVat->g0.PosElements && m_CurrentVat->g0.PosElements <= 1, "Invalid number of vertex position elemnts!\n(m_VtxAttr.PosElements = %d)", m_CurrentVat->g0.PosElements);
m_positionLoader = tableReadPosition[g_VtxDesc.Position][m_CurrentVat->g0.PosFormat][m_CurrentVat->g0.PosElements];
m_VertexSize += tableVertexSize[g_VtxDesc.Position][m_CurrentVat->g0.PosFormat][m_CurrentVat->g0.PosElements];
AddAttributeLoader(LoadPosition);
// Normals
if (g_VtxDesc.Normal != NOT_PRESENT) {