RavEngine
Loading...
Searching...
No Matches
PxPvdImpl.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 PX_PVD_IMPL_H
30#define PX_PVD_IMPL_H
31
32#include "foundation/PxProfiler.h"
33
34#include "foundation/PxAllocator.h"
35#include "PsPvd.h"
36#include "foundation/PxArray.h"
37#include "foundation/PxMutex.h"
38#include "PxPvdCommStreamTypes.h"
39#include "PxPvdFoundation.h"
40#include "PxPvdObjectModelMetaData.h"
41#include "PxPvdObjectRegistrar.h"
42
43namespace physx
44{
45
46namespace profile
47{
48 class PxProfileZoneManager;
49}
50
51namespace pvdsdk
52{
53class PvdMemClient;
54class PvdProfileZoneClient;
55
57{
60 PvdObjectModelMetaData& mMetaData;
61 PxMutex mMutex;
62 uint32_t mRefCount;
63 TInstTypeMap mTypeMap;
64
66 : mMetaData(PvdObjectModelMetaData::create()), mRefCount(0), mTypeMap("MetaDataProvider::mTypeMap")
67 {
68 mMetaData.addRef();
69 }
70 virtual ~MetaDataProvider()
71 {
72 mMetaData.release();
73 }
74
75 virtual void addRef()
76 {
77 TScopedLockType locker(mMutex);
78 ++mRefCount;
79 }
80 virtual void release()
81 {
82 {
83 TScopedLockType locker(mMutex);
84 if(mRefCount)
85 --mRefCount;
86 }
87 if(!mRefCount)
88 PVD_DELETE(this);
89 }
90 virtual PvdObjectModelMetaData& lock()
91 {
92 mMutex.lock();
93 return mMetaData;
94 }
95 virtual void unlock()
96 {
97 mMutex.unlock();
98 }
99
100 virtual bool createInstance(const NamespacedName& clsName, const void* instance)
101 {
102 TScopedLockType locker(mMutex);
103 Option<ClassDescription> cls(mMetaData.findClass(clsName));
104 if(cls.hasValue() == false)
105 return false;
106 int32_t instType = cls->mClassId;
107 mTypeMap.insert(instance, instType);
108 return true;
109 }
110 virtual bool isInstanceValid(const void* instance)
111 {
112 TScopedLockType locker(mMutex);
113 ClassDescription classDesc;
114 bool retval = mTypeMap.find(instance) != NULL;
115#if PX_DEBUG
116 if(retval)
117 classDesc = mMetaData.getClass(mTypeMap.find(instance)->second);
118#endif
119 return retval;
120 }
121 virtual void destroyInstance(const void* instance)
122 {
123 {
124 TScopedLockType locker(mMutex);
125 mTypeMap.erase(instance);
126 }
127 }
128 virtual int32_t getInstanceClassType(const void* instance)
129 {
130 TScopedLockType locker(mMutex);
131 const TInstTypeMap::Entry* entry = mTypeMap.find(instance);
132 if(entry)
133 return entry->second;
134 return -1;
135 }
136
137 private:
138 MetaDataProvider& operator=(const MetaDataProvider&);
140};
141
143
149class PvdImpl : public PsPvd, public PxUserAllocated
150{
151 PX_NOCOPY(PvdImpl)
152
154 typedef void (PvdImpl::*TAllocationHandler)(size_t size, const char* typeName, const char* filename, int line,
155 void* allocatedMemory);
156 typedef void (PvdImpl::*TDeallocationHandler)(void* allocatedMemory);
157
158 public:
159 PvdImpl();
160 virtual ~PvdImpl();
161 void release();
162
163 bool connect(PxPvdTransport& transport, PxPvdInstrumentationFlags flags);
164 void disconnect();
165 bool isConnected(bool useCachedStatus = true);
166 void flush();
167
170
171 void addClient(PvdClient* client);
172 void removeClient(PvdClient* client);
173
174 PvdOMMetaDataProvider& getMetaDataProvider();
175
176 bool registerObject(const void* inItem);
177 bool unRegisterObject(const void* inItem);
178
179 //AllocationListener
180 void onAllocation(size_t size, const char* typeName, const char* filename, int line, void* allocatedMemory);
181 void onDeallocation(void* addr);
182
183 uint64_t getNextStreamId();
184
185 static bool initialize();
186 static PvdImpl* getInstance();
187
188 // Profiling
189
190 virtual void* zoneStart(const char* eventName, bool detached, uint64_t contextId);
191
192 virtual void zoneEnd(void* profilerData, const char *eventName, bool detached, uint64_t contextId);
193
194 private:
195 void sendTransportInitialization();
196
197 PxPvdTransport* mPvdTransport;
198 physx::PxArray<PvdClient*> mPvdClients;
199
200 MetaDataProvider* mSharedMetaProvider; // shared between clients
201 ObjectRegistrar mObjectRegistrar;
202
203 PvdMemClient* mMemClient;
204
206 bool mIsConnected;
207 bool mGPUProfilingWasConnected;
208 bool mIsNVTXSupportEnabled;
209 uint32_t mNVTXContext;
210 uint64_t mNextStreamId;
211 physx::profile::PxProfileZoneManager*mProfileZoneManager;
212 PvdProfileZoneClient* mProfileClient;
213 physx::profile::PxProfileZone* mProfileZone;
214 static PvdImpl* sInstance;
215 static uint32_t sRefCount;
216};
217
218} // namespace pvdsdk
219}
220
221#endif
222
Definition PxArray.h:53
Definition PxHashMap.h:78
Definition PxMutex.h:93
Definition PxMutex.h:89
PX_FORCE_INLINE void unlock() const
Definition PxMutex.h:149
PX_FORCE_INLINE void lock() const
Definition PxMutex.h:130
Definition PxBasicTemplates.h:67
PxPvdTransport is an interface representing the data transport mechanism. This class defines all serv...
Definition PxPvdTransport.h:53
Definition PxUserAllocated.h:43
The profiling system was setup in the expectation that there would be several systems that each had i...
Definition PxProfileZoneManager.h:86
The profiling system was setup in the expectation that there would be several systems that each had i...
Definition PxPvdProfileZone.h:67
Definition PxPvdObjectRegistrar.h:46
Definition PxPvdObjectModelMetaData.h:313
Definition PsPvd.h:56
PvdClient is the per-client connection to PVD. It provides callback when PVD is connected/disconnted....
Definition PxPvdClient.h:54
Definition PxPvdImpl.h:150
bool connect(PxPvdTransport &transport, PxPvdInstrumentationFlags flags)
Definition PxPvdImpl.cpp:125
PxPvdInstrumentationFlags getInstrumentationFlags()
Definition PxPvdImpl.cpp:235
void disconnect()
Definition PxPvdImpl.cpp:180
bool isConnected(bool useCachedStatus=true)
Definition PxPvdImpl.cpp:222
void release()
Releases the pvd instance.
Definition PxPvdImpl.cpp:319
void onDeallocation(void *addr)
callback when memory is deallocated.
Definition PxPvdImpl.cpp:281
PxPvdTransport * getTransport()
Definition PxPvdImpl.cpp:230
virtual void zoneEnd(void *profilerData, const char *eventName, bool detached, uint64_t contextId)
Mark the end of a nested profile block.
Definition PxPvdImpl.cpp:378
virtual void * zoneStart(const char *eventName, bool detached, uint64_t contextId)
Mark the beginning of a nested profile block.
Definition PxPvdImpl.cpp:343
void onAllocation(size_t size, const char *typeName, const char *filename, int line, void *allocatedMemory)
callback when memory is allocated.
Definition PxPvdImpl.cpp:275
Definition PxPvdMemClient.h:49
Definition PxPvdCommStreamTypes.h:61
Definition PxPvdObjectModelMetaData.h:374
Definition PxPvdProfileZoneClient.h:47
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition PxPvdObjectModelMetaData.h:142
Definition PxPvdImpl.h:57
Definition PxPvdObjectModelBaseTypes.h:188