RavEngine
Loading...
Searching...
No Matches
PxsContext.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 PXS_CONTEXT_H
30#define PXS_CONTEXT_H
31
32#include "foundation/PxPinnedArray.h"
33#include "PxVisualizationParameter.h"
34#include "PxSceneDesc.h"
35
36#include "common/PxRenderOutput.h"
37
38#include "CmPool.h"
39
40#include "PxvNphaseImplementationContext.h"
41#include "PxvSimStats.h"
42#include "PxsContactManager.h"
43#include "PxcNpBatch.h"
44#include "PxcConstraintBlockStream.h"
45#include "PxcNpCacheStreamPair.h"
46#include "PxcNpMemBlockPool.h"
47#include "CmUtils.h"
48#include "CmTask.h"
49
50#include "PxContactModifyCallback.h"
51
52#include "PxsTransformCache.h"
53#include "GuPersistentContactManifold.h"
54
55#if PX_SUPPORT_GPU_PHYSX
56namespace physx
57{
58 class PxCudaContextManager;
59}
60#endif
61
62namespace physx
63{
64class PxsRigidBody;
65struct PxcConstraintBlock;
66class PxsMaterialManager;
67class PxsCCDContext;
68struct PxsContactManagerOutput;
69struct PxvContactManagerTouchEvent;
70
71namespace Cm
72{
73 class FlushPool;
74}
75
76namespace IG
77{
78 class SimpleIslandManager;
79 typedef PxU32 EdgeIndex;
80}
81
82enum PxsTouchEventCount
83{
84 PXS_LOST_TOUCH_COUNT,
85 PXS_NEW_TOUCH_COUNT,
86 PXS_CCD_RETOUCH_COUNT, // pairs that are touching at a CCD pass and were touching at discrete collision or at a previous CCD pass already
87 // (but they could have lost touch in between)
88 PXS_TOUCH_EVENT_COUNT
89};
90
92{
93 PX_NOCOPY(PxsContext)
94public:
96 PxCudaContextManager*, const PxU32 poolSlabSize, PxU64 contextID);
98
99 void createTransformCache(PxVirtualAllocatorCallback& allocatorCallback);
100
101 PxsContactManager* createContactManager(PxsContactManager* contactManager, const bool useCCD);
102 void createCache(Gu::Cache& cache, PxGeometryType::Enum geomType0, PxGeometryType::Enum geomType1);
103 void destroyCache(Gu::Cache& cache);
104 void destroyContactManager(PxsContactManager* cm);
105
106 PX_FORCE_INLINE PxU64 getContextId() const { return mContextID; }
107
108 // Collision properties
109 PX_FORCE_INLINE PxContactModifyCallback* getContactModifyCallback() const { return mContactModifyCallback; }
110 PX_FORCE_INLINE void setContactModifyCallback(PxContactModifyCallback* c) { mContactModifyCallback = c; mNpImplementationContext->setContactModifyCallback(c);}
111
112
113 // resource-related
114 void setScratchBlock(void* addr, PxU32 size);
115
116 PX_FORCE_INLINE void setContactDistance(const PxFloatArrayPinned* contactDistances) { mContactDistances = contactDistances; }
117
118 // Task-related
119 void updateContactManager(PxReal dt, bool hasBoundsArrayChanged, bool hasContactDistanceChanged, PxBaseTask* continuation,
120 PxBaseTask* firstPassContinuation, Cm::FanoutTask* updateBoundAndShapeTask);
121 void secondPassUpdateContactManager(PxReal dt, PxBaseTask* continuation);
122 void fetchUpdateContactManager();
123 void swapStreams();
124
125 void resetThreadContexts();
126
127 // Manager status change
128 bool getManagerTouchEventCount(int* newTouch, int* lostTouch, int* ccdTouch) const;
129 bool fillManagerTouchEvents(
130 PxvContactManagerTouchEvent* newTouch, PxI32& newTouchCount,
131 PxvContactManagerTouchEvent* lostTouch, PxI32& lostTouchCount,
132 PxvContactManagerTouchEvent* ccdTouch, PxI32& ccdTouchCount);
133
134 bool fillManagerTouchEvents2(
135 PxvContactManagerTouchEvent* newTouch, PxI32& newTouchCount,
136 PxvContactManagerTouchEvent* lostTouch, PxI32& lostTouchCount,
137 PxvContactManagerTouchEvent* ccdTouch, PxI32& ccdTouchCount);
138
139 void beginUpdate();
140
141 // PX_ENABLE_SIM_STATS
142 PX_FORCE_INLINE PxvSimStats& getSimStats() { return mSimStats; }
143 PX_FORCE_INLINE const PxvSimStats& getSimStats() const { return mSimStats; }
144
145 PX_FORCE_INLINE Cm::FlushPool& getTaskPool() const { return mTaskPool; }
146 PX_FORCE_INLINE PxRenderBuffer& getRenderBuffer() { return mRenderBuffer; }
147
148 PX_FORCE_INLINE PxReal getRenderScale() const { return mVisualizationParams[PxVisualizationParameter::eSCALE]; }
149 PX_FORCE_INLINE PxReal getVisualizationParameter(PxVisualizationParameter::Enum param) const
150 {
151 PX_ASSERT(param < PxVisualizationParameter::eNUM_VALUES);
152
153 return mVisualizationParams[param];
154 }
155
156 PX_FORCE_INLINE void setVisualizationParameter(PxVisualizationParameter::Enum param, PxReal value)
157 {
158 PX_ASSERT(param < PxVisualizationParameter::eNUM_VALUES);
159 PX_ASSERT(value >= 0.0f);
160
161 mVisualizationParams[param] = value;
162 }
163
164 PX_FORCE_INLINE void setVisualizationCullingBox(const PxBounds3& box) { mVisualizationCullingBox = box; }
165 PX_FORCE_INLINE const PxBounds3& getVisualizationCullingBox() const { return mVisualizationCullingBox; }
166
167 PX_FORCE_INLINE bool getPCM() const { return mPCM; }
168 PX_FORCE_INLINE bool getContactCacheFlag() const { return mContactCache; }
169 PX_FORCE_INLINE bool getCreateAveragePoint() const { return mCreateAveragePoint; }
170
171 // general stuff
172 void shiftOrigin(const PxVec3& shift);
173
174 PX_FORCE_INLINE void setPCM(bool enabled) { mPCM = enabled; }
175 PX_FORCE_INLINE void setContactCache(bool enabled) { mContactCache = enabled; }
176
177 PX_FORCE_INLINE PxcScratchAllocator& getScratchAllocator() { return mScratchAllocator; }
178 PX_FORCE_INLINE PxsTransformCache& getTransformCache() { return *mTransformCache; }
179 PX_FORCE_INLINE const PxReal* getContactDistances() const { return mContactDistances->begin(); }
180
181 PX_FORCE_INLINE PxvNphaseImplementationContext* getNphaseImplementationContext() const { return mNpImplementationContext; }
182 PX_FORCE_INLINE void setNphaseImplementationContext(PxvNphaseImplementationContext* ctx) { mNpImplementationContext = ctx; }
183
184 PX_FORCE_INLINE PxvNphaseImplementationContext* getNphaseFallbackImplementationContext() const { return mNpFallbackImplementationContext; }
185 PX_FORCE_INLINE void setNphaseFallbackImplementationContext(PxvNphaseImplementationContext* ctx) { mNpFallbackImplementationContext = ctx; }
186
187 PxU32 getTotalCompressedContactSize() const { return mTotalCompressedCacheSize; }
188 PxU32 getMaxPatchCount() const { return mMaxPatches; }
189
190 PX_FORCE_INLINE PxcThreadCoherentCache<PxcNpThreadContext, PxcNpContext>& getNpThreadContextPool() { return mNpThreadContextPool; }
191
192 PX_FORCE_INLINE PxcNpThreadContext* getNpThreadContext()
193 {
194 // We may want to conditional compile to exclude this on single threaded implementations
195 // if it is determined to be a performance hit.
196 return mNpThreadContextPool.get();
197 }
198
199 PX_FORCE_INLINE void putNpThreadContext(PxcNpThreadContext* threadContext)
200 { mNpThreadContextPool.put(threadContext); }
201 PX_FORCE_INLINE PxMutex& getLock() { return mLock; }
202
203 PX_FORCE_INLINE PxTaskManager& getTaskManager()
204 {
205 PX_ASSERT(mTaskManager);
206 return *mTaskManager;
207 }
208
209 PX_FORCE_INLINE PxCudaContextManager* getCudaContextManager()
210 {
211 return mCudaContextManager;
212 }
213
214 PX_FORCE_INLINE void clearManagerTouchEvents();
215
217 {
218 return this->mContactManagerPool;
219 }
220
221 PX_FORCE_INLINE void setActiveContactManager(const PxsContactManager* manager, PxIntBool useCCD)
222 {
223 /*const PxU32 index = manager->getIndex();
224 if(index >= mActiveContactManager.size())
225 {
226 const PxU32 newSize = (2 * index + 256)&~255;
227 mActiveContactManager.resize(newSize);
228 }
229 mActiveContactManager.set(index);*/
230
231 //Record any pairs that have CCD enabled!
232 if(useCCD)
233 {
234 const PxU32 index = manager->getIndex();
235 if(index >= mActiveContactManagersWithCCD.size())
236 {
237 const PxU32 newSize = (2 * index + 256)&~255;
238 mActiveContactManagersWithCCD.resize(newSize);
239 }
240 mActiveContactManagersWithCCD.set(index);
241 }
242 }
243
244private:
245 void mergeCMDiscreteUpdateResults(PxBaseTask* continuation);
246
247 PxU32 mIndex;
248
249 // Threading
251 mNpThreadContextPool;
252
253 // Contact managers
257
258// PxBitMap mActiveContactManager;
259 PxBitMap mActiveContactManagersWithCCD; //KS - adding to filter any pairs that had a touch
260 PxBitMap mContactManagersWithCCDTouch; //KS - adding to filter any pairs that had a touch
261 PxBitMap mContactManagerTouchEvent;
262 //Cm::BitMap mContactManagerPatchChangeEvent;
263
264 PxU32 mCMTouchEventCount[PXS_TOUCH_EVENT_COUNT];
265
266 PxMutex mLock;
267
268 PxContactModifyCallback* mContactModifyCallback;
269
270 // narrowphase platform-dependent implementations support
271 PxvNphaseImplementationContext* mNpImplementationContext;
272 PxvNphaseImplementationContext* mNpFallbackImplementationContext;
273
274 // debug rendering (CS TODO: MS would like to have these wrapped into a class)
275 PxReal mVisualizationParams[PxVisualizationParameter::eNUM_VALUES];
276
277 PxBounds3 mVisualizationCullingBox;
278
279 PxTaskManager* mTaskManager;
280 Cm::FlushPool& mTaskPool;
281
282 PxCudaContextManager* mCudaContextManager;
283
284 // PxU32 mTouchesLost;
285 // PxU32 mTouchesFound;
286
287 // PX_ENABLE_SIM_STATS
288 PxvSimStats mSimStats;
289 bool mPCM;
290 bool mContactCache;
291 bool mCreateAveragePoint;
292
293 PxsTransformCache* mTransformCache;
294 const PxFloatArrayPinned* mContactDistances;
295
296 PxU32 mMaxPatches;
297 PxU32 mTotalCompressedCacheSize;
298
299 PxU64 mContextID;
300
301 friend class PxsCCDContext;
303 friend class PxgNphaseImplementationContext; //FDTODO ideally it shouldn't be here..
304};
305
306
307PX_FORCE_INLINE void PxsContext::clearManagerTouchEvents()
308{
309 mContactManagerTouchEvent.clear();
310 for(PxU32 i = 0; i < PXS_TOUCH_EVENT_COUNT; ++i)
311 {
312 mCMTouchEventCount[i] = 0;
313 }
314}
315
316
317}
318
319#endif
A task that maintains a list of dependent tasks.
Definition CmTask.h:132
Definition CmFlushPool.h:49
Definition CmPool.h:49
PX_FORCE_INLINE ConstIterator begin() const
Definition PxArray.h:176
Base class of all task types.
Definition PxTask.h:45
Definition PxBitMap.h:52
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
An interface class that the user can implement in order to modify contact constraints.
Definition PxContactModifyCallback.h:459
Definition PxMutex.h:89
Definition PxPool.h:248
Interface for points, lines, triangles, and text buffer.
Definition PxRenderBuffer.h:136
Descriptor class for scenes. See #PxScene.
Definition PxSceneDesc.h:426
The PxTaskManager interface.
Definition PxTaskManager.h:81
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
Definition PxAllocator.h:140
Definition PxcNpThreadContext.h:119
Definition PxcScratchAllocator.h:42
Definition PxcThreadCoherentCache.h:52
CCD context object.
Definition PxsCCD.h:423
Definition PxsContactManager.h:77
Definition PxsContext.h:92
Definition PxsNphaseImplementationContext.h:76
Definition PxsTransformCache.h:60
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
Definition GuContactMethodImpl.h:67
Enum
Definition PxGeometry.h:52
Enum
Definition PxVisualizationParameter.h:63
@ eNUM_VALUES
This is not a parameter, it just records the current number of parameters (as maximum(PxVisualization...
Definition PxVisualizationParameter.h:242
@ eSCALE
This overall visualization scale gets multiplied with the individual scales. Setting to zero ignores ...
Definition PxVisualizationParameter.h:91
Definition PxcNpThreadContext.h:80
Definition PxvManager.h:203
Definition PxvSimStats.h:52