1//
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions
4// are met:
5// * Redistributions of source code must retain the above copyright
6// notice, this list of conditions and the following disclaimer.
7// * Redistributions in binary form must reproduce the above copyright
8// notice, this list of conditions and the following disclaimer in the
9// documentation and/or other materials provided with the distribution.
10// * Neither the name of NVIDIA CORPORATION nor the names of its
11// contributors may be used to endorse or promote products derived
12// from this software without specific prior written permission.
13//
14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
15// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25//
26// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
27// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29
30
31#ifndef DY_THREADCONTEXT_H
32#define DY_THREADCONTEXT_H
33
34#include "foundation/PxTransform.h"
35#include "geomutils/GuContactBuffer.h"
36
37#include "PxvConfig.h"
38#include "PxvDynamics.h"
39#include "PxcThreadCoherentCache.h"
40#include "PxcConstraintBlockStream.h"
41#include "CmBitMap.h"
42#include "CmMatrix34.h"
43#include "DyThresholdTable.h"
44#include "DyArticulation.h"
45#include "DyFrictionPatchStreamPair.h"
46#include "DySolverConstraintDesc.h"
47#include "DyCorrelationBuffer.h"
48#include "PsAllocator.h"
49
50namespace physx
51{
52struct PxsIndexedContactManager;
53
54namespace Dy
55{
56
57/*!
58Cache information specific to the software implementation(non common).
59
60See PxcgetThreadContext.
61
62Not thread-safe, so remember to have one object per thread!
63
64TODO! refactor this and rename(it is a general per thread cache). Move transform cache into its own class.
65*/
66class ThreadContext :
67 public PxcThreadCoherentCache<ThreadContext, PxcNpMemBlockPool>::EntryBase
68{
69 PX_NOCOPY(ThreadContext)
70public:
71
72#if PX_ENABLE_SIM_STATS
73 struct ThreadSimStats
74 {
75 void clear()
76 {
77
78 numActiveConstraints = 0;
79 numActiveDynamicBodies = 0;
80 numActiveKinematicBodies = 0;
81 numAxisSolverConstraints = 0;
82
83 }
84
85 PxU32 numActiveConstraints;
86 PxU32 numActiveDynamicBodies;
87 PxU32 numActiveKinematicBodies;
88 PxU32 numAxisSolverConstraints;
89
90 };
91#endif
92
93 //TODO: tune cache size based on number of active objects.
94 ThreadContext(PxcNpMemBlockPool* memBlockPool);
95 void reset();
96 void resizeArrays(PxU32 frictionConstraintDescCount, PxU32 articulationCount);
97
98 PX_FORCE_INLINE Ps::Array<ArticulationSolverDesc>& getArticulations() { return mArticulations; }
99
100
101#if PX_ENABLE_SIM_STATS
102 PX_FORCE_INLINE ThreadSimStats& getSimStats()
103 {
104 return mThreadSimStats;
105 }
106#endif
107
108 Gu::ContactBuffer mContactBuffer;
109
110 // temporary buffer for correlation
111 PX_ALIGN(16, CorrelationBuffer mCorrelationBuffer);
112
113 FrictionPatchStreamPair mFrictionPatchStreamPair; // patch streams
114
115 PxsConstraintBlockManager mConstraintBlockManager; // for when this thread context is "lead" on an island
116 PxcConstraintBlockStream mConstraintBlockStream; // constraint block pool
117
118
119 // this stuff is just used for reformatting the solver data. Hopefully we should have a more
120 // sane format for this when the dust settles - so it's just temporary. If we keep this around
121 // here we should move these from public to private
122
123 PxU32 mNumDifferentBodyConstraints;
124 PxU32 mNumDifferentBodyFrictionConstraints;
125 PxU32 mNumSelfConstraints;
126 PxU32 mNumStaticConstraints;
127 PxU32 mNumSelfFrictionConstraints;
128 PxU32 mNumSelfConstraintFrictionBlocks;
129
130 Ps::Array<PxU32> mConstraintsPerPartition;
131 Ps::Array<PxU32> mFrictionConstraintsPerPartition;
132 Ps::Array<PxU32> mPartitionNormalizationBitmap;
133 PxsBodyCore** mBodyCoreArray;
134 PxsRigidBody** mRigidBodyArray;
135 ArticulationV** mArticulationArray;
136 Cm::SpatialVector* motionVelocityArray;
137 PxU32* bodyRemapTable;
138 PxU32* mNodeIndexArray;
139
140 //Constraint info for normal constraint sovler
141 PxSolverConstraintDesc* contactConstraintDescArray;
142 PxU32 contactDescArraySize;
143 PxSolverConstraintDesc* orderedContactConstraints;
144 PxConstraintBatchHeader* contactConstraintBatchHeaders;
145 PxU32 numContactConstraintBatches;
146
147 //Constraint info for partitioning
148 PxSolverConstraintDesc* tempConstraintDescArray;
149
150 //Additional constraint info for 1d/2d friction model
151 Ps::Array<PxSolverConstraintDesc> frictionConstraintDescArray;
152 Ps::Array<PxConstraintBatchHeader> frictionConstraintBatchHeaders;
153
154 //Info for tracking compound contact managers (temporary data - could use scratch memory!)
155 Ps::Array<CompoundContactManager> compoundConstraints;
156
157 //Used for sorting constraints. Temporary, could use scratch memory
158 Ps::Array<const PxsIndexedContactManager*> orderedContactList;
159 Ps::Array<const PxsIndexedContactManager*> tempContactList;
160 Ps::Array<PxU32> sortIndexArray;
161
162 Ps::Array<Cm::SpatialVectorF> mZVector;
163 Ps::Array<Cm::SpatialVectorF> mDeltaV;
164
165
166 PxU32 numDifferentBodyBatchHeaders;
167 PxU32 numSelfConstraintBatchHeaders;
168
169
170 PxU32 mOrderedContactDescCount;
171 PxU32 mOrderedFrictionDescCount;
172
173 PxU32 mConstraintSize;
174
175 PxU32 mAxisConstraintCount;
176 SelfConstraintBlock* mSelfConstraintBlocks;
177
178 SelfConstraintBlock* mSelfConstraintFrictionBlocks;
179
180 PxU32 mMaxPartitions;
181 PxU32 mMaxFrictionPartitions;
182 PxU32 mMaxSolverPositionIterations;
183 PxU32 mMaxSolverVelocityIterations;
184 PxU32 mMaxArticulationLength;
185 PxU32 mMaxArticulationSolverLength;
186 PxU32 mMaxArticulationLinks;
187
188 PxSolverConstraintDesc* mContactDescPtr;
189 PxSolverConstraintDesc* mStartContactDescPtr;
190 PxSolverConstraintDesc* mFrictionDescPtr;
191
192private:
193
194 Ps::Array<ArticulationSolverDesc> mArticulations;
195
196#if PX_ENABLE_SIM_STATS
197 ThreadSimStats mThreadSimStats;
198#endif
199
200 public:
201
202};
203
204}
205
206}
207
208#endif //DY_THREADCONTEXT_H
209

source code of qtquick3dphysics/src/3rdparty/PhysX/source/lowleveldynamics/src/DyThreadContext.h