From c7f4d6b9ac9860532b8c84d6fde5ba4b80dca08d Mon Sep 17 00:00:00 2001 From: degasus Date: Thu, 21 Feb 2013 13:45:48 +0100 Subject: [PATCH] wrapper for s_pCurBufferPointer --- Source/Core/VideoCommon/Src/DataReader.h | 9 +++++++++ .../VideoCommon/Src/VertexLoader_Color.cpp | 3 +-- .../VideoCommon/Src/VertexLoader_Normal.cpp | 7 ++----- .../VideoCommon/Src/VertexLoader_Position.cpp | 20 +++++-------------- .../Src/VertexLoader_TextCoord.cpp | 19 ++++++------------ Source/Core/VideoCommon/Src/VideoCommon.h | 2 +- 6 files changed, 24 insertions(+), 36 deletions(-) diff --git a/Source/Core/VideoCommon/Src/DataReader.h b/Source/Core/VideoCommon/Src/DataReader.h index 00dca77134..03061229c0 100644 --- a/Source/Core/VideoCommon/Src/DataReader.h +++ b/Source/Core/VideoCommon/Src/DataReader.h @@ -20,6 +20,8 @@ #ifndef _DATAREADER_H #define _DATAREADER_H +#include "VertexManagerBase.h" + extern u8* g_pVideoData; #if _M_SSE >= 0x301 && !(defined __GNUC__ && !defined __SSSE3__) @@ -145,4 +147,11 @@ __forceinline u8* DataGetPosition() return g_pVideoData; } +template +__forceinline void DataWrite(T data) +{ + *(T*)VertexManager::s_pCurBufferPointer = data; + VertexManager::s_pCurBufferPointer += sizeof(T); +} + #endif diff --git a/Source/Core/VideoCommon/Src/VertexLoader_Color.cpp b/Source/Core/VideoCommon/Src/VertexLoader_Color.cpp index ce2c970fb9..fa1ecbe973 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader_Color.cpp +++ b/Source/Core/VideoCommon/Src/VertexLoader_Color.cpp @@ -34,8 +34,7 @@ extern int colElements[2]; __forceinline void _SetCol(u32 val) { - *(u32*)VertexManager::s_pCurBufferPointer = val; - VertexManager::s_pCurBufferPointer += 4; + DataWrite(val); colIndex++; } diff --git a/Source/Core/VideoCommon/Src/VertexLoader_Normal.cpp b/Source/Core/VideoCommon/Src/VertexLoader_Normal.cpp index 4102fdff69..0b7a37926e 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader_Normal.cpp +++ b/Source/Core/VideoCommon/Src/VertexLoader_Normal.cpp @@ -59,16 +59,13 @@ template inline void ReadIndirect(const T* data) { static_assert(3 == N || 9 == N, "N is only sane as 3 or 9!"); - - auto const dest = reinterpret_cast(VertexManager::s_pCurBufferPointer); for (int i = 0; i != N; ++i) { - dest[i] = FracAdjust(Common::FromBigEndian(data[i])); - LOG_NORM(); + DataWrite(FracAdjust(Common::FromBigEndian(data[i]))); } - VertexManager::s_pCurBufferPointer += sizeof(float) * N; + LOG_NORM(); } template diff --git a/Source/Core/VideoCommon/Src/VertexLoader_Position.cpp b/Source/Core/VideoCommon/Src/VertexLoader_Position.cpp index 14f2819260..ce7a38b8c3 100644 --- a/Source/Core/VideoCommon/Src/VertexLoader_Position.cpp +++ b/Source/Core/VideoCommon/Src/VertexLoader_Position.cpp @@ -88,15 +88,10 @@ void LOADERDECL Pos_ReadDirect() { static_assert(N <= 3, "N > 3 is not sane!"); - auto const dest = reinterpret_cast(VertexManager::s_pCurBufferPointer); - for (int i = 0; i != N; ++i) - dest[i] = PosScale(DataRead()); - - for (int i = N; i != 3; ++i) - dest[i] = 0.f; + for (int i = 0; i < 3; ++i) + DataWrite(i()) : 0.f); LOG_VTX(); - VertexManager::s_pCurBufferPointer += sizeof(float) * 3; } template @@ -109,16 +104,11 @@ void LOADERDECL Pos_ReadIndex() if (index < std::numeric_limits::max()) { auto const data = reinterpret_cast(cached_arraybases[ARRAY_POSITION] + (index * arraystrides[ARRAY_POSITION])); - auto const dest = reinterpret_cast(VertexManager::s_pCurBufferPointer); - for (int i = 0; i != N; ++i) - dest[i] = PosScale(Common::FromBigEndian(data[i])); - - for (int i = N; i != 3; ++i) - dest[i] = 0.f + for (int i = 0; i < 3; ++i) + DataWrite(i __forceinline void LOG_TEX<1>() { // warning: mapping buffer should be disabled to use this - // PRIM_LOG("tex: %f, ", ((float*)VertexManager::s_pCurBufferPointer)[0]); + // PRIM_LOG("tex: %f, ", ((float*)VertexManager::s_pCurBufferPointer)[-1]); } template <> __forceinline void LOG_TEX<2>() { // warning: mapping buffer should be disabled to use this - // PRIM_LOG("tex: %f %f, ", ((float*)VertexManager::s_pCurBufferPointer)[0], ((float*)VertexManager::s_pCurBufferPointer)[1]); + // PRIM_LOG("tex: %f %f, ", ((float*)VertexManager::s_pCurBufferPointer)[-2], ((float*)VertexManager::s_pCurBufferPointer)[-1]); } extern int tcIndex; @@ -66,14 +66,11 @@ float TCScale(float val) template void LOADERDECL TexCoord_ReadDirect() { - auto const dest = reinterpret_cast(VertexManager::s_pCurBufferPointer); - for (int i = 0; i != N; ++i) - dest[i] = TCScale(DataRead()); + DataWrite(TCScale(DataRead())); LOG_TEX(); - VertexManager::s_pCurBufferPointer += sizeof(float) * N; ++tcIndex; } @@ -86,14 +83,10 @@ void LOADERDECL TexCoord_ReadIndex() auto const data = reinterpret_cast(cached_arraybases[ARRAY_TEXCOORD0 + tcIndex] + (index * arraystrides[ARRAY_TEXCOORD0 + tcIndex])); - auto const dest = reinterpret_cast(VertexManager::s_pCurBufferPointer); - for (int i = 0; i != N; ++i) - dest[i] = TCScale(Common::FromBigEndian(data[i])); + DataWrite(TCScale(Common::FromBigEndian(data[i]))); LOG_TEX(); - - VertexManager::s_pCurBufferPointer += sizeof(float) * N; ++tcIndex; } @@ -112,8 +105,8 @@ void LOADERDECL TexCoord_ReadIndex16_Short2_SSE4() const __m128 e = _mm_load1_ps(&tcScale[tcIndex]); const __m128 f = _mm_mul_ps(d, e); _mm_storeu_ps((float*)VertexManager::s_pCurBufferPointer, f); - LOG_TEX<2>(); VertexManager::s_pCurBufferPointer += 8; + LOG_TEX<2>(); tcIndex++; } #endif @@ -128,8 +121,8 @@ void LOADERDECL TexCoord_ReadIndex16_Float2_SSSE3() GC_ALIGNED128(const __m128i a = _mm_loadl_epi64((__m128i*)pData)); GC_ALIGNED128(const __m128i b = _mm_shuffle_epi8(a, kMaskSwap32)); _mm_storel_epi64((__m128i*)VertexManager::s_pCurBufferPointer, b); - LOG_TEX<2>(); VertexManager::s_pCurBufferPointer += 8; + LOG_TEX<2>(); tcIndex++; } #endif diff --git a/Source/Core/VideoCommon/Src/VideoCommon.h b/Source/Core/VideoCommon/Src/VideoCommon.h index 7681d8ba82..b15d539611 100644 --- a/Source/Core/VideoCommon/Src/VideoCommon.h +++ b/Source/Core/VideoCommon/Src/VideoCommon.h @@ -91,7 +91,7 @@ struct TargetRectangle : public MathUtil::Rectangle #endif // warning: mapping buffer should be disabled to use this -// #define LOG_VTX() DEBUG_LOG(VIDEO, "vtx: %f %f %f, ", ((float*)VertexManager::s_pCurBufferPointer)[0], ((float*)VertexManager::s_pCurBufferPointer)[1], ((float*)VertexManager::s_pCurBufferPointer)[2]); +// #define LOG_VTX() DEBUG_LOG(VIDEO, "vtx: %f %f %f, ", ((float*)VertexManager::s_pCurBufferPointer)[-3], ((float*)VertexManager::s_pCurBufferPointer)[-2], ((float*)VertexManager::s_pCurBufferPointer)[-1]); #define LOG_VTX()