2013-04-17 21:09:55 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2014-02-10 11:54:46 -07:00
|
|
|
#pragma once
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2009-02-15 06:45:03 -07:00
|
|
|
// Top vertex loaders
|
|
|
|
// Metroid Prime: P I16-flt N I16-s16 T0 I16-u16 T1 i16-flt
|
|
|
|
|
2010-03-05 05:04:09 -07:00
|
|
|
#include <algorithm>
|
2008-12-07 21:46:09 -07:00
|
|
|
#include <string>
|
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/Common.h"
|
|
|
|
#include "Common/x64Emitter.h"
|
2009-02-28 09:33:59 -07:00
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/CPMemory.h"
|
|
|
|
#include "VideoCommon/DataReader.h"
|
|
|
|
#include "VideoCommon/NativeVertexFormat.h"
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2014-02-23 07:14:27 -07:00
|
|
|
#ifndef _M_GENERIC
|
|
|
|
#ifndef __APPLE__
|
|
|
|
#define USE_VERTEX_LOADER_JIT
|
|
|
|
#endif
|
|
|
|
#endif
|
2008-12-19 14:24:52 -07:00
|
|
|
|
2008-12-07 21:46:09 -07:00
|
|
|
class VertexLoaderUID
|
|
|
|
{
|
|
|
|
u32 vid[5];
|
2010-03-06 03:07:37 -07:00
|
|
|
size_t hash;
|
2008-12-07 21:46:09 -07:00
|
|
|
public:
|
2013-10-28 23:23:17 -06:00
|
|
|
VertexLoaderUID()
|
2013-04-24 07:21:54 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitFromCurrentState(int vtx_attr_group)
|
|
|
|
{
|
2008-12-07 21:46:09 -07:00
|
|
|
vid[0] = g_VtxDesc.Hex & 0xFFFFFFFF;
|
|
|
|
vid[1] = g_VtxDesc.Hex >> 32;
|
|
|
|
vid[2] = g_VtxAttr[vtx_attr_group].g0.Hex & ~VAT_0_FRACBITS;
|
|
|
|
vid[3] = g_VtxAttr[vtx_attr_group].g1.Hex & ~VAT_1_FRACBITS;
|
|
|
|
vid[4] = g_VtxAttr[vtx_attr_group].g2.Hex & ~VAT_2_FRACBITS;
|
2010-03-06 03:07:37 -07:00
|
|
|
hash = CalculateHash();
|
2008-12-07 21:46:09 -07:00
|
|
|
}
|
2013-04-24 07:21:54 -06:00
|
|
|
|
|
|
|
bool operator < (const VertexLoaderUID &other) const
|
|
|
|
{
|
2010-03-05 19:07:48 -07:00
|
|
|
// This is complex because of speed.
|
|
|
|
if (vid[0] < other.vid[0])
|
|
|
|
return true;
|
|
|
|
else if (vid[0] > other.vid[0])
|
|
|
|
return false;
|
2013-04-24 07:21:54 -06:00
|
|
|
|
|
|
|
for (int i = 1; i < 5; ++i)
|
|
|
|
{
|
2010-03-05 19:07:48 -07:00
|
|
|
if (vid[i] < other.vid[i])
|
|
|
|
return true;
|
|
|
|
else if (vid[i] > other.vid[i])
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-24 07:21:54 -06:00
|
|
|
|
2010-03-05 19:07:48 -07:00
|
|
|
return false;
|
|
|
|
}
|
2013-04-24 07:21:54 -06:00
|
|
|
|
|
|
|
bool operator == (const VertexLoaderUID& rh) const
|
|
|
|
{
|
2010-03-06 03:07:37 -07:00
|
|
|
return hash == rh.hash && std::equal(vid, vid + sizeof(vid) / sizeof(vid[0]), rh.vid);
|
|
|
|
}
|
2013-04-24 07:21:54 -06:00
|
|
|
|
|
|
|
size_t GetHash() const
|
|
|
|
{
|
2010-03-06 03:07:37 -07:00
|
|
|
return hash;
|
|
|
|
}
|
2013-04-24 07:21:54 -06:00
|
|
|
|
2010-03-06 03:07:37 -07:00
|
|
|
private:
|
2013-04-24 07:21:54 -06:00
|
|
|
|
|
|
|
size_t CalculateHash()
|
|
|
|
{
|
2010-03-05 19:07:48 -07:00
|
|
|
size_t h = -1;
|
2013-04-24 07:21:54 -06:00
|
|
|
|
2013-10-28 23:09:01 -06:00
|
|
|
for (auto word : vid)
|
2013-04-24 07:21:54 -06:00
|
|
|
{
|
2013-10-28 23:09:01 -06:00
|
|
|
h = h * 137 + word;
|
2010-03-05 19:07:48 -07:00
|
|
|
}
|
2013-04-24 07:21:54 -06:00
|
|
|
|
2010-03-05 19:07:48 -07:00
|
|
|
return h;
|
|
|
|
}
|
2008-12-07 21:46:09 -07:00
|
|
|
};
|
|
|
|
|
2013-02-26 12:49:00 -07:00
|
|
|
// ARMTODO: This should be done in a better way
|
|
|
|
#ifndef _M_GENERIC
|
2014-04-09 00:22:52 -06:00
|
|
|
class VertexLoader : public Gen::X64CodeBlock
|
2013-02-26 12:49:00 -07:00
|
|
|
#else
|
|
|
|
class VertexLoader
|
|
|
|
#endif
|
2008-12-07 21:46:09 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
VertexLoader(const TVtxDesc &vtx_desc, const VAT &vtx_attr);
|
|
|
|
~VertexLoader();
|
|
|
|
|
|
|
|
int GetVertexSize() const {return m_VertexSize;}
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2014-01-30 06:48:23 -07:00
|
|
|
void SetupRunVertices(int vtx_attr_group, int primitive, int const count);
|
2008-12-07 21:46:09 -07:00
|
|
|
void RunVertices(int vtx_attr_group, int primitive, int count);
|
|
|
|
|
|
|
|
// For debugging / profiling
|
2009-02-15 05:38:25 -07:00
|
|
|
void AppendToString(std::string *dest) const;
|
|
|
|
int GetNumLoadedVerts() const { return m_numLoadedVertices; }
|
2008-12-07 21:46:09 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
int m_VertexSize; // number of bytes of a raw GC vertex. Computed by CompileVertexTranslator.
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
// PC vertex format
|
|
|
|
NativeVertexFormat *m_NativeFmt;
|
|
|
|
int native_stride;
|
|
|
|
|
2014-02-23 07:14:27 -07:00
|
|
|
#ifndef USE_VERTEX_LOADER_JIT
|
|
|
|
// Pipeline.
|
2008-12-07 21:46:09 -07:00
|
|
|
TPipelineFunction m_PipelineStages[64]; // TODO - figure out real max. it's lower.
|
|
|
|
int m_numPipelineStages;
|
2014-02-23 07:14:27 -07:00
|
|
|
#endif
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2008-12-19 14:24:52 -07:00
|
|
|
const u8 *m_compiledCode;
|
2008-12-07 21:46:09 -07:00
|
|
|
|
|
|
|
int m_numLoadedVertices;
|
|
|
|
|
|
|
|
void SetVAT(u32 _group0, u32 _group1, u32 _group2);
|
|
|
|
|
|
|
|
void CompileVertexTranslator();
|
2013-02-21 03:36:10 -07:00
|
|
|
void ConvertVertices(int count);
|
2008-12-07 21:46:09 -07:00
|
|
|
|
|
|
|
void WriteCall(TPipelineFunction);
|
2009-01-10 16:10:33 -07:00
|
|
|
|
2013-02-26 12:49:00 -07:00
|
|
|
#ifndef _M_GENERIC
|
2009-02-06 12:52:23 -07:00
|
|
|
void WriteGetVariable(int bits, Gen::OpArg dest, void *address);
|
|
|
|
void WriteSetVariable(int bits, void *address, Gen::OpArg dest);
|
2013-02-26 12:49:00 -07:00
|
|
|
#endif
|
2013-03-19 19:51:12 -06:00
|
|
|
};
|