Main Page   Class List   Class Members  

  • Main Page
  • User's Guide
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

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-2020 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 #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 } // namespace Blast
00159 } // namespace Nv
00160 
00161 
00162 #endif // NVBLASTDEFAULTPROFILER_H
Copyright © 2015-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com