VideoCommon: split VertexLoaderBase from VertexLoader

This commit is contained in:
degasus
2014-12-13 01:51:14 +01:00
parent a71c8158d9
commit 809117102e
17 changed files with 309 additions and 251 deletions

View File

@ -16,6 +16,7 @@
#include "VideoCommon/CPMemory.h"
#include "VideoCommon/DataReader.h"
#include "VideoCommon/NativeVertexFormat.h"
#include "VideoCommon/VertexLoaderBase.h"
#include "VideoCommon/VertexLoaderUtils.h"
#if _M_SSE >= 0x401
@ -29,6 +30,14 @@
#define USE_VERTEX_LOADER_JIT
#endif
#ifdef WIN32
#define LOADERDECL __cdecl
#else
#define LOADERDECL
#endif
typedef void (LOADERDECL *TPipelineFunction)();
// They are used for the communication with the loader functions
extern int tcIndex;
extern int colIndex;
@ -36,105 +45,31 @@ extern int colElements[2];
GC_ALIGNED128(extern float posScale[4]);
GC_ALIGNED64(extern float tcScale[8][2]);
class VertexLoaderUID
{
u32 vid[5];
size_t hash;
public:
VertexLoaderUID()
{
}
VertexLoaderUID(const TVtxDesc& vtx_desc, const VAT& vat)
{
vid[0] = vtx_desc.Hex & 0xFFFFFFFF;
vid[1] = vtx_desc.Hex >> 32;
vid[2] = vat.g0.Hex;
vid[3] = vat.g1.Hex;
vid[4] = vat.g2.Hex;
hash = CalculateHash();
}
bool operator == (const VertexLoaderUID& rh) const
{
return hash == rh.hash && std::equal(vid, vid + sizeof(vid) / sizeof(vid[0]), rh.vid);
}
size_t GetHash() const
{
return hash;
}
private:
size_t CalculateHash()
{
size_t h = -1;
for (auto word : vid)
{
h = h * 137 + word;
}
return h;
}
};
namespace std
{
template <> struct hash<VertexLoaderUID>
{
size_t operator()(const VertexLoaderUID& uid) const
{
return uid.GetHash();
}
};
}
// ARMTODO: This should be done in a better way
#ifndef _M_GENERIC
class VertexLoader : public Gen::X64CodeBlock
class VertexLoader : public Gen::X64CodeBlock, public VertexLoaderBase
#else
class VertexLoader
class VertexLoader : public VertexLoaderBase
#endif
{
public:
VertexLoader(const TVtxDesc &vtx_desc, const VAT &vtx_attr);
~VertexLoader();
void SetupRunVertices(int primitive, int const count);
int RunVertices(int primitive, int count, DataReader src, DataReader dst);
// For debugging / profiling
void AppendToString(std::string *dest) const;
// per loader public state
int m_VertexSize; // number of bytes of a raw GC vertex
PortableVertexDeclaration m_native_vtx_decl;
u32 m_native_components;
// used by VertexLoaderManager
NativeVertexFormat* m_native_vertex_format;
int m_numLoadedVertices;
int RunVertices(int primitive, int count, DataReader src, DataReader dst) override;
std::string GetName() const override { return "OldLoader"; }
bool IsInitialized() override { return true; } // This vertex loader supports all formats
private:
// GC vertex format
TVtxAttr m_VtxAttr; // VAT decoded into easy format
TVtxDesc m_VtxDesc; // Not really used currently - or well it is, but could be easily avoided.
VAT m_vat;
#ifndef USE_VERTEX_LOADER_JIT
// Pipeline.
TPipelineFunction m_PipelineStages[64]; // TODO - figure out real max. it's lower.
int m_numPipelineStages;
#endif
const u8 *m_compiledCode;
void SetVAT(const VAT& vat);
void CompileVertexTranslator();
void ConvertVertices(int count);
void SetupRunVertices(int primitive, int const count);
void WriteCall(TPipelineFunction);
@ -142,6 +77,8 @@ private:
void WriteGetVariable(int bits, Gen::OpArg dest, void *address);
void WriteSetVariable(int bits, void *address, Gen::OpArg dest);
#endif
const u8 *m_compiledCode;
};
#if _M_SSE >= 0x301