Browse Source

WIP: fix some memaccess-class warnings

optimization
nillerusr 2 years ago
parent
commit
db3062c60b
  1. 9
      mathlib/polyhedron.cpp
  2. 9
      public/materialsystem/imaterialsystem.h
  3. 16
      public/mathlib/simdvectormatrix.h
  4. 7
      public/mathlib/ssemath.h
  5. 10
      public/studio.h
  6. 2
      public/tier0/platform.h
  7. 32
      public/tier1/memhelpers.h
  8. 4
      public/vphysics_interface.h
  9. 2
      studiorender/r_studiolight.cpp
  10. 3
      studiorender/studiorendercontext.cpp
  11. 3
      tier0/cpu.cpp
  12. 8
      tier2/camerautils.cpp

9
mathlib/polyhedron.cpp

@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
#include <stdlib.h>
#include <stdio.h>
#include "tier1/utlvector.h"
#include "tier1/memhelpers.h"
#ifdef COMPILER_MSVC
#include <new>
#endif
@ -318,10 +319,10 @@ CPolyhedron *ClipPolyhedron( const CPolyhedron *pExistingPolyhedron, const float @@ -318,10 +319,10 @@ CPolyhedron *ClipPolyhedron( const CPolyhedron *pExistingPolyhedron, const float
pExistingPolyhedron->iPolygonCount );
}
memcpy( pReturn->pVertices, pExistingPolyhedron->pVertices, sizeof( Vector ) * pReturn->iVertexCount );
memcpy( pReturn->pLines, pExistingPolyhedron->pLines, sizeof( Polyhedron_IndexedLine_t ) * pReturn->iLineCount );
memcpy( pReturn->pIndices, pExistingPolyhedron->pIndices, sizeof( Polyhedron_IndexedLineReference_t ) * pReturn->iIndexCount );
memcpy( pReturn->pPolygons, pExistingPolyhedron->pPolygons, sizeof( Polyhedron_IndexedPolygon_t ) * pReturn->iPolygonCount );
memutils::copy( pReturn->pVertices, pExistingPolyhedron->pVertices, pReturn->iVertexCount );
memutils::copy( pReturn->pLines, pExistingPolyhedron->pLines, pReturn->iLineCount );
memutils::copy( pReturn->pIndices, pExistingPolyhedron->pIndices, pReturn->iIndexCount );
memutils::copy( pReturn->pPolygons, pExistingPolyhedron->pPolygons, pReturn->iPolygonCount );
return pReturn;
}

9
public/materialsystem/imaterialsystem.h

@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
#include "materialsystem/deformations.h"
#include "materialsystem/imaterialsystemhardwareconfig.h"
#include "materialsystem/IColorCorrection.h"
#include "tier1/memhelpers.h"
//-----------------------------------------------------------------------------
// forward declarations
@ -1563,12 +1563,9 @@ public: @@ -1563,12 +1563,9 @@ public:
template< class E > inline E* IMatRenderContext::LockRenderDataTyped( int nCount, const E* pSrcData )
{
int nSizeInBytes = nCount * sizeof(E);
E *pDstData = (E*)LockRenderData( nSizeInBytes );
E *pDstData = (E*)LockRenderData( nCount*sizeof(E) );
if ( pSrcData && pDstData )
{
memcpy( pDstData, pSrcData, nSizeInBytes );
}
memutils::copy( pDstData, pSrcData, nCount );
return pDstData;
}

16
public/mathlib/simdvectormatrix.h

@ -20,6 +20,7 @@ @@ -20,6 +20,7 @@
#include "tier0/dbg.h"
#include "tier1/utlsoacontainer.h"
#include "mathlib/ssemath.h"
#include "tier1/memhelpers.h"
class CSIMDVectorMatrix
{
@ -61,19 +62,19 @@ public: @@ -61,19 +62,19 @@ public:
// set up storage and fields for m x n matrix. destroys old data
void SetSize( int width, int height )
{
if ( ( ! m_pData ) || ( width != m_nWidth ) || ( height != m_nHeight ) )
if ( ( ! m_pData ) || ( width > m_nWidth ) || ( height > m_nHeight ) )
{
if ( m_pData )
delete[] m_pData;
m_nWidth = width;
m_nHeight = height;
m_nPaddedWidth = ( m_nWidth + 3) >> 2;
m_pData = NULL;
if ( width && height )
m_pData = new FourVectors[ m_nPaddedWidth * m_nHeight ];
}
m_nWidth = width;
m_nHeight = height;
}
CSIMDVectorMatrix( int width, int height )
@ -86,7 +87,8 @@ public: @@ -86,7 +87,8 @@ public:
{
SetSize( src.m_nWidth, src.m_nHeight );
if ( m_pData )
memcpy( m_pData, src.m_pData, m_nHeight*m_nPaddedWidth*sizeof(m_pData[0]) );
memutils::copy( m_pData, src.m_pData, m_nHeight*m_nPaddedWidth );
return *this;
}
@ -131,7 +133,9 @@ public: @@ -131,7 +133,9 @@ public:
void Clear( void )
{
Assert( m_pData );
memset( m_pData, 0, m_nHeight*m_nPaddedWidth*sizeof(m_pData[0]) );
static FourVectors value{Four_Zeros, Four_Zeros, Four_Zeros};
memutils::set( m_pData, value, m_nHeight*m_nPaddedWidth );
}
void RaiseToPower( float power );

7
public/mathlib/ssemath.h

@ -2613,6 +2613,13 @@ public: @@ -2613,6 +2613,13 @@ public:
z=src.z;
}
FourVectors( fltx4 x, fltx4 y, fltx4 z )
{
this->x=x;
this->y=y;
this->z=z;
}
FORCEINLINE void operator=( FourVectors const &src )
{
x=src.x;

10
public/studio.h

@ -3298,17 +3298,19 @@ inline int Studio_LoadVertexes( const vertexFileHeader_t *pTempVvdHdr, vertexFil @@ -3298,17 +3298,19 @@ inline int Studio_LoadVertexes( const vertexFileHeader_t *pTempVvdHdr, vertexFil
}
// copy vertexes
// TODO(nillerusr): That sucks and needs to be fixed
memcpy(
(mstudiovertex_t *)((byte *)pNewVvdHdr+pNewVvdHdr->vertexDataStart) + target,
(mstudiovertex_t *)((byte *)pTempVvdHdr+pTempVvdHdr->vertexDataStart) + pFixupTable[i].sourceVertexID,
(byte*)((mstudiovertex_t *)((byte *)pNewVvdHdr+pNewVvdHdr->vertexDataStart) + target),
(byte*)((mstudiovertex_t *)((byte *)pTempVvdHdr+pTempVvdHdr->vertexDataStart) + pFixupTable[i].sourceVertexID),
pFixupTable[i].numVertexes*sizeof(mstudiovertex_t) );
if (bNeedsTangentS)
{
// copy tangents
memcpy(
(Vector4D *)((byte *)pNewVvdHdr+pNewVvdHdr->tangentDataStart) + target,
(Vector4D *)((byte *)pTempVvdHdr+pTempVvdHdr->tangentDataStart) + pFixupTable[i].sourceVertexID,
(byte*)((Vector4D *)((byte *)pNewVvdHdr+pNewVvdHdr->tangentDataStart) + target),
(byte*)((Vector4D *)((byte *)pTempVvdHdr+pTempVvdHdr->tangentDataStart) + pFixupTable[i].sourceVertexID),
pFixupTable[i].numVertexes*sizeof(Vector4D) );
}

2
public/tier0/platform.h

@ -1280,7 +1280,7 @@ struct CPUInformation @@ -1280,7 +1280,7 @@ struct CPUInformation
uint32 m_nModel;
uint32 m_nFeatures[3];
CPUInformation(): m_Size(0){}
CPUInformation() = default;
};
// Have to return a pointer, not a reference, because references are not compatible with the

32
public/tier1/memhelpers.h

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
// ======= Copyright nillerusr, 2022 =======
// Helper аunctions for setting/сopying memory ( specially for non-POD types )
// FUCK STL
#ifndef MEMHELPERS_H
#define MEMHELPERS_H
namespace memutils
{
template<typename T>
inline void copy( T *dest, const T *src, size_t n )
{
do
{
--n;
*(dest+n) = *(src+n);
} while( n );
}
template<typename T>
inline void set( T *dest, T value, size_t n )
{
do
{
--n;
*(dest+n) = value;
} while( n );
}
}
#endif //MEMHELPERS_H

4
public/vphysics_interface.h

@ -1039,10 +1039,6 @@ struct fluidparams_t @@ -1039,10 +1039,6 @@ struct fluidparams_t
//-----------------------------------------------------------------------------
struct springparams_t
{
springparams_t()
{
memset( this, 0, sizeof(*this) );
}
float constant; // spring constant
float naturalLength;// relaxed length
float damping; // damping factor

2
studiorender/r_studiolight.cpp

@ -36,7 +36,7 @@ int CopyLocalLightingState( int nMaxLights, LightDesc_t *pDest, int nLightCount, @@ -36,7 +36,7 @@ int CopyLocalLightingState( int nMaxLights, LightDesc_t *pDest, int nLightCount,
for( int i = 0; i < nLightCount; i++ )
{
LightDesc_t *pLight = &pDest[i];
memcpy( pLight, &pSrc[i], sizeof( LightDesc_t ) );
*pLight = pSrc[i];
pLight->m_Flags = 0;
if( pLight->m_Attenuation0 != 0.0f )
{

3
studiorender/studiorendercontext.cpp

@ -19,6 +19,7 @@ @@ -19,6 +19,7 @@
#include "tier1/callqueue.h"
#include "cmodel.h"
#include "tier0/vprof.h"
#include "tier1/memhelpers.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
@ -1994,7 +1995,7 @@ void CStudioRenderContext::SetAmbientLightColors( const Vector *pColors ) @@ -1994,7 +1995,7 @@ void CStudioRenderContext::SetAmbientLightColors( const Vector *pColors )
void CStudioRenderContext::SetAmbientLightColors( const Vector4D *pColors )
{
memcpy( m_RC.m_LightBoxColors, pColors, 6 * sizeof(Vector4D) );
memutils::copy( &m_RC.m_LightBoxColors[0], pColors, 6 );
// FIXME: Would like to get this into the render thread, but there's systemic confusion
// about whether to set lighting state here or in the material system

3
tier0/cpu.cpp

@ -498,9 +498,6 @@ const CPUInformation* GetCPUInformation() @@ -498,9 +498,6 @@ const CPUInformation* GetCPUInformation()
if ( pi.m_Size == sizeof(pi) )
return &pi;
// Redundant, but just in case the user somehow messes with the size.
memset(&pi, 0x0, sizeof(pi));
// Fill out the structure, and return it:
pi.m_Size = sizeof(pi);

8
tier2/camerautils.cpp

@ -69,7 +69,13 @@ void ComputeProjectionMatrix( VMatrix *pCameraToProjection, const Camera_t &came @@ -69,7 +69,13 @@ void ComputeProjectionMatrix( VMatrix *pCameraToProjection, const Camera_t &came
float halfHeight = tan( flFOV * M_PI / 360.0 );
float halfWidth = flApsectRatio * halfHeight;
#endif
memset( pCameraToProjection, 0, sizeof( VMatrix ) );
pCameraToProjection->Init(
0.f, 0.f, 0.f, 0.f,
0.f, 0.f, 0.f, 0.f,
0.f, 0.f, 0.f, 0.f,
0.f, 0.f, 0.f, 0.f
);
pCameraToProjection->m[0][0] = 1.0f / halfWidth;
pCameraToProjection->m[1][1] = 1.0f / halfHeight;
pCameraToProjection->m[2][2] = flZFar / ( flZNear - flZFar );

Loading…
Cancel
Save