wrapper for s_pCurBufferPointer

This commit is contained in:
degasus 2013-02-21 13:45:48 +01:00
parent 4b4dce1bd9
commit c7f4d6b9ac
6 changed files with 24 additions and 36 deletions

View File

@ -20,6 +20,8 @@
#ifndef _DATAREADER_H #ifndef _DATAREADER_H
#define _DATAREADER_H #define _DATAREADER_H
#include "VertexManagerBase.h"
extern u8* g_pVideoData; extern u8* g_pVideoData;
#if _M_SSE >= 0x301 && !(defined __GNUC__ && !defined __SSSE3__) #if _M_SSE >= 0x301 && !(defined __GNUC__ && !defined __SSSE3__)
@ -145,4 +147,11 @@ __forceinline u8* DataGetPosition()
return g_pVideoData; return g_pVideoData;
} }
template <typename T>
__forceinline void DataWrite(T data)
{
*(T*)VertexManager::s_pCurBufferPointer = data;
VertexManager::s_pCurBufferPointer += sizeof(T);
}
#endif #endif

View File

@ -34,8 +34,7 @@ extern int colElements[2];
__forceinline void _SetCol(u32 val) __forceinline void _SetCol(u32 val)
{ {
*(u32*)VertexManager::s_pCurBufferPointer = val; DataWrite(val);
VertexManager::s_pCurBufferPointer += 4;
colIndex++; colIndex++;
} }

View File

@ -59,16 +59,13 @@ template <typename T, int N>
inline void ReadIndirect(const T* data) inline void ReadIndirect(const T* data)
{ {
static_assert(3 == N || 9 == N, "N is only sane as 3 or 9!"); static_assert(3 == N || 9 == N, "N is only sane as 3 or 9!");
auto const dest = reinterpret_cast<float*>(VertexManager::s_pCurBufferPointer);
for (int i = 0; i != N; ++i) for (int i = 0; i != N; ++i)
{ {
dest[i] = FracAdjust(Common::FromBigEndian(data[i])); DataWrite(FracAdjust(Common::FromBigEndian(data[i])));
LOG_NORM();
} }
VertexManager::s_pCurBufferPointer += sizeof(float) * N; LOG_NORM();
} }
template <typename T, int N> template <typename T, int N>

View File

@ -88,15 +88,10 @@ void LOADERDECL Pos_ReadDirect()
{ {
static_assert(N <= 3, "N > 3 is not sane!"); static_assert(N <= 3, "N > 3 is not sane!");
auto const dest = reinterpret_cast<float*>(VertexManager::s_pCurBufferPointer); for (int i = 0; i < 3; ++i)
for (int i = 0; i != N; ++i) DataWrite(i<N ? PosScale(DataRead<T>()) : 0.f);
dest[i] = PosScale(DataRead<T>());
for (int i = N; i != 3; ++i)
dest[i] = 0.f;
LOG_VTX(); LOG_VTX();
VertexManager::s_pCurBufferPointer += sizeof(float) * 3;
} }
template <typename I, typename T, int N> template <typename I, typename T, int N>
@ -109,16 +104,11 @@ void LOADERDECL Pos_ReadIndex()
if (index < std::numeric_limits<I>::max()) if (index < std::numeric_limits<I>::max())
{ {
auto const data = reinterpret_cast<const T*>(cached_arraybases[ARRAY_POSITION] + (index * arraystrides[ARRAY_POSITION])); auto const data = reinterpret_cast<const T*>(cached_arraybases[ARRAY_POSITION] + (index * arraystrides[ARRAY_POSITION]));
auto const dest = reinterpret_cast<float*>(VertexManager::s_pCurBufferPointer);
for (int i = 0; i != N; ++i) for (int i = 0; i < 3; ++i)
dest[i] = PosScale(Common::FromBigEndian(data[i])); DataWrite(i<N ? PosScale(Common::FromBigEndian(data[i])) : 0.f);
for (int i = N; i != 3; ++i)
dest[i] = 0.f
LOG_VTX(); LOG_VTX();
VertexManager::s_pCurBufferPointer += sizeof(float) * 3;
} }
} }
@ -136,8 +126,8 @@ void LOADERDECL Pos_ReadIndex_Float_SSSE3()
GC_ALIGNED128(const __m128i a = _mm_loadu_si128((__m128i*)pData)); GC_ALIGNED128(const __m128i a = _mm_loadu_si128((__m128i*)pData));
GC_ALIGNED128(__m128i b = _mm_shuffle_epi8(a, three ? kMaskSwap32_3 : kMaskSwap32_2)); GC_ALIGNED128(__m128i b = _mm_shuffle_epi8(a, three ? kMaskSwap32_3 : kMaskSwap32_2));
_mm_storeu_si128((__m128i*)VertexManager::s_pCurBufferPointer, b); _mm_storeu_si128((__m128i*)VertexManager::s_pCurBufferPointer, b);
LOG_VTX();
VertexManager::s_pCurBufferPointer += sizeof(float) * 3; VertexManager::s_pCurBufferPointer += sizeof(float) * 3;
LOG_VTX();
} }
} }
#endif #endif

View File

@ -35,14 +35,14 @@ template <>
__forceinline void LOG_TEX<1>() __forceinline void LOG_TEX<1>()
{ {
// warning: mapping buffer should be disabled to use this // 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 <> template <>
__forceinline void LOG_TEX<2>() __forceinline void LOG_TEX<2>()
{ {
// warning: mapping buffer should be disabled to use this // 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; extern int tcIndex;
@ -66,14 +66,11 @@ float TCScale(float val)
template <typename T, int N> template <typename T, int N>
void LOADERDECL TexCoord_ReadDirect() void LOADERDECL TexCoord_ReadDirect()
{ {
auto const dest = reinterpret_cast<float*>(VertexManager::s_pCurBufferPointer);
for (int i = 0; i != N; ++i) for (int i = 0; i != N; ++i)
dest[i] = TCScale(DataRead<T>()); DataWrite(TCScale(DataRead<T>()));
LOG_TEX<N>(); LOG_TEX<N>();
VertexManager::s_pCurBufferPointer += sizeof(float) * N;
++tcIndex; ++tcIndex;
} }
@ -86,14 +83,10 @@ void LOADERDECL TexCoord_ReadIndex()
auto const data = reinterpret_cast<const T*>(cached_arraybases[ARRAY_TEXCOORD0 + tcIndex] auto const data = reinterpret_cast<const T*>(cached_arraybases[ARRAY_TEXCOORD0 + tcIndex]
+ (index * arraystrides[ARRAY_TEXCOORD0 + tcIndex])); + (index * arraystrides[ARRAY_TEXCOORD0 + tcIndex]));
auto const dest = reinterpret_cast<float*>(VertexManager::s_pCurBufferPointer);
for (int i = 0; i != N; ++i) for (int i = 0; i != N; ++i)
dest[i] = TCScale(Common::FromBigEndian(data[i])); DataWrite(TCScale(Common::FromBigEndian(data[i])));
LOG_TEX<N>(); LOG_TEX<N>();
VertexManager::s_pCurBufferPointer += sizeof(float) * N;
++tcIndex; ++tcIndex;
} }
@ -112,8 +105,8 @@ void LOADERDECL TexCoord_ReadIndex16_Short2_SSE4()
const __m128 e = _mm_load1_ps(&tcScale[tcIndex]); const __m128 e = _mm_load1_ps(&tcScale[tcIndex]);
const __m128 f = _mm_mul_ps(d, e); const __m128 f = _mm_mul_ps(d, e);
_mm_storeu_ps((float*)VertexManager::s_pCurBufferPointer, f); _mm_storeu_ps((float*)VertexManager::s_pCurBufferPointer, f);
LOG_TEX<2>();
VertexManager::s_pCurBufferPointer += 8; VertexManager::s_pCurBufferPointer += 8;
LOG_TEX<2>();
tcIndex++; tcIndex++;
} }
#endif #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 a = _mm_loadl_epi64((__m128i*)pData));
GC_ALIGNED128(const __m128i b = _mm_shuffle_epi8(a, kMaskSwap32)); GC_ALIGNED128(const __m128i b = _mm_shuffle_epi8(a, kMaskSwap32));
_mm_storel_epi64((__m128i*)VertexManager::s_pCurBufferPointer, b); _mm_storel_epi64((__m128i*)VertexManager::s_pCurBufferPointer, b);
LOG_TEX<2>();
VertexManager::s_pCurBufferPointer += 8; VertexManager::s_pCurBufferPointer += 8;
LOG_TEX<2>();
tcIndex++; tcIndex++;
} }
#endif #endif

View File

@ -91,7 +91,7 @@ struct TargetRectangle : public MathUtil::Rectangle<int>
#endif #endif
// warning: mapping buffer should be disabled to use this // 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() #define LOG_VTX()