From 238605d8225a9135d6b60646e05d066e25424eee Mon Sep 17 00:00:00 2001 From: Sheikh Dawood Date: Mon, 9 Apr 2018 10:13:48 -0500 Subject: PhysX 3.4, APEX 1.4 patch release @23879214 --- PhysX_3.4/Source/SceneQuery/src/SqAABBTree.cpp | 258 ++----------------------- 1 file changed, 19 insertions(+), 239 deletions(-) (limited to 'PhysX_3.4/Source/SceneQuery/src/SqAABBTree.cpp') diff --git a/PhysX_3.4/Source/SceneQuery/src/SqAABBTree.cpp b/PhysX_3.4/Source/SceneQuery/src/SqAABBTree.cpp index bb628010..bcb0e0ef 100644 --- a/PhysX_3.4/Source/SceneQuery/src/SqAABBTree.cpp +++ b/PhysX_3.4/Source/SceneQuery/src/SqAABBTree.cpp @@ -42,105 +42,42 @@ using namespace Sq; // Progressive building class Sq::FIFOStack : public Ps::UserAllocated { - public: - FIFOStack() : mStack(PX_DEBUG_EXP("SQFIFOStack")), mCurIndex(0) {} - ~FIFOStack() {} +public: + FIFOStack() : mStack(PX_DEBUG_EXP("SQFIFOStack")), mCurIndex(0) {} + ~FIFOStack() {} PX_FORCE_INLINE PxU32 getNbEntries() const { return mStack.size(); } - PX_FORCE_INLINE void push(AABBTreeBuildNode* entry) { mStack.pushBack(entry); } - bool pop(AABBTreeBuildNode*& entry); - private: - Ps::Array mStack; - PxU32 mCurIndex; //!< Current index within the container + PX_FORCE_INLINE void push(AABBTreeBuildNode* entry) { mStack.pushBack(entry); } + bool pop(AABBTreeBuildNode*& entry); +private: + Ps::Array mStack; + PxU32 mCurIndex; //!< Current index within the container }; bool Sq::FIFOStack::pop(AABBTreeBuildNode*& entry) { const PxU32 NbEntries = mStack.size(); // Get current number of entries - if(!NbEntries) + if (!NbEntries) return false; // Can be NULL when no value has been pushed. This is an invalid pop call. entry = mStack[mCurIndex++]; // Get oldest entry, move to next one - if(mCurIndex==NbEntries) + if (mCurIndex == NbEntries) { // All values have been poped mStack.clear(); - mCurIndex=0; + mCurIndex = 0; } return true; } //~Progressive building -NodeAllocator::NodeAllocator() : mPool(NULL), mCurrentSlabIndex(0), mTotalNbNodes(0) -{ -} - -NodeAllocator::~NodeAllocator() -{ - release(); -} - -void NodeAllocator::release() -{ - const PxU32 nbSlabs = mSlabs.size(); - for(PxU32 i=0;imNodeIndex = 0; - mPool->mNbPrimitives = nbPrimitives; - - mSlabs.pushBack(Slab(mPool, 1, estimatedFinalSize)); - mCurrentSlabIndex = 0; - mTotalNbNodes = 1; -} - -// PT: TODO: inline this? -AABBTreeBuildNode* NodeAllocator::getBiNode() -{ - mTotalNbNodes += 2; - Slab& currentSlab = mSlabs[mCurrentSlabIndex]; - if(currentSlab.mNbUsedNodes+2<=currentSlab.mMaxNbNodes) - { - AABBTreeBuildNode* biNode = currentSlab.mPool + currentSlab.mNbUsedNodes; - currentSlab.mNbUsedNodes += 2; - return biNode; - } - else - { - // Allocate new slab - const PxU32 size = 1024; - AABBTreeBuildNode* pool = PX_NEW(AABBTreeBuildNode)[size]; - PxMemZero(pool, sizeof(AABBTreeBuildNode)*size); - - mSlabs.pushBack(Slab(pool, 2, size)); - mCurrentSlabIndex++; - return pool; - } -} - -void NodeAllocator::flatten(AABBTreeRuntimeNode* dest) +void flatten(const NodeAllocator& nodeAllocator, AABBTreeRuntimeNode* dest) { // PT: gathers all build nodes allocated so far and flatten them to a linear destination array of smaller runtime nodes PxU32 offset = 0; - const PxU32 nbSlabs = mSlabs.size(); + const PxU32 nbSlabs = nodeAllocator.mSlabs.size(); for(PxU32 s=0;s=mSlabs[j].mPool && pool[i].mPos= nodeAllocator.mSlabs[j].mPool && pool[i].mPos < nodeAllocator.mSlabs[j].mPool + nodeAllocator.mSlabs[j].mNbUsedNodes) { - localNodeIndex = PxU32(pool[i].mPos - mSlabs[j].mPool); + localNodeIndex = PxU32(pool[i].mPos - nodeAllocator.mSlabs[j].mPool); break; } - nodeBase += mSlabs[j].mNbUsedNodes; + nodeBase += nodeAllocator.mSlabs[j].mNbUsedNodes; } const PxU32 nodeIndex = nodeBase + localNodeIndex; - PX_ASSERT(nodeIndex(ptrValue); - - for(PxU32 i=0;i splitValue) - { - // Swap entries - prims[i] = prims[nbPos]; - prims[nbPos] = index; - // Count primitives assigned to positive space - nbPos++; - } - } - return nbPos; -} - -void AABBTreeBuildNode::subdivide(const AABBTreeBuildParams& params, BuildStats& stats, NodeAllocator& allocator, PxU32* const indices) -{ - PxU32* const PX_RESTRICT primitives = indices + mNodeIndex; - const PxU32 nbPrims = mNbPrimitives; - - // Compute global box & means for current node. The box is stored in mBV. - Vec4V meansV; - { - const PxBounds3* PX_RESTRICT boxes = params.mAABBArray; - PX_ASSERT(boxes); - PX_ASSERT(primitives); - PX_ASSERT(nbPrims); - - Vec4V minV = V4LoadU(&boxes[primitives[0]].minimum.x); - Vec4V maxV = V4LoadU(&boxes[primitives[0]].maximum.x); - - meansV = V4LoadU(¶ms.mCache[primitives[0]].x); - - for(PxU32 i=1;iparams.mLimit) - { - nbPos = nbPrims>>1; - } - else return; - } - - // Now create children and assign their pointers. - mPos = allocator.getBiNode(); - - stats.increaseCount(2); - - // Assign children - PX_ASSERT(!isLeaf()); - AABBTreeBuildNode* Pos = const_cast(mPos); - AABBTreeBuildNode* Neg = Pos + 1; - Pos->mNodeIndex = mNodeIndex; - Pos->mNbPrimitives = nbPos; - Neg->mNodeIndex = mNodeIndex + nbPos; - Neg->mNbPrimitives = mNbPrimitives - nbPos; -} - -void AABBTreeBuildNode::_buildHierarchy(AABBTreeBuildParams& params, BuildStats& stats, NodeAllocator& nodeBase, PxU32* const indices) -{ - // Subdivide current node - subdivide(params, stats, nodeBase, indices); - - // Recurse - if(!isLeaf()) - { - AABBTreeBuildNode* Pos = const_cast(getPos()); - PX_ASSERT(Pos); - AABBTreeBuildNode* Neg = Pos + 1; - Pos->_buildHierarchy(params, stats, nodeBase, indices); - Neg->_buildHierarchy(params, stats, nodeBase, indices); - } - - stats.mTotalPrims += mNbPrimitives; } AABBTree::AABBTree() : @@ -449,7 +228,8 @@ void AABBTree::buildEnd(AABBTreeBuildParams& params, BuildStats& stats) mRuntimePool = PX_NEW(AABBTreeRuntimeNode)[mTotalNbNodes]; PX_ASSERT(mTotalNbNodes==mNodeAllocator.mTotalNbNodes); - mNodeAllocator.flatten(mRuntimePool); + flatten(mNodeAllocator, mRuntimePool); + mNodeAllocator.release(); } bool AABBTree::build(AABBTreeBuildParams& params) -- cgit v1.2.3