RavEngine
Loading...
Searching...
No Matches
SqManager.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 SQ_MANAGER_H
30#define SQ_MANAGER_H
31
32// PT: SQ-API LEVEL 2 (Level 1 = SqPruner.h)
33// PT: this file is part of a "high-level" set of files within Sq. The SqPruner API doesn't rely on them.
34// PT: this should really be at Np level but moving it to Sq allows us to share it.
35
36#include "common/PxPhysXCommonConfig.h"
37
38#include "foundation/PxBitMap.h"
39#include "foundation/PxArray.h"
40#include "SqPruner.h"
41#include "geometry/PxGeometryHelpers.h"
42
43namespace physx
44{
45namespace Sq
46{
47 // PrunerManager-level adapter
48 class Adapter
49 {
50 public:
51 Adapter() {}
52 virtual ~Adapter() {}
53
54 // Retrieves the PxGeometry associated with a given PrunerPayload. This will be called by
55 // the PrunerManager class when computing bounds.
56 virtual const PxGeometry& getGeometry(const Gu::PrunerPayload& payload) const = 0;
57 };
58
59 // PT: extended pruner structure. We might want to move the additional data to the pruner itself later.
60 struct PrunerExt : public PxUserAllocated
61 {
62// private:
63 PrunerExt();
64 ~PrunerExt();
65
66 void init(Gu::Pruner* pruner);
67 void flushMemory();
68 void preallocate(PxU32 nbShapes);
69
70 void addToDirtyList(Gu::PrunerHandle handle, bool dynamic, const PxTransform& transform);
71 void removeFromDirtyList(Gu::PrunerHandle handle);
72 bool processDirtyList(PxU32 index, const Adapter& adapter, float inflation);
73// void growDirtyList(Gu::PrunerHandle handle);
74
75 PX_FORCE_INLINE Gu::Pruner* pruner() { return mPruner; }
76 PX_FORCE_INLINE const Gu::Pruner* pruner() const { return mPruner; }
77
78 Gu::Pruner* mPruner;
79 PxBitMap mDirtyMap;
81 bool mDirtyStatic; // true if dirty list contains a static
82
83 PX_NOCOPY(PrunerExt)
84
85 friend class PrunerManager;
86 };
87}
88}
89
90#include "foundation/PxHashSet.h"
91namespace physx
92{
93namespace Sq
94{
95 class CompoundPruner;
96 typedef PxPair<PrunerCompoundId, Gu::PrunerHandle> CompoundPair;
97 typedef PxCoalescedHashSet<CompoundPair > CompoundPrunerSet;
98 // AB: extended compound pruner structure, buffers compound shape changes and flushes them.
100 {
101// private:
104
105 void flushMemory();
106 void preallocate(PxU32 nbShapes);
107 void flushShapes(const Adapter& adapter, float inflation);
108 void addToDirtyList(PrunerCompoundId compoundId, Gu::PrunerHandle handle, const PxTransform& transform);
109 void removeFromDirtyList(PrunerCompoundId compoundId, Gu::PrunerHandle handle);
110
111 PX_FORCE_INLINE const CompoundPruner* pruner() const { return mPruner; }
112 PX_FORCE_INLINE CompoundPruner* pruner() { return mPruner; }
113
114 CompoundPruner* mPruner;
115 CompoundPrunerSet mDirtyList;
116
117 PX_NOCOPY(CompoundPrunerExt)
118
119 friend class PrunerManager;
120 };
121}
122}
123
124#include "foundation/PxMutex.h"
125#include "SqPrunerData.h"
126
127namespace physx
128{
129class PxRenderOutput;
130class PxBVH;
131class PxSceneLimits; // PT: TODO: decouple from PxSceneLimits
132
133namespace Sq
134{
136 {
137 public:
138 PrunerManager(PxU64 contextID, Gu::Pruner* staticPruner, Gu::Pruner* dynamicPruner,
139 PxU32 dynamicTreeRebuildRateHint, float inflation,
140 const PxSceneLimits& limits, const Adapter& adapter);
142
143 PrunerData addPrunerShape(const Gu::PrunerPayload& payload, bool dynamic, PrunerCompoundId compoundId, const PxBounds3& bounds, const PxTransform& transform, bool hasPruningStructure=false);
144 void addCompoundShape(const PxBVH& bvh, PrunerCompoundId compoundId, const PxTransform& compoundTransform, PrunerData* prunerData, const Gu::PrunerPayload* payloads, const PxTransform* transforms, bool isDynamic);
145 void markForUpdate(PrunerCompoundId compoundId, PrunerData s, const PxTransform& transform);
146 void removePrunerShape(PrunerCompoundId compoundId, PrunerData shapeData, Gu::PrunerPayloadRemovalCallback* removalCallback);
147
148 PX_FORCE_INLINE const Gu::Pruner* getPruner(PruningIndex::Enum index) const { return mPrunerExt[index].mPruner; }
149 PX_FORCE_INLINE Gu::Pruner* getPruner(PruningIndex::Enum index) { return mPrunerExt[index].mPruner; }
150 PX_FORCE_INLINE const CompoundPruner* getCompoundPruner() const { return mCompoundPrunerExt.mPruner; }
151 PX_FORCE_INLINE PxU64 getContextId() const { return mContextID; }
152
153 void preallocate(PxU32 prunerIndex, PxU32 nbShapes);
154
155 void setDynamicTreeRebuildRateHint(PxU32 dynTreeRebuildRateHint);
156 PX_FORCE_INLINE PxU32 getDynamicTreeRebuildRateHint() const { return mRebuildRateHint; }
157
158 void flushUpdates();
159 void forceRebuildDynamicTree(PxU32 prunerIndex);
160
161 void updateCompoundActor(PrunerCompoundId compoundId, const PxTransform& compoundTransform);
162 void removeCompoundActor(PrunerCompoundId compoundId, Gu::PrunerPayloadRemovalCallback* removalCallback);
163
164 void* prepareSceneQueriesUpdate(PruningIndex::Enum index);
165 void sceneQueryBuildStep(void* handle);
166
167 void sync(const Gu::PrunerHandle* handles, const PxU32* boundsIndices, const PxBounds3* bounds, const PxTransform32* transforms, PxU32 count, const PxBitMap& ignoredIndices);
168 void afterSync(bool buildStep, bool commit);
169 void shiftOrigin(const PxVec3& shift);
170 void visualize(PxU32 prunerIndex, PxRenderOutput& out) const;
171
172 void flushMemory();
173 PX_FORCE_INLINE PxU32 getStaticTimestamp() const { return mStaticTimestamp; }
174 PX_FORCE_INLINE const Adapter& getAdapter() const { return mAdapter; }
175 private:
176 const Adapter& mAdapter;
177 PrunerExt mPrunerExt[PruningIndex::eCOUNT];
178 CompoundPrunerExt mCompoundPrunerExt;
179
180 const PxU64 mContextID;
181 PxU32 mStaticTimestamp;
182 PxU32 mRebuildRateHint;
183 const float mInflation; // SQ_PRUNER_EPSILON
184
185 PxMutex mSQLock; // to make sure only one query updates the dirty pruner structure if multiple queries run in parallel
186
187 volatile bool mPrunerNeedsUpdating;
188
189 void flushShapes();
190 PX_FORCE_INLINE void invalidateStaticTimestamp() { mStaticTimestamp++; }
191
192 PX_NOCOPY(PrunerManager)
193 };
194}
195}
196
197#endif
Definition GuPruner.h:76
Definition PxArray.h:53
Class representing a bounding volume hierarchy.
Definition PxBVH.h:63
Definition PxBitMap.h:52
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
A geometry object.
Definition PxGeometry.h:79
Definition PxMutex.h:89
Definition PxRenderOutput.h:50
Class used to retrieve limits(e.g. maximum number of bodies) for a scene. The limits are used as a hi...
Definition PxSceneDesc.h:318
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
Definition PxUserAllocated.h:43
3 Element vector class.
Definition PxVec3.h:50
Definition SqManager.h:49
Definition SqPruner.h:87
Definition SqManager.h:136
#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 GuPrunerPayload.h:63
Definition GuPrunerPayload.h:43
Definition SqManager.h:100
Definition SqManager.h:61