RavEngine
Loading...
Searching...
No Matches
PxcNpThreadContext.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 PXC_NP_THREAD_CONTEXT_H
30#define PXC_NP_THREAD_CONTEXT_H
31
32#include "geometry/PxGeometry.h"
33#include "geomutils/PxContactBuffer.h"
34#include "common/PxRenderOutput.h"
35
36#include "CmRenderBuffer.h"
37
38#include "PxvConfig.h"
39#include "CmScaling.h"
40#include "PxcNpCacheStreamPair.h"
41#include "PxcConstraintBlockStream.h"
42#include "PxcThreadCoherentCache.h"
43#include "PxcScratchAllocator.h"
44#include "foundation/PxBitMap.h"
45#include "../pcm/GuPersistentContactManifold.h"
46#include "../contact/GuContactMethodImpl.h"
47
48namespace physx
49{
50
51class PxsTransformCache;
52class PxsMaterialManager;
53
54namespace Sc
55{
56 class BodySim;
57}
58
64{
65 PxU8* mDataStream;
66 PxI32 mSharedDataIndex;
67 PxU32 mDataStreamSize;
68 PxU32 mSharedDataIndexGPU;
69
70 bool isOverflown() const
71 {
72 //FD: my expectaton is that reading those variables is atomic, shared indices are non-decreasing,
73 //so we can only get a false overflow alert because of concurrency issues, which is not a big deal as it means
74 //it did overflow a bit later
75 return (mSharedDataIndex + mSharedDataIndexGPU) > mDataStreamSize;
76 }
77};
78
80{
81 private:
82 PX_NOCOPY(PxcNpContext)
83 public:
84
85 PxcNpContext() :
86 mNpMemBlockPool (mScratchAllocator),
87 mMeshContactMargin (0.0f),
88 mToleranceLength (0.0f),
89 mContactStreamPool (NULL),
90 mPatchStreamPool (NULL),
91 mForceAndIndiceStreamPool(NULL),
92 mMaterialManager (NULL)
93 {
94 }
95
96 PxcScratchAllocator mScratchAllocator;
97 PxcNpMemBlockPool mNpMemBlockPool;
98 PxReal mMeshContactMargin;
99 PxReal mToleranceLength;
100 Cm::RenderBuffer mRenderBuffer;
101 PxcDataStreamPool* mContactStreamPool;
102 PxcDataStreamPool* mPatchStreamPool;
103 PxcDataStreamPool* mForceAndIndiceStreamPool;
104 PxcDataStreamPool* mConstraintWriteBackStreamPool;
105 PxsMaterialManager* mMaterialManager;
106
107 PX_FORCE_INLINE PxReal getToleranceLength() const { return mToleranceLength; }
108 PX_FORCE_INLINE void setToleranceLength(PxReal x) { mToleranceLength = x; }
109 PX_FORCE_INLINE PxReal getMeshContactMargin() const { return mMeshContactMargin; }
110 PX_FORCE_INLINE void setMeshContactMargin(PxReal x) { mMeshContactMargin = x; }
111
112 PX_FORCE_INLINE PxcNpMemBlockPool& getNpMemBlockPool() { return mNpMemBlockPool; }
113 PX_FORCE_INLINE const PxcNpMemBlockPool& getNpMemBlockPool() const { return mNpMemBlockPool; }
114 PX_FORCE_INLINE void setMaterialManager(PxsMaterialManager* m){ mMaterialManager = m; }
115 PX_FORCE_INLINE PxsMaterialManager* getMaterialManager() const { return mMaterialManager; }
116};
117
118class PxcNpThreadContext : public PxcThreadCoherentCache<PxcNpThreadContext, PxcNpContext>::EntryBase
119{
120 PX_NOCOPY(PxcNpThreadContext)
121public:
124
125#if PX_ENABLE_SIM_STATS
126 void clearStats();
127#else
128 PX_CATCH_UNDEFINED_ENABLE_SIM_STATS
129#endif
130
131 PX_FORCE_INLINE void addLocalNewTouchCount(PxU32 newTouchCMCount) { mLocalNewTouchCount += newTouchCMCount; }
132 PX_FORCE_INLINE void addLocalLostTouchCount(PxU32 lostTouchCMCount) { mLocalLostTouchCount += lostTouchCMCount; }
133 PX_FORCE_INLINE PxU32 getLocalNewTouchCount() const { return mLocalNewTouchCount; }
134 PX_FORCE_INLINE PxU32 getLocalLostTouchCount() const { return mLocalLostTouchCount; }
135
136
137 PX_FORCE_INLINE PxBitMap& getLocalChangeTouch() { return mLocalChangeTouch; }
138
139 void reset(PxU32 cmCount);
140 // debugging
141 PxRenderOutput mRenderOutput;
142
143 // dsequeira: Need to think about this block pool allocation a bit more. Ideally we'd be
144 // taking blocks from a single pool, except that we want to be able to selectively reclaim
145 // blocks if the user needs to defragment, depending on which artifacts they're willing
146 // to tolerate, such that the blocks we don't reclaim are contiguous.
147#if PX_ENABLE_SIM_STATS
150#else
151 PX_CATCH_UNDEFINED_ENABLE_SIM_STATS
152#endif
153 PxcContactBlockStream mContactBlockStream; // constraint block pool
154 PxcNpCacheStreamPair mNpCacheStreamPair; // narrow phase pairwise data cache
155
156 // Everything below here is scratch state. Most of it can even overlap.
157
158 // temporary contact buffer
159 PxContactBuffer mContactBuffer;
160
162
163 Gu::NarrowPhaseParams mNarrowPhaseParams;
164
165 // DS: this stuff got moved here from the PxcNpPairContext. As Pierre says:
167 PxArray<Sc::BodySim*> mBodySimPool;
168 PxsTransformCache* mTransformCache;
169 const PxReal* mContactDistances;
170 bool mPCM;
171 bool mContactCache;
172 bool mCreateAveragePoint; // flag to enforce whether we create average points
173#if PX_ENABLE_SIM_STATS
174 PxU32 mCompressedCacheSize;
175 PxU32 mNbDiscreteContactPairsWithCacheHits;
176 PxU32 mNbDiscreteContactPairsWithContacts;
177#else
178 PX_CATCH_UNDEFINED_ENABLE_SIM_STATS
179#endif
180 PxReal mDt; // AP: still needed for ccd
181 PxU32 mCCDPass;
182 PxU32 mCCDFaceIndex;
183
184 PxU32 mMaxPatches;
185 //PxU32 mTotalContactCount;
186 PxU32 mTotalCompressedCacheSize;
187 //PxU32 mTotalPatchCount;
188
189 PxcDataStreamPool* mContactStreamPool;
190 PxcDataStreamPool* mPatchStreamPool;
191 PxcDataStreamPool* mForceAndIndiceStreamPool; //this stream is used to store the force buffer and triangle index if we are performing mesh/heightfield contact gen
192 PxcDataStreamPool* mConstraintWriteBackStreamPool;
193 PxsMaterialManager* mMaterialManager;
194private:
195 // change touch handling.
196 PxBitMap mLocalChangeTouch;
197 PxU32 mLocalNewTouchCount;
198 PxU32 mLocalLostTouchCount;
199};
200
201}
202
203#endif
Definition CmRenderBuffer.h:45
Definition GuPersistentContactManifold.h:532
Definition PxArray.h:53
Definition PxBitMap.h:52
Definition PxContactBuffer.h:42
Definition PxRenderOutput.h:50
Definition PxcConstraintBlockStream.h:106
Definition PxcNpMemBlockPool.h:52
Definition PxcNpThreadContext.h:119
Definition PxcScratchAllocator.h:42
Definition PxcThreadCoherentCache.h:52
Definition PxsMaterialManager.h:126
Definition PxsTransformCache.h:60
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_ALIGN(alignment, decl)
Definition PxPreprocessor.h:402
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition GuContactMethodImpl.h:49
@ eGEOMETRY_COUNT
internal use only!
Definition PxGeometry.h:65
Definition PxcNpThreadContext.h:64
Definition PxcNpCacheStreamPair.h:43
Definition PxcNpThreadContext.h:80