diff options
| author | Sheikh Dawood <[email protected]> | 2018-04-09 10:13:48 -0500 |
|---|---|---|
| committer | Sheikh Dawood <[email protected]> | 2018-04-09 10:13:48 -0500 |
| commit | 238605d8225a9135d6b60646e05d066e25424eee (patch) | |
| tree | 2b013bd4946bb3c699d7a06ef1f21be85d367f63 /PhysX_3.4/Source/SimulationController/src | |
| parent | Add ParamTool.exe (diff) | |
| download | physx-3.4-238605d8225a9135d6b60646e05d066e25424eee.tar.xz physx-3.4-238605d8225a9135d6b60646e05d066e25424eee.zip | |
PhysX 3.4, APEX 1.4 patch release @23879214
Diffstat (limited to 'PhysX_3.4/Source/SimulationController/src')
8 files changed, 213 insertions, 99 deletions
diff --git a/PhysX_3.4/Source/SimulationController/src/ScActorSim.cpp b/PhysX_3.4/Source/SimulationController/src/ScActorSim.cpp index 56c5528d..f4534e8f 100644 --- a/PhysX_3.4/Source/SimulationController/src/ScActorSim.cpp +++ b/PhysX_3.4/Source/SimulationController/src/ScActorSim.cpp @@ -38,6 +38,7 @@ using namespace physx; Sc::ActorSim::ActorSim(Scene& scene, ActorCore& core) : mFirstElement (NULL), + mNumElements (0), mScene (scene), mCore (core) { @@ -69,6 +70,7 @@ void Sc::ActorSim::onElementAttach(ElementSim& element) { element.mNextInActor = mFirstElement; mFirstElement = &element; + mNumElements++; } void Sc::ActorSim::onElementDetach(ElementSim& element) @@ -84,7 +86,9 @@ void Sc::ActorSim::onElementDetach(ElementSim& element) previousElem->mNextInActor = currentElem->mNextInActor; else mFirstElement = currentElem->mNextInActor; + mNumElements--; return; + } previousElem = currentElem; currentElem = currentElem->mNextInActor; diff --git a/PhysX_3.4/Source/SimulationController/src/ScActorSim.h b/PhysX_3.4/Source/SimulationController/src/ScActorSim.h index ffe93bcf..db30aba9 100644 --- a/PhysX_3.4/Source/SimulationController/src/ScActorSim.h +++ b/PhysX_3.4/Source/SimulationController/src/ScActorSim.h @@ -79,6 +79,8 @@ namespace Sc PX_FORCE_INLINE ElementSim* getElements_() { return mFirstElement; } PX_FORCE_INLINE const ElementSim* getElements_() const { return mFirstElement; } + PX_FORCE_INLINE PxU32 getNbElements() const { return mNumElements; } + // Get the type ID of the actor PX_FORCE_INLINE PxActorType::Enum getActorType() const { return mCore.getActorCoreType(); } @@ -113,6 +115,7 @@ namespace Sc mInteractions; ElementSim* mFirstElement; + PxU32 mNumElements; Scene& mScene; diff --git a/PhysX_3.4/Source/SimulationController/src/ScBodySim.h b/PhysX_3.4/Source/SimulationController/src/ScBodySim.h index 375e58b9..943cf3a0 100644 --- a/PhysX_3.4/Source/SimulationController/src/ScBodySim.h +++ b/PhysX_3.4/Source/SimulationController/src/ScBodySim.h @@ -228,6 +228,8 @@ namespace Sc return (getFlagsFast()&ktFlags) == ktFlags; } + PX_FORCE_INLINE PxU32 getNbShapes() const { return this->mNumElements; } + void createSqBounds(); void destroySqBounds(); void freezeTransforms(Cm::BitMapPinned* shapeChangedMap); diff --git a/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.cpp b/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.cpp index b0cf7a5a..24c6da5e 100644 --- a/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.cpp +++ b/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.cpp @@ -182,7 +182,7 @@ Sc::ElementSimInteraction* Sc::NPhaseCore::findInteraction(ElementSim* _element0 return NULL; } -PxFilterInfo Sc::NPhaseCore::onOverlapFilter(ElementSim* volume0, ElementSim* volume1, Bp::BroadPhasePair* pair) +PxFilterInfo Sc::NPhaseCore::onOverlapFilter(ElementSim* volume0, ElementSim* volume1) { PX_ASSERT(!findInteraction(volume0, volume1)); @@ -196,12 +196,8 @@ PxFilterInfo Sc::NPhaseCore::onOverlapFilter(ElementSim* volume0, ElementSim* vo return finfo; }*/ - if(pair) - pair->mUserData = NULL; - PX_ASSERT(PxMax(volume0->getElementType(), volume1->getElementType()) == ElementType::eSHAPE); - ShapeSim* s0 = static_cast<ShapeSim*>(volume1); ShapeSim* s1 = static_cast<ShapeSim*>(volume0); @@ -214,7 +210,7 @@ PxFilterInfo Sc::NPhaseCore::onOverlapFilter(ElementSim* volume0, ElementSim* vo return finfo; } -Sc::Interaction* Sc::NPhaseCore::onOverlapCreated(ElementSim* volume0, ElementSim* volume1, const PxU32 ccdPass, Bp::BroadPhasePair* pair) +Sc::Interaction* Sc::NPhaseCore::onOverlapCreated(ElementSim* volume0, ElementSim* volume1, const PxU32 ccdPass) { #if PX_USE_PARTICLE_SYSTEM_API PX_COMPILE_TIME_ASSERT(ElementType::eSHAPE < ElementType::ePARTICLE_PACKET); @@ -238,9 +234,6 @@ Sc::Interaction* Sc::NPhaseCore::onOverlapCreated(ElementSim* volume0, ElementSi volumeHi = volume0; } - if(pair) - pair->mUserData = NULL; - switch (volumeHi->getElementType()) { #if PX_USE_PARTICLE_SYSTEM_API @@ -341,11 +334,7 @@ Sc::Interaction* Sc::NPhaseCore::onOverlapCreated(ElementSim* volume0, ElementSi // No actor internal interactions PX_ASSERT(&shapeHi->getActor() != &shapeLo->getActor()); - Sc::ElementSimInteraction* interaction = createRbElementInteraction(*shapeHi, *shapeLo, NULL, NULL, NULL); - if(pair) - pair->mUserData = interaction; - - return interaction; + return createRbElementInteraction(*shapeHi, *shapeLo, NULL, NULL, NULL); } case ElementType::eCOUNT: PX_ASSERT(0); @@ -406,19 +395,14 @@ static PX_FORCE_INLINE void prefetchPairActorsCore(const ActorSim& a0, const Act Ps::prefetchLine((reinterpret_cast<PxU8*>(ac1)) + 128); } -static PX_FORCE_INLINE Sc::Interaction* processElementPair(Sc::NPhaseCore& nPhaseCore, const Bp::AABBOverlap& pair, const PxU32 ccdPass, Bp::BroadPhasePair* bpPairs) +static PX_FORCE_INLINE Sc::Interaction* processElementPair(Sc::NPhaseCore& nPhaseCore, const Bp::AABBOverlap& pair, const PxU32 ccdPass) { ElementSim* e0 = reinterpret_cast<ElementSim*>(pair.mUserData0); ElementSim* e1 = reinterpret_cast<ElementSim*>(pair.mUserData1); - - Bp::BroadPhasePair* thisPair = NULL; - if(pair.mPairHandle != BP_INVALID_BP_HANDLE && bpPairs != NULL) - thisPair = &bpPairs[pair.mPairHandle]; - - return nPhaseCore.onOverlapCreated(e0, e1, ccdPass, thisPair); + return nPhaseCore.onOverlapCreated(e0, e1, ccdPass); } -void Sc::NPhaseCore::onOverlapCreated(const Bp::AABBOverlap* PX_RESTRICT pairs, PxU32 pairCount, const PxU32 ccdPass, Bp::BroadPhasePair* bpPairs) +void Sc::NPhaseCore::onOverlapCreated(const Bp::AABBOverlap* PX_RESTRICT pairs, PxU32 pairCount, const PxU32 ccdPass) { #if PX_USE_PARTICLE_SYSTEM_API PX_COMPILE_TIME_ASSERT(ElementType::eSHAPE < ElementType::ePARTICLE_PACKET); @@ -446,7 +430,7 @@ void Sc::NPhaseCore::onOverlapCreated(const Bp::AABBOverlap* PX_RESTRICT pairs, // unrolling by hand leads to better perf on XBox } - processElementPair(*this, pairs[pairIdx + 0], ccdPass, bpPairs); + processElementPair(*this, pairs[pairIdx + 0], ccdPass); // prefetch actor sim for next batch { @@ -458,7 +442,7 @@ void Sc::NPhaseCore::onOverlapCreated(const Bp::AABBOverlap* PX_RESTRICT pairs, // unrolling by hand leads to better perf on XBox } - processElementPair(*this, pairs[pairIdx + 1], ccdPass, bpPairs); + processElementPair(*this, pairs[pairIdx + 1], ccdPass); // prefetch shape core for next batch { @@ -470,7 +454,7 @@ void Sc::NPhaseCore::onOverlapCreated(const Bp::AABBOverlap* PX_RESTRICT pairs, // unrolling by hand leads to better perf on XBox } - processElementPair(*this, pairs[pairIdx + 2], ccdPass, bpPairs); + processElementPair(*this, pairs[pairIdx + 2], ccdPass); // prefetch actor core for next batch { @@ -482,7 +466,7 @@ void Sc::NPhaseCore::onOverlapCreated(const Bp::AABBOverlap* PX_RESTRICT pairs, // unrolling by hand leads to better perf on XBox } - processElementPair(*this, pairs[pairIdx + 3], ccdPass, bpPairs); + processElementPair(*this, pairs[pairIdx + 3], ccdPass); pairIdx += prefetchLookAhead; } @@ -490,7 +474,7 @@ void Sc::NPhaseCore::onOverlapCreated(const Bp::AABBOverlap* PX_RESTRICT pairs, // process remaining pairs for(PxU32 i=pairIdx; i < pairCount; i++) { - processElementPair(*this, pairs[i], ccdPass, bpPairs); + processElementPair(*this, pairs[i], ccdPass); } } diff --git a/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.h b/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.h index 6b40edf2..1a9f9eec 100644 --- a/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.h +++ b/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.h @@ -171,9 +171,9 @@ namespace Sc NPhaseCore(Scene& scene, const PxSceneDesc& desc); ~NPhaseCore(); - void onOverlapCreated(const Bp::AABBOverlap* PX_RESTRICT pairs, PxU32 pairCount, const PxU32 ccdPass, Bp::BroadPhasePair* bpPairs); - Sc::Interaction* onOverlapCreated(ElementSim* volume0, ElementSim* volume1, const PxU32 ccdPass, Bp::BroadPhasePair* bpPairs); - PxFilterInfo onOverlapFilter(ElementSim* volume0, ElementSim* volume1, Bp::BroadPhasePair* pair); + void onOverlapCreated(const Bp::AABBOverlap* PX_RESTRICT pairs, PxU32 pairCount, const PxU32 ccdPass); + Sc::Interaction* onOverlapCreated(ElementSim* volume0, ElementSim* volume1, const PxU32 ccdPass); + PxFilterInfo onOverlapFilter(ElementSim* volume0, ElementSim* volume1); ElementSimInteraction* onOverlapRemovedStage1(ElementSim* volume0, ElementSim* volume1); diff --git a/PhysX_3.4/Source/SimulationController/src/ScScene.cpp b/PhysX_3.4/Source/SimulationController/src/ScScene.cpp index 6519f7fa..b19852e7 100644 --- a/PhysX_3.4/Source/SimulationController/src/ScScene.cpp +++ b/PhysX_3.4/Source/SimulationController/src/ScScene.cpp @@ -138,7 +138,7 @@ void PxcDisplayContactCacheStats(); class ScAfterIntegrationTask : public Cm::Task { public: - static const PxU32 MaxTasks = 256; + static const PxU32 MaxShapesPerTasks = 512; private: const IG::NodeIndex* const mIndices; const PxU32 mNumBodies; @@ -164,17 +164,17 @@ public: { const PxU32 rigidBodyOffset = Sc::BodySim::getRigidBodyOffset(); - Sc::BodySim* bpUpdates[MaxTasks]; - Sc::BodySim* ccdBodies[MaxTasks]; - Sc::BodySim* activateBodies[MaxTasks]; - Sc::BodySim* deactivateBodies[MaxTasks]; + Sc::BodySim* bpUpdates[MaxShapesPerTasks]; + Sc::BodySim* ccdBodies[MaxShapesPerTasks]; + Sc::BodySim* activateBodies[MaxShapesPerTasks]; + Sc::BodySim* deactivateBodies[MaxShapesPerTasks]; PxU32 nbBpUpdates = 0, nbCcdBodies = 0; IG::SimpleIslandManager& manager = *mScene.getSimpleIslandManager(); const IG::IslandSim& islandSim = manager.getAccurateIslandSim(); Bp::BoundsArray& boundsArray = mScene.getBoundsArray(); - Sc::BodySim* frozen[MaxTasks], * unfrozen[MaxTasks]; + Sc::BodySim* frozen[MaxShapesPerTasks], * unfrozen[MaxShapesPerTasks]; PxU32 nbFrozen = 0, nbUnfrozen = 0; PxU32 nbActivated = 0, nbDeactivated = 0; @@ -305,7 +305,7 @@ public: Cm::FlushPool& flushPool = contextLL->getTaskPool(); - const PxU32 MaxBodiesPerTask = ScAfterIntegrationTask::MaxTasks; + const PxU32 MaxShapesPerTask = ScAfterIntegrationTask::MaxShapesPerTasks; PxsTransformCache& cache = contextLL->getTransformCache(); @@ -315,11 +315,32 @@ public: const IG::NodeIndex*const nodeIndices = islandSim.getActiveNodes(IG::Node::eRIGID_BODY_TYPE); + const PxU32 rigidBodyOffset = Sc::BodySim::getRigidBodyOffset(); + if(1) { - for(PxU32 i = 0; i < numBodies; i+=MaxBodiesPerTask) + PxU32 nbShapes = 0; + PxU32 startIdx = 0; + for(PxU32 i = 0; i < numBodies; i++)//i+=MaxBodiesPerTask) { - ScAfterIntegrationTask* task = PX_PLACEMENT_NEW(flushPool.allocate(sizeof(ScAfterIntegrationTask)), ScAfterIntegrationTask(nodeIndices+i, PxMin(numBodies - i, MaxBodiesPerTask), + if (nbShapes >= MaxShapesPerTask) + { + ScAfterIntegrationTask* task = PX_PLACEMENT_NEW(flushPool.allocate(sizeof(ScAfterIntegrationTask)), ScAfterIntegrationTask(nodeIndices + startIdx, i - startIdx, + contextLL, dynamicContext, cache, *mScene)); + task->setContinuation(continuation); + task->removeReference(); + startIdx = i; + nbShapes = 0; + } + + PxsRigidBody* rigid = islandSim.getRigidBody(nodeIndices[i]); + Sc::BodySim* bodySim = reinterpret_cast<Sc::BodySim*>(reinterpret_cast<PxU8*>(rigid) - rigidBodyOffset); + nbShapes += PxMax(1u, bodySim->getNbShapes()); //Always add at least 1 shape in, even if the body has zero shapes because there is still some per-body overhead + } + + if (nbShapes) + { + ScAfterIntegrationTask* task = PX_PLACEMENT_NEW(flushPool.allocate(sizeof(ScAfterIntegrationTask)), ScAfterIntegrationTask(nodeIndices + startIdx, numBodies - startIdx, contextLL, dynamicContext, cache, *mScene)); task->setContinuation(continuation); task->removeReference(); @@ -341,8 +362,8 @@ public: } // PT: we need to respect that limit even with a single thread, because of hardcoded buffer limits in ScAfterIntegrationTask. - if(nbPerTask>MaxBodiesPerTask) - nbPerTask = MaxBodiesPerTask; + if(nbPerTask>MaxShapesPerTask) + nbPerTask = MaxShapesPerTask; PxU32 start = 0; while(numBodies) @@ -2286,6 +2307,8 @@ void Sc::Scene::preRigidBodyNarrowPhase(PxBaseTask* continuation) const size_t bodyOffset = PX_OFFSET_OF_RT(Sc::BodySim, getLowLevelBody()); + Cm::BitMapPinned& changedMap = mAABBManager->getChangedAABBMgActorHandleMap(); + bool hasContactDistanceChanged = mHasContactDistanceChanged; while ((index = speculativeCCDIter.getNext()) != Cm::BitMap::Iterator::DONE) { @@ -2296,6 +2319,13 @@ void Sc::Scene::preRigidBodyNarrowPhase(PxBaseTask* continuation) hasContactDistanceChanged = true; ccdTask->mBodySims[ccdTask->mNbBodies++] = bodySim; + Sc::ShapeIterator iterator(*bodySim); + Sc::ShapeSim* shapeSim = NULL; + while ((shapeSim = iterator.getNext()) != NULL) + { + changedMap.growAndSet(shapeSim->getElementID()); + } + if (ccdTask->mNbBodies == SpeculativeCCDContactDistanceUpdateTask::MaxBodies) { ccdTask->setContinuation(continuation); @@ -2333,8 +2363,6 @@ void Sc::Scene::preRigidBodyNarrowPhase(PxBaseTask* continuation) //Process dirty shapeSims... Cm::BitMap::Iterator dirtyShapeIter(mDirtyShapeSimMap); - Cm::BitMapPinned& changedMap = mAABBManager->getChangedAABBMgActorHandleMap(); - PxsTransformCache& cache = mLLContext->getTransformCache(); Bp::BoundsArray& boundsArray = mAABBManager->getBoundsArray(); @@ -2877,7 +2905,7 @@ void Sc::Scene::processLostContacts(PxBaseTask* continuation) ElementSim* volume0 = reinterpret_cast<ElementSim*>(p->mUserData0); ElementSim* volume1 = reinterpret_cast<ElementSim*>(p->mUserData1); Sc::ElementSimInteraction* interaction = mNPhaseCore->onOverlapRemovedStage1(volume0, volume1); - p->mUserData = interaction; + p->mPairUserData = interaction; p++; } } @@ -2898,9 +2926,9 @@ void Sc::Scene::lostTouchReports(PxBaseTask*) const Bp::AABBOverlap* PX_RESTRICT p = aabbMgr->getDestroyedOverlaps(Bp::VolumeBuckets::eSHAPE, destroyedOverlapCount); while (destroyedOverlapCount--) { - if (p->mUserData) + if (p->mPairUserData) { - Sc::ElementSimInteraction* elemInteraction = reinterpret_cast<Sc::ElementSimInteraction*>(p->mUserData); + Sc::ElementSimInteraction* elemInteraction = reinterpret_cast<Sc::ElementSimInteraction*>(p->mPairUserData); if (elemInteraction->getType() == Sc::InteractionType::eOVERLAP) mNPhaseCore->lostTouchReports(static_cast<Sc::ShapeInteraction*>(elemInteraction), PxU32(PairReleaseFlag::eWAKE_ON_LOST_TOUCH), 0, outputs, useAdaptiveForce); } @@ -2922,9 +2950,9 @@ void Sc::Scene::unregisterInteractions(PxBaseTask*) const Bp::AABBOverlap* PX_RESTRICT p = aabbMgr->getDestroyedOverlaps(Bp::VolumeBuckets::eSHAPE, destroyedOverlapCount); while (destroyedOverlapCount--) { - if (p->mUserData) + if (p->mPairUserData) { - Sc::ElementSimInteraction* elemInteraction = reinterpret_cast<Sc::ElementSimInteraction*>(p->mUserData); + Sc::ElementSimInteraction* elemInteraction = reinterpret_cast<Sc::ElementSimInteraction*>(p->mPairUserData); if (elemInteraction->getType() == Sc::InteractionType::eOVERLAP || elemInteraction->getType() == Sc::InteractionType::eMARKER) { unregisterInteraction(elemInteraction); @@ -2951,9 +2979,9 @@ void Sc::Scene::destroyManagers(PxBaseTask*) const Bp::AABBOverlap* PX_RESTRICT p = aabbMgr->getDestroyedOverlaps(Bp::VolumeBuckets::eSHAPE, destroyedOverlapCount); while (destroyedOverlapCount--) { - if (p->mUserData) + if (p->mPairUserData) { - Sc::ElementSimInteraction* elemInteraction = reinterpret_cast<Sc::ElementSimInteraction*>(p->mUserData); + Sc::ElementSimInteraction* elemInteraction = reinterpret_cast<Sc::ElementSimInteraction*>(p->mPairUserData); if (elemInteraction->getType() == Sc::InteractionType::eOVERLAP) { Sc::ShapeInteraction* si = static_cast<Sc::ShapeInteraction*>(elemInteraction); @@ -2986,7 +3014,7 @@ void Sc::Scene::processLostContacts2(PxBaseTask* continuation) Bp::AABBOverlap* PX_RESTRICT p = aabbMgr->getDestroyedOverlaps(Bp::VolumeBuckets::eSHAPE, destroyedOverlapCount); while (destroyedOverlapCount--) { - Sc::ElementSimInteraction* pair = reinterpret_cast<Sc::ElementSimInteraction*>(p->mUserData); + Sc::ElementSimInteraction* pair = reinterpret_cast<Sc::ElementSimInteraction*>(p->mPairUserData); if (pair) { if (pair->getType() == InteractionType::eOVERLAP) @@ -3021,7 +3049,7 @@ void Sc::Scene::processLostContacts3(PxBaseTask* /*continuation*/) ElementSim* volume0 = reinterpret_cast<ElementSim*>(p->mUserData0); ElementSim* volume1 = reinterpret_cast<ElementSim*>(p->mUserData1); - mNPhaseCore->onOverlapRemoved(volume0, volume1, false, p->mUserData, outputs, useAdaptiveForce); + mNPhaseCore->onOverlapRemoved(volume0, volume1, false, p->mPairUserData, outputs, useAdaptiveForce); p++; } } @@ -3337,7 +3365,47 @@ void Sc::Scene::integrateKinematicPose() } } -void Sc::Scene::updateKinematicCached() +class KinematicUpdateCachedTask : public Cm::Task +{ +private: + KinematicUpdateCachedTask& operator = (const KinematicUpdateCachedTask&); + + Sc::BodyCore*const* mKinematics; + PxU32 mNbKinematics; + PxsTransformCache& mTransformCache; + Bp::BoundsArray& mBoundsArray; + + +public: + KinematicUpdateCachedTask(Sc::BodyCore*const* kinematics, PxU32 nbKinematics, PxU64 contextId, + PxsTransformCache& transformCache, Bp::BoundsArray& boundsArray) : + Cm::Task(contextId), + mKinematics(kinematics), mNbKinematics(nbKinematics), + mTransformCache(transformCache), mBoundsArray(boundsArray) + { + } + + virtual void runInternal() + { + for (PxU32 i = 0; i < mNbKinematics; ++i) + { + mKinematics[i]->getSim()->updateCached(mTransformCache, mBoundsArray); + } + } + + virtual const char* getName() const + { + return "ScScene.KinematicUpdateCachedTask"; + } + +public: + static const PxU32 NbShapesPerTask = 512; // just a guideline, will not match exactly most of the time + +private: +}; + + +void Sc::Scene::updateKinematicCached(PxBaseTask* continuation) { PX_PROFILE_ZONE("Sim.integrateKinematicPose", getContextId()); @@ -3346,9 +3414,16 @@ void Sc::Scene::updateKinematicCached() BodyCore*const* kineEnd = kinematics + nbKinematics; BodyCore*const* kinePrefetch = kinematics + 16; - for(PxU32 i = 0; i < nbKinematics; ++i) + PxU32 nbShapes = 0; + PxU32 startIndex = 0; + + PxsTransformCache& transformCache = getLowLevelContext()->getTransformCache(); + Bp::BoundsArray& boundsArray = getAABBManager()->getBoundsArray(); + + + for (PxU32 i = 0; i < nbKinematics; ++i) { - if(kinePrefetch < kineEnd) + if (kinePrefetch < kineEnd) { Ps::prefetch(*kinePrefetch, 1024); kinePrefetch++; @@ -3359,9 +3434,43 @@ void Sc::Scene::updateKinematicCached() PX_ASSERT(sim->isKinematic()); PX_ASSERT(sim->isActive()); + nbShapes += sim->getNbShapes(); + + if (nbShapes >= KinematicUpdateCachedTask::NbShapesPerTask) + { + KinematicUpdateCachedTask* task = PX_PLACEMENT_NEW(mTaskPool.allocate(sizeof(KinematicUpdateCachedTask)), KinematicUpdateCachedTask) + (kinematics + startIndex, (i + 1) - startIndex, mContextId, transformCache, boundsArray); + task->setContinuation(continuation); + task->removeReference(); + startIndex = i + 1; + nbShapes = 0; + } + } + + if (nbShapes) + { + KinematicUpdateCachedTask* task = PX_PLACEMENT_NEW(mTaskPool.allocate(sizeof(KinematicUpdateCachedTask)), KinematicUpdateCachedTask) + (kinematics + startIndex, nbKinematics - startIndex, mContextId, transformCache, boundsArray); + task->setContinuation(continuation); + task->removeReference(); + } + + + for (PxU32 i = 0; i < nbKinematics; ++i) + { + BodyCore* b = kinematics[i]; + BodySim* bodySim = b->getSim(); Cm::BitMapPinned& changedAABBMgrActorHandles = mAABBManager->getChangedAABBMgActorHandleMap(); - sim->updateCached(&changedAABBMgrActorHandles); - mSimulationController->addDynamic(&sim->getLowLevelBody(), sim->getNodeIndex().index()); + if (!(bodySim->getInternalFlag() & PxsRigidBody::eFROZEN)) + { + Sc::ShapeSim* sim; + for (Sc::ShapeIterator iterator(*bodySim); (sim = iterator.getNext()) != NULL;) + { + if(sim->isInBroadPhase()) + changedAABBMgrActorHandles.growAndSet(sim->getElementID()); + } + } + mSimulationController->addDynamic(&bodySim->getLowLevelBody(), bodySim->getNodeIndex().index()); } } @@ -4051,7 +4160,7 @@ void Sc::Scene::afterIntegration(PxBaseTask* continuation) } } - updateKinematicCached(); + updateKinematicCached(continuation); mLLContext->getLock().unlock(); } @@ -6171,7 +6280,6 @@ public: Sc::NPhaseCore* mNPhaseCore; const Bp::AABBOverlap* PX_RESTRICT mPairs; - Bp::BroadPhasePair* mBpPairs; PxU32 mNbToProcess; PxU32 mKeepMap[MaxPairs/32]; @@ -6183,11 +6291,10 @@ public: PxU32 mNbToSuppress; PxU32 mNbToCallback; - OverlapFilterTask(PxU64 contextID, Sc::NPhaseCore* nPhaseCore, PxFilterInfo* fInfo, const Bp::AABBOverlap* PX_RESTRICT pairs, Bp::BroadPhasePair* bpPairs, const PxU32 nbToProcess) : + OverlapFilterTask(PxU64 contextID, Sc::NPhaseCore* nPhaseCore, PxFilterInfo* fInfo, const Bp::AABBOverlap* PX_RESTRICT pairs, const PxU32 nbToProcess) : Cm::Task (contextID), mNPhaseCore (nPhaseCore), mPairs (pairs), - mBpPairs (bpPairs), mNbToProcess (nbToProcess), mFinfo (fInfo), mNbToKeep (0), @@ -6206,11 +6313,7 @@ public: Sc::ElementSim* e0 = reinterpret_cast<Sc::ElementSim*>(pair.mUserData0); Sc::ElementSim* e1 = reinterpret_cast<Sc::ElementSim*>(pair.mUserData1); - Bp::BroadPhasePair* thisPair = NULL; - if(pair.mPairHandle != BP_INVALID_BP_HANDLE && mBpPairs != NULL) - thisPair = &mBpPairs[pair.mPairHandle]; - - const PxFilterInfo finfo = mNPhaseCore->onOverlapFilter(e0, e1, thisPair); + const PxFilterInfo finfo = mNPhaseCore->onOverlapFilter(e0, e1); mFinfo[a] = finfo; @@ -6245,12 +6348,10 @@ public: PxsContactManager** mContactManagers; Sc::ShapeInteraction** mShapeInteractions; Sc::ElementInteractionMarker** mInteractionMarkers; - Bp::BroadPhasePair* mBpPairs; PxU32 mNbToProcess; - OnOverlapCreatedTask(PxU64 contextID, Sc::NPhaseCore* nPhaseCore, const Bp::AABBOverlap* PX_RESTRICT pairs, const PxFilterInfo* fInfo, PxsContactManager** contactManagers, Sc::ShapeInteraction** shapeInteractions, Sc::ElementInteractionMarker** interactionMarkers, - Bp::BroadPhasePair* bpPairs, PxU32 nbToProcess) : + PxU32 nbToProcess) : Cm::Task (contextID), mNPhaseCore (nPhaseCore), mPairs (pairs), @@ -6258,7 +6359,6 @@ public: mContactManagers (contactManagers), mShapeInteractions (shapeInteractions), mInteractionMarkers (interactionMarkers), - mBpPairs (bpPairs), mNbToProcess (nbToProcess) { } @@ -6275,15 +6375,8 @@ public: Sc::ShapeSim* s0 = reinterpret_cast<Sc::ShapeSim*>(pair.mUserData1); Sc::ShapeSim* s1 = reinterpret_cast<Sc::ShapeSim*>(pair.mUserData0); - Bp::BroadPhasePair* thisPair = NULL; - if(pair.mPairHandle != BP_INVALID_BP_HANDLE && mBpPairs != NULL) - thisPair = &mBpPairs[pair.mPairHandle]; - Sc::ElementSimInteraction* interaction = mNPhaseCore->createRbElementInteraction(mFinfo[a], *s0, *s1, *currentCm, *currentSI, *currentEI, 0); - if(thisPair) - thisPair->mUserData = interaction; - if(interaction) { if (interaction->getType() == Sc::InteractionType::eOVERLAP) @@ -6379,12 +6472,10 @@ void Sc::Scene::preallocateContactManagers(PxBaseTask* continuation) Sc::ShapeInteraction** shapeInter = mPreallocatedShapeInteractions.begin(); Sc::ElementInteractionMarker** markerIter = mPreallocatedInteractionMarkers.begin(); - Bp::BroadPhasePair* bpPairs = mAABBManager->getBroadPhase()->getBroadPhasePairs(); - Cm::FlushPool& flushPool = mLLContext->getTaskPool(); OnOverlapCreatedTask* createTask = PX_PLACEMENT_NEW(flushPool.allocate(sizeof(OnOverlapCreatedTask)), OnOverlapCreatedTask)(getContextId(), mNPhaseCore, p, - fInfo, cms, shapeInter, markerIter, bpPairs, 0); + fInfo, cms, shapeInter, markerIter, 0); PxU32 batchSize = 0; PxU32 suppressedStartIdx = 0; @@ -6437,7 +6528,7 @@ void Sc::Scene::preallocateContactManagers(PxBaseTask* continuation) createTask = PX_PLACEMENT_NEW(flushPool.allocate(sizeof(OnOverlapCreatedTask)), OnOverlapCreatedTask)(getContextId(), mNPhaseCore, p + createdOverlapCount, - fInfo + createdOverlapCount, cms + createdStartIdx, shapeInter + createdStartIdx, markerIter + suppressedStartIdx, bpPairs, 0); + fInfo + createdOverlapCount, cms + createdStartIdx, shapeInter + createdStartIdx, markerIter + suppressedStartIdx, 0); batchSize = 0; } @@ -6470,7 +6561,6 @@ void Sc::Scene::finishBroadPhase(PxU32 ccdPass, PxBaseTask* continuation) PX_PROFILE_ZONE("Sc::Scene::finishBroadPhase", getContextId()); Bp::SimpleAABBManager* aabbMgr = mAABBManager; - Bp::BroadPhasePair* bpPairs = aabbMgr->getBroadPhase()->getBroadPhasePairs(); { PX_PROFILE_ZONE("Sim.processNewOverlaps", getContextId()); @@ -6488,7 +6578,7 @@ void Sc::Scene::finishBroadPhase(PxU32 ccdPass, PxBaseTask* continuation) mLLContext->getSimStats().mNbNewPairs += createdOverlapCount; - mNPhaseCore->onOverlapCreated(p, createdOverlapCount, ccdPass, bpPairs); + mNPhaseCore->onOverlapCreated(p, createdOverlapCount, ccdPass); } } @@ -6522,7 +6612,7 @@ void Sc::Scene::finishBroadPhase(PxU32 ccdPass, PxBaseTask* continuation) { PxU32 nbToProcess = PxMin(createdOverlapCount - a, nbPairsPerTask); OverlapFilterTask* task = PX_PLACEMENT_NEW(flushPool.allocate(sizeof(OverlapFilterTask)), OverlapFilterTask)(getContextId(), mNPhaseCore, mFilterInfo.begin() + a, - p + a, bpPairs, nbToProcess); + p + a, nbToProcess); task->setContinuation(&mPreallocateContactManagers); task->removeReference(); @@ -6539,7 +6629,6 @@ void Sc::Scene::finishBroadPhaseStage2(const PxU32 ccdPass) PX_PROFILE_ZONE("Sc::Scene::finishBroadPhase2", getContextId()); Bp::SimpleAABBManager* aabbMgr = mAABBManager; - //Bp::BroadPhasePair* bpPairs = aabbMgr->getBroadPhase()->getBroadPhasePairs(); for (PxU32 i = 0; i < Bp::VolumeBuckets::eCOUNT; ++i) { @@ -6572,7 +6661,7 @@ void Sc::Scene::finishBroadPhaseStage2(const PxU32 ccdPass) //First, we have to get the interaction pointer... Sc::ElementSimInteraction* interaction = mNPhaseCore->onOverlapRemovedStage1(volume0, volume1); - p->mUserData = interaction; + p->mPairUserData = interaction; if (interaction) { if (interaction->getType() == Sc::InteractionType::eOVERLAP || interaction->getType() == Sc::InteractionType::eMARKER) @@ -6606,7 +6695,7 @@ void Sc::Scene::finishBroadPhaseStage2(const PxU32 ccdPass) ElementSim* volume0 = reinterpret_cast<ElementSim*>(p->mUserData0); ElementSim* volume1 = reinterpret_cast<ElementSim*>(p->mUserData1); - p->mUserData = NULL; + p->mPairUserData = NULL; //KS - this is a bit ugly. mNPhaseCore->onOverlapRemoved(volume0, volume1, ccdPass, NULL, outputs, useAdaptiveForce); diff --git a/PhysX_3.4/Source/SimulationController/src/ScShapeInteraction.cpp b/PhysX_3.4/Source/SimulationController/src/ScShapeInteraction.cpp index d18961e2..0760d911 100644 --- a/PhysX_3.4/Source/SimulationController/src/ScShapeInteraction.cpp +++ b/PhysX_3.4/Source/SimulationController/src/ScShapeInteraction.cpp @@ -859,18 +859,49 @@ void Sc::ShapeInteraction::updateState(const PxU8 externalDirtyFlags) else if (readInteractionFlag(InteractionFlag::eIS_ACTIVE)) // only re-create the manager if the pair is active { PX_ASSERT(mManager); // if the pair is active, there has to be a manager - PX_ASSERT(activeManagerAllowed()); - // A) This is a newly created pair - // - // B) The contact notification or processing state has changed. - // All existing managers need to be deleted and recreated with the correct flag set - // These flags can only be set at creation in LL - //KS - added this code here because it is no longer done in destroyManager() - a side-effect of the parallelization of the interaction management code - if (mEdgeIndex != IG_INVALID_EDGE) - scene.getSimpleIslandManager()->clearEdgeRigidCM(mEdgeIndex); - destroyManager(); - createManager(NULL); + if (dirtyFlags & InteractionDirtyFlag::eBODY_KINEMATIC) + { + //Kinematic->dynamic transition + //Kinematic->dynamic transition + const IG::IslandSim& islandSim = getScene().getSimpleIslandManager()->getSpeculativeIslandSim(); + + // + //check whether active in the speculative sim! + const BodySim* bodySim0 = getShape0().getBodySim(); + const BodySim* bodySim1 = getShape1().getBodySim(); + + if (!islandSim.getNode(bodySim0->getNodeIndex()).isActiveOrActivating() && + (bodySim1 == NULL || !islandSim.getNode(bodySim1->getNodeIndex()).isActiveOrActivating())) + { + onDeactivate(0); + scene.notifyInteractionDeactivated(this); + } + else + { + //Else we are allowed to be active, so recreate + if (mEdgeIndex != IG_INVALID_EDGE) + scene.getSimpleIslandManager()->clearEdgeRigidCM(mEdgeIndex); + destroyManager(); + createManager(NULL); + } + } + else + { + + PX_ASSERT(activeManagerAllowed()); + + // A) This is a newly created pair + // + // B) The contact notification or processing state has changed. + // All existing managers need to be deleted and recreated with the correct flag set + // These flags can only be set at creation in LL + //KS - added this code here because it is no longer done in destroyManager() - a side-effect of the parallelization of the interaction management code + if (mEdgeIndex != IG_INVALID_EDGE) + scene.getSimpleIslandManager()->clearEdgeRigidCM(mEdgeIndex); + destroyManager(); + createManager(NULL); + } } } diff --git a/PhysX_3.4/Source/SimulationController/src/ScShapeSim.cpp b/PhysX_3.4/Source/SimulationController/src/ScShapeSim.cpp index 159450ce..42bd5e88 100644 --- a/PhysX_3.4/Source/SimulationController/src/ScShapeSim.cpp +++ b/PhysX_3.4/Source/SimulationController/src/ScShapeSim.cpp @@ -185,7 +185,8 @@ void Sc::ShapeSim::removeFromBroadPhase(bool wakeOnLostTouch) void Sc::ShapeSim::reinsertBroadPhase() { - internalRemoveFromBroadPhase(); + if(isInBroadPhase()) + internalRemoveFromBroadPhase(); // internalAddToBroadPhase(); Sc::Scene& scene = getScene(); |