arm64 : fix mempool align

This commit is contained in:
hymei
2022-06-05 01:14:23 +03:00
committed by nillerusr
parent fd38243b54
commit 01413fdd71
13 changed files with 94 additions and 51 deletions
+63 -30
View File
@@ -1293,14 +1293,26 @@ struct mstudio_modelvertexdata_t
// base of external vertex data stores
#ifdef PLATFORM_64BITS
int unused_pVertexData;
int unused_pTangentData;
const void *pVertexData;
const void *pTangentData;
int index_ptr_pVertexData;
int index_ptr_pTangentData;
#else
const void *pVertexData;
const void *pTangentData;
#endif
const void *GetVertexData() const {
#ifdef PLATFORM_64BITS
return *(const void **)((byte *)this + index_ptr_pVertexData);
#else
return pVertexData;
#endif
}
const void *GetTangentData() const {
#ifdef PLATFORM_64BITS
return *(const void **)((byte *)this + index_ptr_pTangentData);
#else
return pTangentData;
#endif
}
};
#ifdef PLATFORM_64BITS
@@ -1323,17 +1335,22 @@ struct mstudio_meshvertexdata_t
#ifdef PLATFORM_64BITS
// MoeMod : fix 64bit ptr size
int unused_modelvertexdata;
int numLODVertexes[MAX_NUM_LODS];
const mstudio_modelvertexdata_t *modelvertexdata;
int index_ptr_modelvertexdata;
#else
// indirection to this mesh's model's vertex data
const mstudio_modelvertexdata_t *modelvertexdata;
#endif
// used for fixup calcs when culling top level lods
// expected number of mesh verts at desired lod
int numLODVertexes[MAX_NUM_LODS];
const mstudio_modelvertexdata_t *pModelVertexData() const {
#ifdef PLATFORM_64BITS
return *(const mstudio_modelvertexdata_t **)((byte *)this + index_ptr_modelvertexdata);
#else
return modelvertexdata;
#endif
}
};
struct mstudiomesh_t
@@ -1364,13 +1381,12 @@ struct mstudiomesh_t
Vector center;
#ifdef PLATFORM_64BITS
mstudio_meshvertexdata_t vertexdata;
#ifdef PLATFORM_64BITS
int unused[6]; // remove as appropriate
const mstudio_modelvertexdata_t *real_modelvertexdata;
#else
mstudio_meshvertexdata_t vertexdata;
int unused[8]; // remove as appropriate
#endif
@@ -1414,14 +1430,12 @@ struct mstudiomodel_t
int eyeballindex;
inline mstudioeyeball_t *pEyeball( int i ) { return (mstudioeyeball_t *)(((byte *)this) + eyeballindex) + i; };
#ifdef PLATFORM_64BITS
mstudio_modelvertexdata_t vertexdata; // sizeof(mstudio_modelvertexdata_t) == 16
int unused[6]; // remove as appropriate
#ifdef PLATFORM_64BITS
int unused[4]; // remove as appropriate
const void *real_pVertexData;
const void *real_pTangentData;
#else
mstudio_modelvertexdata_t vertexdata;
int unused[8]; // remove as appropriate
#endif
};
@@ -1432,7 +1446,7 @@ struct mstudiomodel_t
inline bool mstudio_modelvertexdata_t::HasTangentData( void ) const
{
return (pTangentData != NULL);
return (GetTangentData() != NULL);
}
inline int mstudio_modelvertexdata_t::GetGlobalVertexIndex( int i ) const
@@ -1453,7 +1467,7 @@ inline int mstudio_modelvertexdata_t::GetGlobalTangentIndex( int i ) const
inline mstudiovertex_t *mstudio_modelvertexdata_t::Vertex( int i ) const
{
return (mstudiovertex_t *)pVertexData + GetGlobalVertexIndex( i );
return (mstudiovertex_t *)GetVertexData() + GetGlobalVertexIndex( i );
}
inline Vector *mstudio_modelvertexdata_t::Position( int i ) const
@@ -1471,7 +1485,7 @@ inline Vector4D *mstudio_modelvertexdata_t::TangentS( int i ) const
// NOTE: The tangents vector is 16-bytes in a separate array
// because it only exists on the high end, and if I leave it out
// of the mstudiovertex_t, the vertex is 64-bytes (good for low end)
return (Vector4D *)pTangentData + GetGlobalTangentIndex( i );
return (Vector4D *)GetTangentData() + GetGlobalTangentIndex( i );
}
inline Vector2D *mstudio_modelvertexdata_t::Texcoord( int i ) const
@@ -1491,7 +1505,7 @@ inline mstudiomodel_t *mstudiomesh_t::pModel() const
inline bool mstudio_meshvertexdata_t::HasTangentData( void ) const
{
return modelvertexdata->HasTangentData();
return pModelVertexData()->HasTangentData();
}
inline const mstudio_meshvertexdata_t *mstudiomesh_t::GetVertexData( void *pModelData )
@@ -1499,9 +1513,14 @@ inline const mstudio_meshvertexdata_t *mstudiomesh_t::GetVertexData( void *pMode
// get this mesh's model's vertex data (allow for mstudiomodel_t::GetVertexData
// returning NULL if the data has been converted to 'thin' vertices)
this->pModel()->GetVertexData( pModelData );
#ifdef PLATFORM_64BITS
real_modelvertexdata = &( this->pModel()->vertexdata );
vertexdata.index_ptr_modelvertexdata = (byte *)&real_modelvertexdata - (byte *)&vertexdata;
#else
vertexdata.modelvertexdata = &( this->pModel()->vertexdata );
#endif
if ( !vertexdata.modelvertexdata->pVertexData )
if ( !vertexdata.pModelVertexData()->GetVertexData() )
return NULL;
return &vertexdata;
@@ -1522,37 +1541,37 @@ inline int mstudio_meshvertexdata_t::GetModelVertexIndex( int i ) const
inline int mstudio_meshvertexdata_t::GetGlobalVertexIndex( int i ) const
{
return modelvertexdata->GetGlobalVertexIndex( GetModelVertexIndex( i ) );
return pModelVertexData()->GetGlobalVertexIndex( GetModelVertexIndex( i ) );
}
inline Vector *mstudio_meshvertexdata_t::Position( int i ) const
{
return modelvertexdata->Position( GetModelVertexIndex( i ) );
return pModelVertexData()->Position( GetModelVertexIndex( i ) );
};
inline Vector *mstudio_meshvertexdata_t::Normal( int i ) const
{
return modelvertexdata->Normal( GetModelVertexIndex( i ) );
return pModelVertexData()->Normal( GetModelVertexIndex( i ) );
};
inline Vector4D *mstudio_meshvertexdata_t::TangentS( int i ) const
{
return modelvertexdata->TangentS( GetModelVertexIndex( i ) );
return pModelVertexData()->TangentS( GetModelVertexIndex( i ) );
}
inline Vector2D *mstudio_meshvertexdata_t::Texcoord( int i ) const
{
return modelvertexdata->Texcoord( GetModelVertexIndex( i ) );
return pModelVertexData()->Texcoord( GetModelVertexIndex( i ) );
};
inline mstudioboneweight_t *mstudio_meshvertexdata_t::BoneWeights( int i ) const
{
return modelvertexdata->BoneWeights( GetModelVertexIndex( i ) );
return pModelVertexData()->BoneWeights( GetModelVertexIndex( i ) );
};
inline mstudiovertex_t *mstudio_meshvertexdata_t::Vertex( int i ) const
{
return modelvertexdata->Vertex( GetModelVertexIndex( i ) );
return pModelVertexData()->Vertex( GetModelVertexIndex( i ) );
}
// a group of studio model data
@@ -1972,15 +1991,29 @@ inline const mstudio_modelvertexdata_t * mstudiomodel_t::GetVertexData( void *pM
const vertexFileHeader_t * pVertexHdr = CacheVertexData( pModelData );
if ( !pVertexHdr )
{
#ifdef PLATFORM_64BITS
this->real_pVertexData = NULL;
this->real_pTangentData = NULL;
vertexdata.index_ptr_pVertexData = (byte *)&real_pVertexData - (byte *)&vertexdata;
vertexdata.index_ptr_pTangentData = (byte *)&real_pTangentData - (byte *)&vertexdata;
#else
vertexdata.pVertexData = NULL;
vertexdata.pTangentData = NULL;
#endif
return NULL;
}
#ifdef PLATFORM_64BITS
this->real_pVertexData = pVertexHdr->GetVertexData();
this->real_pTangentData = pVertexHdr->GetTangentData();
vertexdata.index_ptr_pVertexData = (byte *)&real_pVertexData - (byte *)&vertexdata;
vertexdata.index_ptr_pTangentData = (byte *)&real_pTangentData - (byte *)&vertexdata;
#else
vertexdata.pVertexData = pVertexHdr->GetVertexData();
vertexdata.pTangentData = pVertexHdr->GetTangentData();
#endif
if ( !vertexdata.pVertexData )
if ( !vertexdata.GetVertexData() )
return NULL;
return &vertexdata;
+6
View File
@@ -441,7 +441,13 @@ typedef void * HINSTANCE;
// So if being debugged, use INT3 which is precise.
#ifdef OSX
#if defined(__arm__) || defined(__arm64__)
#ifdef __clang__
#define DebuggerBreak() do { if ( Plat_IsInDebugSession() ) { __builtin_debugtrap(); } else { raise(SIGTRAP); } } while(0)
#elif defined __GNUC__
#define DebuggerBreak() do { if ( Plat_IsInDebugSession() ) { __builtin_trap(); } else { raise(SIGTRAP); } } while(0)
#else
#define DebuggerBreak() raise(SIGTRAP)
#endif
#else
#define DebuggerBreak() do { if ( Plat_IsInDebugSession() ) { __asm ( "int $3" ); } else { raise(SIGTRAP); } } while(0)
#endif
+7 -4
View File
@@ -111,7 +111,8 @@ protected:
class CMemoryPoolMT : public CUtlMemoryPool
{
public:
CMemoryPoolMT(int blockSize, int numElements, int growMode = UTLMEMORYPOOL_GROW_FAST, const char *pszAllocOwner = NULL) : CUtlMemoryPool( blockSize, numElements, growMode, pszAllocOwner) {}
// MoeMod : add alignment
CMemoryPoolMT(int blockSize, int numElements, int growMode = UTLMEMORYPOOL_GROW_FAST, const char *pszAllocOwner = NULL, int nAlignment = 0) : CUtlMemoryPool( blockSize, numElements, growMode, pszAllocOwner, nAlignment) {}
void* Alloc() { AUTO_LOCK( m_mutex ); return CUtlMemoryPool::Alloc(); }
@@ -135,7 +136,8 @@ template< class T >
class CClassMemoryPool : public CUtlMemoryPool
{
public:
CClassMemoryPool(int numElements, int growMode = GROW_FAST, int nAlignment = 0 ) :
// MoeMod : bad default align here, should be alignof(T)
CClassMemoryPool(int numElements, int growMode = GROW_FAST, int nAlignment = alignof(T) ) :
CUtlMemoryPool( sizeof(T), numElements, growMode, MEM_ALLOC_CLASSNAME(T), nAlignment ) {
#ifdef PLATFORM_64BITS
COMPILE_TIME_ASSERT( sizeof(CUtlMemoryPool) == 64 );
@@ -315,7 +317,8 @@ inline void CClassMemoryPool<T>::Clear()
for( CBlob *pCur=m_BlobHead.m_pNext; pCur != &m_BlobHead; pCur=pCur->m_pNext )
{
T *p = (T *)pCur->m_Data;
// MoeMod : should realign to real data.
T *p = (T *)AlignValue( pCur->m_Data, m_nAlignment );
T *pLimit = (T *)(pCur->m_Data + pCur->m_NumBytes);
while ( p < pLimit )
{
@@ -361,7 +364,7 @@ inline void CClassMemoryPool<T>::Clear()
static CMemoryPoolMT s_Allocator
#define DEFINE_FIXEDSIZE_ALLOCATOR_MT( _class, _initsize, _grow ) \
CMemoryPoolMT _class::s_Allocator(sizeof(_class), _initsize, _grow, #_class " pool")
CMemoryPoolMT _class::s_Allocator(sizeof(_class), _initsize, _grow, #_class " pool", alignof(_class))
//-----------------------------------------------------------------------------
// Macros that make it simple to make a class use a fixed-size allocator
+1 -1
View File
@@ -1569,7 +1569,7 @@ void CZipFile::SaveDirectory( IWriteStream& stream )
free( e->m_pData );
// temp hackery for the logic below to succeed
e->m_pData = (void*)0xFFFFFFFF;
e->m_pData = (void*)-1;
}
}
}