From 16c0593a52ddaf3a5bde17a2f56f46b9618e5928 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Thu, 12 Jan 2023 15:00:51 -0800 Subject: [PATCH] VertexLoader: Fix loading tangent/binormal caches with NormalIndex3 --- Source/Core/VideoCommon/VertexLoader_Normal.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Source/Core/VideoCommon/VertexLoader_Normal.cpp b/Source/Core/VideoCommon/VertexLoader_Normal.cpp index c713e4c9c6..abb6d27da7 100644 --- a/Source/Core/VideoCommon/VertexLoader_Normal.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Normal.cpp @@ -38,12 +38,13 @@ constexpr float FracAdjust(float val) return val; } -template +template void ReadIndirect(VertexLoader* loader, const T* data) { static_assert(3 == N || 9 == N, "N is only sane as 3 or 9!"); + static_assert(!(Offset != 0 && 9 == N), "N == 9 only makes sense if offset == 0"); - for (u32 i = 0; i < N; ++i) + for (u32 i = Offset; i < N + Offset; ++i) { const float value = FracAdjust(Common::FromBigEndian(data[i])); if (loader->m_remaining == 0) @@ -63,7 +64,7 @@ template void Normal_ReadDirect(VertexLoader* loader) { const auto source = reinterpret_cast(DataGetPosition()); - ReadIndirect(loader, source); + ReadIndirect(loader, source); DataSkip(); } @@ -73,10 +74,10 @@ void Normal_ReadIndex_Offset(VertexLoader* loader) static_assert(std::is_unsigned_v, "Only unsigned I is sane!"); const auto index = DataRead(); - const auto data = reinterpret_cast( - VertexLoaderManager::cached_arraybases[CPArray::Normal] + - (index * g_main_cp_state.array_strides[CPArray::Normal]) + sizeof(T) * 3 * Offset); - ReadIndirect(loader, data); + const auto data = + reinterpret_cast(VertexLoaderManager::cached_arraybases[CPArray::Normal] + + (index * g_main_cp_state.array_strides[CPArray::Normal])); + ReadIndirect(loader, data); } template