VideoCommon: clean up VertexLoader

This commit is contained in:
degasus 2014-12-09 08:35:04 +01:00
parent 02cdb41d3d
commit 3fc7e55cc4
7 changed files with 45 additions and 33 deletions

View File

@ -275,13 +275,17 @@ u8* OpcodeDecoder_Run(DataReader src, u32* cycles, bool in_display_list)
} }
else else
{ {
if (!VertexLoaderManager::RunVertices( int bytes = VertexLoaderManager::RunVertices(
cmd_byte & GX_VAT_MASK, // Vertex loader index (0 - 7) cmd_byte & GX_VAT_MASK, // Vertex loader index (0 - 7)
(cmd_byte & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT, (cmd_byte & GX_PRIMITIVE_MASK) >> GX_PRIMITIVE_SHIFT,
num_vertices, num_vertices,
src, src,
g_bSkipCurrentFrame)) g_bSkipCurrentFrame);
if (bytes < 0)
goto end; goto end;
else
src.Skip(bytes);
} }
totalCycles += 1600; totalCycles += 1600;
} }

View File

@ -491,12 +491,13 @@ void VertexLoader::ConvertVertices ( int count )
#endif #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); SetupRunVertices(vat, primitive, count);
ConvertVertices(count); ConvertVertices(count);
g_vertex_manager->s_pCurBufferPointer = g_vertex_manager_write_ptr; return count;
} }
void VertexLoader::SetVAT(const VAT& vat) void VertexLoader::SetVAT(const VAT& vat)

View File

@ -118,7 +118,7 @@ public:
{ return m_native_vtx_decl; } { return m_native_vtx_decl; }
void SetupRunVertices(const VAT& vat, int primitive, int const count); 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 // For debugging / profiling
void AppendToString(std::string *dest) const; void AppendToString(std::string *dest) const;

View File

@ -130,24 +130,23 @@ static VertexLoader* RefreshLoader(int vtx_attr_group, CPState* state)
return loader; 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) if (!count)
return true; return 0;
CPState* state = &g_main_cp_state; CPState* state = &g_main_cp_state;
VertexLoader* loader = RefreshLoader(vtx_attr_group, state); VertexLoader* loader = RefreshLoader(vtx_attr_group, state);
size_t size = count * loader->GetVertexSize(); int size = count * loader->GetVertexSize();
if (src.size() < size) if ((int)src.size() < size)
return false; return -1;
if (skip_drawing || (bpmem.genMode.cullmode == GenMode::CULL_ALL && primitive < 5)) if (skip_drawing || (bpmem.genMode.cullmode == GenMode::CULL_ALL && primitive < 5))
{ {
// if cull mode is CULL_ALL, ignore triangles and quads // if cull mode is CULL_ALL, ignore triangles and quads
src.Skip(size); return size;
return true;
} }
NativeVertexFormat* native = loader->GetNativeVertexFormat(); NativeVertexFormat* native = loader->GetNativeVertexFormat();
@ -157,19 +156,18 @@ bool RunVertices(int vtx_attr_group, int primitive, int count, DataReader& src,
VertexManager::Flush(); VertexManager::Flush();
s_current_vtx_fmt = native; s_current_vtx_fmt = native;
VertexManager::PrepareForAdditionalData(primitive, count, DataReader dst = VertexManager::PrepareForAdditionalData(primitive, count,
loader->GetNativeVertexDeclaration().stride); loader->GetNativeVertexDeclaration().stride);
count = loader->RunVertices(state->vtx_attr[vtx_attr_group], primitive, count, src, dst);
src.WritePointer(&g_video_buffer_read_ptr);
loader->RunVertices(state->vtx_attr[vtx_attr_group], primitive, count);
src = g_video_buffer_read_ptr;
IndexGenerator::AddIndices(primitive, count); IndexGenerator::AddIndices(primitive, count);
VertexManager::FlushData(count, loader->GetNativeVertexDeclaration().stride);
ADDSTAT(stats.thisFrame.numPrims, count); ADDSTAT(stats.thisFrame.numPrims, count);
INCSTAT(stats.thisFrame.numPrimitiveJoins); INCSTAT(stats.thisFrame.numPrimitiveJoins);
return true; return size;
} }
int GetVertexSize(int vtx_attr_group, bool preprocess) int GetVertexSize(int vtx_attr_group, bool preprocess)

View File

@ -18,8 +18,9 @@ namespace VertexLoaderManager
void MarkAllDirty(); void MarkAllDirty();
int GetVertexSize(int vtx_attr_group, bool preprocess); 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 // For debugging
void AppendListToString(std::string *dest); void AppendListToString(std::string *dest);

View File

@ -51,7 +51,7 @@ u32 VertexManager::GetRemainingSize()
return (u32)(s_pEndBufferPointer - s_pCurBufferPointer); 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 // The SSE vertex loader can write up to 4 bytes past the end
u32 const needed_vertex_bytes = count * stride + 4; 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); g_vertex_manager->ResetBuffer(stride);
IsFlushed = false; IsFlushed = false;
} }
return DataReader(s_pCurBufferPointer, s_pEndBufferPointer);
}
void VertexManager::FlushData(u32 count, u32 stride)
{
s_pCurBufferPointer += count * stride;
} }
u32 VertexManager::GetRemainingIndices(int primitive) u32 VertexManager::GetRemainingIndices(int primitive)

View File

@ -32,21 +32,14 @@ public:
// needs to be virtual for DX11's dtor // needs to be virtual for DX11's dtor
virtual ~VertexManager(); virtual ~VertexManager();
static u8 *s_pCurBufferPointer; static DataReader PrepareForAdditionalData(int primitive, u32 count, u32 stride);
static u8 *s_pBaseBufferPointer; static void FlushData(u32 count, u32 stride);
static u8 *s_pEndBufferPointer;
static u32 GetRemainingSize();
static void PrepareForAdditionalData(int primitive, u32 count, u32 stride);
static u32 GetRemainingIndices(int primitive);
static void Flush(); static void Flush();
virtual ::NativeVertexFormat* CreateNativeVertexFormat() = 0; virtual ::NativeVertexFormat* CreateNativeVertexFormat() = 0;
static void DoState(PointerWrap& p); static void DoState(PointerWrap& p);
virtual void CreateDeviceObjects(){}
virtual void DestroyDeviceObjects(){}
protected: protected:
virtual void vDoState(PointerWrap& p) { } virtual void vDoState(PointerWrap& p) { }
@ -55,12 +48,20 @@ protected:
virtual void ResetBuffer(u32 stride) = 0; 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: private:
static bool IsFlushed; static bool IsFlushed;
// virtual void Draw(u32 stride, bool alphapass) = 0;
// temp
virtual void vFlush(bool useDstAlpha) = 0; virtual void vFlush(bool useDstAlpha) = 0;
virtual void CreateDeviceObjects() {}
virtual void DestroyDeviceObjects() {}
}; };
extern VertexManager *g_vertex_manager; extern VertexManager *g_vertex_manager;