Main Page Class List Class Members

# sdk/globals/include/NvBlastGlobals.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 NVBLASTGLOBALS_H
    00030 #define NVBLASTGLOBALS_H
    00031
    00032 #include <new>
    00033 #include "NvBlastTypes.h"
    00034
    00035
    00036 namespace Nv
    00037 {
    00038 namespace Blast
    00039 {
    00040
    00041
    00045 class AllocatorCallback
    00046 {
    00047 public:
    00051     virtual ~AllocatorCallback()
    00052     {
    00053     }
    00054
    00067     virtual void* allocate(size_t size, const char* typeName, const char* filename, int line) = 0;
    00068
    00074     virtual void deallocate(void* ptr) = 0;
    00075 };
    00076
    00077
    00088 struct ErrorCode
    00089 {
    00090     enum Enum
    00091     {
    00092         eNO_ERROR = 0,
    00093
    00095         eDEBUG_INFO = 1,
    00096
    00098         eDEBUG_WARNING = 2,
    00099
    00101         eINVALID_PARAMETER = 4,
    00102
    00104         eINVALID_OPERATION = 8,
    00105
    00107         eOUT_OF_MEMORY = 16,
    00108
    00112         eINTERNAL_ERROR = 32,
    00113
    00115         eABORT = 64,
    00116
    00118         ePERF_WARNING = 128,
    00119
    00121         eMASK_ALL = -1
    00122     };
    00123 };
    00124
    00125
    00131 class ErrorCallback
    00132 {
    00133 public:
    00134     virtual ~ErrorCallback()
    00135     {
    00136     }
    00137
    00145     virtual void reportError(ErrorCode::Enum code, const char* message, const char* file, int line) = 0;
    00146 };
    00147
    00148
    00149 } // namespace Blast
    00150 } // namespace Nv
    00151
    00152
    00154
    00161 NVBLAST_API Nv::Blast::AllocatorCallback* NvBlastGlobalGetAllocatorCallback();
    00162
    00166 NVBLAST_API void NvBlastGlobalSetAllocatorCallback(Nv::Blast::AllocatorCallback* allocatorCallback);
    00167
    00174 NVBLAST_API Nv::Blast::ErrorCallback* NvBlastGlobalGetErrorCallback();
    00175
    00179 NVBLAST_API void NvBlastGlobalSetErrorCallback(Nv::Blast::ErrorCallback* errorCallback);
    00180
    00181
    00183
    00184 namespace Nv
    00185 {
    00186 namespace Blast
    00187 {
    00188
    00189
    00195 NV_INLINE void logLL(int type, const char* msg, const char* file, int line)
    00196 {
    00197     ErrorCode::Enum errorCode = ErrorCode::eNO_ERROR;
    00198     switch (type)
    00199     {
    00200     case NvBlastMessage::Error:     errorCode = ErrorCode::eINVALID_OPERATION;  break;
    00201     case NvBlastMessage::Warning:   errorCode = ErrorCode::eDEBUG_WARNING;      break;
    00202     case NvBlastMessage::Info:      errorCode = ErrorCode::eDEBUG_INFO;         break;
    00203     case NvBlastMessage::Debug:     errorCode = ErrorCode::eNO_ERROR;           break;
    00204     }
    00205
    00206     NvBlastGlobalGetErrorCallback()->reportError(errorCode, msg, file, line);
    00207 }
    00208
    00209
    00210 } // namespace Blast
    00211 } // namespace Nv
    00212
    00213
    00214
    00216
    00220 #define NVBLAST_ALLOC(_size)                NvBlastGlobalGetAllocatorCallback()->allocate(_size, nullptr, __FILE__, __LINE__)
    00221 #define NVBLAST_ALLOC_NAMED(_size, _name)   NvBlastGlobalGetAllocatorCallback()->allocate(_size, _name, __FILE__, __LINE__)
    00222 #define NVBLAST_FREE(_mem)                  NvBlastGlobalGetAllocatorCallback()->deallocate(_mem)
    00223
    00228 #define NVBLAST_NEW(T) new (NvBlastGlobalGetAllocatorCallback()->allocate(sizeof(T), #T, __FILE__, __LINE__)) T
    00229
    00234 #define NVBLAST_DELETE(obj, T)                  \
    00235     (obj)->~T();                                \
    00236     NvBlastGlobalGetAllocatorCallback()->deallocate(obj)
    00237
    00238
    00239
    00241
    00245 #define NVBLAST_LOG(_code, _msg)    NvBlastGlobalGetErrorCallback()->reportError(_code, _msg, __FILE__, __LINE__)
    00246 #define NVBLAST_LOG_ERROR(_msg)     NVBLAST_LOG(Nv::Blast::ErrorCode::eINVALID_OPERATION, _msg)
    00247 #define NVBLAST_LOG_WARNING(_msg)   NVBLAST_LOG(Nv::Blast::ErrorCode::eDEBUG_WARNING, _msg)
    00248 #define NVBLAST_LOG_INFO(_msg)      NVBLAST_LOG(Nv::Blast::ErrorCode::eDEBUG_INFO, _msg)
    00249 #define NVBLAST_LOG_DEBUG(_msg)     NVBLAST_LOG(Nv::Blast::ErrorCode::eNO_ERROR, _msg)
    00250
    00255 #define NVBLAST_CHECK(_code, _expr, _msg, _onFail)                                                                      \
    00256     {                                                                                                                   \
    00257         if(!(_expr))                                                                                                    \
    00258         {                                                                                                               \
    00259             NVBLAST_LOG(_code, _msg);                                                                                   \
    00260             { _onFail; };                                                                                               \
    00261         }                                                                                                               \
    00262     }
    00263
    00264 #define NVBLAST_CHECK_ERROR(_expr, _msg, _onFail)   NVBLAST_CHECK(Nv::Blast::ErrorCode::eINVALID_OPERATION, _expr, _msg, _onFail)
    00265 #define NVBLAST_CHECK_WARNING(_expr, _msg, _onFail) NVBLAST_CHECK(Nv::Blast::ErrorCode::eDEBUG_WARNING, _expr, _msg, _onFail)
    00266 #define NVBLAST_CHECK_INFO(_expr, _msg, _onFail)    NVBLAST_CHECK(Nv::Blast::ErrorCode::eDEBUG_INFO, _expr, _msg, _onFail)
    00267 #define NVBLAST_CHECK_DEBUG(_expr, _msg, _onFail)   NVBLAST_CHECK(Nv::Blast::ErrorCode::eNO_ERROR, _expr, _msg, _onFail)
    00268
    00269
    00271
    00272
    00273 // Macro to load a uint32_t (or larger) with four characters
    00274 #define NVBLAST_FOURCC(_a, _b, _c, _d)  ( (uint32_t)(_a) | (uint32_t)(_b)<<8 | (uint32_t)(_c)<<16 | (uint32_t)(_d)<<24 )
    00275
    00276
    00277 #endif // ifndef NVBLASTGLOBALS_H