Browse Source

engine: optimize traces

bullshit
nillerusr 1 year ago
parent
commit
8acf608b4d
  1. 28
      engine/cmodel.cpp
  2. 14
      engine/cmodel_private.h
  3. 2
      engine/gl_rsurf.cpp
  4. 14
      engine/spatialpartition.cpp
  5. 2
      public/mathlib/mathlib.h

28
engine/cmodel.cpp

@ -873,9 +873,9 @@ bool IntersectRayWithBoxBrush( TraceInfo_t *pTraceInfo, const cbrush_t *pBrush, @@ -873,9 +873,9 @@ bool IntersectRayWithBoxBrush( TraceInfo_t *pTraceInfo, const cbrush_t *pBrush,
FPExceptionDisabler hideExceptions;
// Load the unaligned ray/box parameters into SIMD registers
fltx4 start = LoadUnaligned3SIMD(pTraceInfo->m_start.Base());
fltx4 extents = LoadUnaligned3SIMD(pTraceInfo->m_extents.Base());
fltx4 delta = LoadUnaligned3SIMD(pTraceInfo->m_delta.Base());
fltx4 start = LoadAlignedSIMD(pTraceInfo->m_start.Base());
fltx4 extents = LoadAlignedSIMD(pTraceInfo->m_extents.Base());
fltx4 delta = LoadAlignedSIMD(pTraceInfo->m_delta.Base());
fltx4 boxMins = LoadAlignedSIMD( pBox->mins.Base() );
fltx4 boxMaxs = LoadAlignedSIMD( pBox->maxs.Base() );
@ -899,7 +899,7 @@ bool IntersectRayWithBoxBrush( TraceInfo_t *pTraceInfo, const cbrush_t *pBrush, @@ -899,7 +899,7 @@ bool IntersectRayWithBoxBrush( TraceInfo_t *pTraceInfo, const cbrush_t *pBrush,
fltx4 crossPlane = OrSIMD(XorSIMD(startOutMins,endOutMins), XorSIMD(startOutMaxs,endOutMaxs));
// now build the per-axis interval of t for intersections
fltx4 invDelta = LoadUnaligned3SIMD(pTraceInfo->m_invDelta.Base());
fltx4 invDelta = LoadAlignedSIMD(pTraceInfo->m_invDelta.Base());
fltx4 tmins = MulSIMD( offsetMinsExpanded, invDelta );
fltx4 tmaxs = MulSIMD( offsetMaxsExpanded, invDelta );
// now sort the interval per axis
@ -1037,9 +1037,9 @@ bool IntersectRayWithBox( const Ray_t &ray, const VectorAligned &inInvDelta, con @@ -1037,9 +1037,9 @@ bool IntersectRayWithBox( const Ray_t &ray, const VectorAligned &inInvDelta, con
pTrace->fraction = 1.0f;
// Load the unaligned ray/box parameters into SIMD registers
fltx4 start = LoadUnaligned3SIMD(ray.m_Start.Base());
fltx4 extents = LoadUnaligned3SIMD(ray.m_Extents.Base());
fltx4 delta = LoadUnaligned3SIMD(ray.m_Delta.Base());
fltx4 start = LoadAlignedSIMD(ray.m_Start.Base());
fltx4 extents = LoadAlignedSIMD(ray.m_Extents.Base());
fltx4 delta = LoadAlignedSIMD(ray.m_Delta.Base());
fltx4 boxMins = LoadAlignedSIMD( inBoxMins.Base() );
fltx4 boxMaxs = LoadAlignedSIMD( inBoxMaxs.Base() );
@ -1372,9 +1372,9 @@ void FASTCALL CM_ClipBoxToBrush( TraceInfo_t * RESTRICT pTraceInfo, const cbrush @@ -1372,9 +1372,9 @@ void FASTCALL CM_ClipBoxToBrush( TraceInfo_t * RESTRICT pTraceInfo, const cbrush
inline bool IsTraceBoxIntersectingBoxBrush( TraceInfo_t *pTraceInfo, cboxbrush_t *pBox )
{
fltx4 start = LoadUnaligned3SIMD(pTraceInfo->m_start.Base());
fltx4 mins = LoadUnaligned3SIMD(pTraceInfo->m_mins.Base());
fltx4 maxs = LoadUnaligned3SIMD(pTraceInfo->m_maxs.Base());
fltx4 start = LoadAlignedSIMD(pTraceInfo->m_start.Base());
fltx4 mins = LoadAlignedSIMD(pTraceInfo->m_mins.Base());
fltx4 maxs = LoadAlignedSIMD(pTraceInfo->m_maxs.Base());
fltx4 boxMins = LoadAlignedSIMD( pBox->mins.Base() );
fltx4 boxMaxs = LoadAlignedSIMD( pBox->maxs.Base() );
@ -1569,15 +1569,15 @@ void FASTCALL CM_TraceToLeaf( TraceInfo_t * RESTRICT pTraceInfo, int ndxLeaf, fl @@ -1569,15 +1569,15 @@ void FASTCALL CM_TraceToLeaf( TraceInfo_t * RESTRICT pTraceInfo, int ndxLeaf, fl
if (IsX360())
{
// set up some relatively constant variables we'll use in the loop below
fltx4 traceStart = LoadUnaligned3SIMD(pTraceInfo->m_start.Base());
fltx4 traceDelta = LoadUnaligned3SIMD(pTraceInfo->m_delta.Base());
fltx4 traceInvDelta = LoadUnaligned3SIMD(pTraceInfo->m_invDelta.Base());
fltx4 traceStart = LoadAlignedSIMD(pTraceInfo->m_start.Base());
fltx4 traceDelta = LoadAlignedSIMD(pTraceInfo->m_delta.Base());
fltx4 traceInvDelta = LoadAlignedSIMD(pTraceInfo->m_invDelta.Base());
static const fltx4 vecEpsilon = {DISPCOLL_DIST_EPSILON,DISPCOLL_DIST_EPSILON,DISPCOLL_DIST_EPSILON,DISPCOLL_DIST_EPSILON};
// only used in !IS_POINT version:
fltx4 extents;
if (!IS_POINT)
{
extents = LoadUnaligned3SIMD(pTraceInfo->m_extents.Base());
extents = LoadAlignedSIMD(pTraceInfo->m_extents.Base());
}
// TODO: this loop probably ought to be unrolled so that we can make a more efficient

14
engine/cmodel_private.h

@ -42,13 +42,13 @@ struct TraceInfo_t @@ -42,13 +42,13 @@ struct TraceInfo_t
m_nCheckDepth = -1;
}
Vector m_start;
Vector m_end;
Vector m_mins;
Vector m_maxs;
Vector m_extents;
Vector m_delta;
Vector m_invDelta;
VectorAligned m_start;
VectorAligned m_end;
VectorAligned m_mins;
VectorAligned m_maxs;
VectorAligned m_extents;
VectorAligned m_delta;
VectorAligned m_invDelta;
trace_t m_trace;
trace_t m_stabTrace;

2
engine/gl_rsurf.cpp

@ -4934,7 +4934,7 @@ static bool EnumerateLeafInBox_R(mnode_t * RESTRICT node, const EnumLeafBoxInfo_ @@ -4934,7 +4934,7 @@ static bool EnumerateLeafInBox_R(mnode_t * RESTRICT node, const EnumLeafBoxInfo_
*/
// take advantage of high throughput/high latency
fltx4 planeNormal = LoadUnaligned3SIMD( plane->normal.Base() );
fltx4 planeNormal = LoadAlignedSIMD( plane->normal.Base() );
fltx4 vecBoxMin = LoadAlignedSIMD(pInfo->m_vecBoxMin);
fltx4 vecBoxMax = LoadAlignedSIMD(pInfo->m_vecBoxMax);
fltx4 cornermin, cornermax;

14
engine/spatialpartition.cpp

@ -987,7 +987,7 @@ private: @@ -987,7 +987,7 @@ private:
int m_iTree;
};
/*
class CIntersectPoint : public CPartitionVisitor
{
public:
@ -1009,7 +1009,7 @@ public: @@ -1009,7 +1009,7 @@ public:
private:
fltx4 m_f4Point;
};
*/
class CIntersectBox : public CPartitionVisitor
{
@ -1040,8 +1040,8 @@ class CIntersectRay : public CPartitionVisitor @@ -1040,8 +1040,8 @@ class CIntersectRay : public CPartitionVisitor
public:
CIntersectRay( CVoxelTree *pPartition, const Ray_t &ray, const Vector &vecInvDelta ) : CPartitionVisitor( pPartition )
{
m_f4Start = LoadUnaligned3SIMD( ray.m_Start.Base() );
m_f4Delta = LoadUnaligned3SIMD( ray.m_Delta.Base() );
m_f4Start = LoadAlignedSIMD( ray.m_Start.Base() );
m_f4Delta = LoadAlignedSIMD( ray.m_Delta.Base() );
m_f4InvDelta = LoadUnaligned3SIMD( vecInvDelta.Base() );
}
@ -1069,10 +1069,10 @@ class CIntersectSweptBox : public CPartitionVisitor @@ -1069,10 +1069,10 @@ class CIntersectSweptBox : public CPartitionVisitor
public:
CIntersectSweptBox( CVoxelTree *pPartition, const Ray_t &ray, const Vector &vecInvDelta ) : CPartitionVisitor( pPartition )
{
m_f4Start = LoadUnaligned3SIMD( ray.m_Start.Base() );
m_f4Delta = LoadUnaligned3SIMD( ray.m_Delta.Base() );
m_f4Start = LoadAlignedSIMD( ray.m_Start.Base() );
m_f4Delta = LoadAlignedSIMD( ray.m_Delta.Base() );
m_f4Extents = LoadAlignedSIMD( ray.m_Extents.Base() );
m_f4InvDelta = LoadUnaligned3SIMD( vecInvDelta.Base() );
m_f4Extents = LoadUnaligned3SIMD( ray.m_Extents.Base() );
}
bool Intersects( const float *pMins, const float *pMaxs ) const

2
public/mathlib/mathlib.h

@ -114,7 +114,7 @@ inline T clamp( T const &val, T const &minVal, T const &maxVal ) @@ -114,7 +114,7 @@ inline T clamp( T const &val, T const &minVal, T const &maxVal )
// FIXME: this should move to a different file
struct cplane_t
{
Vector normal;
VectorAligned normal;
float dist;
byte type; // for fast side tests
byte signbits; // signx + (signy<<1) + (signz<<1)

Loading…
Cancel
Save