1/*
2 * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NVIDIA CORPORATION and its licensors retain all intellectual property
5 * and proprietary rights in and to this software, related documentation
6 * and any modifications thereto. Any use, reproduction, disclosure or
7 * distribution of this software and related documentation without an express
8 * license agreement from NVIDIA CORPORATION is strictly prohibited.
9 */
10// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12
13
14#ifndef PX_SIMULATION_STATISTICS
15#define PX_SIMULATION_STATISTICS
16/** \addtogroup physics
17@{
18*/
19
20#include "PxPhysXConfig.h"
21#include "geometry/PxGeometry.h"
22
23#ifndef PX_DOXYGEN
24namespace physx
25{
26#endif
27
28/**
29\brief Class used to retrieve statistics for a simulation step.
30
31@see PxScene::getSimulationStatistics()
32*/
33class PxSimulationStatistics
34{
35public:
36 /**
37 \brief Identifies each type of broadphase volume.
38 @see nbBroadPhaseAdds nbBroadPhaseRemoves
39 */
40 enum VolumeType
41 {
42 /**
43 \brief A volume belonging to a rigid body object
44 @see PxRigidStatic PxRigidDynamic PxArticulationLink
45 */
46 eRIGID_BODY,
47
48 /**
49 \brief A volume belonging to a particle system
50 @see PxParticleSystem PxParticleFluid
51 */
52 ePARTICLE_SYSTEM,
53
54 /**
55 \brief A volume belonging to a cloth
56 @see PxCloth
57 */
58 eCLOTH,
59
60 eVOLUME_COUNT
61 };
62
63 /**
64 \brief Different types of rigid body collision pair statistics.
65 @see getRbPairStats
66 */
67 enum RbPairStatsType
68 {
69 /**
70 \brief Shape pairs processed as discrete contact pairs for the current simulation step.
71 */
72 eDISCRETE_CONTACT_PAIRS,
73
74 /**
75 \brief Shape pairs processed as swept integration pairs for the current simulation step.
76
77 \note Counts the pairs for which special CCD (continuous collision detection) work was actually done and NOT the number of pairs which were configured for CCD.
78 Furthermore, there can be multiple CCD passes and all processed pairs of all passes are summed up, hence the number can be larger than the amount of pairs which have been configured for CCD.
79
80 @see PxPairFlag::eDETECT_CCD_CONTACT,
81 */
82 eCCD_PAIRS,
83
84 /**
85 \brief Shape pairs processed with user contact modification enabled for the current simulation step.
86
87 @see PxContactModifyCallback
88 */
89 eMODIFIED_CONTACT_PAIRS,
90
91 /**
92 \brief Trigger shape pairs processed for the current simulation step.
93
94 @see PxShapeFlag::eTRIGGER_SHAPE
95 */
96 eTRIGGER_PAIRS
97 };
98
99
100//objects:
101 /**
102 \brief Number of active PxConstraint objects (joints etc.) for the current simulation step.
103 */
104 PxU32 nbActiveConstraints;
105
106 /**
107 \brief Number of active dynamic bodies for the current simulation step.
108
109 \note Does not include active kinematic bodies
110 */
111 PxU32 nbActiveDynamicBodies;
112
113 /**
114 \brief Number of active kinematic bodies for the current simulation step.
115
116 \note Kinematic deactivation occurs at the end of the frame after the last call to PxRigidDynamic::setKinematicTarget() was called so kinematics that are
117 deactivated in a given frame will be included by this counter.
118 */
119 PxU32 nbActiveKinematicBodies;
120
121 /**
122 \brief Number of static bodies for the current simulation step.
123 */
124 PxU32 nbStaticBodies;
125
126 /**
127 \brief Number of dynamic bodies for the current simulation step.
128
129 \note Includes inactive and kinematic bodies, and articulation links
130 */
131 PxU32 nbDynamicBodies;
132
133 /**
134 \brief Number of shapes of each geometry type.
135 */
136
137 PxU32 nbShapes[PxGeometryType::eGEOMETRY_COUNT];
138
139//solver:
140 /**
141 \brief The number of 1D axis constraints(joints+contact) present in the current simulation step.
142 */
143 PxU32 nbAxisSolverConstraints;
144
145 /**
146 \brief The size (in bytes) of the compressed contact stream in the current simulation step
147 */
148 PxU32 compressedContactSize;
149
150 /**
151 \brief The total required size (in bytes) of the contact constraints in the current simulation step
152 */
153 PxU32 requiredContactConstraintMemory;
154
155 /**
156 \brief The peak amount of memory (in bytes) that was allocated for constraints (this includes joints) in the current simulation step
157 */
158 PxU32 peakConstraintMemory;
159
160//broadphase:
161 /**
162 \brief Get number of broadphase volumes of a certain type added for the current simulation step.
163
164 \param[in] type The volume type for which to get the number
165 \return Number of broadphase volumes added.
166
167 @see VolumType
168 */
169 PxU32 getNbBroadPhaseAdds(VolumeType type) const
170 {
171 if (type != eVOLUME_COUNT)
172 return nbBroadPhaseAdds[type];
173 else
174 {
175 PX_ASSERT(false);
176 return 0;
177 }
178 }
179
180 /**
181 \brief Get number of broadphase volumes of a certain type removed for the current simulation step.
182
183 \param[in] type The volume type for which to get the number
184 \return Number of broadphase volumes removed.
185
186 @see VolumType
187 */
188 PxU32 getNbBroadPhaseRemoves(VolumeType type) const
189 {
190 if (type != eVOLUME_COUNT)
191 return nbBroadPhaseRemoves[type];
192 else
193 {
194 PX_ASSERT(false);
195 return 0;
196 }
197 }
198
199//collisions:
200 /**
201 \brief Get number of shape collision pairs of a certain type processed for the current simulation step.
202
203 There is an entry for each geometry pair type.
204
205 \note entry[i][j] = entry[j][i], hence, if you want the sum of all pair
206 types, you need to discard the symmetric entries
207
208 \param[in] pairType The type of pair for which to get information
209 \param[in] g0 The geometry type of one pair object
210 \param[in] g1 The geometry type of the other pair object
211 \return Number of processed pairs of the specified geometry types.
212 */
213 PxU32 getRbPairStats(RbPairStatsType pairType, PxGeometryType::Enum g0, PxGeometryType::Enum g1) const
214 {
215 if (g0 >= PxGeometryType::eGEOMETRY_COUNT || g1 >= PxGeometryType::eGEOMETRY_COUNT)
216 {
217 PX_ASSERT(false);
218 return 0;
219 }
220
221 switch(pairType)
222 {
223 case eDISCRETE_CONTACT_PAIRS:
224 return nbDiscreteContactPairs[g0][g1];
225
226 case eCCD_PAIRS:
227 return nbCCDPairs[g0][g1];
228
229 case eMODIFIED_CONTACT_PAIRS:
230 return nbModifiedContactPairs[g0][g1];
231
232 case eTRIGGER_PAIRS:
233 return nbTriggerPairs[g0][g1];
234
235 default:
236 PX_ASSERT(false);
237 return 0;
238 }
239 }
240
241 PxSimulationStatistics()
242 {
243 for(PxU32 i=0; i < eVOLUME_COUNT; i++)
244 {
245 nbBroadPhaseAdds[i] = 0;
246 nbBroadPhaseRemoves[i] = 0;
247 }
248
249 for(PxU32 i=0; i < PxGeometryType::eGEOMETRY_COUNT; i++)
250 {
251 for(PxU32 j=0; j < PxGeometryType::eGEOMETRY_COUNT; j++)
252 {
253 nbDiscreteContactPairs[i][j] = 0;
254 nbModifiedContactPairs[i][j] = 0;
255 nbCCDPairs[i][j] = 0;
256 nbTriggerPairs[i][j] = 0;
257 }
258 }
259
260 for(PxU32 i=0; i < PxGeometryType::eGEOMETRY_COUNT; i++)
261 {
262 nbShapes[i] = 0;
263 }
264
265 totalDiscreteContactPairsAnyShape = 0;
266
267 nbActiveConstraints = 0;
268 nbActiveDynamicBodies = 0;
269 nbActiveKinematicBodies = 0;
270 nbStaticBodies = 0;
271 nbDynamicBodies = 0;
272 compressedContactSize = 0;
273 requiredContactConstraintMemory = 0;
274 peakConstraintMemory = 0;
275
276 nbAxisSolverConstraints = 0;
277
278 particlesGpuMeshCacheSize = 0;
279 particlesGpuMeshCacheUsed = 0;
280 particlesGpuMeshCacheHitrate = 0.0f;
281 }
282
283
284 //
285 // We advise to not access these members directly. Use the provided accessor methods instead.
286 //
287//broadphase:
288 PxU32 nbBroadPhaseAdds[eVOLUME_COUNT];
289 PxU32 nbBroadPhaseRemoves[eVOLUME_COUNT];
290
291//collisions:
292 PxU32 nbDiscreteContactPairs[PxGeometryType::eGEOMETRY_COUNT][PxGeometryType::eGEOMETRY_COUNT];
293 PxU32 nbCCDPairs[PxGeometryType::eGEOMETRY_COUNT][PxGeometryType::eGEOMETRY_COUNT];
294 PxU32 nbModifiedContactPairs[PxGeometryType::eGEOMETRY_COUNT][PxGeometryType::eGEOMETRY_COUNT];
295 PxU32 nbTriggerPairs[PxGeometryType::eGEOMETRY_COUNT][PxGeometryType::eGEOMETRY_COUNT];
296 PxU32 totalDiscreteContactPairsAnyShape;
297
298//triangle mesh cache statistics
299 PxU32 particlesGpuMeshCacheSize;
300 PxU32 particlesGpuMeshCacheUsed;
301 PxReal particlesGpuMeshCacheHitrate;
302};
303
304#ifndef PX_DOXYGEN
305} // namespace physx
306#endif
307
308/** @} */
309#endif
310