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 #include <PxFoundation.h>
00035
00036 #if NV_NVTX
00037 #include "nvToolsExt.h"
00038 NV_INLINE void platformZoneStart(const char* name) { nvtxRangePushA(name); }
00039 NV_INLINE void platformZoneEnd() { nvtxRangePop(); }
00040
00041 #elif NV_XBOXONE
00042 #include "xboxone/NvBlastProfilerXB1.h"
00043
00044 #elif NV_PS4
00045 #include "ps4/NvBlastProfilerPS4.h"
00046
00047 #else
00048 NV_INLINE void platformZoneStart(const char*) { }
00049 NV_INLINE void platformZoneEnd() { }
00050
00051 #endif
00052
00053 #define SUPPORTS_THREAD_LOCAL (!NV_VC || NV_VC > 12)
00054
00055 namespace Nv
00056 {
00057 namespace Blast
00058 {
00059
00060 struct ExtProfileData
00061 {
00062 const char* name;
00063 void* data;
00064 };
00065
00066 #if SUPPORTS_THREAD_LOCAL
00067 static const int32_t PROFILER_MAX_NESTED_DEPTH = 64;
00068 static thread_local ExtProfileData th_ProfileData[PROFILER_MAX_NESTED_DEPTH];
00069 static thread_local int32_t th_depth = 0;
00070 #endif
00071
00072
00077 class ExtCustomProfiler : public ProfilerCallback
00078 {
00079 public:
00083 ExtCustomProfiler() : m_platformEnabled(false) {}
00084
00085
00087
00088 virtual void zoneStart(const char* name) override
00089 {
00090
00091 #if SUPPORTS_THREAD_LOCAL
00092 if (PxGetProfilerCallback())
00093 {
00094 void* data = PxGetProfilerCallback()->zoneStart(name, false, 0xb1a57);
00095
00096 if (th_depth < PROFILER_MAX_NESTED_DEPTH && th_depth >= 0)
00097 {
00098 th_ProfileData[th_depth].name = name;
00099 th_ProfileData[th_depth].data = data;
00100 th_depth++;
00101 }
00102 else
00103 {
00104 assert(th_depth < PROFILER_MAX_NESTED_DEPTH && th_depth >= 0);
00105 }
00106 }
00107 #endif
00108
00109 if (m_platformEnabled)
00110 {
00111 platformZoneStart(name);
00112 }
00113 }
00114
00115 virtual void zoneEnd() override
00116 {
00117
00118 #if SUPPORTS_THREAD_LOCAL
00119 if (PxGetProfilerCallback())
00120 {
00121 th_depth--;
00122
00123 if (th_depth >= 0)
00124 {
00125 ExtProfileData& pd = th_ProfileData[th_depth];
00126 PxGetProfilerCallback()->zoneEnd(pd.data, pd.name, false, 0xb1a57);
00127 }
00128 else
00129 {
00130 assert(th_depth >= 0);
00131 }
00132 }
00133 #endif
00134
00135 if (m_platformEnabled)
00136 {
00137 platformZoneEnd();
00138 }
00139 }
00140
00141
00143
00149 void setPlatformEnabled(bool enabled)
00150 {
00151 m_platformEnabled = enabled;
00152 }
00153
00154 private:
00155 bool m_platformEnabled;
00156 };
00157
00158 }
00159 }
00160
00161
00162 #endif // NVBLASTDEFAULTPROFILER_H