Skip to content

Commit

Permalink
arm64 : fix mempool align
Browse files Browse the repository at this point in the history
  • Loading branch information
MoeMod authored and nillerusr committed Jun 4, 2022
1 parent fd38243 commit 01413fd
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ build/
.lock-waf*
__pycache__
*.pyc
.DS_Store
4 changes: 2 additions & 2 deletions common/openal/alc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern "C" {
#define ALC_APIENTRY
#endif

#if TARGET_OS_MAC
#if defined(TARGET_OS_MAC) && TARGET_OS_MAC
#pragma export on
#endif

Expand Down Expand Up @@ -279,7 +279,7 @@ typedef void (ALC_APIENTRY *LPALCCAPTURESAMPLES)( ALCdevice *device, A

#endif /* ALC_NO_PROTOTYPES */

#if TARGET_OS_MAC
#if defined(TARGET_OS_MAC) && TARGET_OS_MAC
#pragma export off
#endif

Expand Down
6 changes: 3 additions & 3 deletions common/studiobyteswap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2919,8 +2919,8 @@ END_BYTESWAP_DATADESC()

BEGIN_BYTESWAP_DATADESC( mstudio_modelvertexdata_t )
#ifdef PLATFORM_64BITS
DEFINE_FIELD( unused_pVertexData, FIELD_INTEGER ), // void*
DEFINE_FIELD( unused_pTangentData, FIELD_INTEGER ), // void*
DEFINE_FIELD( index_ptr_pVertexData, FIELD_INTEGER ), // void*
DEFINE_FIELD( index_ptr_pTangentData, FIELD_INTEGER ), // void*
#else
DEFINE_FIELD( pVertexData, FIELD_INTEGER ), // void*
DEFINE_FIELD( pTangentData, FIELD_INTEGER ), // void*
Expand Down Expand Up @@ -3004,7 +3004,7 @@ END_BYTESWAP_DATADESC()

BEGIN_BYTESWAP_DATADESC( mstudio_meshvertexdata_t )
#ifdef PLATFORM_64BITS
DEFINE_FIELD( unused_modelvertexdata, FIELD_INTEGER ), // mstudio_modelvertexdata_t*
DEFINE_FIELD( index_ptr_modelvertexdata, FIELD_INTEGER ), // mstudio_modelvertexdata_t*
#else
DEFINE_FIELD( modelvertexdata, FIELD_INTEGER ), // mstudio_modelvertexdata_t*
#endif
Expand Down
6 changes: 3 additions & 3 deletions datacache/mdlcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct studiodata_t
// array of cache handles to demand loaded virtual model data
int m_nAnimBlockCount;
DataCacheHandle_t *m_pAnimBlock;
unsigned long *m_iFakeAnimBlockStall;
unsigned int *m_iFakeAnimBlockStall;

// vertex data is usually compressed to save memory (model decal code only needs some data)
DataCacheHandle_t m_VertexCache;
Expand Down Expand Up @@ -1169,8 +1169,8 @@ void CMDLCache::AllocateAnimBlocks( studiodata_t *pStudioData, int nCount )

memset( pStudioData->m_pAnimBlock, 0, sizeof(DataCacheHandle_t) * pStudioData->m_nAnimBlockCount );

pStudioData->m_iFakeAnimBlockStall = new unsigned long [pStudioData->m_nAnimBlockCount];
memset( pStudioData->m_iFakeAnimBlockStall, 0, sizeof( unsigned long ) * pStudioData->m_nAnimBlockCount );
pStudioData->m_iFakeAnimBlockStall = new unsigned int [pStudioData->m_nAnimBlockCount];
memset( pStudioData->m_iFakeAnimBlockStall, 0, sizeof( unsigned int ) * pStudioData->m_nAnimBlockCount );
}

void CMDLCache::FreeAnimBlocks( MDLHandle_t handle )
Expand Down
4 changes: 2 additions & 2 deletions engine/dt_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ inline unsigned char* UpdateRoutesExplicit_Template( DTStack *pStack, ProxyCalle
// Early out.
unsigned short iPropProxyIndex = pStack->m_pPrecalc->m_PropProxyIndices[pStack->m_iCurProp];
unsigned char **pTest = &pStack->m_pProxies[iPropProxyIndex];
if ( *pTest != (unsigned char*)0xFFFFFFFF )
if ( *pTest != (unsigned char*)-1 )
return *pTest;

// Ok.. setup this proxy.
Expand All @@ -133,7 +133,7 @@ inline unsigned char* UpdateRoutesExplicit_Template( DTStack *pStack, ProxyCalle
CSendTablePrecalc::CProxyPathEntry *pEntry = &pStack->m_pPrecalc->m_ProxyPathEntries[proxyPath.m_iFirstEntry + i];
int iProxy = pEntry->m_iProxy;

if ( pStack->m_pProxies[iProxy] == (unsigned char*)0xFFFFFFFF )
if ( pStack->m_pProxies[iProxy] == (unsigned char*)-1 )
{
pStack->m_pProxies[iProxy] = ProxyCaller::CallProxy( pStack, pStructBase, pEntry->m_iDatatableProp );
if ( !pStack->m_pProxies[iProxy] )
Expand Down
2 changes: 1 addition & 1 deletion engine/modelloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,7 @@ void *Hunk_AllocNameAlignedClear_( int size, int alignment, const char *pHunkNam
Assert(IsPowerOfTwo(alignment));
void *pMem = Hunk_AllocName( alignment + size, pHunkName );
memset( pMem, 0, size + alignment );
pMem = (void *)( ( ( ( unsigned long )pMem ) + (alignment-1) ) & ~(alignment-1) );
pMem = (void *)( ( ( ( uintp )pMem ) + (alignment-1) ) & ~(alignment-1) );

return pMem;
}
Expand Down
2 changes: 1 addition & 1 deletion engine/r_decal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2304,7 +2304,7 @@ inline void R_DrawDecalMeshList( DecalMeshList_t &meshList )
}

#define DECALMARKERS_SWITCHSORTTREE ((decal_t *)0x00000000)
#define DECALMARKERS_SWITCHBUCKET ((decal_t *)0xFFFFFFFF)
#define DECALMARKERS_SWITCHBUCKET ((decal_t *)-1)
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion game/server/NextBot/NextBotContextualQueryInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum QueryResultType
};

// Can pass this into IContextualQuery::IsHindrance to see if any hindrance is ever possible
#define IS_ANY_HINDRANCE_POSSIBLE ( (CBaseEntity*)0xFFFFFFFF )
#define IS_ANY_HINDRANCE_POSSIBLE ( (CBaseEntity*)-1 )


//----------------------------------------------------------------------------------------------------------------
Expand Down
93 changes: 63 additions & 30 deletions public/studio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
};
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -1491,17 +1505,22 @@ 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 )
{
// 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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions public/tier0/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions public/tier1/mempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class CUtlMemoryPool
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(); }
Expand All @@ -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 );
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion public/zip_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
Loading

0 comments on commit 01413fd

Please sign in to comment.