From 0b97b33ceb58cd72a9586c438f39866ec032d9a4 Mon Sep 17 00:00:00 2001 From: degasus Date: Tue, 21 Jan 2014 19:23:07 +0100 Subject: [PATCH] VertexLoader: inline destionation buffer --- Source/Core/VideoCommon/DataReader.h | 10 ++++++++-- Source/Core/VideoCommon/VertexLoader_Normal.cpp | 5 ++++- Source/Core/VideoCommon/VertexLoader_Position.cpp | 10 ++++++++-- Source/Core/VideoCommon/VertexLoader_TextCoord.cpp | 11 +++++++++-- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Source/Core/VideoCommon/DataReader.h b/Source/Core/VideoCommon/DataReader.h index 95c992a011..b552ca34e4 100644 --- a/Source/Core/VideoCommon/DataReader.h +++ b/Source/Core/VideoCommon/DataReader.h @@ -132,11 +132,17 @@ __forceinline u8* DataGetPosition() return g_pVideoData; } +template +__forceinline void DataWrite(u8* &dst, T data) +{ + *(T*)dst = data; + dst += sizeof(T); +} + template __forceinline void DataWrite(T data) { - *(T*)VertexManager::s_pCurBufferPointer = data; - VertexManager::s_pCurBufferPointer += sizeof(T); + DataWrite(VertexManager::s_pCurBufferPointer, data); } #endif diff --git a/Source/Core/VideoCommon/VertexLoader_Normal.cpp b/Source/Core/VideoCommon/VertexLoader_Normal.cpp index 4a3600addd..fc9cf9e554 100644 --- a/Source/Core/VideoCommon/VertexLoader_Normal.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Normal.cpp @@ -48,12 +48,15 @@ template __forceinline void ReadIndirect(const T* data) { static_assert(3 == N || 9 == N, "N is only sane as 3 or 9!"); + auto dst = VertexManager::s_pCurBufferPointer; for (int i = 0; i != N; ++i) { - DataWrite(FracAdjust(Common::FromBigEndian(data[i]))); + DataWrite(dst, FracAdjust(Common::FromBigEndian(data[i]))); } + VertexManager::s_pCurBufferPointer = dst; + LOG_NORM(); } diff --git a/Source/Core/VideoCommon/VertexLoader_Position.cpp b/Source/Core/VideoCommon/VertexLoader_Position.cpp index e6836ddf6a..6163272fb1 100644 --- a/Source/Core/VideoCommon/VertexLoader_Position.cpp +++ b/Source/Core/VideoCommon/VertexLoader_Position.cpp @@ -77,9 +77,12 @@ void LOADERDECL Pos_ReadDirect() { static_assert(N <= 3, "N > 3 is not sane!"); auto const scale = posScale; + auto dst = VertexManager::s_pCurBufferPointer; for (int i = 0; i < 3; ++i) - DataWrite(i(), scale) : 0.f); + DataWrite(dst, i(), scale) : 0.f); + + VertexManager::s_pCurBufferPointer = dst; LOG_VTX(); } @@ -93,9 +96,12 @@ void LOADERDECL Pos_ReadIndex() auto const index = DataRead(); auto const data = reinterpret_cast(cached_arraybases[ARRAY_POSITION] + (index * arraystrides[ARRAY_POSITION])); auto const scale = posScale; + auto dst = VertexManager::s_pCurBufferPointer; for (int i = 0; i < 3; ++i) - DataWrite(i void LOADERDECL TexCoord_ReadDirect() { auto const scale = tcScale[tcIndex]; + auto dst = VertexManager::s_pCurBufferPointer; + for (int i = 0; i != N; ++i) - DataWrite(TCScale(DataRead(), scale)); + DataWrite(dst, TCScale(DataRead(), scale)); + + VertexManager::s_pCurBufferPointer = dst; LOG_TEX(); @@ -74,9 +78,12 @@ void LOADERDECL TexCoord_ReadIndex() auto const data = reinterpret_cast(cached_arraybases[ARRAY_TEXCOORD0 + tcIndex] + (index * arraystrides[ARRAY_TEXCOORD0 + tcIndex])); auto const scale = tcScale[tcIndex]; + auto dst = VertexManager::s_pCurBufferPointer; for (int i = 0; i != N; ++i) - DataWrite(TCScale(Common::FromBigEndian(data[i]), scale)); + DataWrite(dst, TCScale(Common::FromBigEndian(data[i]), scale)); + + VertexManager::s_pCurBufferPointer = dst; LOG_TEX(); ++tcIndex;