RavEngine
Loading...
Searching...
No Matches
ExtSqManager.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 EXT_SQ_MANAGER_H
30#define EXT_SQ_MANAGER_H
31
32#include "common/PxPhysXCommonConfig.h"
33
34#include "foundation/PxBitMap.h"
35#include "foundation/PxArray.h"
36#include "SqPruner.h"
37#include "SqManager.h"
38
39#include "foundation/PxHashSet.h"
40namespace physx
41{
42namespace Sq
43{
44 class CompoundPruner;
45}
46}
47
48#include "foundation/PxMutex.h"
49
50namespace physx
51{
52class PxRenderOutput;
53class PxBVH;
54class PxSceneLimits;
55
56namespace Gu
57{
58 class BVH;
59}
60
61namespace Sq
62{
63 // PT: this is a customized version of physx::Sq::PrunerManager that supports more than 2 hardcoded pruners.
64 // It might not be possible to support the whole PxSceneQuerySystem API with an arbitrary number of pruners.
66 {
67 public:
68 ExtPrunerManager(PxU64 contextID, float inflation, const Adapter& adapter, bool usesTreeOfPruners);
70
71 PxU32 addPruner(Gu::Pruner* pruner, PxU32 preallocated);
72
73 Gu::PrunerHandle addPrunerShape(const Gu::PrunerPayload& payload, PxU32 prunerIndex, bool dynamic, PrunerCompoundId compoundId, const PxBounds3& bounds, const PxTransform& transform, bool hasPruningStructure=false);
74 void addCompoundShape(const PxBVH& bvh, PrunerCompoundId compoundId, const PxTransform& compoundTransform, Gu::PrunerHandle* prunerHandle, const Gu::PrunerPayload* payloads, const PxTransform* transforms, bool isDynamic);
75 void markForUpdate(PxU32 prunerIndex, bool dynamic, PrunerCompoundId compoundId, Gu::PrunerHandle shapeHandle, const PxTransform& transform);
76 void removePrunerShape(PxU32 prunerIndex, bool dynamic, PrunerCompoundId compoundId, Gu::PrunerHandle shapeHandle, Gu::PrunerPayloadRemovalCallback* removalCallback);
77
78 PX_FORCE_INLINE PxU32 getNbPruners() const { return mPrunerExt.size(); }
79 PX_FORCE_INLINE const Gu::Pruner* getPruner(PxU32 index) const { return mPrunerExt[index]->mPruner; }
80 PX_FORCE_INLINE Gu::Pruner* getPruner(PxU32 index) { return mPrunerExt[index]->mPruner; }
81 PX_FORCE_INLINE const CompoundPruner* getCompoundPruner() const { return mCompoundPrunerExt.mPruner; }
82 PX_FORCE_INLINE PxU64 getContextId() const { return mContextID; }
83
84 void preallocate(PxU32 prunerIndex, PxU32 nbShapes);
85
86 void setDynamicTreeRebuildRateHint(PxU32 dynTreeRebuildRateHint);
87 PX_FORCE_INLINE PxU32 getDynamicTreeRebuildRateHint() const { return mRebuildRateHint; }
88
89 void flushUpdates();
90 void forceRebuildDynamicTree(PxU32 prunerIndex);
91
92 void updateCompoundActor(PrunerCompoundId compoundId, const PxTransform& compoundTransform);
93 void removeCompoundActor(PrunerCompoundId compoundId, Gu::PrunerPayloadRemovalCallback* removalCallback);
94
95 void* prepareSceneQueriesUpdate(PxU32 prunerIndex);
96 void sceneQueryBuildStep(void* handle);
97
98 void sync(PxU32 prunerIndex, const Gu::PrunerHandle* handles, const PxU32* boundsIndices, const PxBounds3* bounds, const PxTransform32* transforms, PxU32 count, const PxBitMap& ignoredIndices);
99 void afterSync(bool buildStep, bool commit);
100 void shiftOrigin(const PxVec3& shift);
101 void visualize(PxU32 prunerIndex, PxRenderOutput& out) const;
102
103 void flushMemory();
104 PX_FORCE_INLINE PxU32 getStaticTimestamp() const { return mStaticTimestamp; }
105 PX_FORCE_INLINE const Adapter& getAdapter() const { return mAdapter; }
106 PX_FORCE_INLINE const Gu::BVH* getTreeOfPruners() const { return mTreeOfPruners; }
107
108 PxU32 startCustomBuildstep();
109 void customBuildstep(PxU32 index);
110 void finishCustomBuildstep();
111
112 void createTreeOfPruners();
113 private:
114 const Adapter& mAdapter;
115 PxArray<PrunerExt*> mPrunerExt;
116 CompoundPrunerExt mCompoundPrunerExt;
117
118 Gu::BVH* mTreeOfPruners;
119
120 const PxU64 mContextID;
121 PxU32 mStaticTimestamp;
122 PxU32 mRebuildRateHint;
123 const float mInflation; // SQ_PRUNER_EPSILON
124
125 PxMutex mSQLock; // to make sure only one query updates the dirty pruner structure if multiple queries run in parallel
126
127 volatile bool mPrunerNeedsUpdating;
128 volatile bool mTimestampNeedsUpdating;
129 const bool mUsesTreeOfPruners;
130
131 void flushShapes();
132 PX_FORCE_INLINE void invalidateStaticTimestamp() { mStaticTimestamp++; }
133
134 PX_NOCOPY(ExtPrunerManager)
135 };
136}
137}
138
139#endif
Represents a BVH.
Definition GuBVH.h:93
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
Definition PxMutex.h:89
Definition PxRenderOutput.h:50
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 ExtSqManager.h:66
#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