Merged identical VertexManager code from DX9/DX11/OGL plugins into VideoCommon. Still need to merge VertexManager::Flush (will be easier after TextureCache is merged). Purposely using a class/virtualfuncs rather than a namespace so multiple VertexManager can be in one plugin (VideoMergeNew? :p).

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6249 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak 2010-10-03 00:41:06 +00:00
parent aaeb21fe3b
commit 841583b8f3
24 changed files with 346 additions and 449 deletions

View File

@ -32,7 +32,7 @@
#include "BPMemory.h"
#include "VertexLoaderManager.h"
#include "NativeVertexWriter.h"
#include "VertexManagerBase.h"
#include "x64Emitter.h"
#include "ABI.h"

View File

@ -29,7 +29,7 @@ files = [
'VertexLoader_TextCoord.cpp',
'TextureConversionShader.cpp',
'ImageWrite.cpp',
'NativeVertexWriter.cpp',
'VertexManagerBase.cpp',
'Statistics.cpp',
'Fifo.cpp',
'VideoState.cpp',

View File

@ -33,7 +33,7 @@
#include "VertexLoader.h"
#include "BPMemory.h"
#include "DataReader.h"
#include "NativeVertexWriter.h"
#include "VertexManagerBase.h"
#include "VertexLoader_Position.h"
#include "VertexLoader_Normal.h"

View File

@ -23,7 +23,7 @@
#include "LookUpTables.h"
#include "VertexLoader.h"
#include "VertexLoader_Color.h"
#include "NativeVertexWriter.h"
#include "VertexManagerBase.h"
#define RSHIFT 0
#define GSHIFT 8

View File

@ -19,7 +19,7 @@
#include "VideoCommon.h"
#include "VertexLoader.h"
#include "VertexLoader_Normal.h"
#include "NativeVertexWriter.h"
#include "VertexManagerBase.h"
#include "CPUDetect.h"
#if _M_SSE >= 0x301 && !(defined __GNUC__ && !defined __SSSE3__)

View File

@ -19,7 +19,7 @@
#include "VideoCommon.h"
#include "VertexLoader.h"
#include "VertexLoader_Position.h"
#include "NativeVertexWriter.h"
#include "VertexManagerBase.h"
#include "CPUDetect.h"
#if _M_SSE >= 0x301 && !(defined __GNUC__ && !defined __SSSE3__)

View File

@ -19,7 +19,7 @@
#include "VideoCommon.h"
#include "VertexLoader.h"
#include "VertexLoader_TextCoord.h"
#include "NativeVertexWriter.h"
#include "VertexManagerBase.h"
#include "CPUDetect.h"
#if _M_SSE >= 0x401

View File

@ -0,0 +1,158 @@
#include "Common.h"
#include "Statistics.h"
#include "OpcodeDecoding.h"
#include "IndexGenerator.h"
#include "VertexManagerBase.h"
VertexManager *g_vertex_manager;
u8 *VertexManager::s_pCurBufferPointer;
u8 *VertexManager::s_pBaseBufferPointer;
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;
TIBuffer = new u16[MAXIBUFFERSIZE];
LIBuffer = new u16[MAXIBUFFERSIZE];
PIBuffer = new u16[MAXIBUFFERSIZE];
IndexGenerator::Start(TIBuffer, LIBuffer, PIBuffer);
}
void VertexManager::ResetBuffer()
{
s_pCurBufferPointer = LocalVBuffer;
}
VertexManager::~VertexManager()
{
delete[] LocalVBuffer;
delete[] TIBuffer;
delete[] LIBuffer;
delete[] PIBuffer;
// TODO: necessary??
ResetBuffer();
}
void VertexManager::AddIndices(int primitive, int numVertices)
{
//switch (primitive)
//{
//case GX_DRAW_QUADS: IndexGenerator::AddQuads(numVertices); break;
//case GX_DRAW_TRIANGLES: IndexGenerator::AddList(numVertices); break;
//case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(numVertices); break;
//case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(numVertices); break;
//case GX_DRAW_LINES: IndexGenerator::AddLineList(numVertices); break;
//case GX_DRAW_LINE_STRIP: IndexGenerator::AddLineStrip(numVertices); break;
//case GX_DRAW_POINTS: IndexGenerator::AddPoints(numVertices); break;
//}
static void (*const primitive_table[])(int) =
{
IndexGenerator::AddQuads,
NULL,
IndexGenerator::AddList,
IndexGenerator::AddStrip,
IndexGenerator::AddFan,
IndexGenerator::AddLineList,
IndexGenerator::AddLineStrip,
IndexGenerator::AddPoints,
};
primitive_table[primitive](numVertices);
}
int VertexManager::GetRemainingSize()
{
return MAXVBUFFERSIZE - (int)(s_pCurBufferPointer - LocalVBuffer);
}
int VertexManager::GetRemainingVertices(int primitive)
{
switch (primitive)
{
case GX_DRAW_QUADS:
case GX_DRAW_TRIANGLES:
case GX_DRAW_TRIANGLE_STRIP:
case GX_DRAW_TRIANGLE_FAN:
return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen()) / 3;
break;
case GX_DRAW_LINES:
case GX_DRAW_LINE_STRIP:
return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen()) / 2;
break;
case GX_DRAW_POINTS:
return (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen());
break;
default:
return 0;
break;
}
}
void VertexManager::AddVertices(int primitive, int numVertices)
{
if (numVertices <= 0)
return;
switch (primitive)
{
case GX_DRAW_QUADS:
case GX_DRAW_TRIANGLES:
case GX_DRAW_TRIANGLE_STRIP:
case GX_DRAW_TRIANGLE_FAN:
if (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen() < 3 * numVertices)
Flush();
break;
case GX_DRAW_LINES:
case GX_DRAW_LINE_STRIP:
if (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen() < 2 * numVertices)
Flush();
break;
case GX_DRAW_POINTS:
if (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen() < numVertices)
Flush();
break;
default:
return;
break;
}
if (Flushed)
{
IndexGenerator::Start(TIBuffer, LIBuffer, PIBuffer);
Flushed = false;
}
ADDSTAT(stats.thisFrame.numPrims, numVertices);
INCSTAT(stats.thisFrame.numPrimitiveJoins);
AddIndices(primitive, numVertices);
}
// TODO: merge this func, (need to merge TextureCache)
void VertexManager::Flush()
{
g_vertex_manager->vFlush();
}

View File

@ -0,0 +1,57 @@
#ifndef _VERTEXMANAGERBASE_H
#define _VERTEXMANAGERBASE_H
class VertexManager
{
public:
enum
{
// values from OGL plugin
//MAXVBUFFERSIZE = 0x1FFFF,
//MAXIBUFFERSIZE = 0xFFFF,
// values from DX9 plugin
//MAXVBUFFERSIZE = 0x50000,
//MAXIBUFFERSIZE = 0xFFFF,
// values from DX11 plugin
MAXVBUFFERSIZE = 0x50000,
MAXIBUFFERSIZE = 0x10000,
};
VertexManager();
virtual ~VertexManager(); // needs to be virtual for DX11's dtor
static void AddVertices(int _primitive, int _numVertices);
// TODO: protected?
static u8 *s_pCurBufferPointer;
static u8 *s_pBaseBufferPointer;
static int GetRemainingSize();
static int GetRemainingVertices(int primitive);
static void Flush();
protected:
// TODO: make private after Flush() is merged
static void ResetBuffer();
static u8 *LocalVBuffer;
static u16 *TIBuffer;
static u16 *LIBuffer;
static u16 *PIBuffer;
static bool Flushed;
private:
static void AddIndices(int primitive, int numVertices);
// temporary
virtual void vFlush() = 0;
};
extern VertexManager *g_vertex_manager;
#endif

View File

@ -30,12 +30,7 @@
#include "CPMemory.h"
#include "XFMemory.h"
#include "VideoCommon.h"
// Temporary ugly declaration.
namespace VertexManager
{
void Flush();
}
#include "VertexManagerBase.h"
static float GC_ALIGNED16(s_fMaterials[16]);
float GC_ALIGNED16(g_fProjectionMatrix[16]);

View File

@ -19,7 +19,7 @@
#include "VideoCommon.h"
#include "XFMemory.h"
#include "CPMemory.h"
#include "NativeVertexWriter.h"
#include "VertexManagerBase.h"
#include "VertexShaderManager.h"
#include "PixelShaderManager.h"

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Version="9.00"
Name="VideoCommon"
ProjectGUID="{E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}"
RootNamespace="VideoCommon"
@ -562,14 +562,6 @@
RelativePath=".\Src\LookUpTables.h"
>
</File>
<File
RelativePath=".\Src\NativeVertexWriter.cpp"
>
</File>
<File
RelativePath=".\Src\NativeVertexWriter.h"
>
</File>
<File
RelativePath=".\Src\OnScreenDisplay.cpp"
>
@ -735,6 +727,18 @@
</File>
</Filter>
</Filter>
<Filter
Name="Base"
>
<File
RelativePath=".\Src\VertexManagerBase.cpp"
>
</File>
<File
RelativePath=".\Src\VertexManagerBase.h"
>
</File>
</Filter>
<File
RelativePath=".\Src\CommandProcessor.cpp"
>

View File

@ -33,7 +33,6 @@
#include "PixelShaderManager.h"
#include "PixelShaderCache.h"
#include "NativeVertexFormat.h"
#include "NativeVertexWriter.h"
#include "TextureCache.h"
#include "main.h"
@ -42,202 +41,98 @@
#include "Globals.h"
#include <string>
using std::string;
using namespace D3D;
// internal state for loading vertices
extern NativeVertexFormat *g_nativeVertexFmt;
namespace VertexManager
namespace DX11
{
static int lastPrimitive;
static u8 *LocalVBuffer;
static u16 *TIBuffer;
static u16 *LIBuffer;
static u16 *PIBuffer;
#define MAXVBUFFERSIZE 0x50000
#define MAXIBUFFERSIZE 0x10000
// TODO: find sensible values for these two
#define NUM_VERTEXBUFFERS 8
#define NUM_INDEXBUFFERS 10
enum
{
NUM_VERTEXBUFFERS = 8,
NUM_INDEXBUFFERS = 10,
};
bool Flushed=false;
ID3D11Buffer* indexbuffers[NUM_INDEXBUFFERS] = {NULL};
ID3D11Buffer* vertexbuffers[NUM_VERTEXBUFFERS] = {NULL};
ID3D11Buffer* indexbuffers[NUM_INDEXBUFFERS] = {};
ID3D11Buffer* vertexbuffers[NUM_VERTEXBUFFERS] = {};
inline ID3D11Buffer* GetSuitableIndexBuffer(const u32 minsize)
{
for (u32 k = 0;k < NUM_INDEXBUFFERS-1;k++)
if (minsize > 2 * (((u32)MAXIBUFFERSIZE)>>(k+1)))
for (u32 k = 0; k < NUM_INDEXBUFFERS-1; ++k)
if (minsize > 2 * (((u32)VertexManager::MAXIBUFFERSIZE)>>(k+1)))
return indexbuffers[k];
return indexbuffers[NUM_INDEXBUFFERS-1];
}
inline ID3D11Buffer* GetSuitableVertexBuffer(const u32 minsize)
{
for (u32 k = 0;k < NUM_VERTEXBUFFERS-1;++k)
if (minsize > (((u32)MAXVBUFFERSIZE)>>(k+1)))
for (u32 k = 0; k < NUM_VERTEXBUFFERS-1; ++k)
if (minsize > (((u32)VertexManager::MAXVBUFFERSIZE)>>(k+1)))
return vertexbuffers[k];
return vertexbuffers[NUM_VERTEXBUFFERS-1];
}
void CreateDeviceObjects()
{
D3D11_BUFFER_DESC bufdesc;
HRESULT hr;
for (u32 k = 0;k < NUM_INDEXBUFFERS;++k)
{
bufdesc = CD3D11_BUFFER_DESC(2*(MAXIBUFFERSIZE>>k), D3D11_BIND_INDEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
hr = D3D::device->CreateBuffer(&bufdesc, NULL, &indexbuffers[k]);
if (FAILED(hr)) PanicAlert("Failed to create index buffer, %s %d\n", __FILE__, __LINE__);
D3D11_BUFFER_DESC bufdesc = CD3D11_BUFFER_DESC(VertexManager::MAXIBUFFERSIZE * 2,
D3D11_BIND_INDEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
for (u32 k = 0; k < NUM_INDEXBUFFERS; ++k, bufdesc.ByteWidth >>= 1)
{
CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, indexbuffers + k)),
"Failed to create index buffer [%i].", k);
D3D::SetDebugObjectName((ID3D11DeviceChild*)indexbuffers[k], "an index buffer of VertexManager");
}
for (u32 k = 0;k < NUM_VERTEXBUFFERS;++k)
bufdesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bufdesc.ByteWidth = VertexManager::MAXVBUFFERSIZE;
for (u32 k = 0; k < NUM_VERTEXBUFFERS; ++k, bufdesc.ByteWidth >>= 1)
{
bufdesc = CD3D11_BUFFER_DESC(MAXVBUFFERSIZE >> k, D3D11_BIND_VERTEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
hr = D3D::device->CreateBuffer(&bufdesc, NULL, &vertexbuffers[k]);
if (FAILED(hr)) PanicAlert("Failed to create vertex buffer, %s %d\n", __FILE__, __LINE__);
CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, vertexbuffers + k)),
"Failed to create vertex buffer [%i].", k);
D3D::SetDebugObjectName((ID3D11DeviceChild*)vertexbuffers[k], "a vertex buffer of VertexManager");
}
}
void DestroyDeviceObjects()
{
for (u32 k = 0;k < NUM_INDEXBUFFERS;++k)
for (u32 k = 0; k < NUM_INDEXBUFFERS; ++k)
SAFE_RELEASE(indexbuffers[k]);
for (u32 k = 0;k < NUM_VERTEXBUFFERS;++k)
for (u32 k = 0; k < NUM_VERTEXBUFFERS; ++k)
SAFE_RELEASE(vertexbuffers[k]);
}
bool Init()
VertexManager::VertexManager()
{
LocalVBuffer = new u8[MAXVBUFFERSIZE];
TIBuffer = new u16[MAXIBUFFERSIZE];
LIBuffer = new u16[MAXIBUFFERSIZE];
PIBuffer = new u16[MAXIBUFFERSIZE];
s_pCurBufferPointer = LocalVBuffer;
s_pBaseBufferPointer = LocalVBuffer;
Flushed=false;
CreateDeviceObjects();
IndexGenerator::Start(TIBuffer,LIBuffer,PIBuffer);
return true;
}
void ResetBuffer()
{
s_pCurBufferPointer = LocalVBuffer;
}
void Shutdown()
VertexManager::~VertexManager()
{
DestroyDeviceObjects();
SAFE_DELETE_ARRAY(LocalVBuffer);
SAFE_DELETE_ARRAY(TIBuffer);
SAFE_DELETE_ARRAY(LIBuffer);
SAFE_DELETE_ARRAY(PIBuffer);
ResetBuffer();
}
void AddIndices(int primitive, int numVertices)
{
switch (primitive)
{
case GX_DRAW_QUADS: IndexGenerator::AddQuads(numVertices); break;
case GX_DRAW_TRIANGLES: IndexGenerator::AddList(numVertices); break;
case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(numVertices); break;
case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(numVertices); break;
case GX_DRAW_LINE_STRIP: IndexGenerator::AddLineStrip(numVertices); break;
case GX_DRAW_LINES: IndexGenerator::AddLineList(numVertices); break;
case GX_DRAW_POINTS: IndexGenerator::AddPoints(numVertices); break;
}
}
int GetRemainingSize()
{
return MAXVBUFFERSIZE - (int)(s_pCurBufferPointer - LocalVBuffer);
}
int GetRemainingVertices(int primitive)
{
switch (primitive)
{
case GX_DRAW_QUADS:
case GX_DRAW_TRIANGLES:
case GX_DRAW_TRIANGLE_STRIP:
case GX_DRAW_TRIANGLE_FAN:
return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen())/3;
case GX_DRAW_LINE_STRIP:
case GX_DRAW_LINES:
return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen())/2;
case GX_DRAW_POINTS:
return (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen());
default: return 0;
}
}
void AddVertices(int primitive, int numVertices)
{
if (numVertices <= 0)
return;
switch (primitive)
{
case GX_DRAW_QUADS:
case GX_DRAW_TRIANGLES:
case GX_DRAW_TRIANGLE_STRIP:
case GX_DRAW_TRIANGLE_FAN:
if (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen() < 3 * numVertices)
Flush();
break;
case GX_DRAW_LINE_STRIP:
case GX_DRAW_LINES:
if (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen() < 2 * numVertices)
Flush();
break;
case GX_DRAW_POINTS:
if (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen() < numVertices)
Flush();
break;
default: return;
}
if (Flushed)
{
IndexGenerator::Start(TIBuffer,LIBuffer,PIBuffer);
Flushed=false;
}
lastPrimitive = primitive;
ADDSTAT(stats.thisFrame.numPrims, numVertices);
INCSTAT(stats.thisFrame.numPrimitiveJoins);
AddIndices(primitive, numVertices);
}
inline void Draw(u32 stride, bool alphapass)
void VertexManager::Draw(u32 stride, bool alphapass)
{
D3D11_MAPPED_SUBRESOURCE map;
ID3D11Buffer* vertexbuffer = GetSuitableVertexBuffer((u32)(s_pCurBufferPointer - LocalVBuffer));
if (!alphapass)
{
context->Map(vertexbuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
D3D::context->Map(vertexbuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
memcpy(map.pData, LocalVBuffer, (u32)(s_pCurBufferPointer - LocalVBuffer));
context->Unmap(vertexbuffer, 0);
D3D::context->Unmap(vertexbuffer, 0);
}
UINT bufoffset = 0;
UINT bufstride = stride;
if (!alphapass) gfxstate->ApplyState();
else gfxstate->AlphaPass();
if (!alphapass)
D3D::gfxstate->ApplyState();
else
D3D::gfxstate->AlphaPass();
if (IndexGenerator::GetNumTriangles() > 0)
{
u32 indexbuffersize = IndexGenerator::GetTriangleindexLen();
@ -294,7 +189,7 @@ inline void Draw(u32 stride, bool alphapass)
}
}
void Flush()
void VertexManager::vFlush()
{
if (LocalVBuffer == s_pCurBufferPointer) return;
if (Flushed) return;
@ -360,9 +255,10 @@ void Flush()
// update alpha only
Draw(stride, true);
}
gfxstate->Reset();
D3D::gfxstate->Reset();
shader_fail:
ResetBuffer();
}
} // namespace

View File

@ -21,17 +21,22 @@
#include "CPMemory.h"
#include "VertexLoader.h"
namespace VertexManager
#include "VertexManagerBase.h"
namespace DX11
{
bool Init();
void Shutdown();
class VertexManager : public ::VertexManager
{
public:
VertexManager();
~VertexManager();
void AddVertices(int _primitive, int _numVertices);
void Flush();
void CreateDeviceObjects();
void DestroyDeviceObjects();
private:
void Draw(u32 stride, bool alphapass);
// temp
void vFlush();
};
} // namespace

View File

@ -216,7 +216,7 @@ void Video_Prepare()
// internal interfaces
Renderer::Init();
TextureCache::Init();
VertexManager::Init();
g_vertex_manager = new DX11::VertexManager;
VertexShaderCache::Init();
PixelShaderCache::Init();
D3D::InitUtils();
@ -257,7 +257,7 @@ void Shutdown()
D3D::ShutdownUtils();
PixelShaderCache::Shutdown();
VertexShaderCache::Shutdown();
VertexManager::Shutdown();
delete g_vertex_manager;
TextureCache::Shutdown();
Renderer::Shutdown();
EmuWindow::Close();

View File

@ -30,7 +30,6 @@
#include "PixelShaderManager.h"
#include "PixelShaderCache.h"
#include "NativeVertexFormat.h"
#include "NativeVertexWriter.h"
#include "TextureCache.h"
#include "main.h"
@ -39,125 +38,12 @@
#include "debugger/debugger.h"
using namespace D3D;
// internal state for loading vertices
extern NativeVertexFormat *g_nativeVertexFmt;
namespace VertexManager
namespace DX9
{
static int lastPrimitive;
static u8 *LocalVBuffer;
static u16 *TIBuffer;
static u16 *LIBuffer;
static u16 *PIBuffer;
#define MAXVBUFFERSIZE 0x50000
#define MAXIBUFFERSIZE 0xFFFF
static bool Flushed=false;
bool Init()
{
LocalVBuffer = new u8[MAXVBUFFERSIZE];
TIBuffer = new u16[MAXIBUFFERSIZE];
LIBuffer = new u16[MAXIBUFFERSIZE];
PIBuffer = new u16[MAXIBUFFERSIZE];
s_pCurBufferPointer = LocalVBuffer;
s_pBaseBufferPointer = LocalVBuffer;
Flushed=false;
IndexGenerator::Start(TIBuffer,LIBuffer,PIBuffer);
return true;
}
void ResetBuffer()
{
s_pCurBufferPointer = LocalVBuffer;
}
void Shutdown()
{
delete [] LocalVBuffer;
delete [] TIBuffer;
delete [] LIBuffer;
delete [] PIBuffer;
ResetBuffer();
}
void AddIndices(int primitive, int numVertices)
{
switch (primitive)
{
case GX_DRAW_QUADS: IndexGenerator::AddQuads(numVertices); break;
case GX_DRAW_TRIANGLES: IndexGenerator::AddList(numVertices); break;
case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(numVertices); break;
case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(numVertices); break;
case GX_DRAW_LINE_STRIP: IndexGenerator::AddLineStrip(numVertices); break;
case GX_DRAW_LINES: IndexGenerator::AddLineList(numVertices); break;
case GX_DRAW_POINTS: IndexGenerator::AddPoints(numVertices); break;
}
}
int GetRemainingSize()
{
return MAXVBUFFERSIZE - (int)(s_pCurBufferPointer - LocalVBuffer);
}
int GetRemainingVertices(int primitive)
{
switch (primitive)
{
case GX_DRAW_QUADS:
case GX_DRAW_TRIANGLES:
case GX_DRAW_TRIANGLE_STRIP:
case GX_DRAW_TRIANGLE_FAN:
return (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen())/3;
case GX_DRAW_LINE_STRIP:
case GX_DRAW_LINES:
return (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen())/2;
case GX_DRAW_POINTS:
return (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen());
default: return 0;
}
}
void AddVertices(int primitive, int numVertices)
{
if (numVertices <= 0)
return;
switch (primitive)
{
case GX_DRAW_QUADS:
case GX_DRAW_TRIANGLES:
case GX_DRAW_TRIANGLE_STRIP:
case GX_DRAW_TRIANGLE_FAN:
if (MAXIBUFFERSIZE - IndexGenerator::GetTriangleindexLen() < 3 * numVertices)
Flush();
break;
case GX_DRAW_LINE_STRIP:
case GX_DRAW_LINES:
if (MAXIBUFFERSIZE - IndexGenerator::GetLineindexLen() < 2 * numVertices)
Flush();
break;
case GX_DRAW_POINTS:
if (MAXIBUFFERSIZE - IndexGenerator::GetPointindexLen() < numVertices)
Flush();
break;
default: return;
}
if (Flushed)
{
IndexGenerator::Start(TIBuffer,LIBuffer,PIBuffer);
Flushed=false;
}
lastPrimitive = primitive;
ADDSTAT(stats.thisFrame.numPrims, numVertices);
INCSTAT(stats.thisFrame.numPrimitiveJoins);
AddIndices(primitive, numVertices);
}
inline void DumpBadShaders()
{
#if defined(_DEBUG) || defined(DEBUGFAST)
@ -176,7 +62,7 @@ inline void DumpBadShaders()
#endif
}
inline void Draw(int stride)
void VertexManager::Draw(int stride)
{
if (IndexGenerator::GetNumTriangles() > 0)
{
@ -222,11 +108,11 @@ inline void Draw(int stride)
}
}
void Flush()
void VertexManager::vFlush()
{
if (LocalVBuffer == s_pCurBufferPointer) return;
if (Flushed) return;
Flushed=true;
Flushed = true;
VideoFifo_CheckEFBAccess();
DVSTARTPROFILE();
@ -289,7 +175,7 @@ void Flush()
if (bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate)
{
DWORD write = 0;
if (!PixelShaderCache::SetShader(true,g_nativeVertexFmt->m_components))
if (!PixelShaderCache::SetShader(true, g_nativeVertexFmt->m_components))
{
DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
goto shader_fail;
@ -297,8 +183,9 @@ void Flush()
// update alpha only
D3D::ChangeRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA);
D3D::ChangeRenderState(D3DRS_ALPHABLENDENABLE, false);
Draw(stride);
D3D::RefreshRenderState(D3DRS_COLORWRITEENABLE);
D3D::RefreshRenderState(D3DRS_ALPHABLENDENABLE);
}
@ -307,4 +194,5 @@ void Flush()
shader_fail:
ResetBuffer();
}
} // namespace
}

View File

@ -21,15 +21,19 @@
#include "CPMemory.h"
#include "VertexLoader.h"
namespace VertexManager
#include "VertexManagerBase.h"
namespace DX9
{
bool Init();
void Shutdown();
class VertexManager : public ::VertexManager
{
private:
void Draw(int stride);
// temp
void vFlush();
};
void AddVertices(int _primitive, int _numVertices);
void Flush();
} // namespace
}
#endif

View File

@ -239,7 +239,7 @@ void Video_Prepare()
// internal interfaces
Renderer::Init();
TextureCache::Init();
VertexManager::Init();
g_vertex_manager = new DX9::VertexManager;
// VideoCommon
BPInit();
Fifo_Init();
@ -275,7 +275,7 @@ void Shutdown()
// internal interfaces
PixelShaderCache::Shutdown();
VertexShaderCache::Shutdown();
VertexManager::Shutdown();
delete g_vertex_manager;
TextureCache::Shutdown();
Renderer::Shutdown();
D3D::Shutdown();

View File

@ -24,7 +24,7 @@
#include "CPMemory.h"
#include "NativeVertexFormat.h"
#include "NativeVertexWriter.h"
#include "VertexManagerBase.h"
#define COMPILED_CODE_SIZE 4096

View File

@ -46,140 +46,30 @@
// internal state for loading vertices
extern NativeVertexFormat *g_nativeVertexFmt;
namespace VertexManager
namespace OGL
{
static int lastPrimitive;
static u8 *LocalVBuffer;
static u16 *TIBuffer;
static u16 *LIBuffer;
static u16 *PIBuffer;
static GLint max_Index_size = 0;
#define MAXVBUFFERSIZE 0x1FFFF
#define MAXIBUFFERSIZE 0xFFFF
#define MAXVBOBUFFERCOUNT 0x8
//static GLint max_Index_size = 0;
//static GLuint s_vboBuffers[MAXVBOBUFFERCOUNT] = {0};
//static int s_nCurVBOIndex = 0; // current free buffer
static bool Flushed=false;
bool Init()
VertexManager::VertexManager()
{
lastPrimitive = GX_DRAW_NONE;
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, (GLint *)&max_Index_size);
if(max_Index_size>MAXIBUFFERSIZE)
max_Index_size = MAXIBUFFERSIZE;
LocalVBuffer = new u8[MAXVBUFFERSIZE];
TIBuffer = new u16[max_Index_size];
LIBuffer = new u16[max_Index_size];
PIBuffer = new u16[max_Index_size];
IndexGenerator::Start(TIBuffer,LIBuffer,PIBuffer);
s_pCurBufferPointer = LocalVBuffer;
s_pBaseBufferPointer = LocalVBuffer;
//s_nCurVBOIndex = 0;
//glGenBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
// TODO: doesn't seem to be used anywhere
//glGetIntegerv(GL_MAX_ELEMENTS_INDICES, (GLint*)&max_Index_size);
//
//if (max_Index_size > MAXIBUFFERSIZE)
// max_Index_size = MAXIBUFFERSIZE;
//
//GL_REPORT_ERRORD();
glEnableClientState(GL_VERTEX_ARRAY);
g_nativeVertexFmt = NULL;
Flushed=false;
GL_REPORT_ERRORD();
return true;
}
void ResetBuffer()
{
//s_nCurVBOIndex = (s_nCurVBOIndex + 1) % ARRAYSIZE(s_vboBuffers);
s_pCurBufferPointer = LocalVBuffer;
}
void Shutdown()
{
delete [] LocalVBuffer;
delete [] TIBuffer;
delete [] LIBuffer;
delete [] PIBuffer;
//glDeleteBuffers(ARRAYSIZE(s_vboBuffers), s_vboBuffers);
//s_nCurVBOIndex = 0;
}
void AddIndices(int primitive, int numVertices)
{
switch (primitive)
{
case GX_DRAW_QUADS: IndexGenerator::AddQuads(numVertices); break;
case GX_DRAW_TRIANGLES: IndexGenerator::AddList(numVertices); break;
case GX_DRAW_TRIANGLE_STRIP: IndexGenerator::AddStrip(numVertices); break;
case GX_DRAW_TRIANGLE_FAN: IndexGenerator::AddFan(numVertices); break;
case GX_DRAW_LINE_STRIP: IndexGenerator::AddLineStrip(numVertices); break;
case GX_DRAW_LINES: IndexGenerator::AddLineList(numVertices); break;
case GX_DRAW_POINTS: IndexGenerator::AddPoints(numVertices); break;
}
}
int GetRemainingSize()
{
return MAXVBUFFERSIZE - (int)(s_pCurBufferPointer - LocalVBuffer);
}
int GetRemainingVertices(int primitive)
{
switch (primitive)
{
case GX_DRAW_QUADS:
case GX_DRAW_TRIANGLES:
case GX_DRAW_TRIANGLE_STRIP:
case GX_DRAW_TRIANGLE_FAN:
return (max_Index_size - IndexGenerator::GetTriangleindexLen())/3;
case GX_DRAW_LINE_STRIP:
case GX_DRAW_LINES:
return (max_Index_size - IndexGenerator::GetLineindexLen())/2;
case GX_DRAW_POINTS:
return (max_Index_size - IndexGenerator::GetPointindexLen());
default: return 0;
}
}
void AddVertices(int primitive, int numVertices)
{
if (numVertices <= 0)
return;
(void)GL_REPORT_ERROR();
switch (primitive)
{
case GX_DRAW_QUADS:
case GX_DRAW_TRIANGLES:
case GX_DRAW_TRIANGLE_STRIP:
case GX_DRAW_TRIANGLE_FAN:
if(max_Index_size - IndexGenerator::GetTriangleindexLen() < 3 * numVertices)
Flush();
break;
case GX_DRAW_LINE_STRIP:
case GX_DRAW_LINES:
if(max_Index_size - IndexGenerator::GetLineindexLen() < 2 * numVertices)
Flush();
break;
case GX_DRAW_POINTS:
if(max_Index_size - IndexGenerator::GetPointindexLen() < numVertices)
Flush();
break;
default: return;
}
if(Flushed)
{
IndexGenerator::Start(TIBuffer,LIBuffer,PIBuffer);
Flushed=false;
}
lastPrimitive = primitive;
ADDSTAT(stats.thisFrame.numPrims, numVertices);
INCSTAT(stats.thisFrame.numPrimitiveJoins);
AddIndices(primitive, numVertices);
}
inline void Draw()
void VertexManager::Draw()
{
if (IndexGenerator::GetNumTriangles() > 0)
{
@ -198,7 +88,7 @@ inline void Draw()
}
}
void Flush()
void VertexManager::vFlush()
{
if (LocalVBuffer == s_pCurBufferPointer) return;
if (Flushed) return;
@ -351,4 +241,5 @@ void Flush()
GL_REPORT_ERRORD();
}
} // namespace

View File

@ -19,18 +19,25 @@
#define _VERTEXMANAGER_H_
#include "CPMemory.h"
#include "NativeVertexWriter.h"
#include "VertexManagerBase.h"
namespace OGL
{
// Handles the OpenGL details of drawing lots of vertices quickly.
// Other functionality is moving out.
namespace VertexManager
class VertexManager : public ::VertexManager
{
public:
VertexManager();
bool Init();
void Shutdown();
void AddIndices(int primitive, int numVertices);
void ResetBuffer();
private:
void Draw();
// temp
void vFlush();
};
}
#endif // _VERTEXMANAGER_H_

View File

@ -226,7 +226,7 @@ void Video_Prepare()
TextureCache::Init();
BPInit();
VertexManager::Init();
g_vertex_manager = new OGL::VertexManager;
Fifo_Init(); // must be done before OpcodeDecoder_Init()
OpcodeDecoder_Init();
VertexShaderCache::Init();
@ -266,7 +266,7 @@ void Shutdown()
VertexShaderManager::Shutdown();
PixelShaderManager::Shutdown();
PixelShaderCache::Shutdown();
VertexManager::Shutdown();
delete g_vertex_manager;
TextureCache::Shutdown();
OpcodeDecoder_Shutdown();
Renderer::Shutdown();

View File

@ -382,14 +382,6 @@
RelativePath="..\..\Core\VideoCommon\Src\memcpy_amd.cpp"
>
</File>
<File
RelativePath="..\..\Core\VideoCommon\Src\NativeVertexWriter.cpp"
>
</File>
<File
RelativePath=".\Src\NativeVertexWriter.h"
>
</File>
<File
RelativePath="..\..\Core\VideoCommon\Src\OpenCL\OCLTextureDecoder.cpp"
>

View File

@ -29,7 +29,7 @@
#include "TransformUnit.h"
#include "SetupUnit.h"
#include "Statistics.h"
#include "NativeVertexWriter.h"
#include "VertexManagerBase.h"
#include "VertexFormatConverter.h"
#include "../../../Core/VideoCommon/Src/DataReader.h"