00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef NVBLASTDEFAULTPROFILER_H
00030 #define NVBLASTDEFAULTPROFILER_H
00031
00032 #include "NvBlastProfiler.h"
00033 #include "PxProfiler.h"
00034
00035 #if NV_NVTX
00036 #include "nvToolsExt.h"
00037 NV_INLINE void platformZoneStart(const char* name) { nvtxRangePushA(name); }
00038 NV_INLINE void platformZoneEnd() { nvtxRangePop(); }
00039
00040 #elif NV_XBOXONE
00041 #include "xboxone/NvBlastProfilerXB1.h"
00042
00043 #elif NV_PS4
00044 #include "ps4/NvBlastProfilerPS4.h"
00045
00046 #else
00047 NV_INLINE void platformZoneStart(const char*) { }
00048 NV_INLINE void platformZoneEnd() { }
00049
00050 #endif
00051
00052 #define SUPPORTS_THREAD_LOCAL (!NV_VC || NV_VC > 12)
00053
00054 namespace Nv
00055 {
00056 namespace Blast
00057 {
00058
00059 struct ExtProfileData
00060 {
00061 const char* name;
00062 void* data;
00063 };
00064
00065 #if SUPPORTS_THREAD_LOCAL
00066 static const int32_t PROFILER_MAX_NESTED_DEPTH = 64;
00067 static thread_local ExtProfileData th_ProfileData[PROFILER_MAX_NESTED_DEPTH];
00068 static thread_local int32_t th_depth = 0;
00069 #endif
00070
00071
00076 class ExtCustomProfiler : public ProfilerCallback
00077 {
00078 public:
00082 ExtCustomProfiler() : m_platformEnabled(false) {}
00083
00084
00086
00087 virtual void zoneStart(const char* name) override
00088 {
00089
00090 #if SUPPORTS_THREAD_LOCAL
00091 if (PxGetProfilerCallback())
00092 {
00093 void* data = PxGetProfilerCallback()->zoneStart(name, false, 0xb1a57);
00094
00095 if (th_depth < PROFILER_MAX_NESTED_DEPTH && th_depth >= 0)
00096 {
00097 th_ProfileData[th_depth].name = name;
00098 th_ProfileData[th_depth].data = data;
00099 th_depth++;
00100 }
00101 else
00102 {
00103 assert(th_depth < PROFILER_MAX_NESTED_DEPTH && th_depth >= 0);
00104 }
00105 }
00106 #endif
00107
00108 if (m_platformEnabled)
00109 {
00110 platformZoneStart(name);
00111 }
00112 }
00113
00114 virtual void zoneEnd() override
00115 {
00116
00117 #if SUPPORTS_THREAD_LOCAL
00118 if (PxGetProfilerCallback())
00119 {
00120 th_depth--;
00121
00122 if (th_depth >= 0)
00123 {
00124 ExtProfileData& pd = th_ProfileData[th_depth];
00125 PxGetProfilerCallback()->zoneEnd(pd.data, pd.name, false, 0xb1a57);
00126 }
00127 else
00128 {
00129 assert(th_depth >= 0);
00130 }
00131 }
00132 #endif
00133
00134 if (m_platformEnabled)
00135 {
00136 platformZoneEnd();
00137 }
00138 }
00139
00140
00142
00148 void setPlatformEnabled(bool enabled)
00149 {
00150 m_platformEnabled = enabled;
00151 }
00152
00153 private:
00154 bool m_platformEnabled;
00155 };
00156
00157 }
00158 }
00159
00160
00161 #endif // NVBLASTDEFAULTPROFILER_H