diff options
| author | Sheikh Dawood Abdul Ajees <[email protected]> | 2017-04-25 16:02:08 -0500 |
|---|---|---|
| committer | Sheikh Dawood Abdul Ajees <[email protected]> | 2017-04-25 16:02:08 -0500 |
| commit | d11708e398c2f6377d9eac2b1f7248c62faab569 (patch) | |
| tree | 5778e794690c046ab4b0205d8f764960a5af168b /PhysX_3.4/Source/SimulationController/src | |
| parent | PhysX 3.4, APEX 1.4 patch release @21821222 (diff) | |
| download | physx-3.4-d11708e398c2f6377d9eac2b1f7248c62faab569.tar.xz physx-3.4-d11708e398c2f6377d9eac2b1f7248c62faab569.zip | |
PhysX 3.4, APEX 1.4 patch release @22017166
Diffstat (limited to 'PhysX_3.4/Source/SimulationController/src')
5 files changed, 234 insertions, 239 deletions
diff --git a/PhysX_3.4/Source/SimulationController/src/ScBodySim.cpp b/PhysX_3.4/Source/SimulationController/src/ScBodySim.cpp index 3a0cc9c7..4ce57c13 100644 --- a/PhysX_3.4/Source/SimulationController/src/ScBodySim.cpp +++ b/PhysX_3.4/Source/SimulationController/src/ScBodySim.cpp @@ -93,7 +93,7 @@ Sc::BodySim::BodySim(Scene& scene, BodyCore& core) : hasPendingForce = (velmod->flags != 0) && (!velmod->getLinearVelModPerSec().isZero() || !velmod->getAngularVelModPerSec().isZero() || !velmod->getLinearVelModPerStep().isZero() || !velmod->getAngularVelModPerStep().isZero()); - mVelModState = velmod->flags; + mVelModState = velmod->flags; velmod->flags = 0; } @@ -121,6 +121,12 @@ Sc::BodySim::BodySim(Scene& scene, BodyCore& core) : } } + + //If a user add force or torque before the body is inserted into the scene, + //this logic will make sure pre solver stage apply external force/torque to the body + if(hasPendingForce && !isArticulationLink()) + scene.getVelocityModifyMap().growAndSet(mNodeIndex.index()); + PX_ASSERT(mActiveListIndex == SC_NOT_IN_SCENE_INDEX); setActive(isAwake, ActorSim::AS_PART_OF_CREATION); @@ -493,10 +499,10 @@ void Sc::BodySim::activateInteractions(PxU32 /*infoFlag*/) Ps::prefetchLine(mInteractions[PxMin(i+1,nbInteractions-1)]); Interaction* interaction = mInteractions[i]; - bool isNotIGControlled = interaction->getType() != Sc::InteractionType::eCONSTRAINTSHADER && interaction->getType() != Sc::InteractionType::eOVERLAP && + bool isNotIGControlled = interaction->getType() != Sc::InteractionType::eOVERLAP && interaction->getType() != Sc::InteractionType::eMARKER; - if (!interaction->readInteractionFlag(InteractionFlag::eIS_ACTIVE) && isNotIGControlled) + if (!interaction->readInteractionFlag(InteractionFlag::eIS_ACTIVE) && (isNotIGControlled)) { const bool proceed = interaction->onActivate(NULL); if (proceed && (interaction->getType() < InteractionType::eTRACKED_IN_SCENE_COUNT)) @@ -515,7 +521,7 @@ void Sc::BodySim::deactivateInteractions(PxU32 infoFlag) Ps::prefetchLine(mInteractions[PxMin(i+1,nbInteractions-1)]); Interaction* interaction = mInteractions[i]; - bool isNotIGControlled = interaction->getType() != Sc::InteractionType::eCONSTRAINTSHADER && interaction->getType() != Sc::InteractionType::eOVERLAP && + bool isNotIGControlled = interaction->getType() != Sc::InteractionType::eOVERLAP && interaction->getType() != Sc::InteractionType::eMARKER; if (interaction->readInteractionFlag(InteractionFlag::eIS_ACTIVE) && isNotIGControlled) diff --git a/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.cpp b/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.cpp index a388dee0..8a4b4b07 100644 --- a/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.cpp +++ b/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.cpp @@ -38,34 +38,25 @@ #include "ScSimStats.h" #if PX_USE_PARTICLE_SYSTEM_API -#include "ScParticleSystemCore.h" -#include "ScParticleBodyInteraction.h" -#include "ScParticlePacketShape.h" -#include "GuOverlapTests.h" -#include "GuBox.h" + #include "ScParticleSystemCore.h" + #include "ScParticleBodyInteraction.h" + #include "ScParticlePacketShape.h" + #include "GuOverlapTests.h" + #include "GuBox.h" #endif #if PX_USE_CLOTH_API -#include "ScClothCore.h" -#include "ScClothSim.h" + #include "ScClothCore.h" + #include "ScClothSim.h" #endif // PX_USE_CLOTH_API #include "PsThread.h" - #include "BpBroadPhase.h" using namespace physx; using namespace Sc; using namespace Gu; - -namespace physx -{ -namespace Sc -{ -} -} - struct Sc::FilterPair { enum Enum @@ -138,10 +129,8 @@ private: uintptr_t mFree; }; -/* Sc::NPhaseCore methods */ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Sc::NPhaseCore::NPhaseCore(Scene& scene, const PxSceneDesc& sceneDesc) : mOwnerScene (scene), mContactReportActorPairSet (PX_DEBUG_EXP("contactReportPairSet")), @@ -162,14 +151,13 @@ Sc::NPhaseCore::NPhaseCore(Scene& scene, const PxSceneDesc& sceneDesc) : #if PX_USE_CLOTH_API ,mClothPool (PX_DEBUG_EXP("clothPool")) #endif - ,mMergeProcessedTriggerInteractions (this, "ScNPhaseCore.mergeProcessedTriggerInteractions") + ,mMergeProcessedTriggerInteractions (scene.getContextId(), this, "ScNPhaseCore.mergeProcessedTriggerInteractions") ,mTmpTriggerProcessingBlock (NULL) ,mTriggerPairsToDeactivateCount (0) { mFilterPairManager = PX_NEW(FilterPairManager); } - Sc::NPhaseCore::~NPhaseCore() { // Clear pending actor pairs (waiting on contact report callback) @@ -198,6 +186,16 @@ PxFilterInfo Sc::NPhaseCore::onOverlapFilter(ElementSim* volume0, ElementSim* vo { PX_ASSERT(!findInteraction(volume0, volume1)); +/* if(0) + { + (void)volume0; + (void)volume1; + (void)pair; + PxFilterInfo finfo; + finfo.filterFlags = PxFilterFlag::eKILL; + return finfo; + }*/ + if(pair) pair->mUserData = NULL; @@ -245,7 +243,6 @@ Sc::Interaction* Sc::NPhaseCore::onOverlapCreated(ElementSim* volume0, ElementSi switch (volumeHi->getElementType()) { - #if PX_USE_PARTICLE_SYSTEM_API case ElementType::ePARTICLE_PACKET: { @@ -357,7 +354,6 @@ Sc::Interaction* Sc::NPhaseCore::onOverlapCreated(ElementSim* volume0, ElementSi return NULL; } - static PX_FORCE_INLINE void prefetchPairElements(const Bp::AABBOverlap& pair, const ElementSim** elementBuffer) { const ElementSim* e0 = reinterpret_cast<const ElementSim*>(pair.mUserData0); @@ -370,7 +366,6 @@ static PX_FORCE_INLINE void prefetchPairElements(const Bp::AABBOverlap& pair, co *(elementBuffer+1) = e1; } - static PX_FORCE_INLINE void prefetchPairActors(const ElementSim& e0, const ElementSim& e1, const ActorSim** actorBuffer) { const ActorSim* a0 = static_cast<const ActorSim*>(&e0.getActor()); @@ -385,7 +380,6 @@ static PX_FORCE_INLINE void prefetchPairActors(const ElementSim& e0, const Eleme *(actorBuffer+1) = a1; } - static PX_FORCE_INLINE void prefetchPairShapesCore(const ElementSim& e0, const ElementSim& e1) { if (e0.getElementType() == ElementType::eSHAPE) @@ -402,7 +396,6 @@ static PX_FORCE_INLINE void prefetchPairShapesCore(const ElementSim& e0, const E } } - static PX_FORCE_INLINE void prefetchPairActorsCore(const ActorSim& a0, const ActorSim& a1) { ActorCore* ac0 = &a0.getActorCore(); @@ -413,7 +406,6 @@ 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) { ElementSim* e0 = reinterpret_cast<ElementSim*>(pair.mUserData0); @@ -426,7 +418,6 @@ static PX_FORCE_INLINE Sc::Interaction* processElementPair(Sc::NPhaseCore& nPhas return nPhaseCore.onOverlapCreated(e0, e1, ccdPass, thisPair); } - void Sc::NPhaseCore::onOverlapCreated(const Bp::AABBOverlap* PX_RESTRICT pairs, PxU32 pairCount, const PxU32 ccdPass, Bp::BroadPhasePair* bpPairs) { #if PX_USE_PARTICLE_SYSTEM_API @@ -511,8 +502,9 @@ void Sc::NPhaseCore::registerInteraction(ElementSimInteraction* interaction) if (sim0 > sim1) Ps::swap(sim0, sim1); - this->mElementSimMap.insert(ElementSimKey(sim0, sim1), interaction); + mElementSimMap.insert(ElementSimKey(sim0, sim1), interaction); } + void Sc::NPhaseCore::unregisterInteraction(ElementSimInteraction* interaction) { ElementSim* sim0 = &interaction->getElement0(); @@ -529,9 +521,7 @@ ElementSimInteraction* Sc::NPhaseCore::onOverlapRemovedStage1(ElementSim* volume return pair; } - -void Sc::NPhaseCore::onOverlapRemoved(ElementSim* volume0, ElementSim* volume1, const PxU32 ccdPass, void* elemSim, PxsContactManagerOutputIterator& outputs, - bool useAdaptiveForce) +void Sc::NPhaseCore::onOverlapRemoved(ElementSim* volume0, ElementSim* volume1, const PxU32 ccdPass, void* elemSim, PxsContactManagerOutputIterator& outputs, bool useAdaptiveForce) { PX_UNUSED(elemSim); // PT: ordering them here is again useless, as "findInteraction" will reorder according to counts... @@ -544,7 +534,6 @@ void Sc::NPhaseCore::onOverlapRemoved(ElementSim* volume0, ElementSim* volume1, // PT: TODO: get rid of 'findInteraction', cf US10491 ElementSimInteraction* interaction = elemSim ? reinterpret_cast<ElementSimInteraction*>(elemSim) : findInteraction(elementHi, elementLo); - // MS: The check below is necessary since at the moment LowLevel broadphase still tracks // killed pairs and hence reports lost overlaps if (interaction) @@ -571,7 +560,6 @@ void Sc::NPhaseCore::onOverlapRemoved(ElementSim* volume0, ElementSim* volume1, #endif // PX_USE_CLOTH_API } - // MS: TODO: optimize this for the actor release case? void Sc::NPhaseCore::onVolumeRemoved(ElementSim* volume, PxU32 flags, PxsContactManagerOutputIterator& outputs, bool useAdaptiveForce) { @@ -620,7 +608,6 @@ void Sc::NPhaseCore::onVolumeRemoved(ElementSim* volume, PxU32 flags, PxsContact mClothOverlaps.erase(shape); } #endif - break; } #if PX_USE_PARTICLE_SYSTEM_API @@ -726,7 +713,6 @@ Sc::ElementSimInteraction* Sc::NPhaseCore::createRbElementInteraction(ShapeSim& return createRbElementInteraction(finfo, s0, s1, contactManager, shapeInteraction, interactionMarker, isTriggerPair); } - #if PX_USE_PARTICLE_SYSTEM_API // PT: function used only once, so safe to force inline static PX_FORCE_INLINE Sc::ParticleElementRbElementInteraction* findParticlePacketBodyInteraction(ParticlePacketShape* ps, ActorSim* actor) @@ -799,7 +785,6 @@ Sc::ElementSimInteraction* Sc::NPhaseCore::createParticlePacketBodyInteraction(P } #endif - void Sc::NPhaseCore::managerNewTouch(Sc::ShapeInteraction& interaction, const PxU32 /*ccdPass*/, bool /*adjustCounters*/, PxsContactManagerOutputIterator& /*outputs*/) { //(1) if the pair hasn't already been assigned, look it up! @@ -816,7 +801,6 @@ void Sc::NPhaseCore::managerNewTouch(Sc::ShapeInteraction& interaction, const Px } } - Sc::ShapeInteraction* Sc::NPhaseCore::createShapeInteraction(ShapeSim& s0, ShapeSim& s1, PxPairFlags pairFlags, PxsContactManager* contactManager, Sc::ShapeInteraction* shapeInteraction) { ShapeSim* _s0 = &s0; @@ -854,7 +838,6 @@ Sc::ShapeInteraction* Sc::NPhaseCore::createShapeInteraction(ShapeSim& s0, Shape return si; } - Sc::TriggerInteraction* Sc::NPhaseCore::createTriggerInteraction(ShapeSim& s0, ShapeSim& s1, PxPairFlags triggerFlags) { ShapeSim* triggerShape; @@ -875,7 +858,6 @@ Sc::TriggerInteraction* Sc::NPhaseCore::createTriggerInteraction(ShapeSim& s0, S return pair; } - Sc::ElementInteractionMarker* Sc::NPhaseCore::createElementInteractionMarker(ElementSim& e0, ElementSim& e1, Sc::ElementInteractionMarker* interactionMarker) { ElementInteractionMarker* pair = interactionMarker ? interactionMarker : mInteractionMarkerPool.allocate(); @@ -1200,7 +1182,6 @@ Sc::ElementSimInteraction* Sc::NPhaseCore::refilterInteraction(ElementSimInterac return NULL; } - PX_INLINE void Sc::NPhaseCore::callPairLost(const ElementSim& e0, const ElementSim& e1, PxU32 pairID, bool objVolumeRemoved) const { PxFilterData fd0, fd1; @@ -1212,7 +1193,6 @@ PX_INLINE void Sc::NPhaseCore::callPairLost(const ElementSim& e0, const ElementS mOwnerScene.getFilterCallbackFast()->pairLost(pairID, fa0, fd0, fa1, fd1, objVolumeRemoved); } - PX_INLINE void Sc::NPhaseCore::runFilterShader(const ElementSim& e0, const ElementSim& e1, PxFilterObjectAttributes& attr0, PxFilterData& filterData0, PxFilterObjectAttributes& attr1, PxFilterData& filterData1, @@ -1228,7 +1208,6 @@ PX_INLINE void Sc::NPhaseCore::runFilterShader(const ElementSim& e0, const Eleme mOwnerScene.getFilterShaderDataSizeFast() ); } - static PX_FORCE_INLINE void fetchActorAndShape(const ElementSim& e, PxActor*& a, PxShape*& s) { if (e.getElementType() == ElementType::eSHAPE) @@ -1247,7 +1226,6 @@ static PX_FORCE_INLINE void fetchActorAndShape(const ElementSim& e, PxActor*& a, #endif } - PX_INLINE PxFilterInfo Sc::NPhaseCore::runFilter(const ElementSim& e0, const ElementSim& e1, PxU32 filterPairIndex, bool doCallbacks) { PxFilterInfo filterInfo; @@ -1317,7 +1295,6 @@ PX_INLINE PxFilterInfo Sc::NPhaseCore::runFilter(const ElementSim& e0, const Ele return filterInfo; } - PX_FORCE_INLINE PxFilterInfo Sc::NPhaseCore::filterOutRbCollisionPair(PxU32 filterPairIndex, const PxFilterFlags filterFlags) { if(filterPairIndex!=INVALID_FILTER_PAIR_INDEX) @@ -1326,9 +1303,7 @@ PX_FORCE_INLINE PxFilterInfo Sc::NPhaseCore::filterOutRbCollisionPair(PxU32 filt return PxFilterInfo(filterFlags); } - -PxFilterInfo Sc::NPhaseCore::filterRbCollisionPairSecondStage(const ShapeSim& s0, const ShapeSim& s1, const Sc::BodySim* b0, const Sc::BodySim* b1, PxU32 filterPairIndex, - bool runCallbacks) +PxFilterInfo Sc::NPhaseCore::filterRbCollisionPairSecondStage(const ShapeSim& s0, const ShapeSim& s1, const Sc::BodySim* b0, const Sc::BodySim* b1, PxU32 filterPairIndex, bool runCallbacks) { PxFilterInfo filterInfo = runFilter(s0, s1, filterPairIndex, runCallbacks); if (runCallbacks || (!(filterInfo.filterFlags & PxFilterFlag::eCALLBACK))) @@ -1336,7 +1311,6 @@ PxFilterInfo Sc::NPhaseCore::filterRbCollisionPairSecondStage(const ShapeSim& s0 return filterInfo; } - PxFilterInfo Sc::NPhaseCore::filterRbCollisionPair(const ShapeSim& s0, const ShapeSim& s1, PxU32 filterPairIndex, PxU32& isTriggerPair, bool runCallbacks) { const Sc::BodySim* b0 = s0.getBodySim(); @@ -1439,7 +1413,6 @@ PxFilterInfo Sc::NPhaseCore::filterRbCollisionPair(const ShapeSim& s0, const Sha } } - Sc::ActorPair* Sc::NPhaseCore::findActorPair(ShapeSim* s0, ShapeSim* s1, Ps::IntBool isReportPair) { PX_ASSERT(!(s0->getFlags() & PxShapeFlag::eTRIGGER_SHAPE) @@ -1447,17 +1420,16 @@ Sc::ActorPair* Sc::NPhaseCore::findActorPair(ShapeSim* s0, ShapeSim* s1, Ps::Int // This method is only for the case where a ShapeInteraction is going to be created. // Else we might create an ActorPair that does not get referenced and causes a mem leak. - BodyPairKey key; RigidSim* aLess = &s0->getRbSim(); RigidSim* aMore = &s1->getRbSim(); - if(aLess > aMore) + if (aLess->getID() > aMore->getID()) Ps::swap(aLess, aMore); - key.mSim0 = aLess; - key.mSim1 = aMore; + key.mSim0 = aLess->getID(); + key.mSim1 = aMore->getID(); Sc::ActorPair*& actorPair = mActorPairMap[key]; @@ -1469,8 +1441,7 @@ Sc::ActorPair* Sc::NPhaseCore::findActorPair(ShapeSim* s0, ShapeSim* s1, Ps::Int else actorPair = mActorPairReportPool.construct(s0->getRbSim(), s1->getRbSim()); } - - + Ps::IntBool actorPairHasReports = actorPair->isReportPair(); if (!isReportPair || actorPairHasReports) @@ -1479,8 +1450,7 @@ Sc::ActorPair* Sc::NPhaseCore::findActorPair(ShapeSim* s0, ShapeSim* s1, Ps::Int { PxU32 size = aLess->getActorInteractionCount(); Interaction** interactions = aLess->getActorInteractions(); - - + ActorPairReport* actorPairReport = mActorPairReportPool.construct(s0->getRbSim(), s1->getRbSim()); actorPairReport->convert(*actorPair); @@ -1504,7 +1474,6 @@ Sc::ActorPair* Sc::NPhaseCore::findActorPair(ShapeSim* s0, ShapeSim* s1, Ps::Int return actorPair; } - PX_FORCE_INLINE void Sc::NPhaseCore::destroyActorPairReport(ActorPairReport& aPair) { PX_ASSERT(aPair.isReportPair()); @@ -1513,7 +1482,6 @@ PX_FORCE_INLINE void Sc::NPhaseCore::destroyActorPairReport(ActorPairReport& aPa mActorPairReportPool.destroy(&aPair); } - Sc::ElementSimInteraction* Sc::NPhaseCore::convert(ElementSimInteraction* pair, InteractionType::Enum newType, PxFilterInfo& filterInfo, bool removeFromDirtyList, PxsContactManagerOutputIterator& outputs, bool useAdaptiveForce) { @@ -1699,6 +1667,7 @@ public: TriggerInteraction** pairsToDeactivate, volatile PxI32& pairsToDeactivateCount, Scene& scene) : + Cm::Task(scene.getContextId()), mTriggerPairs(triggerPairs), mTriggerPairCount(triggerPairCount), mLock(lock), @@ -1794,7 +1763,6 @@ public: return "ScNPhaseCore.triggerInteractionWork"; } - public: static const PxU32 sTriggerPairsPerTask = 64; @@ -1877,7 +1845,6 @@ void Sc::NPhaseCore::processTriggerInteractions(PxBaseTask* continuation) } } - void Sc::NPhaseCore::mergeProcessedTriggerInteractions(PxBaseTask*) { if (mTmpTriggerProcessingBlock) @@ -1895,7 +1862,6 @@ void Sc::NPhaseCore::mergeProcessedTriggerInteractions(PxBaseTask*) } } - void Sc::NPhaseCore::visualize(Cm::RenderOutput& renderOut, PxsContactManagerOutputIterator& outputs) { if(mOwnerScene.getVisualizationScale() == 0.0f) @@ -1905,10 +1871,8 @@ void Sc::NPhaseCore::visualize(Cm::RenderOutput& renderOut, PxsContactManagerOut PxU32 nbActiveInteractions = mOwnerScene.getNbActiveInteractions(InteractionType::eOVERLAP); while(nbActiveInteractions--) static_cast<ShapeInteraction*>(*interactions++)->visualize(renderOut, outputs); - } - void Sc::NPhaseCore::processPersistentContactEvents(PxsContactManagerOutputIterator& outputs) { //TODO: put back this optimization -- now we have to do this stuff if at least one client has a callback registered. @@ -1953,7 +1917,6 @@ void Sc::NPhaseCore::processPersistentContactEvents(PxsContactManagerOutputItera } } - void Sc::NPhaseCore::fireCustomFilteringCallbacks(PxsContactManagerOutputIterator& outputs, bool useAdaptiveForce) { PX_PROFILE_ZONE("Sim.fireCustomFilteringCallbacks", mOwnerScene.getContextId()); @@ -2052,13 +2015,11 @@ void Sc::NPhaseCore::fireCustomFilteringCallbacks(PxsContactManagerOutputIterato } } - void Sc::NPhaseCore::addToDirtyInteractionList(Interaction* pair) { mDirtyInteractions.insert(pair); } - void Sc::NPhaseCore::removeFromDirtyInteractionList(Interaction* pair) { PX_ASSERT(mDirtyInteractions.contains(pair)); @@ -2066,6 +2027,11 @@ void Sc::NPhaseCore::removeFromDirtyInteractionList(Interaction* pair) mDirtyInteractions.erase(pair); } +void Sc::NPhaseCore::reserveSpaceInNphaseCore(const PxU32 nbContactManagers) +{ + PX_UNUSED(nbContactManagers); +} + void Sc::NPhaseCore::updateDirtyInteractions(PxsContactManagerOutputIterator& outputs, bool useAdaptiveForce) { @@ -2127,7 +2093,6 @@ void Sc::NPhaseCore::updateDirtyInteractions(PxsContactManagerOutputIterator& ou mDirtyInteractions.clear(); } - void Sc::NPhaseCore::releaseElementPair(ElementSimInteraction* pair, PxU32 flags, const PxU32 ccdPass, bool removeFromDirtyList, PxsContactManagerOutputIterator& outputs, bool useAdaptiveForce) { @@ -2211,12 +2176,14 @@ void Sc::NPhaseCore::lostTouchReports(ShapeInteraction* si, PxU32 flags, PxU32 c { RigidSim* sim0 = static_cast<RigidSim*>(&si->getActor0()); RigidSim* sim1 = static_cast<RigidSim*>(&si->getActor1()); - if (sim0 > sim1) - Ps::swap(sim0, sim1); BodyPairKey pair; - pair.mSim0 = sim0; - pair.mSim1 = sim1; + + if (sim0->getID() > sim1->getID()) + Ps::swap(sim0, sim1); + + pair.mSim0 = sim0->getID(); + pair.mSim1 = sim1->getID(); mActorPairMap.erase(pair); @@ -2254,19 +2221,15 @@ void Sc::NPhaseCore::lostTouchReports(ShapeInteraction* si, PxU32 flags, PxU32 c } } - void Sc::NPhaseCore::releaseShapeInteraction(ShapeInteraction* si, PxU32 flags, const PxU32 ccdPass, PxsContactManagerOutputIterator& outputs, bool useAdaptiveForce) { - if (flags & PairReleaseFlag::eSHAPE_BP_VOLUME_REMOVED) { lostTouchReports(si, flags, ccdPass, outputs, useAdaptiveForce); } mShapeInteractionPool.destroy(si); - } - void Sc::NPhaseCore::clearContactReportActorPairs(bool shrinkToZero) { for(PxU32 i=0; i < mContactReportActorPairSet.size(); i++) @@ -2283,16 +2246,11 @@ void Sc::NPhaseCore::clearContactReportActorPairs(bool shrinkToZero) } else { - - RigidSim* sim0 = &aPair->getActorA(); - RigidSim* sim1 = &aPair->getActorB(); - - if(sim0 > sim1) - Ps::swap(sim0, sim1); - BodyPairKey pair; - pair.mSim0 = sim0; - pair.mSim1 = sim1; + PxU32 actorAID = aPair->getActorAID(); + PxU32 actorBID = aPair->getActorBID(); + pair.mSim0 = PxMin(actorAID, actorBID); + pair.mSim1 = PxMax(actorAID, actorBID); mActorPairMap.erase(pair); destroyActorPairReport(*aPair); @@ -2305,7 +2263,6 @@ void Sc::NPhaseCore::clearContactReportActorPairs(bool shrinkToZero) mContactReportActorPairSet.reset(); } - #if PX_USE_PARTICLE_SYSTEM_API Sc::ParticleElementRbElementInteraction* Sc::NPhaseCore::insertParticleElementRbElementPair(ParticlePacketShape& particleShape, ShapeSim& rbShape, ActorElementPair* actorElementPair, const PxU32 ccdPass) { @@ -2318,7 +2275,6 @@ Sc::ParticleElementRbElementInteraction* Sc::NPhaseCore::insertParticleElementRb } #endif - void Sc::NPhaseCore::addToPersistentContactEventPairs(ShapeInteraction* si) { // Pairs which request events which do not get triggered by the sdk and thus need to be tested actively every frame. @@ -2347,7 +2303,6 @@ void Sc::NPhaseCore::addToPersistentContactEventPairs(ShapeInteraction* si) mNextFramePersistentContactEventPairIndex++; } - void Sc::NPhaseCore::addToPersistentContactEventPairsDelayed(ShapeInteraction* si) { // Pairs which request events which do not get triggered by the sdk and thus need to be tested actively every frame. @@ -2362,7 +2317,6 @@ void Sc::NPhaseCore::addToPersistentContactEventPairsDelayed(ShapeInteraction* s mPersistentContactEventPairList.pushBack(si); } - void Sc::NPhaseCore::removeFromPersistentContactEventPairs(ShapeInteraction* si) { PX_ASSERT(si->getPairFlags() & (PxPairFlag::eNOTIFY_TOUCH_PERSISTS | ShapeInteraction::CONTACT_FORCE_THRESHOLD_PAIRS)); @@ -2396,7 +2350,6 @@ void Sc::NPhaseCore::removeFromPersistentContactEventPairs(ShapeInteraction* si) mPersistentContactEventPairList[index]->mReportPairIndex = index; } - void Sc::NPhaseCore::addToForceThresholdContactEventPairs(ShapeInteraction* si) { PX_ASSERT(si->getPairFlags() & ShapeInteraction::CONTACT_FORCE_THRESHOLD_PAIRS); @@ -2410,7 +2363,6 @@ void Sc::NPhaseCore::addToForceThresholdContactEventPairs(ShapeInteraction* si) mForceThresholdContactEventPairList.pushBack(si); } - void Sc::NPhaseCore::removeFromForceThresholdContactEventPairs(ShapeInteraction* si) { PX_ASSERT(si->getPairFlags() & ShapeInteraction::CONTACT_FORCE_THRESHOLD_PAIRS); @@ -2428,14 +2380,12 @@ void Sc::NPhaseCore::removeFromForceThresholdContactEventPairs(ShapeInteraction* mForceThresholdContactEventPairList[index]->mReportPairIndex = index; } - PxU8* Sc::NPhaseCore::reserveContactReportPairData(PxU32 pairCount, PxU32 extraDataSize, PxU32& bufferIndex) { extraDataSize = Sc::ContactStreamManager::computeExtraDataBlockSize(extraDataSize); return mContactReportBuffer.allocateNotThreadSafe(extraDataSize + (pairCount * sizeof(Sc::ContactShapePair)), bufferIndex); } - PxU8* Sc::NPhaseCore::resizeContactReportPairData(PxU32 pairCount, PxU32 extraDataSize, Sc::ContactStreamManager& csm) { PX_ASSERT((pairCount > csm.maxPairCount) || (extraDataSize > csm.getMaxExtraDataSize())); @@ -2470,17 +2420,14 @@ PxU8* Sc::NPhaseCore::resizeContactReportPairData(PxU32 pairCount, PxU32 extraDa if (extraDataSize > maxExtraDataSize) csm.setMaxExtraDataSize(extraDataSize); } - return stream; } - Sc::ActorPairContactReportData* Sc::NPhaseCore::createActorPairContactReportData() { return mActorPairContactReportDataPool.construct(); } - void Sc::NPhaseCore::releaseActorPairContactReportData(ActorPairContactReportData* data) { mActorPairContactReportDataPool.destroy(data); @@ -2499,5 +2446,3 @@ void Sc::NPhaseCore::pool_deleteParticleElementRbElementPair(ParticleElementRbEl mActorElementPairPool.destroy(aep); } #endif // PX_USE_PARTICLE_SYSTEM_API - - diff --git a/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.h b/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.h index 1c178018..6b40edf2 100644 --- a/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.h +++ b/PhysX_3.4/Source/SimulationController/src/ScNPhaseCore.h @@ -119,8 +119,8 @@ namespace Sc struct BodyPairKey { - RigidSim* mSim0; - RigidSim* mSim1; + PxU32 mSim0; + PxU32 mSim1; bool operator == (const BodyPairKey& pair) const { return mSim0 == pair.mSim0 && mSim1 == pair.mSim1; } }; @@ -129,12 +129,8 @@ namespace Sc PX_INLINE PxU32 hash(const BodyPairKey& key) { - PxU32 add0 = (size_t(key.mSim0))&0xFFFFFFFF; - PxU32 add1 = (size_t(key.mSim1))&0xFFFFFFFF; - - //Clear the lower 2 bits, they will be 0s anyway - add0 = add0 >> 2; - add1 = add1 >> 2; + PxU32 add0 = key.mSim0; + PxU32 add1 = key.mSim1; PxU32 base = PxU32((add0 & 0xFFFF) | (add1 << 16)); @@ -203,6 +199,8 @@ namespace Sc void removeFromDirtyInteractionList(Interaction* interaction); void updateDirtyInteractions(PxsContactManagerOutputIterator& outputs, bool useAdaptiveForce); + void reserveSpaceInNphaseCore(const PxU32 nbContactManagers); + /* Description: Perform trigger overlap tests. diff --git a/PhysX_3.4/Source/SimulationController/src/ScScene.cpp b/PhysX_3.4/Source/SimulationController/src/ScScene.cpp index 1bdeaffe..1f161f18 100644 --- a/PhysX_3.4/Source/SimulationController/src/ScScene.cpp +++ b/PhysX_3.4/Source/SimulationController/src/ScScene.cpp @@ -149,10 +149,14 @@ private: public: - ScAfterIntegrationTask(const IG::NodeIndex* const indices, PxU32 numBodies, PxsContext* context, Context* dynamicsContext, PxsTransformCache& cache, - Sc::Scene& scene) : - mIndices(indices), mNumBodies(numBodies), mContext(context), mDynamicsContext(dynamicsContext), - mCache(cache), mScene(scene) + ScAfterIntegrationTask(const IG::NodeIndex* const indices, PxU32 numBodies, PxsContext* context, Context* dynamicsContext, PxsTransformCache& cache, Sc::Scene& scene) : + Cm::Task (scene.getContextId()), + mIndices (indices), + mNumBodies (numBodies), + mContext (context), + mDynamicsContext(dynamicsContext), + mCache (cache), + mScene (scene) { } @@ -378,10 +382,15 @@ private: public: - PxgUpdateBodyAndShapeStatusTask(const IG::NodeIndex* const indices, PxU32 numBodies, PxsBodySim* bodySimsLL, PxU32* activatedBodies, PxU32* deactivatedBodies, - Sc::Scene& scene, PxI32& ccdBodyWriteIndex) : - mNodeIndices(indices), mNumBodies(numBodies), mScene(scene), mBodySimsLL(bodySimsLL), mActivatedBodies(activatedBodies), - mDeactivatedBodies(deactivatedBodies), mCCDBodyWriteIndex(ccdBodyWriteIndex) + PxgUpdateBodyAndShapeStatusTask(const IG::NodeIndex* const indices, PxU32 numBodies, PxsBodySim* bodySimsLL, PxU32* activatedBodies, PxU32* deactivatedBodies, Sc::Scene& scene, PxI32& ccdBodyWriteIndex) : + Cm::Task (scene.getContextId()), + mNodeIndices (indices), + mNumBodies (numBodies), + mScene (scene), + mBodySimsLL (bodySimsLL), + mActivatedBodies (activatedBodies), + mDeactivatedBodies (deactivatedBodies), + mCCDBodyWriteIndex (ccdBodyWriteIndex) { } @@ -566,48 +575,48 @@ Sc::Scene::Scene(const PxSceneDesc& desc, PxU64 contextID) : mVisualizationParameterChanged (false), mNbRigidStatics (0), mNbRigidDynamics (0), - mClothPreprocessing (this, "ScScene.clothPreprocessing"), - mSecondPassNarrowPhase (this, "ScScene.secondPassNarrowPhase"), - mPostNarrowPhase (this, "ScScene.postNarrowPhase"), - mParticlePostCollPrep ("ScScene.particlePostCollPrep"), - mParticlePostShapeGen (this, "ScScene.particlePostShapeGen"), - mFinalizationPhase (this, "ScScene.finalizationPhase"), - mUpdateCCDMultiPass (this, "ScScene.updateCCDMultiPass"), - mAfterIntegration (this, "ScScene.afterIntegration"), - mConstraintProjection (this, "ScScene.constraintProjection"), - mPostSolver (this, "ScScene.postSolver"), - mSolver (this, "ScScene.rigidBodySolver"), - mUpdateBodiesAndShapes (this, "ScScene.updateBodiesAndShapes"), - mUpdateSimulationController (this, "ScScene.updateSimulationController"), - mUpdateDynamics (this, "ScScene.updateDynamics"), - mProcessLostContactsTask (this, "ScScene.processLostContact"), - mProcessLostContactsTask2 (this, "ScScene.processLostContact2"), - mProcessLostContactsTask3 (this, "ScScene.processLostContact3"), - mDestroyManagersTask (this, "ScScene.destroyManagers"), - mLostTouchReportsTask (this, "ScScene.lostTouchReports"), - mUnregisterInteractionsTask (this, "ScScene.unregisterInteractions"), - mProcessNarrowPhaseLostTouchTasks(this, "ScScene.processNpLostTouchTask"), - mProcessNPLostTouchEvents (this, "ScScene.processNPLostTouchEvents"), - mPostThirdPassIslandGenTask (this, "ScScene.postThirdPassIslandGenTask"), - mPostIslandGen (this, "ScScene.postIslandGen"), - mIslandGen (this, "ScScene.islandGen"), - mPreRigidBodyNarrowPhase (this, "ScScene.preRigidBodyNarrowPhase"), - mSetEdgesConnectedTask (this, "ScScene.setEdgesConnectedTask"), - mFetchPatchEventsTask (this, "ScScene.fetchPatchEventsTask"), - mProcessLostPatchesTask (this, "ScScene.processLostSolverPatchesTask"), - mRigidBodyNarrowPhase (this, "ScScene.rigidBodyNarrowPhase"), - mRigidBodyNPhaseUnlock (this, "ScScene.unblockNarrowPhase"), - mPostBroadPhase (this, "ScScene.postBroadPhase"), - mPostBroadPhase2 (this, "ScScene.postBroadPhase2"), - mPostBroadPhase3 (this, "ScScene.postBroadPhase3"), - mPreallocateContactManagers (this, "ScScene.preallocateContactManagers"), - mIslandInsertion (this, "ScScene.islandInsertion"), - mRegisterContactManagers (this, "ScScene.registerContactManagers"), - mRegisterInteractions (this, "ScScene.registerInteractions"), - mRegisterSceneInteractions (this, "ScScene.registerSceneInteractions"), - mBroadPhase (this, "ScScene.broadPhase"), - mAdvanceStep (this, "ScScene.advanceStep"), - mCollideStep (this, "ScScene.collideStep"), + mClothPreprocessing (contextID, this, "ScScene.clothPreprocessing"), + mSecondPassNarrowPhase (contextID, this, "ScScene.secondPassNarrowPhase"), + mPostNarrowPhase (contextID, this, "ScScene.postNarrowPhase"), + mParticlePostCollPrep (contextID, "ScScene.particlePostCollPrep"), + mParticlePostShapeGen (contextID, this, "ScScene.particlePostShapeGen"), + mFinalizationPhase (contextID, this, "ScScene.finalizationPhase"), + mUpdateCCDMultiPass (contextID, this, "ScScene.updateCCDMultiPass"), + mAfterIntegration (contextID, this, "ScScene.afterIntegration"), + mConstraintProjection (contextID, this, "ScScene.constraintProjection"), + mPostSolver (contextID, this, "ScScene.postSolver"), + mSolver (contextID, this, "ScScene.rigidBodySolver"), + mUpdateBodiesAndShapes (contextID, this, "ScScene.updateBodiesAndShapes"), + mUpdateSimulationController (contextID, this, "ScScene.updateSimulationController"), + mUpdateDynamics (contextID, this, "ScScene.updateDynamics"), + mProcessLostContactsTask (contextID, this, "ScScene.processLostContact"), + mProcessLostContactsTask2 (contextID, this, "ScScene.processLostContact2"), + mProcessLostContactsTask3 (contextID, this, "ScScene.processLostContact3"), + mDestroyManagersTask (contextID, this, "ScScene.destroyManagers"), + mLostTouchReportsTask (contextID, this, "ScScene.lostTouchReports"), + mUnregisterInteractionsTask (contextID, this, "ScScene.unregisterInteractions"), + mProcessNarrowPhaseLostTouchTasks(contextID, this, "ScScene.processNpLostTouchTask"), + mProcessNPLostTouchEvents (contextID, this, "ScScene.processNPLostTouchEvents"), + mPostThirdPassIslandGenTask (contextID, this, "ScScene.postThirdPassIslandGenTask"), + mPostIslandGen (contextID, this, "ScScene.postIslandGen"), + mIslandGen (contextID, this, "ScScene.islandGen"), + mPreRigidBodyNarrowPhase (contextID, this, "ScScene.preRigidBodyNarrowPhase"), + mSetEdgesConnectedTask (contextID, this, "ScScene.setEdgesConnectedTask"), + mFetchPatchEventsTask (contextID, this, "ScScene.fetchPatchEventsTask"), + mProcessLostPatchesTask (contextID, this, "ScScene.processLostSolverPatchesTask"), + mRigidBodyNarrowPhase (contextID, this, "ScScene.rigidBodyNarrowPhase"), + mRigidBodyNPhaseUnlock (contextID, this, "ScScene.unblockNarrowPhase"), + mPostBroadPhase (contextID, this, "ScScene.postBroadPhase"), + mPostBroadPhase2 (contextID, this, "ScScene.postBroadPhase2"), + mPostBroadPhase3 (contextID, this, "ScScene.postBroadPhase3"), + mPreallocateContactManagers (contextID, this, "ScScene.preallocateContactManagers"), + mIslandInsertion (contextID, this, "ScScene.islandInsertion"), + mRegisterContactManagers (contextID, this, "ScScene.registerContactManagers"), + mRegisterInteractions (contextID, this, "ScScene.registerInteractions"), + mRegisterSceneInteractions (contextID, this, "ScScene.registerSceneInteractions"), + mBroadPhase (contextID, this, "ScScene.broadPhase"), + mAdvanceStep (contextID, this, "ScScene.advanceStep"), + mCollideStep (contextID, this, "ScScene.collideStep"), mTaskPool (16384), mContactReportsNeedPostSolverVelocity(false), mSimulationStage (SimulationStage::eCOMPLETE), @@ -2106,6 +2115,11 @@ void Sc::Scene::broadPhase(PxBaseTask* continuation) void Sc::Scene::postBroadPhase(PxBaseTask* continuation) { PX_PROFILE_START_CROSSTHREAD("Basic.postBroadPhase", getContextId()); + + //Notify narrow phase that broad phase has completed + mLLContext->getNphaseImplementationContext()->postBroadPhaseUpdateContactManager(); + mAABBManager->postBroadPhase(continuation, &mRigidBodyNPhaseUnlock); + mAABBManager->getChangedAABBMgActorHandleMap().clear(); // - Finishes broadphase update @@ -2165,8 +2179,11 @@ public: Sc::ShapeSim* mShapes[MaxShapes]; PxU32 mNbShapes; - DirtyShapeUpdatesTask(PxsTransformCache& cache, Bp::BoundsArray& boundsArray) : - mCache(cache), mBoundsArray(boundsArray), mNbShapes(0) + DirtyShapeUpdatesTask(PxU64 contextID, PxsTransformCache& cache, Bp::BoundsArray& boundsArray) : + Cm::Task (contextID), + mCache (cache), + mBoundsArray(boundsArray), + mNbShapes (0) { } @@ -2195,8 +2212,12 @@ public: Bp::BoundsArray& mBoundsArray; - SpeculativeCCDContactDistanceUpdateTask(PxReal* contactDistances, const PxReal dt, Bp::BoundsArray& boundsArray) : - mContactDistances(contactDistances), mDt(dt), mNbBodies(0), mBoundsArray(boundsArray) + SpeculativeCCDContactDistanceUpdateTask(PxU64 contextID, PxReal* contactDistances, const PxReal dt, Bp::BoundsArray& boundsArray) : + Cm::Task (contextID), + mContactDistances (contactDistances), + mDt (dt), + mNbBodies (0), + mBoundsArray (boundsArray) { } @@ -2222,8 +2243,11 @@ public: Sc::ArticulationSim* mArticulation; Bp::BoundsArray& mBoundsArray; - SpeculativeCCDContactDistanceArticulationUpdateTask(PxReal* contactDistances, const PxReal dt, Bp::BoundsArray& boundsArray) : - mContactDistances(contactDistances), mDt(dt), mBoundsArray(boundsArray) + SpeculativeCCDContactDistanceArticulationUpdateTask(PxU64 contextID, PxReal* contactDistances, const PxReal dt, Bp::BoundsArray& boundsArray) : + Cm::Task (contextID), + mContactDistances (contactDistances), + mDt (dt), + mBoundsArray (boundsArray) { } @@ -2250,7 +2274,7 @@ void Sc::Scene::preRigidBodyNarrowPhase(PxBaseTask* continuation) //calculate contact distance for speculative CCD shapes Cm::BitMap::Iterator speculativeCCDIter(mSpeculativeCCDRigidBodyBitMap); - SpeculativeCCDContactDistanceUpdateTask* ccdTask = PX_PLACEMENT_NEW(pool.allocate(sizeof(SpeculativeCCDContactDistanceUpdateTask)), SpeculativeCCDContactDistanceUpdateTask)(mContactDistance->begin(), mDt, *mBoundsArray); + SpeculativeCCDContactDistanceUpdateTask* ccdTask = PX_PLACEMENT_NEW(pool.allocate(sizeof(SpeculativeCCDContactDistanceUpdateTask)), SpeculativeCCDContactDistanceUpdateTask)(getContextId(), mContactDistance->begin(), mDt, *mBoundsArray); IG::IslandSim& islandSim = mSimpleIslandManager->getAccurateIslandSim(); @@ -2270,7 +2294,7 @@ void Sc::Scene::preRigidBodyNarrowPhase(PxBaseTask* continuation) { ccdTask->setContinuation(continuation); ccdTask->removeReference(); - ccdTask = PX_PLACEMENT_NEW(pool.allocate(sizeof(SpeculativeCCDContactDistanceUpdateTask)), SpeculativeCCDContactDistanceUpdateTask)(mContactDistance->begin(), mDt, *mBoundsArray); + ccdTask = PX_PLACEMENT_NEW(pool.allocate(sizeof(SpeculativeCCDContactDistanceUpdateTask)), SpeculativeCCDContactDistanceUpdateTask)(getContextId(), mContactDistance->begin(), mDt, *mBoundsArray); } } } @@ -2291,7 +2315,7 @@ void Sc::Scene::preRigidBodyNarrowPhase(PxBaseTask* continuation) if (articulationSim) { hasContactDistanceChanged = true; - articulationUpdateTask = PX_PLACEMENT_NEW(pool.allocate(sizeof(SpeculativeCCDContactDistanceArticulationUpdateTask)), SpeculativeCCDContactDistanceArticulationUpdateTask)(mContactDistance->begin(), mDt, *mBoundsArray); + articulationUpdateTask = PX_PLACEMENT_NEW(pool.allocate(sizeof(SpeculativeCCDContactDistanceArticulationUpdateTask)), SpeculativeCCDContactDistanceArticulationUpdateTask)(getContextId(), mContactDistance->begin(), mDt, *mBoundsArray); articulationUpdateTask->mArticulation = articulationSim; articulationUpdateTask->setContinuation(continuation); articulationUpdateTask->removeReference(); @@ -2308,7 +2332,7 @@ void Sc::Scene::preRigidBodyNarrowPhase(PxBaseTask* continuation) PxsTransformCache& cache = mLLContext->getTransformCache(); Bp::BoundsArray& boundsArray = mAABBManager->getBoundsArray(); - DirtyShapeUpdatesTask* task = PX_PLACEMENT_NEW(pool.allocate(sizeof(DirtyShapeUpdatesTask)), DirtyShapeUpdatesTask)(cache, boundsArray); + DirtyShapeUpdatesTask* task = PX_PLACEMENT_NEW(pool.allocate(sizeof(DirtyShapeUpdatesTask)), DirtyShapeUpdatesTask)(getContextId(), cache, boundsArray); bool hasDirtyShapes = false; while ((index = dirtyShapeIter.getNext()) != Cm::BitMap::Iterator::DONE) @@ -2323,7 +2347,7 @@ void Sc::Scene::preRigidBodyNarrowPhase(PxBaseTask* continuation) { task->setContinuation(continuation); task->removeReference(); - task = PX_PLACEMENT_NEW(pool.allocate(sizeof(DirtyShapeUpdatesTask)), DirtyShapeUpdatesTask)(cache, boundsArray); + task = PX_PLACEMENT_NEW(pool.allocate(sizeof(DirtyShapeUpdatesTask)), DirtyShapeUpdatesTask)(getContextId(), cache, boundsArray); } } } @@ -2354,13 +2378,12 @@ void Sc::Scene::rigidBodyNarrowPhase(PxBaseTask* continuation) mPostBroadPhase3.addDependent(*continuation); mPostBroadPhase2.setContinuation(&mPostBroadPhase3); mPostBroadPhase.setContinuation(&mPostBroadPhase2); - mRigidBodyNPhaseUnlock.setContinuation(continuation); - mRigidBodyNPhaseUnlock.addReference(); //Must be decremented by both BP and NP before it runs mBroadPhase.setContinuation(&mPostBroadPhase); + mRigidBodyNPhaseUnlock.setContinuation(continuation); + mRigidBodyNPhaseUnlock.addReference(); mLLContext->resetThreadContexts(); - mLLContext->updateContactManager(mDt, mBoundsArray->hasChanged(), mHasContactDistanceChanged, continuation, &mRigidBodyNPhaseUnlock); // Starts update of contact managers if (hasParticleSystems()) { @@ -2389,6 +2412,8 @@ void Sc::Scene::rigidBodyNarrowPhase(PxBaseTask* continuation) } #endif + mLLContext->updateContactManager(mDt, mBoundsArray->hasChanged(), mHasContactDistanceChanged, continuation, &mRigidBodyNPhaseUnlock); // Starts update of contact managers + mPostBroadPhase3.removeReference(); mPostBroadPhase2.removeReference(); mPostBroadPhase.removeReference(); @@ -2494,8 +2519,12 @@ class InteractionNewTouchTask : public Cm::Task const bool mUseAdaptiveForce; public: - InteractionNewTouchTask(PxvContactManagerTouchEvent* events, PxU32 nbEvents, PxsContactManagerOutputIterator& outputs, bool useAdaptiveForce) : mEvents(events), mNbEvents(nbEvents), mOutputs(outputs), - mUseAdaptiveForce(useAdaptiveForce) + InteractionNewTouchTask(PxU64 contextID, PxvContactManagerTouchEvent* events, PxU32 nbEvents, PxsContactManagerOutputIterator& outputs, bool useAdaptiveForce) : + Cm::Task (contextID), + mEvents (events), + mNbEvents (nbEvents), + mOutputs (outputs), + mUseAdaptiveForce (useAdaptiveForce) { } @@ -2695,10 +2724,12 @@ PX_FORCE_INLINE void Sc::Scene::putInteractionsToSleep(PxU32 infoFlag) { const IG::IslandSim& islandSim = mSimpleIslandManager->getSpeculativeIslandSim(); - for (PxU32 a = 0; a < IG::Edge::eEDGE_TYPE_COUNT; ++a) + //KS - only deactivate contact managers based on speculative state to trigger contact gen. When the actors were deactivated based on accurate state + //joints should have been deactivated. + { - PxU32 nbDeactivatingEdges = islandSim.getNbDeactivatingEdges(IG::Edge::EdgeType(a)); - const IG::EdgeIndex* deactivatingEdgeIds = islandSim.getDeactivatingEdges(IG::Edge::EdgeType(a)); + PxU32 nbDeactivatingEdges = islandSim.getNbDeactivatingEdges(IG::Edge::eCONTACT_MANAGER); + const IG::EdgeIndex* deactivatingEdgeIds = islandSim.getDeactivatingEdges(IG::Edge::eCONTACT_MANAGER); for (PxU32 i = 0; i < nbDeactivatingEdges; ++i) { @@ -2749,12 +2780,14 @@ PX_FORCE_INLINE void Sc::Scene::wakeObjectsUp(PxU32 infoFlag) PX_FORCE_INLINE void Sc::Scene::wakeInteractions(PxU32 /*infoFlag*/) { + PX_PROFILE_ZONE("ScScene.wakeInteractions", getContextId()); const IG::IslandSim& speculativeSim = mSimpleIslandManager->getSpeculativeIslandSim(); - for (PxU32 a = 0; a < IG::Edge::eEDGE_TYPE_COUNT; ++a) + //KS - only wake contact managers based on speculative state to trigger contact gen. Waking actors based on accurate state + //should activate and joints. { - PxU32 nbActivatingEdges = speculativeSim.getNbActivatedEdges(IG::Edge::EdgeType(a)); - const IG::EdgeIndex* activatingEdges = speculativeSim.getActivatedEdges(IG::Edge::EdgeType(a)); + PxU32 nbActivatingEdges = speculativeSim.getNbActivatedEdges(IG::Edge::eCONTACT_MANAGER); + const IG::EdgeIndex* activatingEdges = speculativeSim.getActivatedEdges(IG::Edge::eCONTACT_MANAGER); for (PxU32 i = 0; i < nbActivatingEdges; ++i) { @@ -3084,22 +3117,12 @@ void Sc::Scene::updateCCDMultiPass(PxBaseTask* parentContinuation) mCCDBroadPhaseAABB.reserve(2); for (int j = 0; j < 2; j++) { - mPostCCDPass.pushBack( - Cm::DelegateTask<Sc::Scene, &Sc::Scene::postCCDPass>( - this, "ScScene.postCCDPass")); - mUpdateCCDSinglePass.pushBack( - Cm::DelegateTask<Sc::Scene, &Sc::Scene::updateCCDSinglePass>( - this, "ScScene.updateCCDSinglePass")); - mUpdateCCDSinglePass2.pushBack( - Cm::DelegateTask<Sc::Scene, &Sc::Scene::updateCCDSinglePassStage2>( - this, "ScScene.updateCCDSinglePassStage2")); - mUpdateCCDSinglePass3.pushBack(Cm::DelegateTask<Sc::Scene, &Sc::Scene::updateCCDSinglePassStage3>( - this, "ScScene.updateCCDSinglePassStage3")); - mCCDBroadPhase.pushBack( - Cm::DelegateTask<Sc::Scene, &Sc::Scene::ccdBroadPhase>( - this, "ScScene.ccdBroadPhase")); - mCCDBroadPhaseAABB.pushBack(Cm::DelegateTask<Sc::Scene, &Sc::Scene::ccdBroadPhaseAABB>( - this, "ScScene.ccdBroadPhaseAABB")); + mPostCCDPass.pushBack(Cm::DelegateTask<Sc::Scene, &Sc::Scene::postCCDPass>(getContextId(), this, "ScScene.postCCDPass")); + mUpdateCCDSinglePass.pushBack(Cm::DelegateTask<Sc::Scene, &Sc::Scene::updateCCDSinglePass>(getContextId(), this, "ScScene.updateCCDSinglePass")); + mUpdateCCDSinglePass2.pushBack(Cm::DelegateTask<Sc::Scene, &Sc::Scene::updateCCDSinglePassStage2>(getContextId(), this, "ScScene.updateCCDSinglePassStage2")); + mUpdateCCDSinglePass3.pushBack(Cm::DelegateTask<Sc::Scene, &Sc::Scene::updateCCDSinglePassStage3>(getContextId(), this, "ScScene.updateCCDSinglePassStage3")); + mCCDBroadPhase.pushBack(Cm::DelegateTask<Sc::Scene, &Sc::Scene::ccdBroadPhase>(getContextId(), this, "ScScene.ccdBroadPhase")); + mCCDBroadPhaseAABB.pushBack(Cm::DelegateTask<Sc::Scene, &Sc::Scene::ccdBroadPhaseAABB>(getContextId(), this, "ScScene.ccdBroadPhaseAABB")); } } @@ -3126,8 +3149,11 @@ public: static const PxU32 MaxPerTask = 256; - UpdateCCDBoundsTask(Sc::BodySim** bodySims, PxU32 nbToProcess, PxI32* numFastMovingShapes) : mBodySims(bodySims), - mNbToProcess(nbToProcess), mNumFastMovingShapes(numFastMovingShapes) + UpdateCCDBoundsTask(PxU64 contextID, Sc::BodySim** bodySims, PxU32 nbToProcess, PxI32* numFastMovingShapes) : + Cm::Task (contextID), + mBodySims (bodySims), + mNbToProcess (nbToProcess), + mNumFastMovingShapes(numFastMovingShapes) { } @@ -3178,7 +3204,7 @@ void Sc::Scene::ccdBroadPhaseAABB(PxBaseTask* continuation) for (PxU32 i = 0; i < mCcdBodies.size(); i+= UpdateCCDBoundsTask::MaxPerTask) { const PxU32 nbToProcess = PxMin(UpdateCCDBoundsTask::MaxPerTask, mCcdBodies.size() - i); - UpdateCCDBoundsTask* task = PX_PLACEMENT_NEW(flushPool.allocate(sizeof(UpdateCCDBoundsTask)), UpdateCCDBoundsTask)(&mCcdBodies[i], nbToProcess, &mNumFastMovingShapes); + UpdateCCDBoundsTask* task = PX_PLACEMENT_NEW(flushPool.allocate(sizeof(UpdateCCDBoundsTask)), UpdateCCDBoundsTask)(getContextId(), &mCcdBodies[i], nbToProcess, &mNumFastMovingShapes); task->setContinuation(continuation); task->removeReference(); } @@ -3238,6 +3264,7 @@ void Sc::Scene::updateCCDSinglePass(PxBaseTask* continuation) PX_PROFILE_ZONE("Sim.updateCCDSinglePass", getContextId()); mReportShapePairTimeStamp++; // This will makes sure that new report pairs will get created instead of re-using the existing ones. + mAABBManager->postBroadPhase(continuation, NULL); const PxU32 currentPass = mCCDContext->getCurrentCCDPass() + 1; // 0 is reserved for discrete collision phase finishBroadPhase(currentPass, continuation); @@ -3338,12 +3365,12 @@ private: ConstraintProjectionTask& operator = (const ConstraintProjectionTask&); public: - ConstraintProjectionTask(Sc::ConstraintGroupNode* const* projectionRoots, PxU32 projectionRootCount, Ps::Array<Sc::BodySim*>& projectedBodies, PxsContext* llContext) - : - mProjectionRoots(projectionRoots), + ConstraintProjectionTask(Sc::ConstraintGroupNode* const* projectionRoots, PxU32 projectionRootCount, Ps::Array<Sc::BodySim*>& projectedBodies, PxsContext* llContext) : + Cm::Task (llContext->getContextId()), + mProjectionRoots (projectionRoots), mProjectionRootCount(projectionRootCount), - mProjectedBodies(projectedBodies), - mLLContext(llContext) + mProjectedBodies (projectedBodies), + mLLContext (llContext) { } @@ -3757,6 +3784,7 @@ public: public: ScBeforeSolverTask(PxReal dt, IG::SimpleIslandManager* islandManager, PxsSimulationController* simulationController, PxU64 contextID, bool simUsesAdaptiveForce) : + Cm::Task (contextID), mDt (dt), mIslandManager (islandManager), mSimulationController (simulationController), @@ -3863,10 +3891,6 @@ void Sc::Scene::beforeSolver(PxBaseTask* continuation) mBodyGravityDirty = false; } -#if PX_DEBUG -bool DEBUG_solverlock = false; -#endif - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class UpdatProjectedPoseTask : public Cm::Task @@ -3875,7 +3899,10 @@ class UpdatProjectedPoseTask : public Cm::Task PxU32 mNbBodiesToProcess; public: - UpdatProjectedPoseTask(Sc::BodySim** projectedBodies, PxU32 nbBodiesToProcess) : mProjectedBodies(projectedBodies), mNbBodiesToProcess(nbBodiesToProcess) + UpdatProjectedPoseTask(PxU64 contextID, Sc::BodySim** projectedBodies, PxU32 nbBodiesToProcess) : + Cm::Task (contextID), + mProjectedBodies (projectedBodies), + mNbBodiesToProcess (nbBodiesToProcess) { } @@ -3977,7 +4004,7 @@ void Sc::Scene::afterIntegration(PxBaseTask* continuation) for (PxU32 a = 0; a < mProjectedBodies.size(); a += maxBodiesPerTask) { UpdatProjectedPoseTask* task = - PX_PLACEMENT_NEW(flushPool.allocate(sizeof(UpdatProjectedPoseTask)), UpdatProjectedPoseTask)(&mProjectedBodies[a], PxMin(maxBodiesPerTask, mProjectedBodies.size() - a)); + PX_PLACEMENT_NEW(flushPool.allocate(sizeof(UpdatProjectedPoseTask)), UpdatProjectedPoseTask)(getContextId(), &mProjectedBodies[a], PxMin(maxBodiesPerTask, mProjectedBodies.size() - a)); task->setContinuation(continuation); task->removeReference(); } @@ -6150,8 +6177,16 @@ public: PxU32 mNbToSuppress; PxU32 mNbToCallback; - OverlapFilterTask(Sc::NPhaseCore* nPhaseCore, PxFilterInfo* fInfo, const Bp::AABBOverlap* PX_RESTRICT pairs, Bp::BroadPhasePair* bpPairs, const PxU32 nbToProcess) : mNPhaseCore(nPhaseCore), - mPairs(pairs), mBpPairs(bpPairs), mNbToProcess(nbToProcess), mFinfo(fInfo), mNbToKeep(0), mNbToSuppress(0), mNbToCallback(0) + OverlapFilterTask(PxU64 contextID, Sc::NPhaseCore* nPhaseCore, PxFilterInfo* fInfo, const Bp::AABBOverlap* PX_RESTRICT pairs, Bp::BroadPhasePair* bpPairs, const PxU32 nbToProcess) : + Cm::Task (contextID), + mNPhaseCore (nPhaseCore), + mPairs (pairs), + mBpPairs (bpPairs), + mNbToProcess (nbToProcess), + mFinfo (fInfo), + mNbToKeep (0), + mNbToSuppress (0), + mNbToCallback (0) { PxMemZero(mKeepMap, sizeof(mKeepMap)); PxMemZero(mCallbackMap, sizeof(mCallbackMap)); @@ -6169,7 +6204,7 @@ public: if(pair.mPairHandle != BP_INVALID_BP_HANDLE && mBpPairs != NULL) thisPair = &mBpPairs[pair.mPairHandle]; - PxFilterInfo finfo = mNPhaseCore->onOverlapFilter(e0, e1, thisPair); + const PxFilterInfo finfo = mNPhaseCore->onOverlapFilter(e0, e1, thisPair); mFinfo[a] = finfo; @@ -6200,7 +6235,7 @@ class OnOverlapCreatedTask : public Cm::Task public: Sc::NPhaseCore* mNPhaseCore; const Bp::AABBOverlap* PX_RESTRICT mPairs; - PxFilterInfo* mFinfo; + const PxFilterInfo* mFinfo; PxsContactManager** mContactManagers; Sc::ShapeInteraction** mShapeInteractions; Sc::ElementInteractionMarker** mInteractionMarkers; @@ -6208,9 +6243,17 @@ public: PxU32 mNbToProcess; - OnOverlapCreatedTask(Sc::NPhaseCore* nPhaseCore, const Bp::AABBOverlap* PX_RESTRICT pairs, PxFilterInfo* fInfo, PxsContactManager** contactManagers, Sc::ShapeInteraction** shapeInteractions, Sc::ElementInteractionMarker** interactionMarkers, - Bp::BroadPhasePair* bpPairs, PxU32 nbToProcess) : mNPhaseCore(nPhaseCore), mPairs(pairs), mFinfo(fInfo), mContactManagers(contactManagers), mShapeInteractions(shapeInteractions), - mInteractionMarkers(interactionMarkers), mBpPairs(bpPairs), mNbToProcess(nbToProcess) + 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) : + Cm::Task (contextID), + mNPhaseCore (nPhaseCore), + mPairs (pairs), + mFinfo (fInfo), + mContactManagers (contactManagers), + mShapeInteractions (shapeInteractions), + mInteractionMarkers (interactionMarkers), + mBpPairs (bpPairs), + mNbToProcess (nbToProcess) { } @@ -6292,7 +6335,7 @@ void Sc::Scene::preallocateContactManagers(PxBaseTask* continuation) Sc::ShapeSim* s0 = reinterpret_cast<Sc::ShapeSim*>(pair.mUserData0); Sc::ShapeSim* s1 = reinterpret_cast<Sc::ShapeSim*>(pair.mUserData1); - PxFilterInfo finfo = mNPhaseCore->filterRbCollisionPairSecondStage(*s0, *s1, s0->getBodySim(), s1->getBodySim(), INVALID_FILTER_PAIR_INDEX, true); + const PxFilterInfo finfo = mNPhaseCore->filterRbCollisionPairSecondStage(*s0, *s1, s0->getBodySim(), s1->getBodySim(), INVALID_FILTER_PAIR_INDEX, true); task->mFinfo[index] = finfo; @@ -6334,7 +6377,7 @@ void Sc::Scene::preallocateContactManagers(PxBaseTask* continuation) Cm::FlushPool& flushPool = mLLContext->getTaskPool(); - OnOverlapCreatedTask* createTask = PX_PLACEMENT_NEW(flushPool.allocate(sizeof(OnOverlapCreatedTask)), OnOverlapCreatedTask)(mNPhaseCore, p, + OnOverlapCreatedTask* createTask = PX_PLACEMENT_NEW(flushPool.allocate(sizeof(OnOverlapCreatedTask)), OnOverlapCreatedTask)(getContextId(), mNPhaseCore, p, fInfo, cms, shapeInter, markerIter, bpPairs, 0); PxU32 batchSize = 0; @@ -6387,7 +6430,7 @@ void Sc::Scene::preallocateContactManagers(PxBaseTask* continuation) - createTask = PX_PLACEMENT_NEW(flushPool.allocate(sizeof(OnOverlapCreatedTask)), OnOverlapCreatedTask)(mNPhaseCore, p + createdOverlapCount, + createTask = PX_PLACEMENT_NEW(flushPool.allocate(sizeof(OnOverlapCreatedTask)), OnOverlapCreatedTask)(getContextId(), mNPhaseCore, p + createdOverlapCount, fInfo + createdOverlapCount, cms + createdStartIdx, shapeInter + createdStartIdx, markerIter + suppressedStartIdx, bpPairs, 0); batchSize = 0; @@ -6425,6 +6468,24 @@ void Sc::Scene::finishBroadPhase(PxU32 ccdPass, PxBaseTask* continuation) { PX_PROFILE_ZONE("Sim.processNewOverlaps", getContextId()); + + { + //KS - these functions call "registerInActors", while OverlapFilterTask reads the list of interactions + //in an actor. This could lead to a race condition and a crash if they occur at the same time, so we + //serialize these operations + PX_PROFILE_ZONE("Sim.processNewOverlaps.createOverlapsNoShapeInteractions", getContextId()); + for (PxU32 i = Bp::VolumeBuckets::ePARTICLE; i < Bp::VolumeBuckets::eCOUNT; ++i) + { + + PxU32 createdOverlapCount; + const Bp::AABBOverlap* PX_RESTRICT p = aabbMgr->getCreatedOverlaps(i, createdOverlapCount); + + + mLLContext->getSimStats().mNbNewPairs += createdOverlapCount; + mNPhaseCore->onOverlapCreated(p, createdOverlapCount, ccdPass, bpPairs); + } + } + { PxU32 createdOverlapCount; @@ -6454,31 +6515,16 @@ void Sc::Scene::finishBroadPhase(PxU32 ccdPass, PxBaseTask* continuation) for (PxU32 a = 0; a < createdOverlapCount; a += nbPairsPerTask) { PxU32 nbToProcess = PxMin(createdOverlapCount - a, nbPairsPerTask); - OverlapFilterTask* task = PX_PLACEMENT_NEW(flushPool.allocate(sizeof(OverlapFilterTask)), OverlapFilterTask)(mNPhaseCore, mFilterInfo.begin() + a, + OverlapFilterTask* task = PX_PLACEMENT_NEW(flushPool.allocate(sizeof(OverlapFilterTask)), OverlapFilterTask)(getContextId(), mNPhaseCore, mFilterInfo.begin() + a, p + a, bpPairs, nbToProcess); task->setContinuation(&mPreallocateContactManagers); task->removeReference(); mOverlapFilterTasks.pushBack(task); } - } mPreallocateContactManagers.removeReference(); - - { - PX_PROFILE_ZONE("Sim.processNewOverlaps.createOverlapsNoShapeInteractions", getContextId()); - for (PxU32 i = Bp::VolumeBuckets::ePARTICLE; i < Bp::VolumeBuckets::eCOUNT; ++i) - { - - PxU32 createdOverlapCount; - const Bp::AABBOverlap* PX_RESTRICT p = aabbMgr->getCreatedOverlaps(i, createdOverlapCount); - - - mLLContext->getSimStats().mNbNewPairs += createdOverlapCount; - mNPhaseCore->onOverlapCreated(p, createdOverlapCount, ccdPass, bpPairs); - } - } } } diff --git a/PhysX_3.4/Source/SimulationController/src/particles/ScParticleSystemSim.cpp b/PhysX_3.4/Source/SimulationController/src/particles/ScParticleSystemSim.cpp index 0c44d322..5fb2a990 100644 --- a/PhysX_3.4/Source/SimulationController/src/particles/ScParticleSystemSim.cpp +++ b/PhysX_3.4/Source/SimulationController/src/particles/ScParticleSystemSim.cpp @@ -53,7 +53,7 @@ Sc::ParticleSystemSim::ParticleSystemSim(Scene& scene, ParticleSystemCore& core) , mParticlePacketShapePool(PX_DEBUG_EXP("ParticlePacketShapePool")) , mParticlePacketShapes(PX_DEBUG_EXP("ParticleSysPacketShapes")) , mInteractionCount(0) -, mCollisionInputPrepTask(this, "ScParticleSystemSim.prepareCollisionInput") +, mCollisionInputPrepTask(scene.getContextId(), this, "ScParticleSystemSim.prepareCollisionInput") { // Set size of interaction list ActorSim::setInteractionCountHint(32); |