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 PX_SIMULATION_STATISTICS |
32 | #define PX_SIMULATION_STATISTICS |
33 | /** \addtogroup physics |
34 | @{ |
35 | */ |
36 | |
37 | #include "foundation/PxAssert.h" |
38 | #include "PxPhysXConfig.h" |
39 | #include "geometry/PxGeometry.h" |
40 | |
41 | #if !PX_DOXYGEN |
42 | namespace physx |
43 | { |
44 | #endif |
45 | |
46 | /** |
47 | \brief Class used to retrieve statistics for a simulation step. |
48 | |
49 | @see PxScene::getSimulationStatistics() |
50 | */ |
51 | class PxSimulationStatistics |
52 | { |
53 | public: |
54 | |
55 | /** |
56 | \brief Different types of rigid body collision pair statistics. |
57 | @see getRbPairStats |
58 | */ |
59 | enum RbPairStatsType |
60 | { |
61 | /** |
62 | \brief Shape pairs processed as discrete contact pairs for the current simulation step. |
63 | */ |
64 | eDISCRETE_CONTACT_PAIRS, |
65 | |
66 | /** |
67 | \brief Shape pairs processed as swept integration pairs for the current simulation step. |
68 | |
69 | \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. |
70 | 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. |
71 | |
72 | @see PxPairFlag::eDETECT_CCD_CONTACT, |
73 | */ |
74 | eCCD_PAIRS, |
75 | |
76 | /** |
77 | \brief Shape pairs processed with user contact modification enabled for the current simulation step. |
78 | |
79 | @see PxContactModifyCallback |
80 | */ |
81 | eMODIFIED_CONTACT_PAIRS, |
82 | |
83 | /** |
84 | \brief Trigger shape pairs processed for the current simulation step. |
85 | |
86 | @see PxShapeFlag::eTRIGGER_SHAPE |
87 | */ |
88 | eTRIGGER_PAIRS |
89 | }; |
90 | |
91 | |
92 | //objects: |
93 | /** |
94 | \brief Number of active PxConstraint objects (joints etc.) for the current simulation step. |
95 | */ |
96 | PxU32 nbActiveConstraints; |
97 | |
98 | /** |
99 | \brief Number of active dynamic bodies for the current simulation step. |
100 | |
101 | \note Does not include active kinematic bodies |
102 | */ |
103 | PxU32 nbActiveDynamicBodies; |
104 | |
105 | /** |
106 | \brief Number of active kinematic bodies for the current simulation step. |
107 | |
108 | \note Kinematic deactivation occurs at the end of the frame after the last call to PxRigidDynamic::setKinematicTarget() was called so kinematics that are |
109 | deactivated in a given frame will be included by this counter. |
110 | */ |
111 | PxU32 nbActiveKinematicBodies; |
112 | |
113 | /** |
114 | \brief Number of static bodies for the current simulation step. |
115 | */ |
116 | PxU32 nbStaticBodies; |
117 | |
118 | /** |
119 | \brief Number of dynamic bodies for the current simulation step. |
120 | |
121 | \note Includes inactive bodies and articulation links |
122 | \note Does not include kinematic bodies |
123 | */ |
124 | PxU32 nbDynamicBodies; |
125 | |
126 | /** |
127 | \brief Number of kinematic bodies for the current simulation step. |
128 | |
129 | \note Includes inactive bodies |
130 | */ |
131 | PxU32 nbKinematicBodies; |
132 | |
133 | /** |
134 | \brief Number of shapes of each geometry type. |
135 | */ |
136 | |
137 | PxU32 nbShapes[PxGeometryType::eGEOMETRY_COUNT]; |
138 | |
139 | /** |
140 | \brief Number of aggregates in the scene. |
141 | */ |
142 | PxU32 nbAggregates; |
143 | |
144 | /** |
145 | \brief Number of articulations in the scene. |
146 | */ |
147 | PxU32 nbArticulations; |
148 | |
149 | //solver: |
150 | /** |
151 | \brief The number of 1D axis constraints(joints+contact) present in the current simulation step. |
152 | */ |
153 | PxU32 nbAxisSolverConstraints; |
154 | |
155 | /** |
156 | \brief The size (in bytes) of the compressed contact stream in the current simulation step |
157 | */ |
158 | PxU32 compressedContactSize; |
159 | |
160 | /** |
161 | \brief The total required size (in bytes) of the contact constraints in the current simulation step |
162 | */ |
163 | PxU32 requiredContactConstraintMemory; |
164 | |
165 | /** |
166 | \brief The peak amount of memory (in bytes) that was allocated for constraints (this includes joints) in the current simulation step |
167 | */ |
168 | PxU32 peakConstraintMemory; |
169 | |
170 | //broadphase: |
171 | /** |
172 | \brief Get number of broadphase volumes added for the current simulation step. |
173 | |
174 | \return Number of broadphase volumes added. |
175 | */ |
176 | PX_FORCE_INLINE PxU32 getNbBroadPhaseAdds() const |
177 | { |
178 | return nbBroadPhaseAdds; |
179 | } |
180 | |
181 | /** |
182 | \brief Get number of broadphase volumes removed for the current simulation step. |
183 | |
184 | \return Number of broadphase volumes removed. |
185 | */ |
186 | PX_FORCE_INLINE PxU32 getNbBroadPhaseRemoves() const |
187 | { |
188 | return nbBroadPhaseRemoves; |
189 | } |
190 | |
191 | //collisions: |
192 | /** |
193 | \brief Get number of shape collision pairs of a certain type processed for the current simulation step. |
194 | |
195 | There is an entry for each geometry pair type. |
196 | |
197 | \note entry[i][j] = entry[j][i], hence, if you want the sum of all pair |
198 | types, you need to discard the symmetric entries |
199 | |
200 | \param[in] pairType The type of pair for which to get information |
201 | \param[in] g0 The geometry type of one pair object |
202 | \param[in] g1 The geometry type of the other pair object |
203 | \return Number of processed pairs of the specified geometry types. |
204 | */ |
205 | PxU32 getRbPairStats(RbPairStatsType pairType, PxGeometryType::Enum g0, PxGeometryType::Enum g1) const |
206 | { |
207 | PX_ASSERT_WITH_MESSAGE( (pairType >= eDISCRETE_CONTACT_PAIRS) && |
208 | (pairType <= eTRIGGER_PAIRS), |
209 | "Invalid pairType in PxSimulationStatistics::getRbPairStats" ); |
210 | |
211 | if (g0 >= PxGeometryType::eGEOMETRY_COUNT || g1 >= PxGeometryType::eGEOMETRY_COUNT) |
212 | { |
213 | PX_ASSERT(false); |
214 | return 0; |
215 | } |
216 | |
217 | PxU32 nbPairs = 0; |
218 | switch(pairType) |
219 | { |
220 | case eDISCRETE_CONTACT_PAIRS: |
221 | nbPairs = nbDiscreteContactPairs[g0][g1]; |
222 | break; |
223 | case eCCD_PAIRS: |
224 | nbPairs = nbCCDPairs[g0][g1]; |
225 | break; |
226 | case eMODIFIED_CONTACT_PAIRS: |
227 | nbPairs = nbModifiedContactPairs[g0][g1]; |
228 | break; |
229 | case eTRIGGER_PAIRS: |
230 | nbPairs = nbTriggerPairs[g0][g1]; |
231 | break; |
232 | } |
233 | return nbPairs; |
234 | } |
235 | |
236 | /** |
237 | \brief Total number of (non CCD) pairs reaching narrow phase |
238 | */ |
239 | PxU32 nbDiscreteContactPairsTotal; |
240 | |
241 | /** |
242 | \brief Total number of (non CCD) pairs for which contacts are successfully cached (<=nbDiscreteContactPairsTotal) |
243 | \note This includes pairs for which no contacts are generated, it still counts as a cache hit. |
244 | */ |
245 | PxU32 nbDiscreteContactPairsWithCacheHits; |
246 | |
247 | /** |
248 | \brief Total number of (non CCD) pairs for which at least 1 contact was generated (<=nbDiscreteContactPairsTotal) |
249 | */ |
250 | PxU32 nbDiscreteContactPairsWithContacts; |
251 | |
252 | /** |
253 | \brief Number of new pairs found by BP this frame |
254 | */ |
255 | PxU32 nbNewPairs; |
256 | |
257 | /** |
258 | \brief Number of lost pairs from BP this frame |
259 | */ |
260 | PxU32 nbLostPairs; |
261 | |
262 | /** |
263 | \brief Number of new touches found by NP this frame |
264 | */ |
265 | PxU32 nbNewTouches; |
266 | |
267 | /** |
268 | \brief Number of lost touches from NP this frame |
269 | */ |
270 | PxU32 nbLostTouches; |
271 | |
272 | /** |
273 | \brief Number of partitions used by the solver this frame |
274 | */ |
275 | PxU32 nbPartitions; |
276 | |
277 | PxSimulationStatistics() : |
278 | nbActiveConstraints (0), |
279 | nbActiveDynamicBodies (0), |
280 | nbActiveKinematicBodies (0), |
281 | nbStaticBodies (0), |
282 | nbDynamicBodies (0), |
283 | nbKinematicBodies (0), |
284 | nbAggregates (0), |
285 | nbArticulations (0), |
286 | nbAxisSolverConstraints (0), |
287 | compressedContactSize (0), |
288 | requiredContactConstraintMemory (0), |
289 | peakConstraintMemory (0), |
290 | nbDiscreteContactPairsTotal (0), |
291 | nbDiscreteContactPairsWithCacheHits (0), |
292 | nbDiscreteContactPairsWithContacts (0), |
293 | nbNewPairs (0), |
294 | nbLostPairs (0), |
295 | nbNewTouches (0), |
296 | nbLostTouches (0), |
297 | nbPartitions (0) |
298 | { |
299 | nbBroadPhaseAdds = 0; |
300 | nbBroadPhaseRemoves = 0; |
301 | |
302 | for(PxU32 i=0; i < PxGeometryType::eGEOMETRY_COUNT; i++) |
303 | { |
304 | for(PxU32 j=0; j < PxGeometryType::eGEOMETRY_COUNT; j++) |
305 | { |
306 | nbDiscreteContactPairs[i][j] = 0; |
307 | nbModifiedContactPairs[i][j] = 0; |
308 | nbCCDPairs[i][j] = 0; |
309 | nbTriggerPairs[i][j] = 0; |
310 | } |
311 | } |
312 | |
313 | for(PxU32 i=0; i < PxGeometryType::eGEOMETRY_COUNT; i++) |
314 | { |
315 | nbShapes[i] = 0; |
316 | } |
317 | } |
318 | |
319 | |
320 | // |
321 | // We advise to not access these members directly. Use the provided accessor methods instead. |
322 | // |
323 | //broadphase: |
324 | PxU32 nbBroadPhaseAdds; |
325 | PxU32 nbBroadPhaseRemoves; |
326 | |
327 | //collisions: |
328 | PxU32 nbDiscreteContactPairs[PxGeometryType::eGEOMETRY_COUNT][PxGeometryType::eGEOMETRY_COUNT]; |
329 | PxU32 nbCCDPairs[PxGeometryType::eGEOMETRY_COUNT][PxGeometryType::eGEOMETRY_COUNT]; |
330 | PxU32 nbModifiedContactPairs[PxGeometryType::eGEOMETRY_COUNT][PxGeometryType::eGEOMETRY_COUNT]; |
331 | PxU32 nbTriggerPairs[PxGeometryType::eGEOMETRY_COUNT][PxGeometryType::eGEOMETRY_COUNT]; |
332 | }; |
333 | |
334 | #if !PX_DOXYGEN |
335 | } // namespace physx |
336 | #endif |
337 | |
338 | /** @} */ |
339 | #endif |
340 | |