VertexLoaders: make positions more compact

This commit is contained in:
Tillmann Karras 2015-03-17 07:05:19 +01:00
parent 5a51bc10e5
commit 8d90ecda7f
5 changed files with 19 additions and 18 deletions

View File

@ -131,12 +131,13 @@ void VertexLoader::CompileVertexTranslator()
WriteCall(VertexLoader_Position::GetFunction(m_VtxDesc.Position, m_VtxAttr.PosFormat, m_VtxAttr.PosElements));
m_VertexSize += VertexLoader_Position::GetSize(m_VtxDesc.Position, m_VtxAttr.PosFormat, m_VtxAttr.PosElements);
m_native_vtx_decl.position.components = 3;
int pos_elements = m_VtxAttr.PosElements + 2;
m_native_vtx_decl.position.components = pos_elements;
m_native_vtx_decl.position.enable = true;
m_native_vtx_decl.position.offset = nat_offset;
m_native_vtx_decl.position.type = VAR_FLOAT;
m_native_vtx_decl.position.integer = false;
nat_offset += 12;
nat_offset += pos_elements * sizeof(float);
// Normals
if (m_VtxDesc.Normal != NOT_PRESENT)

View File

@ -370,7 +370,8 @@ void VertexLoaderARM64::GenerateVertexLoader()
load_size <<= 3;
s32 offset = GetAddressImm(ARRAY_POSITION, m_VtxDesc.Position, EncodeRegTo64(scratch1_reg), load_size);
ReadVertex(m_VtxDesc.Position, m_VtxAttr.PosFormat, m_VtxAttr.PosElements + 2, 3,
int pos_elements = m_VtxAttr.PosElements + 2;
ReadVertex(m_VtxDesc.Position, m_VtxAttr.PosFormat, pos_elements, pos_elements,
m_VtxAttr.ByteDequant, m_VtxAttr.PosFrac, &m_native_vtx_decl.position, offset);
}

View File

@ -332,7 +332,8 @@ void VertexLoaderX64::GenerateVertexLoader()
}
OpArg data = GetVertexAddr(ARRAY_POSITION, m_VtxDesc.Position);
ReadVertex(data, m_VtxDesc.Position, m_VtxAttr.PosFormat, m_VtxAttr.PosElements + 2, 3,
int pos_elements = 2 + m_VtxAttr.PosElements;
ReadVertex(data, m_VtxDesc.Position, m_VtxAttr.PosFormat, pos_elements, pos_elements,
m_VtxAttr.ByteDequant, m_VtxAttr.PosFrac, &m_native_vtx_decl.position);
if (m_VtxDesc.Normal)
@ -408,7 +409,7 @@ void VertexLoaderX64::GenerateVertexLoader()
m_native_vtx_decl.texcoords[i].offset = m_dst_ofs;
PXOR(XMM0, R(XMM0));
CVTSI2SS(XMM0, R(scratch1));
SHUFPS(XMM0, R(XMM0), 0x45);
SHUFPS(XMM0, R(XMM0), 0x45); // 000X -> 0X00
MOVUPS(MDisp(dst_reg, m_dst_ofs), XMM0);
m_dst_ofs += sizeof(float) * 3;
}

View File

@ -30,8 +30,8 @@ void LOADERDECL Pos_ReadDirect(VertexLoader* loader)
DataReader dst(g_vertex_manager_write_ptr, nullptr);
DataReader src(g_video_buffer_read_ptr, nullptr);
for (int i = 0; i < 3; ++i)
dst.Write(i < N ? PosScale(src.Read<T>(), scale) : 0.f);
for (int i = 0; i < N; ++i)
dst.Write(PosScale(src.Read<T>(), scale));
g_vertex_manager_write_ptr = dst.GetPointer();
g_video_buffer_read_ptr = src.GetPointer();
@ -50,8 +50,8 @@ void LOADERDECL Pos_ReadIndex(VertexLoader* loader)
auto const scale = loader->m_posScale;
DataReader dst(g_vertex_manager_write_ptr, nullptr);
for (int i = 0; i < 3; ++i)
dst.Write(i < N ? PosScale(Common::FromBigEndian(data[i]), scale) : 0.f);
for (int i = 0; i < N; ++i)
dst.Write(PosScale(Common::FromBigEndian(data[i]), scale));
g_vertex_manager_write_ptr = dst.GetPointer();
LOG_VTX();

View File

@ -54,7 +54,7 @@ protected:
ResetPointers();
}
void CreateAndCheckSizes(size_t input_size, size_t output_size = 3 * sizeof(float))
void CreateAndCheckSizes(size_t input_size, size_t output_size)
{
m_loader.reset(VertexLoaderBase::CreateVertexLoader(m_vtx_desc, m_vtx_attr));
ASSERT_EQ((int)input_size, m_loader->m_VertexSize);
@ -150,7 +150,7 @@ TEST_P(VertexLoaderParamTest, PositionAll)
cached_arraybases[ARRAY_POSITION] = m_src.GetPointer();
g_main_cp_state.array_strides[ARRAY_POSITION] = elements * elem_size;
}
CreateAndCheckSizes(input_size);
CreateAndCheckSizes(input_size, elements * sizeof(float));
for (float value : values)
{
switch (format)
@ -179,8 +179,6 @@ TEST_P(VertexLoaderParamTest, PositionAll)
}
ExpectOut(f * scale);
ExpectOut(g * scale);
if (elements == 2)
m_dst.Skip(sizeof(float));
}
}
@ -188,14 +186,14 @@ TEST_F(VertexLoaderTest, PositionIndex16FloatXY)
{
m_vtx_desc.Position = INDEX16;
m_vtx_attr.g0.PosFormat = FORMAT_FLOAT;
CreateAndCheckSizes(sizeof(u16));
CreateAndCheckSizes(sizeof(u16), 2 * sizeof(float));
Input<u16>(1); Input<u16>(0);
cached_arraybases[ARRAY_POSITION] = m_src.GetPointer();
g_main_cp_state.array_strides[ARRAY_POSITION] = sizeof(float); // ;)
Input(1.f); Input(2.f); Input(3.f);
RunVertices(2);
ExpectOut(2); ExpectOut(3); m_dst.Skip(sizeof(float));
ExpectOut(1); ExpectOut(2); m_dst.Skip(sizeof(float));
ExpectOut(2); ExpectOut(3);
ExpectOut(1); ExpectOut(2);
}
class VertexLoaderSpeedTest : public VertexLoaderTest, public ::testing::WithParamInterface<std::tuple<int, int>> {};
@ -219,7 +217,7 @@ TEST_P(VertexLoaderSpeedTest, PositionDirectAll)
m_vtx_attr.g0.PosElements = elements;
elements += 2;
size_t elem_size = 1 << (format / 2);
CreateAndCheckSizes(elements * elem_size);
CreateAndCheckSizes(elements * elem_size, elements * sizeof(float));
for (int i = 0; i < 1000; ++i)
RunVertices(100000);
}