47
47
#include " materialsystem/imaterialvar.h"
48
48
#include " coordsize.h"
49
49
#include " mempool.h"
50
+ #include " mathlib/ssemath.h"
50
51
#ifndef SWDS
51
52
#include " Overlay.h"
52
53
#endif
@@ -4839,10 +4840,12 @@ static bool EnumerateLeafInBox_R(mnode_t *node, EnumLeafBoxInfo_t& info )
4839
4840
}
4840
4841
}
4841
4842
4842
- #ifdef _X360
4843
4843
4844
+ #if defined(_X360) || USE_DXMATH
4845
+ #ifdef _DEBUG
4844
4846
static fltx4 AlignThatVector (const Vector &vc)
4845
4847
{
4848
+ #ifdef _X360
4846
4849
fltx4 out = __loadunalignedvector (vc.Base ());
4847
4850
4848
4851
/*
@@ -4853,7 +4856,12 @@ static fltx4 AlignThatVector(const Vector &vc)
4853
4856
4854
4857
// squelch the w component
4855
4858
return __vrlimi ( out, __vzero (), 1 , 0 );
4859
+ #elif USE_DXMATH
4860
+ fltx4 out = LoadUnaligned3SIMD (vc.Base ());
4861
+ return DirectX::XMVectorSetW (out, 0 );
4862
+ #endif
4856
4863
}
4864
+ #endif
4857
4865
4858
4866
// -----------------------------------------------------------------------------
4859
4867
// Finds all leaves of the BSP tree within a particular volume
@@ -4864,9 +4872,11 @@ static bool EnumerateLeafInBox_R(mnode_t * RESTRICT node, const EnumLeafBoxInfo_
4864
4872
if (node->contents == CONTENTS_SOLID)
4865
4873
return true ; // solid
4866
4874
4875
+ #ifdef _X360
4867
4876
// speculatively get the children into the cache
4868
4877
__dcbt (0 ,node->children [0 ]);
4869
4878
__dcbt (0 ,node->children [1 ]);
4879
+ #endif
4870
4880
4871
4881
// constructing these here prevents LHS if we spill.
4872
4882
// it's not quite a quick enough operation to do extemporaneously.
@@ -4937,6 +4947,7 @@ static bool EnumerateLeafInBox_R(mnode_t * RESTRICT node, const EnumLeafBoxInfo_
4937
4947
fltx4 vecBoxMax = LoadAlignedSIMD (pInfo->m_vecBoxMax );
4938
4948
fltx4 cornermin, cornermax;
4939
4949
// by now planeNormal is ready...
4950
+ #ifdef _X360
4940
4951
fltx4 control = XMVectorGreaterOrEqual ( planeNormal, __vzero () );
4941
4952
// now control[i] = planeNormal[i] > 0 ? 0xFF : 0x00
4942
4953
cornermin = XMVectorSelect ( vecBoxMax, vecBoxMin, control); // cornermin[i] = control[i] ? vecBoxMin[i] : vecBoxMax[i]
@@ -4945,6 +4956,7 @@ static bool EnumerateLeafInBox_R(mnode_t * RESTRICT node, const EnumLeafBoxInfo_
4945
4956
// compute dot products
4946
4957
fltx4 dotCornerMax = __vmsum3fp (planeNormal, cornermax); // vsumfp ignores w component
4947
4958
fltx4 dotCornerMin = __vmsum3fp (planeNormal, cornermin);
4959
+
4948
4960
fltx4 vPlaneDist = ReplicateX4 (plane->dist );
4949
4961
UINT conditionRegister;
4950
4962
XMVectorGreaterR (&conditionRegister,vPlaneDist,dotCornerMax);
@@ -4954,6 +4966,25 @@ static bool EnumerateLeafInBox_R(mnode_t * RESTRICT node, const EnumLeafBoxInfo_
4954
4966
XMVectorGreaterOrEqualR (&conditionRegister,dotCornerMin,vPlaneDist);
4955
4967
if ( XMComparisonAllTrue (conditionRegister) )
4956
4968
return EnumerateLeafInBox_R ( node->children [0 ], pInfo );
4969
+ #elif USE_DXMATH
4970
+ fltx4 control = DirectX::XMVectorGreaterOrEqual ( planeNormal, LoadZeroSIMD () );
4971
+ // now control[i] = planeNormal[i] > 0 ? 0xFF : 0x00
4972
+ cornermin = DirectX::XMVectorSelect ( vecBoxMax, vecBoxMin, control); // cornermin[i] = control[i] ? vecBoxMin[i] : vecBoxMax[i]
4973
+ cornermax = DirectX::XMVectorSelect ( vecBoxMin, vecBoxMax, control);
4974
+ // compute dot products
4975
+ fltx4 dotCornerMax = DirectX::XMVector3Dot (planeNormal, cornermax); // vsumfp ignores w component
4976
+ fltx4 dotCornerMin = DirectX::XMVector3Dot (planeNormal, cornermin);
4977
+
4978
+ fltx4 vPlaneDist = ReplicateX4 (plane->dist );
4979
+ uint conditionRegister;
4980
+ DirectX::XMVectorGreaterR (&conditionRegister,vPlaneDist,dotCornerMax);
4981
+ if (DirectX::XMComparisonAllTrue (conditionRegister)) // plane->normal . cornermax <= plane->dist
4982
+ return EnumerateLeafInBox_R ( node->children [1 ], pInfo );
4983
+
4984
+ DirectX::XMVectorGreaterOrEqualR (&conditionRegister,dotCornerMin,vPlaneDist);
4985
+ if ( DirectX::XMComparisonAllTrue (conditionRegister) )
4986
+ return EnumerateLeafInBox_R ( node->children [0 ], pInfo );
4987
+ #endif
4957
4988
4958
4989
return EnumerateLeafInBox_R ( node->children [0 ], pInfo ) &&
4959
4990
EnumerateLeafInBox_R ( node->children [1 ], pInfo );
@@ -5326,7 +5357,7 @@ bool CEngineBSPTree::EnumerateLeavesInBox( const Vector& mins, const Vector& max
5326
5357
info.m_nContext = context;
5327
5358
info.m_vecBoxMax = maxs;
5328
5359
info.m_vecBoxMin = mins;
5329
- #ifdef _X360
5360
+ #if defined( _X360) || USE_DXMATH
5330
5361
if (opt_EnumerateLeavesFastAlgorithm.GetBool ())
5331
5362
return EnumerateLeafInBox_R ( host_state.worldbrush ->nodes , &info );
5332
5363
else
0 commit comments