From 3fc7e55cc4623c1c49efb4c317ab0202499bb5fd Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 9 Dec 2014 08:35:04 +0100 Subject: [PATCH] VideoCommon: clean up VertexLoader --- Source/Core/VideoCommon/OpcodeDecoding.cpp | 8 +++++-- Source/Core/VideoCommon/VertexLoader.cpp | 7 +++--- Source/Core/VideoCommon/VertexLoader.h | 2 +- .../Core/VideoCommon/VertexLoaderManager.cpp | 24 +++++++++---------- Source/Core/VideoCommon/VertexLoaderManager.h | 5 ++-- Source/Core/VideoCommon/VertexManagerBase.cpp | 9 ++++++- Source/Core/VideoCommon/VertexManagerBase.h | 23 +++++++++--------- 7 files changed, 45 insertions(+), 33 deletions(-) diff --git a/Source/Core/VideoCommon/OpcodeDecoding.cpp b/Source/Core/VideoCommon/OpcodeDecoding.cpp index 12a9d5b350..34b821605f 100644 --- a/Source/Core/VideoCommon/OpcodeDecoding.cpp +++ b/Source/Core/VideoCommon/OpcodeDecoding.cpp @@ -275,13 +275,17 @@ u8* OpcodeDecoder_Run(DataReader src, u32* cycles, bool in_display_list) } else { - if (!VertexLoaderManager::RunVertices( + int bytes = VertexLoaderManager::RunVertices( cmd_byte & GX_VAT_MASK, // Vertex loader index (0 - 7) (cmd_byte & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT, num_vertices, src, - g_bSkipCurrentFrame)) + g_bSkipCurrentFrame); + + if (bytes < 0) goto end; + else + src.Skip(bytes); } totalCycles += 1600; } diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp index e767f46638..f293564e85 100644 --- a/Source/Core/VideoCommon/VertexLoader.cpp +++ b/Source/Core/VideoCommon/VertexLoader.cpp @@ -491,12 +491,13 @@ void VertexLoader::ConvertVertices ( int count ) #endif } -void VertexLoader::RunVertices(const VAT& vat, int primitive, int const count) +int VertexLoader::RunVertices(const VAT& vat, int primitive, int count, DataReader src, DataReader dst) { - g_vertex_manager_write_ptr = g_vertex_manager->s_pCurBufferPointer; + dst.WritePointer(&g_vertex_manager_write_ptr); + src.WritePointer(&g_video_buffer_read_ptr); SetupRunVertices(vat, primitive, count); ConvertVertices(count); - g_vertex_manager->s_pCurBufferPointer = g_vertex_manager_write_ptr; + return count; } void VertexLoader::SetVAT(const VAT& vat) diff --git a/Source/Core/VideoCommon/VertexLoader.h b/Source/Core/VideoCommon/VertexLoader.h index 60b9bb3def..df1bb445a5 100644 --- a/Source/Core/VideoCommon/VertexLoader.h +++ b/Source/Core/VideoCommon/VertexLoader.h @@ -118,7 +118,7 @@ public: { return m_native_vtx_decl; } void SetupRunVertices(const VAT& vat, int primitive, int const count); - void RunVertices(const VAT& vat, int primitive, int count); + int RunVertices(const VAT& vat, int primitive, int count, DataReader src, DataReader dst); // For debugging / profiling void AppendToString(std::string *dest) const; diff --git a/Source/Core/VideoCommon/VertexLoaderManager.cpp b/Source/Core/VideoCommon/VertexLoaderManager.cpp index 0262cafb2d..cf638c2495 100644 --- a/Source/Core/VideoCommon/VertexLoaderManager.cpp +++ b/Source/Core/VideoCommon/VertexLoaderManager.cpp @@ -130,24 +130,23 @@ static VertexLoader* RefreshLoader(int vtx_attr_group, CPState* state) return loader; } -bool RunVertices(int vtx_attr_group, int primitive, int count, DataReader& src, bool skip_drawing) +int RunVertices(int vtx_attr_group, int primitive, int count, DataReader src, bool skip_drawing) { if (!count) - return true; + return 0; CPState* state = &g_main_cp_state; VertexLoader* loader = RefreshLoader(vtx_attr_group, state); - size_t size = count * loader->GetVertexSize(); - if (src.size() < size) - return false; + int size = count * loader->GetVertexSize(); + if ((int)src.size() < size) + return -1; if (skip_drawing || (bpmem.genMode.cullmode == GenMode::CULL_ALL && primitive < 5)) { // if cull mode is CULL_ALL, ignore triangles and quads - src.Skip(size); - return true; + return size; } NativeVertexFormat* native = loader->GetNativeVertexFormat(); @@ -157,19 +156,18 @@ bool RunVertices(int vtx_attr_group, int primitive, int count, DataReader& src, VertexManager::Flush(); s_current_vtx_fmt = native; - VertexManager::PrepareForAdditionalData(primitive, count, + DataReader dst = VertexManager::PrepareForAdditionalData(primitive, count, loader->GetNativeVertexDeclaration().stride); - - src.WritePointer(&g_video_buffer_read_ptr); - loader->RunVertices(state->vtx_attr[vtx_attr_group], primitive, count); - src = g_video_buffer_read_ptr; + count = loader->RunVertices(state->vtx_attr[vtx_attr_group], primitive, count, src, dst); IndexGenerator::AddIndices(primitive, count); + VertexManager::FlushData(count, loader->GetNativeVertexDeclaration().stride); + ADDSTAT(stats.thisFrame.numPrims, count); INCSTAT(stats.thisFrame.numPrimitiveJoins); - return true; + return size; } int GetVertexSize(int vtx_attr_group, bool preprocess) diff --git a/Source/Core/VideoCommon/VertexLoaderManager.h b/Source/Core/VideoCommon/VertexLoaderManager.h index a687b7641f..e100480fd3 100644 --- a/Source/Core/VideoCommon/VertexLoaderManager.h +++ b/Source/Core/VideoCommon/VertexLoaderManager.h @@ -18,8 +18,9 @@ namespace VertexLoaderManager void MarkAllDirty(); int GetVertexSize(int vtx_attr_group, bool preprocess); - // Returns false if buf_size is insufficient. - bool RunVertices(int vtx_attr_group, int primitive, int count, DataReader& src, bool skip_drawing = false); + + // Returns -1 if buf_size is insufficient, else the amount of bytes consumed + int RunVertices(int vtx_attr_group, int primitive, int count, DataReader src, bool skip_drawing = false); // For debugging void AppendListToString(std::string *dest); diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index dcd8780ede..84e0bb5efe 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -51,7 +51,7 @@ u32 VertexManager::GetRemainingSize() return (u32)(s_pEndBufferPointer - s_pCurBufferPointer); } -void VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 stride) +DataReader VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 stride) { // The SSE vertex loader can write up to 4 bytes past the end u32 const needed_vertex_bytes = count * stride + 4; @@ -83,6 +83,13 @@ void VertexManager::PrepareForAdditionalData(int primitive, u32 count, u32 strid g_vertex_manager->ResetBuffer(stride); IsFlushed = false; } + + return DataReader(s_pCurBufferPointer, s_pEndBufferPointer); +} + +void VertexManager::FlushData(u32 count, u32 stride) +{ + s_pCurBufferPointer += count * stride; } u32 VertexManager::GetRemainingIndices(int primitive) diff --git a/Source/Core/VideoCommon/VertexManagerBase.h b/Source/Core/VideoCommon/VertexManagerBase.h index d506d273d2..c854cd3586 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.h +++ b/Source/Core/VideoCommon/VertexManagerBase.h @@ -32,21 +32,14 @@ public: // needs to be virtual for DX11's dtor virtual ~VertexManager(); - static u8 *s_pCurBufferPointer; - static u8 *s_pBaseBufferPointer; - static u8 *s_pEndBufferPointer; - - static u32 GetRemainingSize(); - static void PrepareForAdditionalData(int primitive, u32 count, u32 stride); - static u32 GetRemainingIndices(int primitive); + static DataReader PrepareForAdditionalData(int primitive, u32 count, u32 stride); + static void FlushData(u32 count, u32 stride); static void Flush(); virtual ::NativeVertexFormat* CreateNativeVertexFormat() = 0; static void DoState(PointerWrap& p); - virtual void CreateDeviceObjects(){} - virtual void DestroyDeviceObjects(){} protected: virtual void vDoState(PointerWrap& p) { } @@ -55,12 +48,20 @@ protected: virtual void ResetBuffer(u32 stride) = 0; + static u8* s_pCurBufferPointer; + static u8* s_pBaseBufferPointer; + static u8* s_pEndBufferPointer; + + static u32 GetRemainingSize(); + static u32 GetRemainingIndices(int primitive); + private: static bool IsFlushed; - // virtual void Draw(u32 stride, bool alphapass) = 0; - // temp virtual void vFlush(bool useDstAlpha) = 0; + + virtual void CreateDeviceObjects() {} + virtual void DestroyDeviceObjects() {} }; extern VertexManager *g_vertex_manager;