Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'vertex-loader-cleanup'
  • Loading branch information
degasus committed Mar 6, 2013
2 parents 1214bf1 + 10983b0 commit 8d5299c
Show file tree
Hide file tree
Showing 18 changed files with 730 additions and 1,692 deletions.
35 changes: 35 additions & 0 deletions Source/Core/Common/Src/CommonFuncs.h
Expand Up @@ -172,6 +172,41 @@ inline u64 swap64(u64 data) {return ((u64)swap32(data) << 32) | swap32(data >> 3
inline u16 swap16(const u8* _pData) {return swap16(*(const u16*)_pData);}
inline u32 swap32(const u8* _pData) {return swap32(*(const u32*)_pData);}
inline u64 swap64(const u8* _pData) {return swap64(*(const u64*)_pData);}

template <int count>
void swap(u8*);

template <>
inline void swap<1>(u8* data)
{}

template <>
inline void swap<2>(u8* data)
{
*reinterpret_cast<u16*>(data) = swap16(data);
}

template <>
inline void swap<4>(u8* data)
{
*reinterpret_cast<u32*>(data) = swap32(data);
}

template <>
inline void swap<8>(u8* data)
{
*reinterpret_cast<u64*>(data) = swap64(data);
}

template <typename T>
inline T FromBigEndian(T data)
{
//static_assert(std::is_arithmetic<T>::value, "function only makes sense with arithmetic types");

swap<sizeof(data)>(reinterpret_cast<u8*>(&data));
return data;
}

} // Namespace Common

#endif // _COMMONFUNCS_H_
98 changes: 39 additions & 59 deletions Source/Core/VideoCommon/Src/DataReader.h
Expand Up @@ -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__)
Expand All @@ -31,43 +33,63 @@ __forceinline void DataSkip(u32 skip)
g_pVideoData += skip;
}

// probably unnecessary
template <int count>
__forceinline void DataSkip()
{
g_pVideoData += count;
}

template <typename T>
__forceinline T DataPeek(int _uOffset)
{
auto const result = Common::FromBigEndian(*reinterpret_cast<T*>(g_pVideoData + _uOffset));
return result;
}

// TODO: kill these
__forceinline u8 DataPeek8(int _uOffset)
{
return g_pVideoData[_uOffset];
return DataPeek<u8>(_uOffset);
}

__forceinline u16 DataPeek16(int _uOffset)
{
return Common::swap16(*(u16*)&g_pVideoData[_uOffset]);
return DataPeek<u16>(_uOffset);
}

__forceinline u32 DataPeek32(int _uOffset)
{
return Common::swap32(*(u32*)&g_pVideoData[_uOffset]);
return DataPeek<u32>(_uOffset);
}

template <typename T>
__forceinline T DataRead()
{
auto const result = DataPeek<T>(0);
DataSkip<sizeof(T)>();
return result;
}

// TODO: kill these
__forceinline u8 DataReadU8()
{
return *g_pVideoData++;
return DataRead<u8>();
}

__forceinline s8 DataReadS8()
{
return (s8)(*g_pVideoData++);
return DataRead<s8>();
}

__forceinline u16 DataReadU16()
{
u16 tmp = Common::swap16(*(u16*)g_pVideoData);
g_pVideoData += 2;
return tmp;
return DataRead<u16>();
}

__forceinline u32 DataReadU32()
{
u32 tmp = Common::swap32(*(u32*)g_pVideoData);
g_pVideoData += 4;
return tmp;
return DataRead<u32>();
}

typedef void (*DataReadU32xNfunc)(u32 *buf);
Expand Down Expand Up @@ -120,58 +142,16 @@ __forceinline u32 DataReadU32Unswapped()
return tmp;
}

template<class T>
__forceinline T DataRead()
{
T tmp = *(T*)g_pVideoData;
g_pVideoData += sizeof(T);
return tmp;
}

template <>
__forceinline u16 DataRead()
{
u16 tmp = Common::swap16(*(u16*)g_pVideoData);
g_pVideoData += 2;
return tmp;
}

template <>
__forceinline s16 DataRead()
{
s16 tmp = (s16)Common::swap16(*(u16*)g_pVideoData);
g_pVideoData += 2;
return tmp;
}

template <>
__forceinline u32 DataRead()
{
u32 tmp = (u32)Common::swap32(*(u32*)g_pVideoData);
g_pVideoData += 4;
return tmp;
}

template <>
__forceinline s32 DataRead()
{
s32 tmp = (s32)Common::swap32(*(u32*)g_pVideoData);
g_pVideoData += 4;
return tmp;
}

__forceinline float DataReadF32()
__forceinline u8* DataGetPosition()
{
union {u32 i; float f;} temp;
temp.i = Common::swap32(*(u32*)g_pVideoData);
g_pVideoData += 4;
float tmp = temp.f;
return tmp;
return g_pVideoData;
}

__forceinline u8* DataGetPosition()
template <typename T>
__forceinline void DataWrite(T data)
{
return g_pVideoData;
*(T*)VertexManager::s_pCurBufferPointer = data;
VertexManager::s_pCurBufferPointer += sizeof(T);
}

#endif

0 comments on commit 8d5299c

Please sign in to comment.