2013-04-18 03:09:55 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/Common.h"
|
|
|
|
#include "Common/CPUDetect.h"
|
|
|
|
|
|
|
|
#include "VideoCommon/VertexLoader.h"
|
|
|
|
#include "VideoCommon/VertexLoader_TextCoord.h"
|
|
|
|
#include "VideoCommon/VertexManagerBase.h"
|
|
|
|
#include "VideoCommon/VideoCommon.h"
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2010-04-09 03:02:12 +00:00
|
|
|
#if _M_SSE >= 0x401
|
|
|
|
#include <smmintrin.h>
|
2010-07-31 15:26:46 +00:00
|
|
|
#elif _M_SSE >= 0x301 && !(defined __GNUC__ && !defined __SSSE3__)
|
2010-04-09 03:02:12 +00:00
|
|
|
#include <tmmintrin.h>
|
|
|
|
#endif
|
|
|
|
|
2013-02-21 06:40:22 +00:00
|
|
|
template <int N>
|
|
|
|
void LOG_TEX();
|
|
|
|
|
|
|
|
template <>
|
|
|
|
__forceinline void LOG_TEX<1>()
|
|
|
|
{
|
2013-02-21 11:18:50 +00:00
|
|
|
// warning: mapping buffer should be disabled to use this
|
2013-02-21 12:45:48 +00:00
|
|
|
// PRIM_LOG("tex: %f, ", ((float*)VertexManager::s_pCurBufferPointer)[-1]);
|
2013-02-21 06:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
__forceinline void LOG_TEX<2>()
|
|
|
|
{
|
2013-02-21 11:18:50 +00:00
|
|
|
// warning: mapping buffer should be disabled to use this
|
2013-02-21 12:45:48 +00:00
|
|
|
// PRIM_LOG("tex: %f %f, ", ((float*)VertexManager::s_pCurBufferPointer)[-2], ((float*)VertexManager::s_pCurBufferPointer)[-1]);
|
2013-02-21 06:40:22 +00:00
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
extern int tcIndex;
|
|
|
|
extern float tcScale[8];
|
|
|
|
|
|
|
|
void LOADERDECL TexCoord_Read_Dummy()
|
|
|
|
{
|
|
|
|
tcIndex++;
|
|
|
|
}
|
|
|
|
|
2013-02-21 06:40:22 +00:00
|
|
|
template <typename T>
|
2014-01-21 17:54:16 +00:00
|
|
|
float TCScale(T val, float scale)
|
2013-02-21 06:40:22 +00:00
|
|
|
{
|
2014-01-21 17:54:16 +00:00
|
|
|
return val * scale;
|
2013-02-21 06:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
2014-01-21 17:54:16 +00:00
|
|
|
float TCScale(float val, float scale)
|
2013-04-24 13:21:54 +00:00
|
|
|
{
|
|
|
|
return val;
|
|
|
|
}
|
2013-02-21 06:40:22 +00:00
|
|
|
|
2013-02-21 02:43:53 +00:00
|
|
|
template <typename T, int N>
|
|
|
|
void LOADERDECL TexCoord_ReadDirect()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2014-01-21 17:54:16 +00:00
|
|
|
auto const scale = tcScale[tcIndex];
|
2014-01-21 22:44:51 +00:00
|
|
|
DataWriter dst;
|
|
|
|
DataReader src;
|
2014-01-21 17:54:16 +00:00
|
|
|
|
2013-02-21 06:40:22 +00:00
|
|
|
for (int i = 0; i != N; ++i)
|
2014-01-21 22:44:51 +00:00
|
|
|
dst.Write(TCScale(src.Read<T>(), scale));
|
2013-02-21 06:40:22 +00:00
|
|
|
|
|
|
|
LOG_TEX<N>();
|
2013-03-20 01:51:12 +00:00
|
|
|
|
2013-02-21 02:43:53 +00:00
|
|
|
++tcIndex;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 02:43:53 +00:00
|
|
|
template <typename I, typename T, int N>
|
|
|
|
void LOADERDECL TexCoord_ReadIndex()
|
2008-12-08 05:25:12 +00:00
|
|
|
{
|
2013-02-21 04:22:41 +00:00
|
|
|
static_assert(!std::numeric_limits<I>::is_signed, "Only unsigned I is sane!");
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-21 02:43:53 +00:00
|
|
|
auto const index = DataRead<I>();
|
2013-02-21 06:40:22 +00:00
|
|
|
auto const data = reinterpret_cast<const T*>(cached_arraybases[ARRAY_TEXCOORD0 + tcIndex]
|
|
|
|
+ (index * arraystrides[ARRAY_TEXCOORD0 + tcIndex]));
|
2014-01-21 17:54:16 +00:00
|
|
|
auto const scale = tcScale[tcIndex];
|
2014-01-21 22:44:51 +00:00
|
|
|
DataWriter dst;
|
2013-03-20 01:51:12 +00:00
|
|
|
|
2013-02-21 06:40:22 +00:00
|
|
|
for (int i = 0; i != N; ++i)
|
2014-01-21 22:44:51 +00:00
|
|
|
dst.Write(TCScale(Common::FromBigEndian(data[i]), scale));
|
2013-03-20 01:51:12 +00:00
|
|
|
|
2013-02-21 06:40:22 +00:00
|
|
|
LOG_TEX<N>();
|
2013-02-21 02:43:53 +00:00
|
|
|
++tcIndex;
|
2010-04-09 15:13:42 +00:00
|
|
|
}
|
2010-04-09 03:02:12 +00:00
|
|
|
|
|
|
|
#if _M_SSE >= 0x401
|
2010-04-09 15:13:42 +00:00
|
|
|
static const __m128i kMaskSwap16_2 = _mm_set_epi32(0xFFFFFFFFL, 0xFFFFFFFFL, 0xFFFFFFFFL, 0x02030001L);
|
2010-04-09 03:02:12 +00:00
|
|
|
|
2013-02-21 18:42:09 +00:00
|
|
|
template <typename I>
|
|
|
|
void LOADERDECL TexCoord_ReadIndex_Short2_SSE4()
|
2010-04-09 15:13:42 +00:00
|
|
|
{
|
2013-02-21 18:42:09 +00:00
|
|
|
static_assert(!std::numeric_limits<I>::is_signed, "Only unsigned I is sane!");
|
2013-03-20 01:51:12 +00:00
|
|
|
|
2010-04-09 15:13:42 +00:00
|
|
|
// Heavy in ZWW
|
2013-02-21 18:42:09 +00:00
|
|
|
auto const index = DataRead<I>();
|
|
|
|
const s32 *pData = (const s32*)(cached_arraybases[ARRAY_TEXCOORD0+tcIndex] + (index * arraystrides[ARRAY_TEXCOORD0+tcIndex]));
|
2010-04-09 03:02:12 +00:00
|
|
|
const __m128i a = _mm_cvtsi32_si128(*pData);
|
|
|
|
const __m128i b = _mm_shuffle_epi8(a, kMaskSwap16_2);
|
|
|
|
const __m128i c = _mm_cvtepi16_epi32(b);
|
|
|
|
const __m128 d = _mm_cvtepi32_ps(c);
|
|
|
|
const __m128 e = _mm_load1_ps(&tcScale[tcIndex]);
|
|
|
|
const __m128 f = _mm_mul_ps(d, e);
|
|
|
|
_mm_storeu_ps((float*)VertexManager::s_pCurBufferPointer, f);
|
2013-02-21 18:42:09 +00:00
|
|
|
VertexManager::s_pCurBufferPointer += sizeof(float) * 2;
|
2013-02-21 12:45:48 +00:00
|
|
|
LOG_TEX<2>();
|
2008-12-08 05:25:12 +00:00
|
|
|
tcIndex++;
|
|
|
|
}
|
2010-04-09 15:13:42 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2010-04-09 03:02:12 +00:00
|
|
|
#if _M_SSE >= 0x301
|
2010-04-09 15:13:42 +00:00
|
|
|
static const __m128i kMaskSwap32 = _mm_set_epi32(0xFFFFFFFFL, 0xFFFFFFFFL, 0x04050607L, 0x00010203L);
|
2010-04-09 03:02:12 +00:00
|
|
|
|
2013-02-21 18:42:09 +00:00
|
|
|
template <typename I>
|
|
|
|
void LOADERDECL TexCoord_ReadIndex_Float2_SSSE3()
|
2010-04-09 15:13:42 +00:00
|
|
|
{
|
2013-02-21 18:42:09 +00:00
|
|
|
static_assert(!std::numeric_limits<I>::is_signed, "Only unsigned I is sane!");
|
2013-03-20 01:51:12 +00:00
|
|
|
|
2013-02-21 18:42:09 +00:00
|
|
|
auto const index = DataRead<I>();
|
|
|
|
const u32 *pData = (const u32 *)(cached_arraybases[ARRAY_TEXCOORD0+tcIndex] + (index * arraystrides[ARRAY_TEXCOORD0+tcIndex]));
|
2011-10-08 15:33:21 +00:00
|
|
|
GC_ALIGNED128(const __m128i a = _mm_loadl_epi64((__m128i*)pData));
|
|
|
|
GC_ALIGNED128(const __m128i b = _mm_shuffle_epi8(a, kMaskSwap32));
|
2013-02-21 10:45:29 +00:00
|
|
|
_mm_storel_epi64((__m128i*)VertexManager::s_pCurBufferPointer, b);
|
2013-02-21 18:42:09 +00:00
|
|
|
VertexManager::s_pCurBufferPointer += sizeof(float) * 2;
|
2013-02-21 12:45:48 +00:00
|
|
|
LOG_TEX<2>();
|
2010-04-09 03:02:12 +00:00
|
|
|
tcIndex++;
|
2008-12-08 05:25:12 +00:00
|
|
|
}
|
2010-04-09 15:13:42 +00:00
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
|
2010-04-09 15:13:42 +00:00
|
|
|
static TPipelineFunction tableReadTexCoord[4][8][2] = {
|
2010-02-28 11:36:00 +00:00
|
|
|
{
|
|
|
|
{NULL, NULL,},
|
|
|
|
{NULL, NULL,},
|
|
|
|
{NULL, NULL,},
|
|
|
|
{NULL, NULL,},
|
|
|
|
{NULL, NULL,},
|
|
|
|
},
|
|
|
|
{
|
2013-02-21 02:43:53 +00:00
|
|
|
{TexCoord_ReadDirect<u8, 1>, TexCoord_ReadDirect<u8, 2>,},
|
|
|
|
{TexCoord_ReadDirect<s8, 1>, TexCoord_ReadDirect<s8, 2>,},
|
|
|
|
{TexCoord_ReadDirect<u16, 1>, TexCoord_ReadDirect<u16, 2>,},
|
|
|
|
{TexCoord_ReadDirect<s16, 1>, TexCoord_ReadDirect<s16, 2>,},
|
|
|
|
{TexCoord_ReadDirect<float, 1>, TexCoord_ReadDirect<float, 2>,},
|
2010-02-28 11:36:00 +00:00
|
|
|
},
|
|
|
|
{
|
2013-02-21 02:43:53 +00:00
|
|
|
{TexCoord_ReadIndex<u8, u8, 1>, TexCoord_ReadIndex<u8, u8, 2>,},
|
|
|
|
{TexCoord_ReadIndex<u8, s8, 1>, TexCoord_ReadIndex<u8, s8, 2>,},
|
|
|
|
{TexCoord_ReadIndex<u8, u16, 1>, TexCoord_ReadIndex<u8, u16, 2>,},
|
|
|
|
{TexCoord_ReadIndex<u8, s16, 1>, TexCoord_ReadIndex<u8, s16, 2>,},
|
|
|
|
{TexCoord_ReadIndex<u8, float, 1>, TexCoord_ReadIndex<u8, float, 2>,},
|
2010-02-28 11:36:00 +00:00
|
|
|
},
|
|
|
|
{
|
2013-02-21 02:43:53 +00:00
|
|
|
{TexCoord_ReadIndex<u16, u8, 1>, TexCoord_ReadIndex<u16, u8, 2>,},
|
|
|
|
{TexCoord_ReadIndex<u16, s8, 1>, TexCoord_ReadIndex<u16, s8, 2>,},
|
|
|
|
{TexCoord_ReadIndex<u16, u16, 1>, TexCoord_ReadIndex<u16, u16, 2>,},
|
|
|
|
{TexCoord_ReadIndex<u16, s16, 1>, TexCoord_ReadIndex<u16, s16, 2>,},
|
|
|
|
{TexCoord_ReadIndex<u16, float, 1>, TexCoord_ReadIndex<u16, float, 2>,},
|
2010-02-28 11:36:00 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2010-04-09 15:13:42 +00:00
|
|
|
static int tableReadTexCoordVertexSize[4][8][2] = {
|
2010-02-28 11:36:00 +00:00
|
|
|
{
|
2013-02-21 02:43:53 +00:00
|
|
|
{0, 0,}, {0, 0,}, {0, 0,}, {0, 0,}, {0, 0,},
|
2010-02-28 11:36:00 +00:00
|
|
|
},
|
|
|
|
{
|
2013-02-21 02:43:53 +00:00
|
|
|
{1, 2,}, {1, 2,}, {2, 4,}, {2, 4,}, {4, 8,},
|
2010-02-28 11:36:00 +00:00
|
|
|
},
|
|
|
|
{
|
2013-02-21 02:43:53 +00:00
|
|
|
{1, 1,}, {1, 1,}, {1, 1,}, {1, 1,}, {1, 1,},
|
2010-02-28 11:36:00 +00:00
|
|
|
},
|
|
|
|
{
|
2013-02-21 02:43:53 +00:00
|
|
|
{2, 2,}, {2, 2,}, {2, 2,}, {2, 2,}, {2, 2,},
|
2010-02-28 11:36:00 +00:00
|
|
|
},
|
|
|
|
};
|
2010-04-09 15:13:42 +00:00
|
|
|
|
2013-04-24 13:21:54 +00:00
|
|
|
void VertexLoader_TextCoord::Init(void)
|
|
|
|
{
|
2010-04-09 15:13:42 +00:00
|
|
|
|
|
|
|
#if _M_SSE >= 0x301
|
|
|
|
|
2013-02-21 18:42:09 +00:00
|
|
|
if (cpu_info.bSSSE3)
|
|
|
|
{
|
|
|
|
tableReadTexCoord[2][4][1] = TexCoord_ReadIndex_Float2_SSSE3<u8>;
|
|
|
|
tableReadTexCoord[3][4][1] = TexCoord_ReadIndex_Float2_SSSE3<u16>;
|
2010-04-09 15:13:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if _M_SSE >= 0x401
|
|
|
|
|
2013-02-21 18:42:09 +00:00
|
|
|
if (cpu_info.bSSE4_1)
|
|
|
|
{
|
|
|
|
tableReadTexCoord[2][3][1] = TexCoord_ReadIndex_Short2_SSE4<u8>;
|
|
|
|
tableReadTexCoord[3][3][1] = TexCoord_ReadIndex_Short2_SSE4<u16>;
|
2010-04-09 15:13:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-24 13:21:54 +00:00
|
|
|
unsigned int VertexLoader_TextCoord::GetSize(unsigned int _type, unsigned int _format, unsigned int _elements)
|
|
|
|
{
|
2010-04-09 15:13:42 +00:00
|
|
|
return tableReadTexCoordVertexSize[_type][_format][_elements];
|
|
|
|
}
|
|
|
|
|
2013-04-24 13:21:54 +00:00
|
|
|
TPipelineFunction VertexLoader_TextCoord::GetFunction(unsigned int _type, unsigned int _format, unsigned int _elements)
|
|
|
|
{
|
2010-04-09 15:13:42 +00:00
|
|
|
return tableReadTexCoord[_type][_format][_elements];
|
|
|
|
}
|
|
|
|
|
2013-04-24 13:21:54 +00:00
|
|
|
TPipelineFunction VertexLoader_TextCoord::GetDummyFunction()
|
|
|
|
{
|
2010-04-09 15:13:42 +00:00
|
|
|
return TexCoord_Read_Dummy;
|
|
|
|
}
|