diff --git a/Source/Core/VideoCommon/VertexLoader.cpp b/Source/Core/VideoCommon/VertexLoader.cpp index d27d5287ad..49b6d23e1a 100644 --- a/Source/Core/VideoCommon/VertexLoader.cpp +++ b/Source/Core/VideoCommon/VertexLoader.cpp @@ -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) diff --git a/Source/Core/VideoCommon/VertexLoaderARM64.cpp b/Source/Core/VideoCommon/VertexLoaderARM64.cpp index 4a404e9a75..397a179e9e 100644 --- a/Source/Core/VideoCommon/VertexLoaderARM64.cpp +++ b/Source/Core/VideoCommon/VertexLoaderARM64.cpp @@ -370,8 +370,9 @@ 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, - m_VtxAttr.ByteDequant, m_VtxAttr.PosFrac, &m_native_vtx_decl.position, offset); + 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); } if (m_VtxDesc.Normal) diff --git a/Source/Core/VideoCommon/VertexLoaderX64.cpp b/Source/Core/VideoCommon/VertexLoaderX64.cpp index 8d01a5d598..df1a5580b7 100644 --- a/Source/Core/VideoCommon/VertexLoaderX64.cpp +++ b/Source/Core/VideoCommon/VertexLoaderX64.cpp @@ -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; } diff --git a/Source/Core/VideoCommon/VertexLoader_Position.cpp b/Source/Core/VideoCommon/VertexLoader_Position.cpp index 18460ff1e1..3c30d05ed6 100644 --- a/Source/Core/VideoCommon/VertexLoader_Position.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Position.cpp @@ -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(), scale) : 0.f); + for (int i = 0; i < N; ++i) + dst.Write(PosScale(src.Read(), 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(); diff --git a/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp index d3a5bc7b82..1c6579b795 100644 --- a/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp +++ b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp @@ -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(1); Input(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> {}; @@ -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); }