NvBlastGlobals.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
27 
28 
29 #ifndef NVBLASTGLOBALS_H
30 #define NVBLASTGLOBALS_H
31 
32 #include <new>
33 #include "NvBlastTypes.h"
34 
35 
36 namespace Nv
37 {
38 namespace Blast
39 {
40 
41 
46 {
47 public:
52  {
53  }
54 
67  virtual void* allocate(size_t size, const char* typeName, const char* filename, int line) = 0;
68 
74  virtual void deallocate(void* ptr) = 0;
75 };
76 
77 
88 struct ErrorCode
89 {
90  enum Enum
91  {
92  eNO_ERROR = 0,
93 
95  eDEBUG_INFO = 1,
96 
98  eDEBUG_WARNING = 2,
99 
101  eINVALID_PARAMETER = 4,
102 
104  eINVALID_OPERATION = 8,
105 
107  eOUT_OF_MEMORY = 16,
108 
112  eINTERNAL_ERROR = 32,
113 
115  eABORT = 64,
116 
118  ePERF_WARNING = 128,
119 
121  eMASK_ALL = -1
122  };
123 };
124 
125 
132 {
133 public:
134  virtual ~ErrorCallback()
135  {
136  }
137 
145  virtual void reportError(ErrorCode::Enum code, const char* message, const char* file, int line) = 0;
146 };
147 
148 
149 } // namespace Blast
150 } // namespace Nv
151 
152 
154 
162 
167 
175 
180 
181 
183 
184 namespace Nv
185 {
186 namespace Blast
187 {
188 
189 
195 NV_INLINE void logLL(int type, const char* msg, const char* file, int line)
196 {
198  switch (type)
199  {
200  case NvBlastMessage::Error: errorCode = ErrorCode::eINVALID_OPERATION; break;
201  case NvBlastMessage::Warning: errorCode = ErrorCode::eDEBUG_WARNING; break;
202  case NvBlastMessage::Info: errorCode = ErrorCode::eDEBUG_INFO; break;
203  case NvBlastMessage::Debug: errorCode = ErrorCode::eNO_ERROR; break;
204  }
205 
206  NvBlastGlobalGetErrorCallback()->reportError(errorCode, msg, file, line);
207 }
208 
209 
210 } // namespace Blast
211 } // namespace Nv
212 
213 
214 
216 
220 #define NVBLAST_ALLOC(_size) NvBlastGlobalGetAllocatorCallback()->allocate(_size, nullptr, __FILE__, __LINE__)
221 #define NVBLAST_ALLOC_NAMED(_size, _name) NvBlastGlobalGetAllocatorCallback()->allocate(_size, _name, __FILE__, __LINE__)
222 #define NVBLAST_FREE(_mem) NvBlastGlobalGetAllocatorCallback()->deallocate(_mem)
223 
228 #define NVBLAST_NEW(T) new (NvBlastGlobalGetAllocatorCallback()->allocate(sizeof(T), #T, __FILE__, __LINE__)) T
229 
234 #define NVBLAST_DELETE(obj, T) \
235  (obj)->~T(); \
236  NvBlastGlobalGetAllocatorCallback()->deallocate(obj)
237 
238 
239 
241 
245 #define NVBLAST_LOG(_code, _msg) NvBlastGlobalGetErrorCallback()->reportError(_code, _msg, __FILE__, __LINE__)
246 #define NVBLAST_LOG_ERROR(_msg) NVBLAST_LOG(Nv::Blast::ErrorCode::eINVALID_OPERATION, _msg)
247 #define NVBLAST_LOG_WARNING(_msg) NVBLAST_LOG(Nv::Blast::ErrorCode::eDEBUG_WARNING, _msg)
248 #define NVBLAST_LOG_INFO(_msg) NVBLAST_LOG(Nv::Blast::ErrorCode::eDEBUG_INFO, _msg)
249 #define NVBLAST_LOG_DEBUG(_msg) NVBLAST_LOG(Nv::Blast::ErrorCode::eNO_ERROR, _msg)
250 
255 #define NVBLAST_CHECK(_code, _expr, _msg, _onFail) \
256  { \
257  if(!(_expr)) \
258  { \
259  NVBLAST_LOG(_code, _msg); \
260  { _onFail; }; \
261  } \
262  }
263 
264 #define NVBLAST_CHECK_ERROR(_expr, _msg, _onFail) NVBLAST_CHECK(Nv::Blast::ErrorCode::eINVALID_OPERATION, _expr, _msg, _onFail)
265 #define NVBLAST_CHECK_WARNING(_expr, _msg, _onFail) NVBLAST_CHECK(Nv::Blast::ErrorCode::eDEBUG_WARNING, _expr, _msg, _onFail)
266 #define NVBLAST_CHECK_INFO(_expr, _msg, _onFail) NVBLAST_CHECK(Nv::Blast::ErrorCode::eDEBUG_INFO, _expr, _msg, _onFail)
267 #define NVBLAST_CHECK_DEBUG(_expr, _msg, _onFail) NVBLAST_CHECK(Nv::Blast::ErrorCode::eNO_ERROR, _expr, _msg, _onFail)
268 
269 
271 
272 
273 // Macro to load a uint32_t (or larger) with four characters
274 #define NVBLAST_FOURCC(_a, _b, _c, _d) ( (uint32_t)(_a) | (uint32_t)(_b)<<8 | (uint32_t)(_c)<<16 | (uint32_t)(_d)<<24 )
275 
276 
277 #endif // ifndef NVBLASTGLOBALS_H
Error messages.
Definition: NvBlastTypes.h:49
virtual void deallocate(void *ptr)=0
Frees memory previously allocated by allocate().
virtual void * allocate(size_t size, const char *typeName, const char *filename, int line)=0
Allocates size bytes of memory, which must be 16-byte aligned.
An informational message.
Definition: NvBlastGlobals.h:95
virtual void reportError(ErrorCode::Enum code, const char *message, const char *file, int line)=0
Reports an error code.
NV_INLINE void logLL(int type, const char *msg, const char *file, int line)
Definition: NvBlastGlobals.h:195
Warning messages.
Definition: NvBlastTypes.h:50
User defined interface class. Used by the library to emit debug information.
Definition: NvBlastGlobals.h:131
Information messages.
Definition: NvBlastTypes.h:51
void NvBlastGlobalSetAllocatorCallback(Nv::Blast::AllocatorCallback *allocatorCallback)
Error codes.
Definition: NvBlastGlobals.h:88
Nv::Blast::AllocatorCallback * NvBlastGlobalGetAllocatorCallback()
method was called at a time when an operation is not possible
Definition: NvBlastGlobals.h:104
#define NVBLAST_API
Definition: NvBlastPreprocessor.h:37
virtual ~AllocatorCallback()
destructor
Definition: NvBlastGlobals.h:51
Definition: NvBlastGlobals.h:92
a warning message for the user to help with debugging
Definition: NvBlastGlobals.h:98
Abstract base class for an application defined memory allocator that can be used by toolkit (Tk) or a...
Definition: NvBlastGlobals.h:45
void NvBlastGlobalSetErrorCallback(Nv::Blast::ErrorCallback *errorCallback)
virtual ~ErrorCallback()
Definition: NvBlastGlobals.h:134
Nv::Blast::ErrorCallback * NvBlastGlobalGetErrorCallback()
Used only in debug version of dll.
Definition: NvBlastTypes.h:52
Enum
Definition: NvBlastGlobals.h:90
Definition: NvBlastExtAuthoring.h:34