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:
parent
aaeb21fe3b
commit
841583b8f3
|
@ -32,7 +32,7 @@
|
||||||
#include "BPMemory.h"
|
#include "BPMemory.h"
|
||||||
|
|
||||||
#include "VertexLoaderManager.h"
|
#include "VertexLoaderManager.h"
|
||||||
#include "NativeVertexWriter.h"
|
#include "VertexManagerBase.h"
|
||||||
#include "x64Emitter.h"
|
#include "x64Emitter.h"
|
||||||
#include "ABI.h"
|
#include "ABI.h"
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ files = [
|
||||||
'VertexLoader_TextCoord.cpp',
|
'VertexLoader_TextCoord.cpp',
|
||||||
'TextureConversionShader.cpp',
|
'TextureConversionShader.cpp',
|
||||||
'ImageWrite.cpp',
|
'ImageWrite.cpp',
|
||||||
'NativeVertexWriter.cpp',
|
'VertexManagerBase.cpp',
|
||||||
'Statistics.cpp',
|
'Statistics.cpp',
|
||||||
'Fifo.cpp',
|
'Fifo.cpp',
|
||||||
'VideoState.cpp',
|
'VideoState.cpp',
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
#include "VertexLoader.h"
|
#include "VertexLoader.h"
|
||||||
#include "BPMemory.h"
|
#include "BPMemory.h"
|
||||||
#include "DataReader.h"
|
#include "DataReader.h"
|
||||||
#include "NativeVertexWriter.h"
|
#include "VertexManagerBase.h"
|
||||||
|
|
||||||
#include "VertexLoader_Position.h"
|
#include "VertexLoader_Position.h"
|
||||||
#include "VertexLoader_Normal.h"
|
#include "VertexLoader_Normal.h"
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "LookUpTables.h"
|
#include "LookUpTables.h"
|
||||||
#include "VertexLoader.h"
|
#include "VertexLoader.h"
|
||||||
#include "VertexLoader_Color.h"
|
#include "VertexLoader_Color.h"
|
||||||
#include "NativeVertexWriter.h"
|
#include "VertexManagerBase.h"
|
||||||
|
|
||||||
#define RSHIFT 0
|
#define RSHIFT 0
|
||||||
#define GSHIFT 8
|
#define GSHIFT 8
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "VideoCommon.h"
|
#include "VideoCommon.h"
|
||||||
#include "VertexLoader.h"
|
#include "VertexLoader.h"
|
||||||
#include "VertexLoader_Normal.h"
|
#include "VertexLoader_Normal.h"
|
||||||
#include "NativeVertexWriter.h"
|
#include "VertexManagerBase.h"
|
||||||
#include "CPUDetect.h"
|
#include "CPUDetect.h"
|
||||||
|
|
||||||
#if _M_SSE >= 0x301 && !(defined __GNUC__ && !defined __SSSE3__)
|
#if _M_SSE >= 0x301 && !(defined __GNUC__ && !defined __SSSE3__)
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "VideoCommon.h"
|
#include "VideoCommon.h"
|
||||||
#include "VertexLoader.h"
|
#include "VertexLoader.h"
|
||||||
#include "VertexLoader_Position.h"
|
#include "VertexLoader_Position.h"
|
||||||
#include "NativeVertexWriter.h"
|
#include "VertexManagerBase.h"
|
||||||
#include "CPUDetect.h"
|
#include "CPUDetect.h"
|
||||||
|
|
||||||
#if _M_SSE >= 0x301 && !(defined __GNUC__ && !defined __SSSE3__)
|
#if _M_SSE >= 0x301 && !(defined __GNUC__ && !defined __SSSE3__)
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "VideoCommon.h"
|
#include "VideoCommon.h"
|
||||||
#include "VertexLoader.h"
|
#include "VertexLoader.h"
|
||||||
#include "VertexLoader_TextCoord.h"
|
#include "VertexLoader_TextCoord.h"
|
||||||
#include "NativeVertexWriter.h"
|
#include "VertexManagerBase.h"
|
||||||
#include "CPUDetect.h"
|
#include "CPUDetect.h"
|
||||||
|
|
||||||
#if _M_SSE >= 0x401
|
#if _M_SSE >= 0x401
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
|
@ -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
|
|
@ -30,12 +30,7 @@
|
||||||
#include "CPMemory.h"
|
#include "CPMemory.h"
|
||||||
#include "XFMemory.h"
|
#include "XFMemory.h"
|
||||||
#include "VideoCommon.h"
|
#include "VideoCommon.h"
|
||||||
|
#include "VertexManagerBase.h"
|
||||||
// Temporary ugly declaration.
|
|
||||||
namespace VertexManager
|
|
||||||
{
|
|
||||||
void Flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
static float GC_ALIGNED16(s_fMaterials[16]);
|
static float GC_ALIGNED16(s_fMaterials[16]);
|
||||||
float GC_ALIGNED16(g_fProjectionMatrix[16]);
|
float GC_ALIGNED16(g_fProjectionMatrix[16]);
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "VideoCommon.h"
|
#include "VideoCommon.h"
|
||||||
#include "XFMemory.h"
|
#include "XFMemory.h"
|
||||||
#include "CPMemory.h"
|
#include "CPMemory.h"
|
||||||
#include "NativeVertexWriter.h"
|
#include "VertexManagerBase.h"
|
||||||
#include "VertexShaderManager.h"
|
#include "VertexShaderManager.h"
|
||||||
#include "PixelShaderManager.h"
|
#include "PixelShaderManager.h"
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="Windows-1252"?>
|
<?xml version="1.0" encoding="Windows-1252"?>
|
||||||
<VisualStudioProject
|
<VisualStudioProject
|
||||||
ProjectType="Visual C++"
|
ProjectType="Visual C++"
|
||||||
Version="9,00"
|
Version="9.00"
|
||||||
Name="VideoCommon"
|
Name="VideoCommon"
|
||||||
ProjectGUID="{E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}"
|
ProjectGUID="{E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}"
|
||||||
RootNamespace="VideoCommon"
|
RootNamespace="VideoCommon"
|
||||||
|
@ -562,14 +562,6 @@
|
||||||
RelativePath=".\Src\LookUpTables.h"
|
RelativePath=".\Src\LookUpTables.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\Src\NativeVertexWriter.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\Src\NativeVertexWriter.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath=".\Src\OnScreenDisplay.cpp"
|
RelativePath=".\Src\OnScreenDisplay.cpp"
|
||||||
>
|
>
|
||||||
|
@ -735,6 +727,18 @@
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="Base"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath=".\Src\VertexManagerBase.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\Src\VertexManagerBase.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\Src\CommandProcessor.cpp"
|
RelativePath=".\Src\CommandProcessor.cpp"
|
||||||
>
|
>
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
#include "PixelShaderManager.h"
|
#include "PixelShaderManager.h"
|
||||||
#include "PixelShaderCache.h"
|
#include "PixelShaderCache.h"
|
||||||
#include "NativeVertexFormat.h"
|
#include "NativeVertexFormat.h"
|
||||||
#include "NativeVertexWriter.h"
|
|
||||||
#include "TextureCache.h"
|
#include "TextureCache.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
@ -42,202 +41,98 @@
|
||||||
|
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
|
|
||||||
#include <string>
|
|
||||||
using std::string;
|
|
||||||
|
|
||||||
using namespace D3D;
|
|
||||||
|
|
||||||
// internal state for loading vertices
|
// internal state for loading vertices
|
||||||
extern NativeVertexFormat *g_nativeVertexFmt;
|
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
|
// TODO: find sensible values for these two
|
||||||
#define NUM_VERTEXBUFFERS 8
|
enum
|
||||||
#define NUM_INDEXBUFFERS 10
|
{
|
||||||
|
NUM_VERTEXBUFFERS = 8,
|
||||||
|
NUM_INDEXBUFFERS = 10,
|
||||||
|
};
|
||||||
|
|
||||||
bool Flushed=false;
|
ID3D11Buffer* indexbuffers[NUM_INDEXBUFFERS] = {};
|
||||||
|
ID3D11Buffer* vertexbuffers[NUM_VERTEXBUFFERS] = {};
|
||||||
ID3D11Buffer* indexbuffers[NUM_INDEXBUFFERS] = {NULL};
|
|
||||||
ID3D11Buffer* vertexbuffers[NUM_VERTEXBUFFERS] = {NULL};
|
|
||||||
|
|
||||||
inline ID3D11Buffer* GetSuitableIndexBuffer(const u32 minsize)
|
inline ID3D11Buffer* GetSuitableIndexBuffer(const u32 minsize)
|
||||||
{
|
{
|
||||||
for (u32 k = 0;k < NUM_INDEXBUFFERS-1;k++)
|
for (u32 k = 0; k < NUM_INDEXBUFFERS-1; ++k)
|
||||||
if (minsize > 2 * (((u32)MAXIBUFFERSIZE)>>(k+1)))
|
if (minsize > 2 * (((u32)VertexManager::MAXIBUFFERSIZE)>>(k+1)))
|
||||||
return indexbuffers[k];
|
return indexbuffers[k];
|
||||||
return indexbuffers[NUM_INDEXBUFFERS-1];
|
return indexbuffers[NUM_INDEXBUFFERS-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ID3D11Buffer* GetSuitableVertexBuffer(const u32 minsize)
|
inline ID3D11Buffer* GetSuitableVertexBuffer(const u32 minsize)
|
||||||
{
|
{
|
||||||
for (u32 k = 0;k < NUM_VERTEXBUFFERS-1;++k)
|
for (u32 k = 0; k < NUM_VERTEXBUFFERS-1; ++k)
|
||||||
if (minsize > (((u32)MAXVBUFFERSIZE)>>(k+1)))
|
if (minsize > (((u32)VertexManager::MAXVBUFFERSIZE)>>(k+1)))
|
||||||
return vertexbuffers[k];
|
return vertexbuffers[k];
|
||||||
return vertexbuffers[NUM_VERTEXBUFFERS-1];
|
return vertexbuffers[NUM_VERTEXBUFFERS-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateDeviceObjects()
|
void CreateDeviceObjects()
|
||||||
{
|
{
|
||||||
D3D11_BUFFER_DESC bufdesc;
|
D3D11_BUFFER_DESC bufdesc = CD3D11_BUFFER_DESC(VertexManager::MAXIBUFFERSIZE * 2,
|
||||||
HRESULT hr;
|
D3D11_BIND_INDEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
|
||||||
for (u32 k = 0;k < NUM_INDEXBUFFERS;++k)
|
for (u32 k = 0; k < NUM_INDEXBUFFERS; ++k, bufdesc.ByteWidth >>= 1)
|
||||||
{
|
{
|
||||||
bufdesc = CD3D11_BUFFER_DESC(2*(MAXIBUFFERSIZE>>k), D3D11_BIND_INDEX_BUFFER, D3D11_USAGE_DYNAMIC, D3D11_CPU_ACCESS_WRITE);
|
CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, indexbuffers + k)),
|
||||||
hr = D3D::device->CreateBuffer(&bufdesc, NULL, &indexbuffers[k]);
|
"Failed to create index buffer [%i].", k);
|
||||||
if (FAILED(hr)) PanicAlert("Failed to create index buffer, %s %d\n", __FILE__, __LINE__);
|
|
||||||
D3D::SetDebugObjectName((ID3D11DeviceChild*)indexbuffers[k], "an index buffer of VertexManager");
|
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);
|
CHECK(SUCCEEDED(D3D::device->CreateBuffer(&bufdesc, NULL, vertexbuffers + k)),
|
||||||
hr = D3D::device->CreateBuffer(&bufdesc, NULL, &vertexbuffers[k]);
|
"Failed to create vertex buffer [%i].", k);
|
||||||
if (FAILED(hr)) PanicAlert("Failed to create vertex buffer, %s %d\n", __FILE__, __LINE__);
|
|
||||||
D3D::SetDebugObjectName((ID3D11DeviceChild*)vertexbuffers[k], "a vertex buffer of VertexManager");
|
D3D::SetDebugObjectName((ID3D11DeviceChild*)vertexbuffers[k], "a vertex buffer of VertexManager");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DestroyDeviceObjects()
|
void DestroyDeviceObjects()
|
||||||
{
|
{
|
||||||
for (u32 k = 0;k < NUM_INDEXBUFFERS;++k)
|
for (u32 k = 0; k < NUM_INDEXBUFFERS; ++k)
|
||||||
SAFE_RELEASE(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]);
|
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();
|
CreateDeviceObjects();
|
||||||
|
|
||||||
IndexGenerator::Start(TIBuffer,LIBuffer,PIBuffer);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetBuffer()
|
VertexManager::~VertexManager()
|
||||||
{
|
|
||||||
s_pCurBufferPointer = LocalVBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Shutdown()
|
|
||||||
{
|
{
|
||||||
DestroyDeviceObjects();
|
DestroyDeviceObjects();
|
||||||
SAFE_DELETE_ARRAY(LocalVBuffer);
|
|
||||||
SAFE_DELETE_ARRAY(TIBuffer);
|
|
||||||
SAFE_DELETE_ARRAY(LIBuffer);
|
|
||||||
SAFE_DELETE_ARRAY(PIBuffer);
|
|
||||||
ResetBuffer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddIndices(int primitive, int numVertices)
|
void VertexManager::Draw(u32 stride, bool alphapass)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
D3D11_MAPPED_SUBRESOURCE map;
|
D3D11_MAPPED_SUBRESOURCE map;
|
||||||
ID3D11Buffer* vertexbuffer = GetSuitableVertexBuffer((u32)(s_pCurBufferPointer - LocalVBuffer));
|
ID3D11Buffer* vertexbuffer = GetSuitableVertexBuffer((u32)(s_pCurBufferPointer - LocalVBuffer));
|
||||||
|
|
||||||
if (!alphapass)
|
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));
|
memcpy(map.pData, LocalVBuffer, (u32)(s_pCurBufferPointer - LocalVBuffer));
|
||||||
context->Unmap(vertexbuffer, 0);
|
D3D::context->Unmap(vertexbuffer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT bufoffset = 0;
|
UINT bufoffset = 0;
|
||||||
UINT bufstride = stride;
|
UINT bufstride = stride;
|
||||||
|
|
||||||
if (!alphapass) gfxstate->ApplyState();
|
if (!alphapass)
|
||||||
else gfxstate->AlphaPass();
|
D3D::gfxstate->ApplyState();
|
||||||
|
else
|
||||||
|
D3D::gfxstate->AlphaPass();
|
||||||
|
|
||||||
if (IndexGenerator::GetNumTriangles() > 0)
|
if (IndexGenerator::GetNumTriangles() > 0)
|
||||||
{
|
{
|
||||||
u32 indexbuffersize = IndexGenerator::GetTriangleindexLen();
|
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 (LocalVBuffer == s_pCurBufferPointer) return;
|
||||||
if (Flushed) return;
|
if (Flushed) return;
|
||||||
|
@ -360,9 +255,10 @@ void Flush()
|
||||||
// update alpha only
|
// update alpha only
|
||||||
Draw(stride, true);
|
Draw(stride, true);
|
||||||
}
|
}
|
||||||
gfxstate->Reset();
|
D3D::gfxstate->Reset();
|
||||||
|
|
||||||
shader_fail:
|
shader_fail:
|
||||||
ResetBuffer();
|
ResetBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -21,17 +21,22 @@
|
||||||
#include "CPMemory.h"
|
#include "CPMemory.h"
|
||||||
#include "VertexLoader.h"
|
#include "VertexLoader.h"
|
||||||
|
|
||||||
namespace VertexManager
|
#include "VertexManagerBase.h"
|
||||||
|
|
||||||
|
namespace DX11
|
||||||
{
|
{
|
||||||
|
|
||||||
bool Init();
|
class VertexManager : public ::VertexManager
|
||||||
void Shutdown();
|
{
|
||||||
|
public:
|
||||||
|
VertexManager();
|
||||||
|
~VertexManager();
|
||||||
|
|
||||||
void AddVertices(int _primitive, int _numVertices);
|
private:
|
||||||
void Flush();
|
void Draw(u32 stride, bool alphapass);
|
||||||
|
// temp
|
||||||
void CreateDeviceObjects();
|
void vFlush();
|
||||||
void DestroyDeviceObjects();
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
|
@ -216,7 +216,7 @@ void Video_Prepare()
|
||||||
// internal interfaces
|
// internal interfaces
|
||||||
Renderer::Init();
|
Renderer::Init();
|
||||||
TextureCache::Init();
|
TextureCache::Init();
|
||||||
VertexManager::Init();
|
g_vertex_manager = new DX11::VertexManager;
|
||||||
VertexShaderCache::Init();
|
VertexShaderCache::Init();
|
||||||
PixelShaderCache::Init();
|
PixelShaderCache::Init();
|
||||||
D3D::InitUtils();
|
D3D::InitUtils();
|
||||||
|
@ -257,7 +257,7 @@ void Shutdown()
|
||||||
D3D::ShutdownUtils();
|
D3D::ShutdownUtils();
|
||||||
PixelShaderCache::Shutdown();
|
PixelShaderCache::Shutdown();
|
||||||
VertexShaderCache::Shutdown();
|
VertexShaderCache::Shutdown();
|
||||||
VertexManager::Shutdown();
|
delete g_vertex_manager;
|
||||||
TextureCache::Shutdown();
|
TextureCache::Shutdown();
|
||||||
Renderer::Shutdown();
|
Renderer::Shutdown();
|
||||||
EmuWindow::Close();
|
EmuWindow::Close();
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#include "PixelShaderManager.h"
|
#include "PixelShaderManager.h"
|
||||||
#include "PixelShaderCache.h"
|
#include "PixelShaderCache.h"
|
||||||
#include "NativeVertexFormat.h"
|
#include "NativeVertexFormat.h"
|
||||||
#include "NativeVertexWriter.h"
|
|
||||||
#include "TextureCache.h"
|
#include "TextureCache.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
@ -39,125 +38,12 @@
|
||||||
|
|
||||||
#include "debugger/debugger.h"
|
#include "debugger/debugger.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace D3D;
|
|
||||||
|
|
||||||
// internal state for loading vertices
|
// internal state for loading vertices
|
||||||
extern NativeVertexFormat *g_nativeVertexFmt;
|
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()
|
inline void DumpBadShaders()
|
||||||
{
|
{
|
||||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||||
|
@ -176,7 +62,7 @@ inline void DumpBadShaders()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void Draw(int stride)
|
void VertexManager::Draw(int stride)
|
||||||
{
|
{
|
||||||
if (IndexGenerator::GetNumTriangles() > 0)
|
if (IndexGenerator::GetNumTriangles() > 0)
|
||||||
{
|
{
|
||||||
|
@ -222,11 +108,11 @@ inline void Draw(int stride)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Flush()
|
void VertexManager::vFlush()
|
||||||
{
|
{
|
||||||
if (LocalVBuffer == s_pCurBufferPointer) return;
|
if (LocalVBuffer == s_pCurBufferPointer) return;
|
||||||
if (Flushed) return;
|
if (Flushed) return;
|
||||||
Flushed=true;
|
Flushed = true;
|
||||||
VideoFifo_CheckEFBAccess();
|
VideoFifo_CheckEFBAccess();
|
||||||
|
|
||||||
DVSTARTPROFILE();
|
DVSTARTPROFILE();
|
||||||
|
@ -289,7 +175,7 @@ void Flush()
|
||||||
if (bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate)
|
if (bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate)
|
||||||
{
|
{
|
||||||
DWORD write = 0;
|
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");});
|
DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");});
|
||||||
goto shader_fail;
|
goto shader_fail;
|
||||||
|
@ -297,8 +183,9 @@ void Flush()
|
||||||
// update alpha only
|
// update alpha only
|
||||||
D3D::ChangeRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA);
|
D3D::ChangeRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA);
|
||||||
D3D::ChangeRenderState(D3DRS_ALPHABLENDENABLE, false);
|
D3D::ChangeRenderState(D3DRS_ALPHABLENDENABLE, false);
|
||||||
|
|
||||||
Draw(stride);
|
Draw(stride);
|
||||||
|
|
||||||
D3D::RefreshRenderState(D3DRS_COLORWRITEENABLE);
|
D3D::RefreshRenderState(D3DRS_COLORWRITEENABLE);
|
||||||
D3D::RefreshRenderState(D3DRS_ALPHABLENDENABLE);
|
D3D::RefreshRenderState(D3DRS_ALPHABLENDENABLE);
|
||||||
}
|
}
|
||||||
|
@ -307,4 +194,5 @@ void Flush()
|
||||||
shader_fail:
|
shader_fail:
|
||||||
ResetBuffer();
|
ResetBuffer();
|
||||||
}
|
}
|
||||||
} // namespace
|
|
||||||
|
}
|
||||||
|
|
|
@ -21,15 +21,19 @@
|
||||||
#include "CPMemory.h"
|
#include "CPMemory.h"
|
||||||
#include "VertexLoader.h"
|
#include "VertexLoader.h"
|
||||||
|
|
||||||
namespace VertexManager
|
#include "VertexManagerBase.h"
|
||||||
|
|
||||||
|
namespace DX9
|
||||||
{
|
{
|
||||||
|
|
||||||
bool Init();
|
class VertexManager : public ::VertexManager
|
||||||
void Shutdown();
|
{
|
||||||
|
private:
|
||||||
|
void Draw(int stride);
|
||||||
|
// temp
|
||||||
|
void vFlush();
|
||||||
|
};
|
||||||
|
|
||||||
void AddVertices(int _primitive, int _numVertices);
|
}
|
||||||
void Flush();
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -239,7 +239,7 @@ void Video_Prepare()
|
||||||
// internal interfaces
|
// internal interfaces
|
||||||
Renderer::Init();
|
Renderer::Init();
|
||||||
TextureCache::Init();
|
TextureCache::Init();
|
||||||
VertexManager::Init();
|
g_vertex_manager = new DX9::VertexManager;
|
||||||
// VideoCommon
|
// VideoCommon
|
||||||
BPInit();
|
BPInit();
|
||||||
Fifo_Init();
|
Fifo_Init();
|
||||||
|
@ -275,7 +275,7 @@ void Shutdown()
|
||||||
// internal interfaces
|
// internal interfaces
|
||||||
PixelShaderCache::Shutdown();
|
PixelShaderCache::Shutdown();
|
||||||
VertexShaderCache::Shutdown();
|
VertexShaderCache::Shutdown();
|
||||||
VertexManager::Shutdown();
|
delete g_vertex_manager;
|
||||||
TextureCache::Shutdown();
|
TextureCache::Shutdown();
|
||||||
Renderer::Shutdown();
|
Renderer::Shutdown();
|
||||||
D3D::Shutdown();
|
D3D::Shutdown();
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
#include "CPMemory.h"
|
#include "CPMemory.h"
|
||||||
#include "NativeVertexFormat.h"
|
#include "NativeVertexFormat.h"
|
||||||
#include "NativeVertexWriter.h"
|
#include "VertexManagerBase.h"
|
||||||
|
|
||||||
#define COMPILED_CODE_SIZE 4096
|
#define COMPILED_CODE_SIZE 4096
|
||||||
|
|
||||||
|
|
|
@ -46,140 +46,30 @@
|
||||||
// internal state for loading vertices
|
// internal state for loading vertices
|
||||||
extern NativeVertexFormat *g_nativeVertexFmt;
|
extern NativeVertexFormat *g_nativeVertexFmt;
|
||||||
|
|
||||||
namespace VertexManager
|
namespace OGL
|
||||||
{
|
{
|
||||||
|
|
||||||
static int lastPrimitive;
|
//static GLint max_Index_size = 0;
|
||||||
|
|
||||||
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 GLuint s_vboBuffers[MAXVBOBUFFERCOUNT] = {0};
|
//static GLuint s_vboBuffers[MAXVBOBUFFERCOUNT] = {0};
|
||||||
//static int s_nCurVBOIndex = 0; // current free buffer
|
//static int s_nCurVBOIndex = 0; // current free buffer
|
||||||
static bool Flushed=false;
|
|
||||||
|
|
||||||
|
VertexManager::VertexManager()
|
||||||
bool Init()
|
|
||||||
{
|
{
|
||||||
lastPrimitive = GX_DRAW_NONE;
|
// TODO: doesn't seem to be used anywhere
|
||||||
glGetIntegerv(GL_MAX_ELEMENTS_INDICES, (GLint *)&max_Index_size);
|
|
||||||
|
//glGetIntegerv(GL_MAX_ELEMENTS_INDICES, (GLint*)&max_Index_size);
|
||||||
if(max_Index_size>MAXIBUFFERSIZE)
|
//
|
||||||
max_Index_size = MAXIBUFFERSIZE;
|
//if (max_Index_size > MAXIBUFFERSIZE)
|
||||||
|
// max_Index_size = MAXIBUFFERSIZE;
|
||||||
LocalVBuffer = new u8[MAXVBUFFERSIZE];
|
//
|
||||||
TIBuffer = new u16[max_Index_size];
|
//GL_REPORT_ERRORD();
|
||||||
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);
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
g_nativeVertexFmt = NULL;
|
|
||||||
Flushed=false;
|
|
||||||
GL_REPORT_ERRORD();
|
GL_REPORT_ERRORD();
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetBuffer()
|
void VertexManager::Draw()
|
||||||
{
|
|
||||||
//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()
|
|
||||||
{
|
{
|
||||||
if (IndexGenerator::GetNumTriangles() > 0)
|
if (IndexGenerator::GetNumTriangles() > 0)
|
||||||
{
|
{
|
||||||
|
@ -198,7 +88,7 @@ inline void Draw()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Flush()
|
void VertexManager::vFlush()
|
||||||
{
|
{
|
||||||
if (LocalVBuffer == s_pCurBufferPointer) return;
|
if (LocalVBuffer == s_pCurBufferPointer) return;
|
||||||
if (Flushed) return;
|
if (Flushed) return;
|
||||||
|
@ -351,4 +241,5 @@ void Flush()
|
||||||
|
|
||||||
GL_REPORT_ERRORD();
|
GL_REPORT_ERRORD();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -19,18 +19,25 @@
|
||||||
#define _VERTEXMANAGER_H_
|
#define _VERTEXMANAGER_H_
|
||||||
|
|
||||||
#include "CPMemory.h"
|
#include "CPMemory.h"
|
||||||
#include "NativeVertexWriter.h"
|
|
||||||
|
#include "VertexManagerBase.h"
|
||||||
|
|
||||||
|
namespace OGL
|
||||||
|
{
|
||||||
|
|
||||||
// Handles the OpenGL details of drawing lots of vertices quickly.
|
// Handles the OpenGL details of drawing lots of vertices quickly.
|
||||||
// Other functionality is moving out.
|
// Other functionality is moving out.
|
||||||
namespace VertexManager
|
class VertexManager : public ::VertexManager
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
VertexManager();
|
||||||
|
|
||||||
bool Init();
|
private:
|
||||||
void Shutdown();
|
void Draw();
|
||||||
void AddIndices(int primitive, int numVertices);
|
// temp
|
||||||
void ResetBuffer();
|
void vFlush();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _VERTEXMANAGER_H_
|
#endif // _VERTEXMANAGER_H_
|
||||||
|
|
|
@ -226,7 +226,7 @@ void Video_Prepare()
|
||||||
TextureCache::Init();
|
TextureCache::Init();
|
||||||
|
|
||||||
BPInit();
|
BPInit();
|
||||||
VertexManager::Init();
|
g_vertex_manager = new OGL::VertexManager;
|
||||||
Fifo_Init(); // must be done before OpcodeDecoder_Init()
|
Fifo_Init(); // must be done before OpcodeDecoder_Init()
|
||||||
OpcodeDecoder_Init();
|
OpcodeDecoder_Init();
|
||||||
VertexShaderCache::Init();
|
VertexShaderCache::Init();
|
||||||
|
@ -266,7 +266,7 @@ void Shutdown()
|
||||||
VertexShaderManager::Shutdown();
|
VertexShaderManager::Shutdown();
|
||||||
PixelShaderManager::Shutdown();
|
PixelShaderManager::Shutdown();
|
||||||
PixelShaderCache::Shutdown();
|
PixelShaderCache::Shutdown();
|
||||||
VertexManager::Shutdown();
|
delete g_vertex_manager;
|
||||||
TextureCache::Shutdown();
|
TextureCache::Shutdown();
|
||||||
OpcodeDecoder_Shutdown();
|
OpcodeDecoder_Shutdown();
|
||||||
Renderer::Shutdown();
|
Renderer::Shutdown();
|
||||||
|
|
|
@ -382,14 +382,6 @@
|
||||||
RelativePath="..\..\Core\VideoCommon\Src\memcpy_amd.cpp"
|
RelativePath="..\..\Core\VideoCommon\Src\memcpy_amd.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\Core\VideoCommon\Src\NativeVertexWriter.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\Src\NativeVertexWriter.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\Core\VideoCommon\Src\OpenCL\OCLTextureDecoder.cpp"
|
RelativePath="..\..\Core\VideoCommon\Src\OpenCL\OCLTextureDecoder.cpp"
|
||||||
>
|
>
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include "TransformUnit.h"
|
#include "TransformUnit.h"
|
||||||
#include "SetupUnit.h"
|
#include "SetupUnit.h"
|
||||||
#include "Statistics.h"
|
#include "Statistics.h"
|
||||||
#include "NativeVertexWriter.h"
|
#include "VertexManagerBase.h"
|
||||||
#include "VertexFormatConverter.h"
|
#include "VertexFormatConverter.h"
|
||||||
#include "../../../Core/VideoCommon/Src/DataReader.h"
|
#include "../../../Core/VideoCommon/Src/DataReader.h"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue