VertexManager cleanup

This commit is contained in:
Jordan Woyak 2013-02-22 01:41:52 -06:00
parent 21bd5be753
commit db1be085c2
6 changed files with 54 additions and 82 deletions

View File

@ -571,8 +571,9 @@ void VertexLoader::RunVertices(int vtx_attr_group, int primitive, int count)
"Increase MAXVBUFFERSIZE or we need primitive breaking afterall.");
}
VertexManager::AddVertices(primitive, count);
ConvertVertices(count);
VertexManager::AddVertices(primitive, count);
//VertexManager::Flush();
}

View File

@ -12,25 +12,17 @@
#include "BPStructs.h"
#include "VertexManagerBase.h"
#include "MainBase.h"
#include "VideoConfig.h"
VertexManager *g_vertex_manager;
u8 *VertexManager::s_pBaseBufferPointer;
u8 *VertexManager::s_pCurBufferPointer;
u8 *VertexManager::s_pBaseBufferPointer;
u8 *VertexManager::s_pEndBufferPointer;
u8 *VertexManager::LocalVBuffer;
u16 *VertexManager::TIBuffer;
u16 *VertexManager::LIBuffer;
u16 *VertexManager::PIBuffer;
bool VertexManager::Flushed;
VertexManager::VertexManager()
{
Flushed = false;
LocalVBuffer = new u8[MAXVBUFFERSIZE];
s_pCurBufferPointer = s_pBaseBufferPointer = LocalVBuffer;
s_pEndBufferPointer = s_pBaseBufferPointer + MAXVBUFFERSIZE;
@ -39,12 +31,7 @@ VertexManager::VertexManager()
LIBuffer = new u16[MAXIBUFFERSIZE];
PIBuffer = new u16[MAXIBUFFERSIZE];
IndexGenerator::Start(TIBuffer, LIBuffer, PIBuffer);
}
void VertexManager::ResetBuffer()
{
s_pCurBufferPointer = s_pBaseBufferPointer;
ResetBuffer();
}
VertexManager::~VertexManager()
@ -59,12 +46,25 @@ VertexManager::~VertexManager()
ResetBuffer();
}
void VertexManager::ResetBuffer()
{
s_pCurBufferPointer = s_pBaseBufferPointer;
IndexGenerator::Start(TIBuffer, LIBuffer, PIBuffer);
}
int VertexManager::GetRemainingSize()
{
return (int)(s_pEndBufferPointer - s_pCurBufferPointer);
}
bool VertexManager::IsFlushed() const
{
return s_pBaseBufferPointer == s_pCurBufferPointer;
}
// Not used anywhere
// TODO: use this
#if 0
int VertexManager::GetRemainingVertices(int primitive)
{
switch (primitive)
@ -90,42 +90,38 @@ int VertexManager::GetRemainingVertices(int primitive)
break;
}
}
#endif
void VertexManager::AddVertices(int primitive, u32 numVertices)
{
if (numVertices <= 0)
return;
if (Flushed)
{
IndexGenerator::Start(TIBuffer, LIBuffer, PIBuffer);
Flushed = false;
}
ADDSTAT(stats.thisFrame.numPrims, numVertices);
INCSTAT(stats.thisFrame.numPrimitiveJoins);
IndexGenerator::AddIndices(primitive, numVertices);
}
void VertexManager::Flush()
{
if (g_vertex_manager->IsFlushed())
return;
// loading a state will invalidate BP, so check for it
g_video_backend->CheckInvalidState();
VideoFifo_CheckEFBAccess();
g_vertex_manager->vFlush();
g_vertex_manager->ResetBuffer();
}
// TODO: need to merge more stuff into VideoCommon to use this
#if (0)
void VertexManager::Flush()
{
if (s_pBaseBufferPointer == s_pCurBufferPointer || Flushed)
return;
Flushed = true;
VideoFifo_CheckEFBAccess();
#if defined(_DEBUG) || defined(DEBUGFAST)
PRIM_LOG("frame%d:\n texgen=%d, numchan=%d, dualtex=%d, ztex=%d, cole=%d, alpe=%d, ze=%d", g_ActiveConfig.iSaveTargetId, xfregs.numTexGens,
xfregs.nNumChans, (int)xfregs.bEnableDualTexTransform, bpmem.ztex2.op,
@ -198,9 +194,9 @@ void VertexManager::Flush()
// finally bind
if (false == PixelShaderCache::SetShader(false, g_nativeVertexFmt->m_components))
goto shader_fail;
return;
if (false == VertexShaderCache::SetShader(g_nativeVertexFmt->m_components))
goto shader_fail;
return;
const int stride = g_nativeVertexFmt->GetVertexStride();
//if (g_nativeVertexFmt)
@ -212,7 +208,7 @@ void VertexManager::Flush()
if (false == g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate)
{
if (false == PixelShaderCache::SetShader(true, g_nativeVertexFmt->m_components))
goto shader_fail;
return;
g_vertex_manager->Draw(stride, true);
}
@ -246,9 +242,6 @@ void VertexManager::Flush()
}
#endif
++g_Config.iSaveTargetId;
shader_fail:
ResetBuffer();
}
#endif
@ -259,12 +252,9 @@ void VertexManager::DoState(PointerWrap& p)
void VertexManager::DoStateShared(PointerWrap& p)
{
p.DoPointer(s_pCurBufferPointer, LocalVBuffer);
p.DoPointer(s_pCurBufferPointer, g_vertex_manager->LocalVBuffer);
p.DoArray(LocalVBuffer, MAXVBUFFERSIZE);
p.DoArray(TIBuffer, MAXIBUFFERSIZE);
p.DoArray(LIBuffer, MAXIBUFFERSIZE);
p.DoArray(PIBuffer, MAXIBUFFERSIZE);
if (p.GetMode() == PointerWrap::MODE_READ)
Flushed = false;
p.DoArray(g_vertex_manager->TIBuffer, MAXIBUFFERSIZE);
p.DoArray(g_vertex_manager->LIBuffer, MAXIBUFFERSIZE);
p.DoArray(g_vertex_manager->PIBuffer, MAXIBUFFERSIZE);
}

View File

@ -32,46 +32,47 @@ public:
static void AddVertices(int _primitive, u32 _numVertices);
// TODO: protected?
static u8 *s_pBaseBufferPointer;
static u8 *s_pCurBufferPointer;
static u8 *s_pBaseBufferPointer;
static u8 *s_pEndBufferPointer;
static int GetRemainingSize();
static int GetRemainingVertices(int primitive);
//int GetRemainingVertices(int primitive);
static void Flush();
virtual ::NativeVertexFormat* CreateNativeVertexFormat() = 0;
static u16* GetTriangleIndexBuffer() { return TIBuffer; }
static u16* GetLineIndexBuffer() { return LIBuffer; }
static u16* GetPointIndexBuffer() { return PIBuffer; }
static u8* GetVertexBuffer() { return s_pBaseBufferPointer; }
// TODO: use these instead of TIBuffer, etc
// u16* GetTriangleIndexBuffer() { return TIBuffer; }
// u16* GetLineIndexBuffer() { return LIBuffer; }
// u16* GetPointIndexBuffer() { return PIBuffer; }
// u8* GetVertexBuffer() { return s_pBaseBufferPointer; }
static void DoState(PointerWrap& p);
virtual void CreateDeviceObjects(){};
virtual void DestroyDeviceObjects(){};
protected:
// TODO: make private after Flush() is merged
static void ResetBuffer();
static u16 *TIBuffer;
static u16 *LIBuffer;
static u16 *PIBuffer;
static bool Flushed;
u16* TIBuffer;
u16* LIBuffer;
u16* PIBuffer;
virtual void vDoState(PointerWrap& p) { DoStateShared(p); }
void DoStateShared(PointerWrap& p);
private:
bool IsFlushed() const;
void ResetBuffer();
//virtual void Draw(u32 stride, bool alphapass) = 0;
// temp
virtual void vFlush() = 0;
static u8 *LocalVBuffer;
u8* LocalVBuffer;
};
extern VertexManager *g_vertex_manager;

View File

@ -211,11 +211,6 @@ void VertexManager::Draw(UINT stride)
void VertexManager::vFlush()
{
if (s_pBaseBufferPointer == s_pCurBufferPointer) return;
if (Flushed) return;
Flushed=true;
VideoFifo_CheckEFBAccess();
u32 usedtextures = 0;
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; ++i)
if (bpmem.tevorders[i / 2].getEnable(i & 1))
@ -263,12 +258,12 @@ void VertexManager::vFlush()
g_nativeVertexFmt->m_components))
{
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
goto shader_fail;
return;
}
if (!VertexShaderCache::SetShader(g_nativeVertexFmt->m_components))
{
GFX_DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
goto shader_fail;
return;
}
LoadBuffers();
unsigned int stride = g_nativeVertexFmt->GetVertexStride();
@ -280,9 +275,6 @@ void VertexManager::vFlush()
GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true);
g_renderer->RestoreState();
shader_fail:
ResetBuffer();
}
} // namespace

View File

@ -307,11 +307,6 @@ void VertexManager::DrawVA(int stride)
void VertexManager::vFlush()
{
if (s_pBaseBufferPointer == s_pCurBufferPointer) return;
if (Flushed) return;
Flushed = true;
VideoFifo_CheckEFBAccess();
u32 usedtextures = 0;
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; ++i)
if (bpmem.tevorders[i / 2].getEnable(i & 1))
@ -388,7 +383,6 @@ shader_fail:
CurrentIBufferIndex += IndexGenerator::GetTriangleindexLen() + IndexGenerator::GetLineindexLen() + IndexGenerator::GetPointindexLen();
CurrentVBufferIndex += IndexGenerator::GetNumVerts() * stride;
}
ResetBuffer();
}
}

View File

@ -100,10 +100,6 @@ void VertexManager::Draw()
void VertexManager::vFlush()
{
if (s_pBaseBufferPointer == s_pCurBufferPointer) return;
if (Flushed) return;
Flushed=true;
VideoFifo_CheckEFBAccess();
#if defined(_DEBUG) || defined(DEBUGFAST)
PRIM_LOG("frame%d:\n texgen=%d, numchan=%d, dualtex=%d, ztex=%d, cole=%d, alpe=%d, ze=%d", g_ActiveConfig.iSaveTargetId, xfregs.numTexGen.numTexGens,
xfregs.numChan.numColorChans, xfregs.dualTexTrans.enabled, bpmem.ztex2.op,
@ -240,8 +236,6 @@ void VertexManager::vFlush()
GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true);
//s_nCurVBOIndex = (s_nCurVBOIndex + 1) % ARRAYSIZE(s_vboBuffers);
s_pCurBufferPointer = s_pBaseBufferPointer;
IndexGenerator::Start(TIBuffer,LIBuffer,PIBuffer);
#if defined(_DEBUG) || defined(DEBUGFAST)
if (g_ActiveConfig.iLog & CONF_SAVESHADERS)