VideoLoader: remove VAT_*_FRACBITS

They are used to remove the flush amounts, but as we don't
flush anymore on vertex loader changes (only on native
vertex format right now), this optimization is now unneeded.

This will allow us to hard code the frac factors within the
vertex loaders.
This commit is contained in:
degasus 2014-12-11 22:39:58 +01:00
parent 9b2909357b
commit ec28a80e00
6 changed files with 40 additions and 50 deletions

View File

@ -176,7 +176,7 @@ void SWVertexLoader::LoadVertex()
// convert the vertex from the gc format to the videocommon (hardware optimized) format
u8* old = g_video_buffer_read_ptr;
m_CurrentLoader->RunVertices(
g_main_cp_state.vtx_attr[m_attributeIndex], m_primitiveType, 1,
m_primitiveType, 1,
DataReader(g_video_buffer_read_ptr, nullptr), // src
DataReader(m_LoadedVertices.data(), m_LoadedVertices.data() + m_LoadedVertices.size()) // dst
);

View File

@ -45,13 +45,6 @@ enum
FORMAT_32B_8888 = 5,
};
enum
{
VAT_0_FRACBITS = 0x3e0001f0,
VAT_1_FRACBITS = 0x07c3e1f0,
VAT_2_FRACBITS = 0xf87c3e1f,
};
#pragma pack(4)
union TVtxDesc
{

View File

@ -119,6 +119,7 @@ VertexLoader::VertexLoader(const TVtxDesc &vtx_desc, const VAT &vtx_attr)
VertexLoader_TextCoord::Init();
m_VtxDesc = vtx_desc;
m_vat = vtx_attr;
SetVAT(vtx_attr);
#ifdef USE_VERTEX_LOADER_JIT
@ -444,21 +445,10 @@ void VertexLoader::WriteSetVariable(int bits, void *address, OpArg value)
}
#endif
void VertexLoader::SetupRunVertices(const VAT& vat, int primitive, int const count)
void VertexLoader::SetupRunVertices(int primitive, int const count)
{
m_numLoadedVertices += count;
// Load position and texcoord scale factors.
m_VtxAttr.PosFrac = vat.g0.PosFrac;
m_VtxAttr.texCoord[0].Frac = vat.g0.Tex0Frac;
m_VtxAttr.texCoord[1].Frac = vat.g1.Tex1Frac;
m_VtxAttr.texCoord[2].Frac = vat.g1.Tex2Frac;
m_VtxAttr.texCoord[3].Frac = vat.g1.Tex3Frac;
m_VtxAttr.texCoord[4].Frac = vat.g2.Tex4Frac;
m_VtxAttr.texCoord[5].Frac = vat.g2.Tex5Frac;
m_VtxAttr.texCoord[6].Frac = vat.g2.Tex6Frac;
m_VtxAttr.texCoord[7].Frac = vat.g2.Tex7Frac;
posScale[0] = posScale[1] = posScale[2] = posScale[3] = fractionTable[m_VtxAttr.PosFrac];
if (m_native_components & VB_HAS_UVALL)
for (int i = 0; i < 8; i++)
@ -468,7 +458,7 @@ void VertexLoader::SetupRunVertices(const VAT& vat, int primitive, int const cou
// Prepare bounding box
if (!g_ActiveConfig.backend_info.bSupportsBBox)
BoundingBox::Prepare(vat, primitive, m_VtxDesc, m_native_vtx_decl);
BoundingBox::Prepare(m_vat, primitive, m_VtxDesc, m_native_vtx_decl);
}
void VertexLoader::ConvertVertices ( int count )
@ -491,11 +481,11 @@ void VertexLoader::ConvertVertices ( int count )
#endif
}
int VertexLoader::RunVertices(const VAT& vat, int primitive, int count, DataReader src, DataReader dst)
int VertexLoader::RunVertices(int primitive, int count, DataReader src, DataReader dst)
{
dst.WritePointer(&g_vertex_manager_write_ptr);
src.WritePointer(&g_video_buffer_read_ptr);
SetupRunVertices(vat, primitive, count);
SetupRunVertices(primitive, count);
ConvertVertices(count);
return count;
}

View File

@ -51,9 +51,9 @@ public:
{
vid[0] = vtx_desc.Hex & 0xFFFFFFFF;
vid[1] = vtx_desc.Hex >> 32;
vid[2] = vat.g0.Hex & ~VAT_0_FRACBITS;
vid[3] = vat.g1.Hex & ~VAT_1_FRACBITS;
vid[4] = vat.g2.Hex & ~VAT_2_FRACBITS;
vid[2] = vat.g0.Hex;
vid[3] = vat.g1.Hex;
vid[4] = vat.g2.Hex;
hash = CalculateHash();
}
@ -117,8 +117,8 @@ public:
const PortableVertexDeclaration& GetNativeVertexDeclaration() const
{ return m_native_vtx_decl; }
void SetupRunVertices(const VAT& vat, int primitive, int const count);
int RunVertices(const VAT& vat, int primitive, int count, DataReader src, DataReader dst);
void SetupRunVertices(int primitive, int const count);
int RunVertices(int primitive, int count, DataReader src, DataReader dst);
// For debugging / profiling
void AppendToString(std::string *dest) const;
@ -133,6 +133,7 @@ private:
// GC vertex format
TVtxAttr m_VtxAttr; // VAT decoded into easy format
TVtxDesc m_VtxDesc; // Not really used currently - or well it is, but could be easily avoided.
VAT m_vat;
// PC vertex format
u32 m_native_components;

View File

@ -159,7 +159,7 @@ int RunVertices(int vtx_attr_group, int primitive, int count, DataReader src, bo
DataReader dst = VertexManager::PrepareForAdditionalData(primitive, count,
loader->GetNativeVertexDeclaration().stride);
count = loader->RunVertices(state->vtx_attr[vtx_attr_group], primitive, count, src, dst);
count = loader->RunVertices(primitive, count, src, dst);
IndexGenerator::AddIndices(primitive, count);

View File

@ -93,10 +93,10 @@ TEST_F(VertexLoaderTest, PositionDirectFloatXYZ)
m_vtx_attr.g0.PosElements = 1; // XYZ
m_vtx_attr.g0.PosFormat = 4; // Float
VertexLoader loader(m_vtx_desc, m_vtx_attr);
VertexLoader* loader = new VertexLoader(m_vtx_desc, m_vtx_attr);
ASSERT_EQ(3 * sizeof (float), (u32)loader.GetNativeVertexDeclaration().stride);
ASSERT_EQ(3 * sizeof (float), (u32)loader.GetVertexSize());
ASSERT_EQ(3 * sizeof (float), (u32)loader->GetNativeVertexDeclaration().stride);
ASSERT_EQ(3 * sizeof (float), (u32)loader->GetVertexSize());
// Write some vertices.
Input(0.0f); Input(0.0f); Input(0.0f);
@ -105,9 +105,10 @@ TEST_F(VertexLoaderTest, PositionDirectFloatXYZ)
Input(0.0f); Input(0.0f); Input(1.0f);
// Convert 4 points. "7" -> primitive are points.
int count = loader.RunVertices(m_vtx_attr, 7, 4, src, dst);
src.Skip(4 * loader.GetVertexSize());
dst.Skip(count * loader.GetNativeVertexDeclaration().stride);
int count = loader->RunVertices(7, 4, src, dst);
src.Skip(4 * loader->GetVertexSize());
dst.Skip(count * loader->GetNativeVertexDeclaration().stride);
delete loader;
ExpectOut(0.0f); ExpectOut(0.0f); ExpectOut(0.0f);
ExpectOut(1.0f); ExpectOut(0.0f); ExpectOut(0.0f);
@ -117,10 +118,12 @@ TEST_F(VertexLoaderTest, PositionDirectFloatXYZ)
// Test that scale does nothing for floating point inputs.
Input(1.0f); Input(2.0f); Input(4.0f);
m_vtx_attr.g0.PosFrac = 1;
count = loader.RunVertices(m_vtx_attr, 7, 1, src, dst);
src.Skip(1 * loader.GetVertexSize());
dst.Skip(count * loader.GetNativeVertexDeclaration().stride);
loader = new VertexLoader(m_vtx_desc, m_vtx_attr);
count = loader->RunVertices(7, 1, src, dst);
src.Skip(1 * loader->GetVertexSize());
dst.Skip(count * loader->GetNativeVertexDeclaration().stride);
ExpectOut(1.0f); ExpectOut(2.0f); ExpectOut(4.0f);
delete loader;
}
TEST_F(VertexLoaderTest, PositionDirectU16XY)
@ -129,10 +132,10 @@ TEST_F(VertexLoaderTest, PositionDirectU16XY)
m_vtx_attr.g0.PosElements = 0; // XY
m_vtx_attr.g0.PosFormat = 2; // U16
VertexLoader loader(m_vtx_desc, m_vtx_attr);
VertexLoader* loader = new VertexLoader(m_vtx_desc, m_vtx_attr);
ASSERT_EQ(3 * sizeof (float), (u32)loader.GetNativeVertexDeclaration().stride);
ASSERT_EQ(2 * sizeof (u16), (u32)loader.GetVertexSize());
ASSERT_EQ(3 * sizeof (float), (u32)loader->GetNativeVertexDeclaration().stride);
ASSERT_EQ(2 * sizeof (u16), (u32)loader->GetVertexSize());
// Write some vertices.
Input<u16>(0); Input<u16>(0);
@ -142,9 +145,10 @@ TEST_F(VertexLoaderTest, PositionDirectU16XY)
Input<u16>(12345); Input<u16>(54321);
// Convert 5 points. "7" -> primitive are points.
int count = loader.RunVertices(m_vtx_attr, 7, 5, src, dst);
src.Skip(5 * loader.GetVertexSize());
dst.Skip(count * loader.GetNativeVertexDeclaration().stride);
int count = loader->RunVertices(7, 5, src, dst);
src.Skip(5 * loader->GetVertexSize());
dst.Skip(count * loader->GetNativeVertexDeclaration().stride);
delete loader;
ExpectOut(0.0f); ExpectOut(0.0f); ExpectOut(0.0f);
ExpectOut(1.0f); ExpectOut(2.0f); ExpectOut(0.0f);
@ -155,10 +159,12 @@ TEST_F(VertexLoaderTest, PositionDirectU16XY)
// Test that scale works on U16 inputs.
Input<u16>(42); Input<u16>(24);
m_vtx_attr.g0.PosFrac = 1;
count = loader.RunVertices(m_vtx_attr, 7, 1, src, dst);
src.Skip(1 * loader.GetVertexSize());
dst.Skip(count * loader.GetNativeVertexDeclaration().stride);
loader = new VertexLoader(m_vtx_desc, m_vtx_attr);
count = loader->RunVertices(7, 1, src, dst);
src.Skip(1 * loader->GetVertexSize());
dst.Skip(count * loader->GetNativeVertexDeclaration().stride);
ExpectOut(21.0f); ExpectOut(12.0f); ExpectOut(0.0f);
delete loader;
}
TEST_F(VertexLoaderTest, PositionDirectFloatXYZSpeed)
@ -175,7 +181,7 @@ TEST_F(VertexLoaderTest, PositionDirectFloatXYZSpeed)
for (int i = 0; i < 1000; ++i)
{
ResetPointers();
int count = loader.RunVertices(m_vtx_attr, 7, 100000, src, dst);
int count = loader.RunVertices(7, 100000, src, dst);
src.Skip(100000 * loader.GetVertexSize());
dst.Skip(count * loader.GetNativeVertexDeclaration().stride);
}
@ -195,7 +201,7 @@ TEST_F(VertexLoaderTest, PositionDirectU16XYSpeed)
for (int i = 0; i < 1000; ++i)
{
ResetPointers();
int count = loader.RunVertices(m_vtx_attr, 7, 100000, src, dst);
int count = loader.RunVertices(7, 100000, src, dst);
src.Skip(100000 * loader.GetVertexSize());
dst.Skip(count * loader.GetNativeVertexDeclaration().stride);
}
@ -258,7 +264,7 @@ TEST_F(VertexLoaderTest, LargeFloatVertexSpeed)
for (int i = 0; i < 100; ++i)
{
ResetPointers();
int count = loader.RunVertices(m_vtx_attr, 7, 100000, src, dst);
int count = loader.RunVertices(7, 100000, src, dst);
src.Skip(100000 * loader.GetVertexSize());
dst.Skip(count * loader.GetNativeVertexDeclaration().stride);
}