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
{
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;
}

View File

@ -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)

View File

@ -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;

View File

@ -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)

View File

@ -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);

View File

@ -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)

View File

@ -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;