VertexLoader: Remove global state dependency on g_nativeVertexFmt

This commit is contained in:
Pierre Bourdon
2014-07-26 01:10:44 +02:00
parent 78c3a22060
commit 73f9a22e2e
6 changed files with 83 additions and 74 deletions

View File

@ -22,7 +22,6 @@
#include "VideoCommon/VertexLoader_Position.h"
#include "VideoCommon/VertexLoader_TextCoord.h"
#include "VideoCommon/VertexLoaderManager.h"
#include "VideoCommon/VertexManagerBase.h"
#include "VideoCommon/VideoCommon.h"
#include "VideoCommon/VideoConfig.h"
@ -31,8 +30,6 @@
#define COMPILED_CODE_SIZE 4096
NativeVertexFormat *g_nativeVertexFmt;
#ifndef _WIN32
#undef inline
#define inline
@ -539,8 +536,7 @@ void VertexLoader::CompileVertexTranslator()
// Position in pc vertex format.
int nat_offset = 0;
PortableVertexDeclaration vtx_decl;
memset(&vtx_decl, 0, sizeof(vtx_decl));
memset(&m_native_vtx_decl, 0, sizeof(m_native_vtx_decl));
// Position Matrix Index
if (m_VtxDesc.PosMatIdx)
@ -572,11 +568,11 @@ void VertexLoader::CompileVertexTranslator()
}
m_VertexSize += VertexLoader_Position::GetSize(m_VtxDesc.Position, m_VtxAttr.PosFormat, m_VtxAttr.PosElements);
nat_offset += 12;
vtx_decl.position.components = 3;
vtx_decl.position.enable = true;
vtx_decl.position.offset = 0;
vtx_decl.position.type = VAR_FLOAT;
vtx_decl.position.integer = false;
m_native_vtx_decl.position.components = 3;
m_native_vtx_decl.position.enable = true;
m_native_vtx_decl.position.offset = 0;
m_native_vtx_decl.position.type = VAR_FLOAT;
m_native_vtx_decl.position.integer = false;
// Normals
if (m_VtxDesc.Normal != NOT_PRESENT)
@ -598,11 +594,11 @@ void VertexLoader::CompileVertexTranslator()
for (int i = 0; i < (vtx_attr.NormalElements ? 3 : 1); i++)
{
vtx_decl.normals[i].components = 3;
vtx_decl.normals[i].enable = true;
vtx_decl.normals[i].offset = nat_offset;
vtx_decl.normals[i].type = VAR_FLOAT;
vtx_decl.normals[i].integer = false;
m_native_vtx_decl.normals[i].components = 3;
m_native_vtx_decl.normals[i].enable = true;
m_native_vtx_decl.normals[i].offset = nat_offset;
m_native_vtx_decl.normals[i].type = VAR_FLOAT;
m_native_vtx_decl.normals[i].integer = false;
nat_offset += 12;
}
@ -613,9 +609,9 @@ void VertexLoader::CompileVertexTranslator()
for (int i = 0; i < 2; i++)
{
vtx_decl.colors[i].components = 4;
vtx_decl.colors[i].type = VAR_UNSIGNED_BYTE;
vtx_decl.colors[i].integer = false;
m_native_vtx_decl.colors[i].components = 4;
m_native_vtx_decl.colors[i].type = VAR_UNSIGNED_BYTE;
m_native_vtx_decl.colors[i].integer = false;
switch (col[i])
{
case NOT_PRESENT:
@ -663,8 +659,8 @@ void VertexLoader::CompileVertexTranslator()
if (col[i] != NOT_PRESENT)
{
components |= VB_HAS_COL0 << i;
vtx_decl.colors[i].offset = nat_offset;
vtx_decl.colors[i].enable = true;
m_native_vtx_decl.colors[i].offset = nat_offset;
m_native_vtx_decl.colors[i].enable = true;
nat_offset += 4;
}
}
@ -672,9 +668,9 @@ void VertexLoader::CompileVertexTranslator()
// Texture matrix indices (remove if corresponding texture coordinate isn't enabled)
for (int i = 0; i < 8; i++)
{
vtx_decl.texcoords[i].offset = nat_offset;
vtx_decl.texcoords[i].type = VAR_FLOAT;
vtx_decl.texcoords[i].integer = false;
m_native_vtx_decl.texcoords[i].offset = nat_offset;
m_native_vtx_decl.texcoords[i].type = VAR_FLOAT;
m_native_vtx_decl.texcoords[i].integer = false;
const int format = m_VtxAttr.texCoord[i].Format;
const int elements = m_VtxAttr.texCoord[i].Elements;
@ -696,18 +692,18 @@ void VertexLoader::CompileVertexTranslator()
if (components & (VB_HAS_TEXMTXIDX0 << i))
{
vtx_decl.texcoords[i].enable = true;
m_native_vtx_decl.texcoords[i].enable = true;
if (tc[i] != NOT_PRESENT)
{
// if texmtx is included, texcoord will always be 3 floats, z will be the texmtx index
vtx_decl.texcoords[i].components = 3;
m_native_vtx_decl.texcoords[i].components = 3;
nat_offset += 12;
WriteCall(m_VtxAttr.texCoord[i].Elements ? TexMtx_Write_Float : TexMtx_Write_Float2);
}
else
{
components |= VB_HAS_UV0 << i; // have to include since using now
vtx_decl.texcoords[i].components = 4;
m_native_vtx_decl.texcoords[i].components = 4;
nat_offset += 16; // still include the texture coordinate, but this time as 6 + 2 bytes
WriteCall(TexMtx_Write_Float4);
}
@ -716,8 +712,8 @@ void VertexLoader::CompileVertexTranslator()
{
if (tc[i] != NOT_PRESENT)
{
vtx_decl.texcoords[i].enable = true;
vtx_decl.texcoords[i].components = vtx_attr.texCoord[i].Elements ? 2 : 1;
m_native_vtx_decl.texcoords[i].enable = true;
m_native_vtx_decl.texcoords[i].components = vtx_attr.texCoord[i].Elements ? 2 : 1;
nat_offset += 4 * (vtx_attr.texCoord[i].Elements ? 2 : 1);
}
}
@ -746,16 +742,16 @@ void VertexLoader::CompileVertexTranslator()
if (m_VtxDesc.PosMatIdx)
{
WriteCall(PosMtx_Write);
vtx_decl.posmtx.components = 4;
vtx_decl.posmtx.enable = true;
vtx_decl.posmtx.offset = nat_offset;
vtx_decl.posmtx.type = VAR_UNSIGNED_BYTE;
vtx_decl.posmtx.integer = true;
m_native_vtx_decl.posmtx.components = 4;
m_native_vtx_decl.posmtx.enable = true;
m_native_vtx_decl.posmtx.offset = nat_offset;
m_native_vtx_decl.posmtx.type = VAR_UNSIGNED_BYTE;
m_native_vtx_decl.posmtx.integer = true;
nat_offset += 4;
}
native_stride = nat_offset;
vtx_decl.stride = native_stride;
m_native_components = components;
m_native_vtx_decl.stride = nat_offset;
#ifdef USE_VERTEX_LOADER_JIT
// End loop here
@ -770,7 +766,6 @@ void VertexLoader::CompileVertexTranslator()
ABI_PopAllCalleeSavedRegsAndAdjustStack();
RET();
#endif
m_NativeFmt = VertexLoaderManager::GetNativeVertexFormat(vtx_decl, components);
}
void VertexLoader::WriteCall(TPipelineFunction func)
@ -817,14 +812,6 @@ void VertexLoader::SetupRunVertices(const VAT& vat, int primitive, int const cou
{
m_numLoadedVertices += count;
// Flush if our vertex format is different from the currently set.
if (g_nativeVertexFmt != nullptr && g_nativeVertexFmt != m_NativeFmt)
{
VertexManager::Flush();
// Also move the Set() here?
}
g_nativeVertexFmt = m_NativeFmt;
// Load position and texcoord scale factors.
m_VtxAttr.PosFrac = vat.g0.PosFrac;
m_VtxAttr.texCoord[0].Frac = vat.g0.Tex0Frac;
@ -837,7 +824,7 @@ void VertexLoader::SetupRunVertices(const VAT& vat, int primitive, int const cou
m_VtxAttr.texCoord[7].Frac = vat.g2.Tex7Frac;
posScale = fractionTable[m_VtxAttr.PosFrac];
if (m_NativeFmt->m_components & VB_HAS_UVALL)
if (m_native_components & VB_HAS_UVALL)
for (int i = 0; i < 8; i++)
tcScale[i] = fractionTable[m_VtxAttr.texCoord[i].Frac];
for (int i = 0; i < 2; i++)
@ -879,7 +866,8 @@ void VertexLoader::RunVertices(const VAT& vat, int primitive, int const count)
return;
}
SetupRunVertices(vat, primitive, count);
VertexManager::PrepareForAdditionalData(primitive, count, native_stride);
VertexManager::PrepareForAdditionalData(primitive, count,
m_native_vtx_decl.stride);
ConvertVertices(count);
IndexGenerator::AddIndices(primitive, count);