diff --git a/Source/Core/VideoCommon/Src/DLCache.cpp b/Source/Core/VideoCommon/Src/DLCache.cpp index 009c27dd97..0e146ebccf 100644 --- a/Source/Core/VideoCommon/Src/DLCache.cpp +++ b/Source/Core/VideoCommon/Src/DLCache.cpp @@ -32,7 +32,7 @@ #include "BPMemory.h" #include "VertexLoaderManager.h" -#include "NativeVertexWriter.h" +#include "VertexManagerBase.h" #include "x64Emitter.h" #include "ABI.h" diff --git a/Source/Core/VideoCommon/Src/SConscript b/Source/Core/VideoCommon/Src/SConscript index 672f3d022e..5763cdf150 100644 --- a/Source/Core/VideoCommon/Src/SConscript +++ b/Source/Core/VideoCommon/Src/SConscript @@ -29,7 +29,7 @@ files = [ 'VertexLoader_TextCoord.cpp', 'TextureConversionShader.cpp', 'ImageWrite.cpp', - 'NativeVertexWriter.cpp', + 'VertexManagerBase.cpp', 'Statistics.cpp', 'Fifo.cpp', 'VideoState.cpp', diff --git a/Source/Core/VideoCommon/Src/VertexLoader.cpp b/Source/Core/VideoCommon/Src/VertexLoader.cpp index 9e096159de..fba141d4cc 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader.cpp +++ b/Source/Core/VideoCommon/Src/VertexLoader.cpp @@ -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" diff --git a/Source/Core/VideoCommon/Src/VertexLoader_Color.cpp b/Source/Core/VideoCommon/Src/VertexLoader_Color.cpp index d27b32f312..362a777ffb 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader_Color.cpp +++ b/Source/Core/VideoCommon/Src/VertexLoader_Color.cpp @@ -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 diff --git a/Source/Core/VideoCommon/Src/VertexLoader_Normal.cpp b/Source/Core/VideoCommon/Src/VertexLoader_Normal.cpp index c76cf1246c..323eb2783e 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader_Normal.cpp +++ b/Source/Core/VideoCommon/Src/VertexLoader_Normal.cpp @@ -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__) diff --git a/Source/Core/VideoCommon/Src/VertexLoader_Position.cpp b/Source/Core/VideoCommon/Src/VertexLoader_Position.cpp index 1ff74113ac..1ed6c6ef63 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader_Position.cpp +++ b/Source/Core/VideoCommon/Src/VertexLoader_Position.cpp @@ -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__) diff --git a/Source/Core/VideoCommon/Src/VertexLoader_TextCoord.cpp b/Source/Core/VideoCommon/Src/VertexLoader_TextCoord.cpp index ae4b8c668a..de853081ed 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader_TextCoord.cpp +++ b/Source/Core/VideoCommon/Src/VertexLoader_TextCoord.cpp @@ -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 diff --git a/Source/Core/VideoCommon/Src/VertexManagerBase.cpp b/Source/Core/VideoCommon/Src/VertexManagerBase.cpp new file mode 100644 index 0000000000..642978dcf5 --- /dev/null +++ b/Source/Core/VideoCommon/Src/VertexManagerBase.cpp @@ -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(); +} diff --git a/Source/Core/VideoCommon/Src/VertexManagerBase.h b/Source/Core/VideoCommon/Src/VertexManagerBase.h new file mode 100644 index 0000000000..c73730d705 --- /dev/null +++ b/Source/Core/VideoCommon/Src/VertexManagerBase.h @@ -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 diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp index db272fd08c..501791a953 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp @@ -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]); diff --git a/Source/Core/VideoCommon/Src/XFStructs.cpp b/Source/Core/VideoCommon/Src/XFStructs.cpp index b505351aff..0b93599967 100644 --- a/Source/Core/VideoCommon/Src/XFStructs.cpp +++ b/Source/Core/VideoCommon/Src/XFStructs.cpp @@ -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" diff --git a/Source/Core/VideoCommon/VideoCommon.vcproj b/Source/Core/VideoCommon/VideoCommon.vcproj index fd9c57a138..f74939b9da 100644 --- a/Source/Core/VideoCommon/VideoCommon.vcproj +++ b/Source/Core/VideoCommon/VideoCommon.vcproj @@ -1,7 +1,7 @@ - - - - @@ -735,6 +727,18 @@ + + + + + + diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp index d26088c0d3..630eff7184 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp @@ -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 -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 diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.h b/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.h index 6215b9d547..5850be0e20 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.h +++ b/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.h @@ -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 diff --git a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp index 30c97f9839..39cef47abc 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp @@ -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(); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp index e6302ad2f4..882a776a49 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp @@ -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 + +} diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.h b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.h index 2fcb8c0639..39f13763f1 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.h @@ -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 diff --git a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp index b556ccc10f..2c1d4b0506 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp @@ -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(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp index f47f3f6d87..63048acaf1 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/NativeVertexFormat.cpp @@ -24,7 +24,7 @@ #include "CPMemory.h" #include "NativeVertexFormat.h" -#include "NativeVertexWriter.h" +#include "VertexManagerBase.h" #define COMPILED_CODE_SIZE 4096 diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp index e3b9ccc0bb..80906d4a6d 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp @@ -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 diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.h b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.h index 2b397d3acf..0b5d93860d 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.h @@ -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_ diff --git a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp index 9e7ca60170..94d4531a62 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp @@ -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(); diff --git a/Source/Plugins/Plugin_VideoSoftware/Plugin_VideoSoftware.vcproj b/Source/Plugins/Plugin_VideoSoftware/Plugin_VideoSoftware.vcproj index ef3ac99774..4ff6a9cad7 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Plugin_VideoSoftware.vcproj +++ b/Source/Plugins/Plugin_VideoSoftware/Plugin_VideoSoftware.vcproj @@ -382,14 +382,6 @@ RelativePath="..\..\Core\VideoCommon\Src\memcpy_amd.cpp" > - - - - diff --git a/Source/Plugins/Plugin_VideoSoftware/Src/VertexLoader.cpp b/Source/Plugins/Plugin_VideoSoftware/Src/VertexLoader.cpp index 4f9d96f37d..8dba89fce7 100644 --- a/Source/Plugins/Plugin_VideoSoftware/Src/VertexLoader.cpp +++ b/Source/Plugins/Plugin_VideoSoftware/Src/VertexLoader.cpp @@ -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"