sdk/extensions/physx/include/NvBlastExtCustomProfiler.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and
00007 // any modifications thereto. Any use, reproduction, disclosure, or
00008 // distribution of this software and related documentation without an express
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 //
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2016-2018 NVIDIA Corporation. All rights reserved.
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 } // namespace Blast
00158 } // namespace Nv
00159 
00160 
00161 #endif // NVBLASTDEFAULTPROFILER_H