// Copyright 2013 Dolphin Emulator Project // Licensed under GPLv2 // Refer to the license.txt file included. #include #include "Common/CommonTypes.h" #include "Common/CPUDetect.h" #include "VideoCommon/VertexLoader.h" #include "VideoCommon/VertexLoader_TextCoord.h" #include "VideoCommon/VertexManagerBase.h" #include "VideoCommon/VideoCommon.h" template void LOG_TEX(); template <> __forceinline void LOG_TEX<1>() { // warning: mapping buffer should be disabled to use this // PRIM_LOG("tex: %f, ", ((float*)g_vertex_manager_write_ptr)[-1]); } template <> __forceinline void LOG_TEX<2>() { // warning: mapping buffer should be disabled to use this // PRIM_LOG("tex: %f %f, ", ((float*)g_vertex_manager_write_ptr)[-2], ((float*)g_vertex_manager_write_ptr)[-1]); } static void LOADERDECL TexCoord_Read_Dummy() { tcIndex++; } template float TCScale(T val, float scale) { return val * scale; } template <> float TCScale(float val, float scale) { return val; } template void LOADERDECL TexCoord_ReadDirect() { auto const scale = tcScale[tcIndex][0]; DataReader dst(g_vertex_manager_write_ptr, nullptr); DataReader src(g_video_buffer_read_ptr, nullptr); for (int i = 0; i != N; ++i) dst.Write(TCScale(src.Read(), scale)); dst.WritePointer(&g_vertex_manager_write_ptr); src.WritePointer(&g_video_buffer_read_ptr); LOG_TEX(); ++tcIndex; } template void LOADERDECL TexCoord_ReadIndex() { static_assert(std::is_unsigned::value, "Only unsigned I is sane!"); auto const index = DataRead(); auto const data = reinterpret_cast(cached_arraybases[ARRAY_TEXCOORD0 + tcIndex] + (index * g_main_cp_state.array_strides[ARRAY_TEXCOORD0 + tcIndex])); auto const scale = tcScale[tcIndex][0]; DataReader dst(g_vertex_manager_write_ptr, nullptr); for (int i = 0; i != N; ++i) dst.Write(TCScale(Common::FromBigEndian(data[i]), scale)); dst.WritePointer(&g_vertex_manager_write_ptr); LOG_TEX(); ++tcIndex; } #if _M_SSE >= 0x301 template void LOADERDECL TexCoord_ReadDirect2_SSSE3() { const T* pData = reinterpret_cast(DataGetPosition()); __m128 scale = _mm_castsi128_ps(_mm_loadl_epi64((__m128i*)tcScale[tcIndex])); Vertex_Read_SSSE3(pData, scale); DataSkip<2 * sizeof(T)>(); LOG_TEX<2>(); tcIndex++; } template void LOADERDECL TexCoord_ReadIndex2_SSSE3() { static_assert(std::is_unsigned::value, "Only unsigned I is sane!"); auto const index = DataRead(); const T* pData = (const T*)(cached_arraybases[ARRAY_TEXCOORD0 + tcIndex] + (index * g_main_cp_state.array_strides[ARRAY_TEXCOORD0 + tcIndex])); __m128 scale = _mm_castsi128_ps(_mm_loadl_epi64((__m128i*)tcScale[tcIndex])); Vertex_Read_SSSE3(pData, scale); LOG_TEX<2>(); tcIndex++; } #endif static TPipelineFunction tableReadTexCoord[4][8][2] = { { {nullptr, nullptr,}, {nullptr, nullptr,}, {nullptr, nullptr,}, {nullptr, nullptr,}, {nullptr, nullptr,}, }, { {TexCoord_ReadDirect, TexCoord_ReadDirect,}, {TexCoord_ReadDirect, TexCoord_ReadDirect,}, {TexCoord_ReadDirect, TexCoord_ReadDirect,}, {TexCoord_ReadDirect, TexCoord_ReadDirect,}, {TexCoord_ReadDirect, TexCoord_ReadDirect,}, }, { {TexCoord_ReadIndex, TexCoord_ReadIndex,}, {TexCoord_ReadIndex, TexCoord_ReadIndex,}, {TexCoord_ReadIndex, TexCoord_ReadIndex,}, {TexCoord_ReadIndex, TexCoord_ReadIndex,}, {TexCoord_ReadIndex, TexCoord_ReadIndex,}, }, { {TexCoord_ReadIndex, TexCoord_ReadIndex,}, {TexCoord_ReadIndex, TexCoord_ReadIndex,}, {TexCoord_ReadIndex, TexCoord_ReadIndex,}, {TexCoord_ReadIndex, TexCoord_ReadIndex,}, {TexCoord_ReadIndex, TexCoord_ReadIndex,}, }, }; static int tableReadTexCoordVertexSize[4][8][2] = { { {0, 0,}, {0, 0,}, {0, 0,}, {0, 0,}, {0, 0,}, }, { {1, 2,}, {1, 2,}, {2, 4,}, {2, 4,}, {4, 8,}, }, { {1, 1,}, {1, 1,}, {1, 1,}, {1, 1,}, {1, 1,}, }, { {2, 2,}, {2, 2,}, {2, 2,}, {2, 2,}, {2, 2,}, }, }; void VertexLoader_TextCoord::Init() { #if _M_SSE >= 0x301 if (cpu_info.bSSSE3) { tableReadTexCoord[1][0][1] = TexCoord_ReadDirect2_SSSE3; tableReadTexCoord[1][1][1] = TexCoord_ReadDirect2_SSSE3; tableReadTexCoord[1][2][1] = TexCoord_ReadDirect2_SSSE3; tableReadTexCoord[1][3][1] = TexCoord_ReadDirect2_SSSE3; tableReadTexCoord[1][4][1] = TexCoord_ReadDirect2_SSSE3; tableReadTexCoord[2][0][1] = TexCoord_ReadIndex2_SSSE3; tableReadTexCoord[3][0][1] = TexCoord_ReadIndex2_SSSE3; tableReadTexCoord[2][1][1] = TexCoord_ReadIndex2_SSSE3; tableReadTexCoord[3][1][1] = TexCoord_ReadIndex2_SSSE3; tableReadTexCoord[2][2][1] = TexCoord_ReadIndex2_SSSE3; tableReadTexCoord[3][2][1] = TexCoord_ReadIndex2_SSSE3; tableReadTexCoord[2][3][1] = TexCoord_ReadIndex2_SSSE3; tableReadTexCoord[3][3][1] = TexCoord_ReadIndex2_SSSE3; tableReadTexCoord[2][4][1] = TexCoord_ReadIndex2_SSSE3; tableReadTexCoord[3][4][1] = TexCoord_ReadIndex2_SSSE3; } #endif } unsigned int VertexLoader_TextCoord::GetSize(u64 _type, unsigned int _format, unsigned int _elements) { return tableReadTexCoordVertexSize[_type][_format][_elements]; } TPipelineFunction VertexLoader_TextCoord::GetFunction(u64 _type, unsigned int _format, unsigned int _elements) { return tableReadTexCoord[_type][_format][_elements]; } TPipelineFunction VertexLoader_TextCoord::GetDummyFunction() { return TexCoord_Read_Dummy; }