RavEngine
Loading...
Searching...
No Matches
DyContext.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef DY_CONTEXT_H
30#define DY_CONTEXT_H
31
32#include "PxSceneDesc.h"
33#include "DyThresholdTable.h"
34#include "PxcNpThreadContext.h"
35#include "PxsSimulationController.h"
36#include "DyConstraintWriteBack.h"
37#include "foundation/PxAllocator.h"
38
39#define DY_MAX_VELOCITY_COUNT 4
40
41namespace physx
42{
43
44class PxsIslandManager;
45class PxcNpMemBlockPool;
46
47namespace Cm
48{
49 class EventProfiler;
50 class FlushPool;
51}
52
53namespace IG
54{
55 class SimpleIslandManager;
56 class IslandSim;
57}
58
59template<typename T, typename P> class PxcThreadCoherentCache;
60class PxcScratchAllocator;
61struct PxvSimStats;
62class PxTaskManager;
63class PxsContactManagerOutputIterator;
64struct PxsContactManagerOutput;
65class PxsContactManager;
66struct PxsContactManagerOutputCounts;
67
68class PxvNphaseImplementationContext;
69
70
71namespace Dy
72{
73
74
76{
77 PX_NOCOPY(Context)
78public:
79
80 // PT: TODO: consider making all of these public at this point
81 PX_FORCE_INLINE PxReal getMaxBiasCoefficient() const { return mMaxBiasCoefficient; }
82 PX_FORCE_INLINE void setMaxBiasCoefficient(PxReal coeff) { mMaxBiasCoefficient = coeff; }
83
99
105
110 PX_FORCE_INLINE PxReal getLengthScale() const { return mLengthScale; }
111
127
133
144
155
161
167
172 PX_FORCE_INLINE ThresholdStream& getThresholdStream() { return *mThresholdStream; }
173
174 PX_FORCE_INLINE ThresholdStream& getForceChangedThresholdStream() { return *mForceChangedThresholdStream; }
175
180 PX_FORCE_INLINE ThresholdTable& getThresholdTable() { return mThresholdTable; }
181
187
191 virtual void destroy() = 0;
192
193 PX_FORCE_INLINE PxcDataStreamPool& getContactStreamPool() { return mContactStreamPool; }
194
195 PX_FORCE_INLINE PxcDataStreamPool& getPatchStreamPool() { return mPatchStreamPool; }
196
197 PX_FORCE_INLINE PxcDataStreamPool& getForceStreamPool() { return mForceStreamPool; }
198
199 PX_FORCE_INLINE PxPinnedArray<Dy::ConstraintWriteback>& getConstraintWriteBackPool() { return mConstraintWriteBackPool; }
200
205 PX_FORCE_INLINE PxReal getDt() const { return mDt; }
210 PX_FORCE_INLINE PxReal getInvDt() const { return mInvDt; }
211
212 PX_FORCE_INLINE PxVec3 getGravity() const { return mGravity; }
213
229 virtual void update(IG::SimpleIslandManager& simpleIslandManager, PxBaseTask* continuation, PxBaseTask* processLostTouchTask,
230 PxvNphaseImplementationContext* nPhaseContext, const PxU32 maxPatchesPerCM, const PxU32 maxArticulationLinks, const PxReal dt, const PxVec3& gravity, PxBitMapPinned& changedHandleMap) = 0;
231
232 virtual void processLostPatches(IG::SimpleIslandManager& simpleIslandManager, PxsContactManager** lostPatchManagers, PxU32 nbLostPatchManagers, PxsContactManagerOutputCounts* outCounts) = 0;
233 virtual void processFoundPatches(IG::SimpleIslandManager& simpleIslandManager, PxsContactManager** foundPatchManagers, PxU32 nbFoundPatchManagers, PxsContactManagerOutputCounts* outCounts) = 0;
234
235
239 virtual void updateBodyCore(PxBaseTask* continuation) = 0;
240
244 virtual void mergeResults() = 0;
245
246 virtual void setSimulationController(PxsSimulationController* simulationController) = 0;
247
248 virtual void getDataStreamBase(void*& contactStreamBase, void*& patchStreamBase, void*& forceAndIndiceStreamBase) = 0;
249
250 virtual PxSolverType::Enum getSolverType() const = 0;
251
252 void createThresholdStream(PxVirtualAllocatorCallback& callback) { PX_ASSERT(!mThresholdStream); mThresholdStream = PX_NEW(ThresholdStream)(callback); }
253
254 void createForceChangeThresholdStream(PxVirtualAllocatorCallback& callback) { PX_ASSERT(!mForceChangedThresholdStream); mForceChangedThresholdStream = PX_NEW(ThresholdStream)(callback); }
255
256 //Forces any cached body state to be updated!
257 void setStateDirty(bool dirty) { mBodyStateDirty = dirty; }
258
259 bool isStateDirty() { return mBodyStateDirty;}
260
261 void setSuppressReadback(bool suppressReadback) { mSuppressReadback = suppressReadback; }
262
263 bool getSuppressReadback() { return mSuppressReadback; }
264
265 void setDt(const PxReal dt) { mDt = dt; }
266
267protected:
268
269 Context(IG::SimpleIslandManager* islandManager, PxVirtualAllocatorCallback* allocatorCallback,
270 PxvSimStats& simStats, bool enableStabilization, bool useEnhancedDeterminism,
271 const PxReal maxBiasCoefficient, const PxReal lengthScale) :
272 mThresholdStream (NULL),
273 mForceChangedThresholdStream(NULL),
274 mIslandManager (islandManager),
275 mDt (1.0f),
276 mInvDt (1.0f),
277 mMaxBiasCoefficient (maxBiasCoefficient),
278 mEnableStabilization (enableStabilization),
279 mUseEnhancedDeterminism (useEnhancedDeterminism),
280 mBounceThreshold (-2.0f),
281 mLengthScale (lengthScale),
282 mSolverBatchSize (32),
283 mConstraintWriteBackPool (PxVirtualAllocator(allocatorCallback)),
284 mSimStats (simStats),
285 mBodyStateDirty (false),
286 mSuppressReadback (false)
287 {
288 }
289
290 virtual ~Context()
291 {
292 PX_DELETE(mThresholdStream);
293 PX_DELETE(mForceChangedThresholdStream);
294 }
295
296 ThresholdStream* mThresholdStream;
297 ThresholdStream* mForceChangedThresholdStream;
298 ThresholdTable mThresholdTable;
299
300 IG::SimpleIslandManager* mIslandManager;
301 PxsSimulationController* mSimulationController;
305 PxReal mDt;
309 PxReal mInvDt;
310
311 PxReal mMaxBiasCoefficient;
312
313 const bool mEnableStabilization;
314
315 const bool mUseEnhancedDeterminism;
316
317 PxVec3 mGravity;
322
331
336
341
342
347
352
357
358
363
368
374
379
384
385 PxvSimStats& mSimStats;
386
387 bool mBodyStateDirty;
388 bool mSuppressReadback;
389};
390
391Context* createDynamicsContext( PxcNpMemBlockPool* memBlockPool,
392 PxcScratchAllocator& scratchAllocator, Cm::FlushPool& taskPool,
393 PxvSimStats& simStats, PxTaskManager* taskManager, PxVirtualAllocatorCallback* allocatorCallback, PxsMaterialManager* materialManager,
394 IG::SimpleIslandManager* islandManager, PxU64 contextID,
395 const bool enableStabilization, const bool useEnhancedDeterminism, const PxReal maxBiasCoefficient,
396 const bool frictionEveryIteration, const PxReal lengthScale
397 );
398
399Context* createTGSDynamicsContext(PxcNpMemBlockPool* memBlockPool,
400 PxcScratchAllocator& scratchAllocator, Cm::FlushPool& taskPool,
401 PxvSimStats& simStats, PxTaskManager* taskManager, PxVirtualAllocatorCallback* allocatorCallback, PxsMaterialManager* materialManager,
402 IG::SimpleIslandManager* islandManager, PxU64 contextID,
403 const bool enableStabilization, const bool useEnhancedDeterminism, const PxReal lengthScale
404);
405
406
407}
408
409}
410
411#endif
412
Definition CmFlushPool.h:49
Definition DyContext.h:76
PX_FORCE_INLINE ThresholdTable & getThresholdTable()
Returns the threshold table.
Definition DyContext.h:180
PX_FORCE_INLINE void setFrictionOffsetThreshold(PxReal offset)
Sets the friction offset threshold.
Definition DyContext.h:126
PX_FORCE_INLINE void setSolverArticBatchSize(PxU32 f)
Sets the solver batch size.
Definition DyContext.h:154
PX_FORCE_INLINE PxU32 getSolverBatchSize() const
Returns the solver batch size.
Definition DyContext.h:138
PX_FORCE_INLINE void setFrictionType(PxFrictionType::Enum f)
Sets the friction model to be used.
Definition DyContext.h:186
PxcDataStreamPool mForceStreamPool
Structure to encapsulate force stream allocations. Used by GPU solver to reference pre-allocated pinn...
Definition DyContext.h:378
PX_FORCE_INLINE PxReal getLengthScale() const
Returns the length scale.
Definition DyContext.h:110
virtual void updateBodyCore(PxBaseTask *continuation)=0
This method copy gpu solver body data to cpu body core.
virtual void mergeResults()=0
Called after update's task chain has completed. This collects the results of the solver together.
PX_FORCE_INLINE PxReal getInvDt() const
Returns 1/(current frame's timestep)
Definition DyContext.h:210
PxcDataStreamPool mPatchStreamPool
Struct to encapsulate the contact patch stream allocations. Used by GPU solver to reference pre-alloc...
Definition DyContext.h:373
PxcDataStreamPool mContactStreamPool
Structure to encapsulate contact stream allocations. Used by GPU solver to reference pre-allocated pi...
Definition DyContext.h:367
PX_FORCE_INLINE PxReal getFrictionOffsetThreshold() const
Returns the friction offset threshold.
Definition DyContext.h:93
PX_FORCE_INLINE PxFrictionType::Enum getFrictionType() const
Returns the friction model being used.
Definition DyContext.h:166
PxReal mDt
Time-step.
Definition DyContext.h:305
PxReal mBounceThreshold
Threshold controlling the relative velocity at which the solver transitions between restitution and b...
Definition DyContext.h:326
PX_FORCE_INLINE PxU32 getMaxSolverConstraintSize() const
Returns the maximum solver constraint size.
Definition DyContext.h:160
PX_FORCE_INLINE void setCorrelationDistance(PxReal f)
Sets the correlation distance.
Definition DyContext.h:121
PX_FORCE_INLINE PxReal getCorrelationDistance() const
Returns the correlation distance.
Definition DyContext.h:98
PxReal mCCDSeparationThreshold
Threshold controlling whether distant contacts are processed using bias, restitution or a combination...
Definition DyContext.h:335
PxReal mCorrelationDistance
Threshold for controlling friction correlation.
Definition DyContext.h:340
PX_FORCE_INLINE PxReal getDt() const
Returns the current frame's timestep.
Definition DyContext.h:205
PxU32 mSolverArticBatchSize
The minimum number of articulations required to generate a solver task chain.
Definition DyContext.h:356
virtual void update(IG::SimpleIslandManager &simpleIslandManager, PxBaseTask *continuation, PxBaseTask *processLostTouchTask, PxvNphaseImplementationContext *nPhaseContext, const PxU32 maxPatchesPerCM, const PxU32 maxArticulationLinks, const PxReal dt, const PxVec3 &gravity, PxBitMapPinned &changedHandleMap)=0
The entry point for the constraint solver.
PX_FORCE_INLINE PxReal getCCDSeparationThreshold() const
Returns the CCD separation threshold.
Definition DyContext.h:104
PX_FORCE_INLINE void setSolverBatchSize(PxU32 f)
Sets the solver batch size.
Definition DyContext.h:143
virtual void destroy()=0
Destroys this dynamics context.
PxFrictionType::Enum mFrictionType
The current friction model being used.
Definition DyContext.h:362
PX_FORCE_INLINE ThresholdStream & getThresholdStream()
Returns the threshold stream.
Definition DyContext.h:172
PxPinnedArray< Dy::ConstraintWriteback > mConstraintWriteBackPool
Structure to encapsulate constraint write back allocations. Used by GPU/CPU solver to reference pre-a...
Definition DyContext.h:383
PxReal mFrictionOffsetThreshold
Threshold controlling whether friction anchors are constructed or not. If the separation is above mFr...
Definition DyContext.h:330
PxU32 mMaxSolverConstraintSize
max solver constraint size
Definition DyContext.h:321
PxReal mInvDt
1/time-step.
Definition DyContext.h:309
PxReal mLengthScale
The length scale from PxTolerancesScale::length.
Definition DyContext.h:346
PX_FORCE_INLINE PxReal getBounceThreshold() const
Returns the bounce threshold.
Definition DyContext.h:88
PxU32 mSolverBatchSize
The minimum size of an island to generate a solver task chain.
Definition DyContext.h:351
PX_FORCE_INLINE void setCCDSeparationThreshold(PxReal offset)
Sets the friction offset threshold.
Definition DyContext.h:132
PX_FORCE_INLINE void setBounceThreshold(PxReal f)
Sets the bounce threshold.
Definition DyContext.h:116
PX_FORCE_INLINE PxU32 getSolverArticBatchSize() const
Returns the solver batch size.
Definition DyContext.h:149
Definition DyThresholdTable.h:81
Definition DyThresholdTable.h:90
Definition PxsSimpleIslandManager.h:87
Definition PxArray.h:53
Base class of all task types.
Definition PxTask.h:45
The PxTaskManager interface.
Definition PxTaskManager.h:81
3 Element vector class.
Definition PxVec3.h:50
Definition PxAllocator.h:140
Definition PxcNpMemBlockPool.h:52
Definition PxcScratchAllocator.h:42
Definition PxsContactManager.h:77
Definition PxsMaterialManager.h:126
Definition PxsSimulationController.h:124
Definition PxvNphaseImplementationContext.h:120
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Enum
Definition PxSceneDesc.h:71
Enum
Definition PxSceneDesc.h:89
Definition PxcNpThreadContext.h:64
Definition PxvSimStats.h:52