PxPreprocessor.h
Go to the documentation of this file.
1 //
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions
4 // are met:
5 // * Redistributions of source code must retain the above copyright
6 // notice, this list of conditions and the following disclaimer.
7 // * Redistributions in binary form must reproduce the above copyright
8 // notice, this list of conditions and the following disclaimer in the
9 // documentation and/or other materials provided with the distribution.
10 // * Neither the name of NVIDIA CORPORATION nor the names of its
11 // contributors may be used to endorse or promote products derived
12 // from this software without specific prior written permission.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
15 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
27 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29 
30 #ifndef PXFOUNDATION_PXPREPROCESSOR_H
31 #define PXFOUNDATION_PXPREPROCESSOR_H
32 
33 #include <stddef.h>
34 #if !defined(PX_GENERATE_META_DATA)
35 #include <ciso646>
36 #endif
37 
41 #define PX_STRINGIZE_HELPER(X) #X
42 #define PX_STRINGIZE(X) PX_STRINGIZE_HELPER(X)
43 
44 #define PX_CONCAT_HELPER(X, Y) X##Y
45 #define PX_CONCAT(X, Y) PX_CONCAT_HELPER(X, Y)
46 
47 /*
48 The following preprocessor identifiers specify compiler, OS, and architecture.
49 All definitions have a value of 1 or 0, use '#if' instead of '#ifdef'.
50 */
51 
55 #if defined(_MSC_VER)
56 #if _MSC_VER >= 1910
57 #define PX_VC 15
58 #elif _MSC_VER >= 1900
59 #define PX_VC 14
60 #elif _MSC_VER >= 1800
61 #define PX_VC 12
62 #elif _MSC_VER >= 1700
63 #define PX_VC 11
64 #elif _MSC_VER >= 1600
65 #define PX_VC 10
66 #elif _MSC_VER >= 1500
67 #define PX_VC 9
68 #else
69 #error "Unknown VC version"
70 #endif
71 #elif defined(__clang__)
72 #define PX_CLANG 1
73  #if defined (__clang_major__)
74  #define PX_CLANG_MAJOR __clang_major__
75  #elif defined (_clang_major)
76  #define PX_CLANG_MAJOR _clang_major
77  #else
78  #define PX_CLANG_MAJOR 0
79  #endif
80 #elif defined(__GNUC__) // note: __clang__ implies __GNUC__
81 #define PX_GCC 1
82 #else
83 #error "Unknown compiler"
84 #endif
85 
89 #if defined(_XBOX_ONE)
90 #define PX_XBOXONE 1
91 #elif defined(_GAMING_XBOX) || defined (_GAMING_XBOX_SCARLETT)
92 #define PX_XBOX_SERIES_X 1
93 #elif defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP
94 #define PX_UWP 1
95 #elif defined(_WIN64) // note: _XBOX_ONE implies _WIN64
96 #define PX_WIN64 1
97 #elif defined(_WIN32) // note: _M_PPC implies _WIN32
98 #define PX_WIN32 1
99 #elif defined(__ANDROID__)
100 #define PX_ANDROID 1
101 #elif defined(__linux__) || defined (__EMSCRIPTEN__) // note: __ANDROID__ implies __linux__
102 #define PX_LINUX 1
103 #elif defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
104 #define PX_IOS 1
105 #elif defined(__APPLE__)
106 #define PX_OSX 1
107 #elif defined(__ORBIS__)
108 #define PX_PS4 1
109 #elif defined(__NX__)
110 #define PX_SWITCH 1
111 #else
112 #error "Unknown operating system"
113 #endif
114 
118 #if defined(__x86_64__) || defined(_M_X64) // ps4 compiler defines _M_X64 without value
119 #define PX_X64 1
120 #elif defined(__i386__) || defined(_M_IX86) || defined (__EMSCRIPTEN__)
121 #define PX_X86 1
122 #elif defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64)
123 #define PX_A64 1
124 #elif defined(__arm__) || defined(_M_ARM)
125 #define PX_ARM 1
126 #elif defined(__ppc__) || defined(_M_PPC) || defined(__CELLOS_LV2__)
127 #define PX_PPC 1
128 #else
129 #error "Unknown architecture"
130 #endif
131 
135 #if !defined(PX_SIMD_DISABLED)
136 #if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) || (defined (__EMSCRIPTEN__) && defined(__SSE2__))
137 #define PX_SSE2 1
138 #endif
139 #if defined(_M_ARM) || defined(__ARM_NEON__) || defined(__ARM_NEON)
140 #define PX_NEON 1
141 #endif
142 #if defined(_M_PPC) || defined(__CELLOS_LV2__)
143 #define PX_VMX 1
144 #endif
145 #endif
146 
150 #ifndef PX_VC
151 #define PX_VC 0
152 #endif
153 #ifndef PX_CLANG
154 #define PX_CLANG 0
155 #endif
156 #ifndef PX_GCC
157 #define PX_GCC 0
158 #endif
159 #ifndef PX_XBOXONE
160 #define PX_XBOXONE 0
161 #endif
162 #ifndef PX_XBOX_SERIES_X
163 #define PX_XBOX_SERIES_X 0
164 #endif
165 #ifndef PX_WIN64
166 #define PX_WIN64 0
167 #endif
168 #ifndef PX_WIN32
169 #define PX_WIN32 0
170 #endif
171 #ifndef PX_ANDROID
172 #define PX_ANDROID 0
173 #endif
174 #ifndef PX_LINUX
175 #define PX_LINUX 0
176 #endif
177 #ifndef PX_IOS
178 #define PX_IOS 0
179 #endif
180 #ifndef PX_OSX
181 #define PX_OSX 0
182 #endif
183 #ifndef PX_PS4
184 #define PX_PS4 0
185 #endif
186 #ifndef PX_SWITCH
187 #define PX_SWITCH 0
188 #endif
189 #ifndef PX_UWP
190 #define PX_UWP 0
191 #endif
192 #ifndef PX_X64
193 #define PX_X64 0
194 #endif
195 #ifndef PX_X86
196 #define PX_X86 0
197 #endif
198 #ifndef PX_A64
199 #define PX_A64 0
200 #endif
201 #ifndef PX_ARM
202 #define PX_ARM 0
203 #endif
204 #ifndef PX_PPC
205 #define PX_PPC 0
206 #endif
207 #ifndef PX_SSE2
208 #define PX_SSE2 0
209 #endif
210 #ifndef PX_NEON
211 #define PX_NEON 0
212 #endif
213 #ifndef PX_VMX
214 #define PX_VMX 0
215 #endif
216 
217 /*
218 define anything not defined through the command line to 0
219 */
220 #ifndef PX_DEBUG
221 #define PX_DEBUG 0
222 #endif
223 #ifndef PX_CHECKED
224 #define PX_CHECKED 0
225 #endif
226 #ifndef PX_PROFILE
227 #define PX_PROFILE 0
228 #endif
229 #ifndef PX_DEBUG_CRT
230 #define PX_DEBUG_CRT 0
231 #endif
232 #ifndef PX_NVTX
233 #define PX_NVTX 0
234 #endif
235 #ifndef PX_DOXYGEN
236 #define PX_DOXYGEN 0
237 #endif
238 
242 // compiler
243 #define PX_GCC_FAMILY (PX_CLANG || PX_GCC)
244 // os
245 #define PX_WINDOWS_FAMILY (PX_WIN32 || PX_WIN64 || PX_UWP)
246 #define PX_MICROSOFT_FAMILY (PX_XBOXONE || PX_WINDOWS_FAMILY || PX_XBOX_SERIES_X)
247 #define PX_LINUX_FAMILY (PX_LINUX || PX_ANDROID)
248 #define PX_APPLE_FAMILY (PX_IOS || PX_OSX) // equivalent to #if __APPLE__
249 #define PX_UNIX_FAMILY (PX_LINUX_FAMILY || PX_APPLE_FAMILY) // shortcut for unix/posix platforms
250 #if defined(__EMSCRIPTEN__)
251 #define PX_EMSCRIPTEN 1
252 #else
253 #define PX_EMSCRIPTEN 0
254 #endif
255 // architecture
256 #define PX_INTEL_FAMILY (PX_X64 || PX_X86)
257 #define PX_ARM_FAMILY (PX_ARM || PX_A64)
258 #define PX_P64_FAMILY (PX_X64 || PX_A64) // shortcut for 64-bit architectures
259 
263 #if defined(_LIBCPP_VERSION) || PX_WIN64 || PX_WIN32 || PX_PS4 || PX_XBOXONE || PX_UWP || PX_EMSCRIPTEN || PX_XBOX_SERIES_X
264 #define PX_LIBCPP 1
265 #else
266 #define PX_LIBCPP 0
267 #endif
268 
269 // legacy define for PhysX
270 #define PX_WINDOWS (PX_WINDOWS_FAMILY && !PX_ARM_FAMILY)
271 
275 #ifndef PX_ENABLE_ASSERTS
276 #if PX_DEBUG && !defined(__CUDACC__)
277 #define PX_ENABLE_ASSERTS 1
278 #else
279 #define PX_ENABLE_ASSERTS 0
280 #endif
281 #endif
282 
286 #ifndef PX_C_EXPORT
287 #if PX_WINDOWS_FAMILY || PX_LINUX
288 #define PX_C_EXPORT extern "C"
289 #else
290 #define PX_C_EXPORT
291 #endif
292 #endif
293 
294 #if PX_UNIX_FAMILY&& __GNUC__ >= 4
295 #define PX_UNIX_EXPORT __attribute__((visibility("default")))
296 #else
297 #define PX_UNIX_EXPORT
298 #endif
299 
300 #if (PX_WINDOWS_FAMILY || PX_XBOXONE || PX_PS4 || PX_XBOX_SERIES_X)
301 #define PX_DLL_EXPORT __declspec(dllexport)
302 #define PX_DLL_IMPORT __declspec(dllimport)
303 #else
304 #define PX_DLL_EXPORT PX_UNIX_EXPORT
305 #define PX_DLL_IMPORT
306 #endif
307 
311 #ifndef PX_CALL_CONV
312 #if PX_MICROSOFT_FAMILY
313 #define PX_CALL_CONV __cdecl
314 #else
315 #define PX_CALL_CONV
316 #endif
317 #endif
318 
322 #if PX_VC
323 #define PX_PUSH_PACK_DEFAULT __pragma(pack(push, 8))
324 #define PX_POP_PACK __pragma(pack(pop))
325 #elif PX_GCC_FAMILY
326 #define PX_PUSH_PACK_DEFAULT _Pragma("pack(push, 8)")
327 #define PX_POP_PACK _Pragma("pack(pop)")
328 #else
329 #define PX_PUSH_PACK_DEFAULT
330 #define PX_POP_PACK
331 #endif
332 
336 #define PX_INLINE inline
337 #if PX_MICROSOFT_FAMILY
338 #pragma inline_depth(255)
339 #endif
340 
344 #if PX_VC
345 #define PX_FORCE_INLINE __forceinline
346 #elif PX_LINUX // Workaround; Fedora Core 3 do not agree with force inline and PxcPool
347 #define PX_FORCE_INLINE inline
348 #elif PX_GCC_FAMILY
349 #define PX_FORCE_INLINE inline __attribute__((always_inline))
350 #else
351 #define PX_FORCE_INLINE inline
352 #endif
353 
357 #if PX_MICROSOFT_FAMILY
358 #define PX_NOINLINE __declspec(noinline)
359 #elif PX_GCC_FAMILY
360 #define PX_NOINLINE __attribute__((noinline))
361 #else
362 #define PX_NOINLINE
363 #endif
364 
368 #if defined(__CUDACC__)
369 #define PX_RESTRICT __restrict__
370 #else
371 #define PX_RESTRICT __restrict
372 #endif
373 
377 #if PX_MICROSOFT_FAMILY
378 #define PX_NOALIAS __declspec(noalias)
379 #else
380 #define PX_NOALIAS
381 #endif
382 
394 #ifndef PX_ALIGN
395 #if PX_MICROSOFT_FAMILY
396 #define PX_ALIGN(alignment, decl) __declspec(align(alignment)) decl
397 #define PX_ALIGN_PREFIX(alignment) __declspec(align(alignment))
398 #define PX_ALIGN_SUFFIX(alignment)
399 #elif PX_GCC_FAMILY
400 #define PX_ALIGN(alignment, decl) decl __attribute__((aligned(alignment)))
401 #define PX_ALIGN_PREFIX(alignment)
402 #define PX_ALIGN_SUFFIX(alignment) __attribute__((aligned(alignment)))
403 #elif defined __CUDACC__
404 #define PX_ALIGN(alignment, decl) __align__(alignment) decl
405 #define PX_ALIGN_PREFIX(alignment)
406 #define PX_ALIGN_SUFFIX(alignment) __align__(alignment))
407 #else
408 #define PX_ALIGN(alignment, decl)
409 #define PX_ALIGN_PREFIX(alignment)
410 #define PX_ALIGN_SUFFIX(alignment)
411 #endif
412 #endif
413 
424 #define PX_DEPRECATED
425 
430 // static assert
431 #if(defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))) || (PX_PS4) || (PX_APPLE_FAMILY) || (PX_SWITCH) || (PX_CLANG && PX_ARM)
432 #define PX_COMPILE_TIME_ASSERT(exp) typedef char PX_CONCAT(PxCompileTimeAssert_Dummy, __COUNTER__)[(exp) ? 1 : -1] __attribute__((unused))
433 #else
434 #define PX_COMPILE_TIME_ASSERT(exp) typedef char PxCompileTimeAssert_Dummy[(exp) ? 1 : -1]
435 #endif
436 
437 #if PX_GCC_FAMILY
438 #define PX_OFFSET_OF(X, Y) __builtin_offsetof(X, Y)
439 #else
440 #define PX_OFFSET_OF(X, Y) offsetof(X, Y)
441 #endif
442 
443 #define PX_OFFSETOF_BASE 0x100 // casting the null ptr takes a special-case code path, which we don't want
444 #define PX_OFFSET_OF_RT(Class, Member) \
445  (reinterpret_cast<size_t>(&reinterpret_cast<Class*>(PX_OFFSETOF_BASE)->Member) - size_t(PX_OFFSETOF_BASE))
446 
447 // check that exactly one of NDEBUG and _DEBUG is defined
448 #if !defined(NDEBUG) ^ defined(_DEBUG)
449 #error Exactly one of NDEBUG and _DEBUG needs to be defined!
450 #endif
451 
452 // make sure PX_CHECKED is defined in all _DEBUG configurations as well
453 #if !PX_CHECKED && PX_DEBUG
454 #error PX_CHECKED must be defined when PX_DEBUG is defined
455 #endif
456 
457 #ifdef __CUDACC__
458 #define PX_CUDA_CALLABLE __host__ __device__
459 #else
460 #define PX_CUDA_CALLABLE
461 #endif
462 
463 // avoid unreferenced parameter warning
464 // preferred solution: omit the parameter's name from the declaration
465 template <class T>
467 {
468 }
469 
470 // Ensure that the application hasn't tweaked the pack value to less than 8, which would break
471 // matching between the API headers and the binaries
472 // This assert works on win32/win64, but may need further specialization on other platforms.
473 // Some GCC compilers need the compiler flag -malign-double to be set.
474 // Apparently the apple-clang-llvm compiler doesn't support malign-double.
475 #if PX_PS4 || PX_APPLE_FAMILY || (PX_CLANG && !PX_ARM)
476 struct PxPackValidation
477 {
478  char _;
479  long a;
480 };
481 #elif PX_ANDROID || (PX_CLANG && PX_ARM)
482 struct PxPackValidation
483 {
484  char _;
485  double a;
486 };
487 #else
489 {
490  char _;
491  long long a;
492 };
493 #endif
494 // clang (as of version 3.9) cannot align doubles on 8 byte boundary when compiling for Intel 32 bit target
495 #if !PX_APPLE_FAMILY && !PX_EMSCRIPTEN && !(PX_CLANG && PX_X86)
497 #endif
498 
499 // use in a cpp file to suppress LNK4221
500 #if PX_VC
501 #define PX_DUMMY_SYMBOL \
502  namespace \
503  { \
504  char PxDummySymbol; \
505  }
506 #else
507 #define PX_DUMMY_SYMBOL
508 #endif
509 
510 #if PX_GCC_FAMILY
511 #define PX_WEAK_SYMBOL __attribute__((weak)) // this is to support SIMD constant merging in template specialization
512 #else
513 #define PX_WEAK_SYMBOL
514 #endif
515 
516 // Macro for avoiding default assignment and copy, because doing this by inheritance can increase class size on some
517 // platforms.
518 #define PX_NOCOPY(Class) \
519  \
520 protected: \
521  Class(const Class&); \
522  Class& operator=(const Class&);
523 
524 #ifndef DISABLE_CUDA_PHYSX
525 //CUDA is currently supported only on windows
526 #define PX_SUPPORT_GPU_PHYSX ((PX_WINDOWS_FAMILY) || (PX_LINUX && PX_X64))
527 #else
528 #define PX_SUPPORT_GPU_PHYSX 0
529 #endif
530 
531 #define PX_SUPPORT_COMPUTE_PHYSX 0
532 
533 #ifndef PX_SUPPORT_EXTERN_TEMPLATE
534 #define PX_SUPPORT_EXTERN_TEMPLATE ((!PX_ANDROID) && (PX_VC != 11))
535 #else
536 #define PX_SUPPORT_EXTERN_TEMPLATE 0
537 #endif
538 
540 #endif // #ifndef PXFOUNDATION_PXPREPROCESSOR_H
Definition: PxPreprocessor.h:488
#define PX_OFFSET_OF(X, Y)
Definition: PxPreprocessor.h:440
#define PX_COMPILE_TIME_ASSERT(exp)
Definition: PxPreprocessor.h:434
PX_CUDA_CALLABLE PX_INLINE void PX_UNUSED(T const &)
Definition: PxPreprocessor.h:466
long long a
Definition: PxPreprocessor.h:491
char _
Definition: PxPreprocessor.h:490
#define PX_INLINE
Definition: PxPreprocessor.h:336
#define PX_CUDA_CALLABLE
Definition: PxPreprocessor.h:460