4747#include " materialsystem/imaterialvar.h"
4848#include " coordsize.h"
4949#include " mempool.h"
50+ #include " mathlib/ssemath.h"
5051#ifndef SWDS
5152#include " Overlay.h"
5253#endif
@@ -4839,10 +4840,12 @@ static bool EnumerateLeafInBox_R(mnode_t *node, EnumLeafBoxInfo_t& info )
48394840 }
48404841}
48414842
4842- #ifdef _X360
48434843
4844+ #if defined(_X360) || USE_DXMATH
4845+ #ifdef _DEBUG
48444846static fltx4 AlignThatVector (const Vector &vc)
48454847{
4848+ #ifdef _X360
48464849 fltx4 out = __loadunalignedvector (vc.Base ());
48474850
48484851 /*
@@ -4853,7 +4856,12 @@ static fltx4 AlignThatVector(const Vector &vc)
48534856
48544857 // squelch the w component
48554858 return __vrlimi ( out, __vzero (), 1 , 0 );
4859+ #elif USE_DXMATH
4860+ fltx4 out = LoadUnaligned3SIMD (vc.Base ());
4861+ return DirectX::XMVectorSetW (out, 0 );
4862+ #endif
48564863}
4864+ #endif
48574865
48584866// -----------------------------------------------------------------------------
48594867// 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_
48644872 if (node->contents == CONTENTS_SOLID)
48654873 return true ; // solid
48664874
4875+ #ifdef _X360
48674876 // speculatively get the children into the cache
48684877 __dcbt (0 ,node->children [0 ]);
48694878 __dcbt (0 ,node->children [1 ]);
4879+ #endif
48704880
48714881 // constructing these here prevents LHS if we spill.
48724882 // 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_
49374947 fltx4 vecBoxMax = LoadAlignedSIMD (pInfo->m_vecBoxMax );
49384948 fltx4 cornermin, cornermax;
49394949 // by now planeNormal is ready...
4950+ #ifdef _X360
49404951 fltx4 control = XMVectorGreaterOrEqual ( planeNormal, __vzero () );
49414952 // now control[i] = planeNormal[i] > 0 ? 0xFF : 0x00
49424953 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_
49454956 // compute dot products
49464957 fltx4 dotCornerMax = __vmsum3fp (planeNormal, cornermax); // vsumfp ignores w component
49474958 fltx4 dotCornerMin = __vmsum3fp (planeNormal, cornermin);
4959+
49484960 fltx4 vPlaneDist = ReplicateX4 (plane->dist );
49494961 UINT conditionRegister;
49504962 XMVectorGreaterR (&conditionRegister,vPlaneDist,dotCornerMax);
@@ -4954,6 +4966,25 @@ static bool EnumerateLeafInBox_R(mnode_t * RESTRICT node, const EnumLeafBoxInfo_
49544966 XMVectorGreaterOrEqualR (&conditionRegister,dotCornerMin,vPlaneDist);
49554967 if ( XMComparisonAllTrue (conditionRegister) )
49564968 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
49574988
49584989 return EnumerateLeafInBox_R ( node->children [0 ], pInfo ) &&
49594990 EnumerateLeafInBox_R ( node->children [1 ], pInfo );
@@ -5326,7 +5357,7 @@ bool CEngineBSPTree::EnumerateLeavesInBox( const Vector& mins, const Vector& max
53265357 info.m_nContext = context;
53275358 info.m_vecBoxMax = maxs;
53285359 info.m_vecBoxMin = mins;
5329- #ifdef _X360
5360+ #if defined( _X360) || USE_DXMATH
53305361 if (opt_EnumerateLeavesFastAlgorithm.GetBool ())
53315362 return EnumerateLeafInBox_R ( host_state.worldbrush ->nodes , &info );
53325363 else
0 commit comments