PxPreprocessor.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) 2008-2018 NVIDIA Corporation. All rights reserved.
00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
00029 
00030 #ifndef PXFOUNDATION_PXPREPROCESSOR_H
00031 #define PXFOUNDATION_PXPREPROCESSOR_H
00032 
00033 #include <stddef.h>
00034 #if !defined(PX_GENERATE_META_DATA)
00035 #include <ciso646>  
00036 #endif
00037 
00041 #define PX_STRINGIZE_HELPER(X) #X
00042 #define PX_STRINGIZE(X) PX_STRINGIZE_HELPER(X)
00043 
00044 #define PX_CONCAT_HELPER(X, Y) X##Y
00045 #define PX_CONCAT(X, Y) PX_CONCAT_HELPER(X, Y)
00046 
00047 /*
00048 The following preprocessor identifiers specify compiler, OS, and architecture.
00049 All definitions have a value of 1 or 0, use '#if' instead of '#ifdef'.
00050 */
00051 
00055 #if defined(_MSC_VER)
00056 #if _MSC_VER >= 1910
00057 #define PX_VC 15
00058 #elif _MSC_VER >= 1900
00059 #define PX_VC 14
00060 #elif _MSC_VER >= 1800
00061 #define PX_VC 12
00062 #elif _MSC_VER >= 1700
00063 #define PX_VC 11
00064 #elif _MSC_VER >= 1600
00065 #define PX_VC 10
00066 #elif _MSC_VER >= 1500
00067 #define PX_VC 9
00068 #else
00069 #error "Unknown VC version"
00070 #endif
00071 #elif defined(__clang__)
00072 #define PX_CLANG 1
00073 #elif defined(__GNUC__) // note: __clang__ implies __GNUC__
00074 #define PX_GCC 1
00075 #else
00076 #error "Unknown compiler"
00077 #endif
00078 
00082 #if defined(_XBOX_ONE)
00083 #define PX_XBOXONE 1
00084 #elif defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP
00085 #define PX_UWP 1
00086 #elif defined(_WIN64) // note: _XBOX_ONE implies _WIN64
00087 #define PX_WIN64 1
00088 #elif defined(_WIN32) // note: _M_PPC implies _WIN32
00089 #define PX_WIN32 1
00090 #elif defined(__ANDROID__)
00091 #define PX_ANDROID 1
00092 #elif defined(__linux__) || defined (__EMSCRIPTEN__) // note: __ANDROID__ implies __linux__
00093 #define PX_LINUX 1
00094 #elif defined(__APPLE__) && (defined(__arm__) || defined(__arm64__))
00095 #define PX_IOS 1
00096 #elif defined(__APPLE__)
00097 #define PX_OSX 1
00098 #elif defined(__ORBIS__)
00099 #define PX_PS4 1
00100 #elif defined(__NX__)
00101 #define PX_SWITCH 1
00102 #else
00103 #error "Unknown operating system"
00104 #endif
00105 
00109 #if defined(__x86_64__) || defined(_M_X64) // ps4 compiler defines _M_X64 without value
00110 #define PX_X64 1
00111 #elif defined(__i386__) || defined(_M_IX86) || defined (__EMSCRIPTEN__)
00112 #define PX_X86 1
00113 #elif defined(__arm64__) || defined(__aarch64__)
00114 #define PX_A64 1
00115 #elif defined(__arm__) || defined(_M_ARM)
00116 #define PX_ARM 1
00117 #elif defined(__ppc__) || defined(_M_PPC) || defined(__CELLOS_LV2__)
00118 #define PX_PPC 1
00119 #else
00120 #error "Unknown architecture"
00121 #endif
00122 
00126 #if !defined(PX_SIMD_DISABLED)
00127 #if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) || (defined (__EMSCRIPTEN__) && defined(__SSE2__))
00128 #define PX_SSE2 1
00129 #endif
00130 #if defined(_M_ARM) || defined(__ARM_NEON__) || defined(__ARM_NEON)
00131 #define PX_NEON 1
00132 #endif
00133 #if defined(_M_PPC) || defined(__CELLOS_LV2__)
00134 #define PX_VMX 1
00135 #endif
00136 #endif
00137 
00141 #ifndef PX_VC
00142 #define PX_VC 0
00143 #endif
00144 #ifndef PX_CLANG
00145 #define PX_CLANG 0
00146 #endif
00147 #ifndef PX_GCC
00148 #define PX_GCC 0
00149 #endif
00150 #ifndef PX_XBOXONE
00151 #define PX_XBOXONE 0
00152 #endif
00153 #ifndef PX_WIN64
00154 #define PX_WIN64 0
00155 #endif
00156 #ifndef PX_WIN32
00157 #define PX_WIN32 0
00158 #endif
00159 #ifndef PX_ANDROID
00160 #define PX_ANDROID 0
00161 #endif
00162 #ifndef PX_LINUX
00163 #define PX_LINUX 0
00164 #endif
00165 #ifndef PX_IOS
00166 #define PX_IOS 0
00167 #endif
00168 #ifndef PX_OSX
00169 #define PX_OSX 0
00170 #endif
00171 #ifndef PX_PS4
00172 #define PX_PS4 0
00173 #endif
00174 #ifndef PX_SWITCH
00175 #define PX_SWITCH 0
00176 #endif
00177 #ifndef PX_UWP
00178 #define PX_UWP 0
00179 #endif
00180 #ifndef PX_X64
00181 #define PX_X64 0
00182 #endif
00183 #ifndef PX_X86
00184 #define PX_X86 0
00185 #endif
00186 #ifndef PX_A64
00187 #define PX_A64 0
00188 #endif
00189 #ifndef PX_ARM
00190 #define PX_ARM 0
00191 #endif
00192 #ifndef PX_PPC
00193 #define PX_PPC 0
00194 #endif
00195 #ifndef PX_SSE2
00196 #define PX_SSE2 0
00197 #endif
00198 #ifndef PX_NEON
00199 #define PX_NEON 0
00200 #endif
00201 #ifndef PX_VMX
00202 #define PX_VMX 0
00203 #endif
00204 
00205 /*
00206 define anything not defined through the command line to 0
00207 */
00208 #ifndef PX_DEBUG
00209 #define PX_DEBUG 0
00210 #endif
00211 #ifndef PX_CHECKED
00212 #define PX_CHECKED 0
00213 #endif
00214 #ifndef PX_PROFILE
00215 #define PX_PROFILE 0
00216 #endif
00217 #ifndef PX_DEBUG_CRT
00218 #define PX_DEBUG_CRT 0
00219 #endif
00220 #ifndef PX_NVTX
00221 #define PX_NVTX 0
00222 #endif
00223 #ifndef PX_DOXYGEN
00224 #define PX_DOXYGEN 0
00225 #endif
00226 
00230 // compiler
00231 #define PX_GCC_FAMILY (PX_CLANG || PX_GCC)
00232 // os
00233 #define PX_WINDOWS_FAMILY (PX_WIN32 || PX_WIN64 || PX_UWP)
00234 #define PX_MICROSOFT_FAMILY (PX_XBOXONE || PX_WINDOWS_FAMILY)
00235 #define PX_LINUX_FAMILY (PX_LINUX || PX_ANDROID)
00236 #define PX_APPLE_FAMILY (PX_IOS || PX_OSX)                  // equivalent to #if __APPLE__
00237 #define PX_UNIX_FAMILY (PX_LINUX_FAMILY || PX_APPLE_FAMILY) // shortcut for unix/posix platforms
00238 #if defined(__EMSCRIPTEN__)
00239 #define PX_EMSCRIPTEN 1
00240 #else
00241 #define PX_EMSCRIPTEN 0
00242 #endif
00243 // architecture
00244 #define PX_INTEL_FAMILY (PX_X64 || PX_X86)
00245 #define PX_ARM_FAMILY (PX_ARM || PX_A64)
00246 #define PX_P64_FAMILY (PX_X64 || PX_A64) // shortcut for 64-bit architectures
00247 
00251 #if defined(_LIBCPP_VERSION) || PX_WIN64 || PX_WIN32 || PX_PS4 || PX_XBOXONE || PX_UWP || PX_EMSCRIPTEN
00252 #define PX_LIBCPP 1
00253 #else
00254 #define PX_LIBCPP 0
00255 #endif
00256 
00257 // legacy define for PhysX
00258 #define PX_WINDOWS (PX_WINDOWS_FAMILY && !PX_ARM_FAMILY)
00259 
00263 #ifndef PX_ENABLE_ASSERTS
00264 #if PX_DEBUG && !defined(__CUDACC__)
00265 #define PX_ENABLE_ASSERTS 1
00266 #else
00267 #define PX_ENABLE_ASSERTS 0
00268 #endif
00269 #endif
00270 
00274 #ifndef PX_C_EXPORT
00275 #if PX_WINDOWS_FAMILY || PX_LINUX
00276 #define PX_C_EXPORT extern "C"
00277 #else
00278 #define PX_C_EXPORT
00279 #endif
00280 #endif
00281 
00282 #if PX_UNIX_FAMILY&& __GNUC__ >= 4
00283 #define PX_UNIX_EXPORT __attribute__((visibility("default")))
00284 #else
00285 #define PX_UNIX_EXPORT
00286 #endif
00287 
00288 #if PX_WINDOWS_FAMILY
00289 #define PX_DLL_EXPORT __declspec(dllexport)
00290 #define PX_DLL_IMPORT __declspec(dllimport)
00291 #else
00292 #define PX_DLL_EXPORT PX_UNIX_EXPORT
00293 #define PX_DLL_IMPORT
00294 #endif
00295 
00305 #if PX_WINDOWS_FAMILY && !PX_ARM_FAMILY
00306 #ifndef PX_FOUNDATION_DLL
00307 #define PX_FOUNDATION_API PX_DLL_IMPORT
00308 #elif PX_FOUNDATION_DLL
00309 #define PX_FOUNDATION_API PX_DLL_EXPORT
00310 #endif
00311 #elif PX_UNIX_FAMILY
00312 #ifdef PX_FOUNDATION_DLL
00313 #define PX_FOUNDATION_API PX_UNIX_EXPORT
00314 #endif
00315 #endif
00316 
00317 #ifndef PX_FOUNDATION_API
00318 #define PX_FOUNDATION_API
00319 #endif
00320 
00324 #ifndef PX_CALL_CONV
00325 #if PX_MICROSOFT_FAMILY
00326 #define PX_CALL_CONV __cdecl
00327 #else
00328 #define PX_CALL_CONV
00329 #endif
00330 #endif
00331 
00335 #if PX_VC
00336 #define PX_PUSH_PACK_DEFAULT __pragma(pack(push, 8))
00337 #define PX_POP_PACK __pragma(pack(pop))
00338 #elif PX_GCC_FAMILY
00339 #define PX_PUSH_PACK_DEFAULT _Pragma("pack(push, 8)")
00340 #define PX_POP_PACK _Pragma("pack(pop)")
00341 #else
00342 #define PX_PUSH_PACK_DEFAULT
00343 #define PX_POP_PACK
00344 #endif
00345 
00349 #define PX_INLINE inline
00350 #if PX_MICROSOFT_FAMILY
00351 #pragma inline_depth(255)
00352 #endif
00353 
00357 #if PX_VC
00358 #define PX_FORCE_INLINE __forceinline
00359 #elif PX_LINUX // Workaround; Fedora Core 3 do not agree with force inline and PxcPool
00360 #define PX_FORCE_INLINE inline
00361 #elif PX_GCC_FAMILY
00362 #define PX_FORCE_INLINE inline __attribute__((always_inline))
00363 #else
00364 #define PX_FORCE_INLINE inline
00365 #endif
00366 
00370 #if PX_MICROSOFT_FAMILY
00371 #define PX_NOINLINE __declspec(noinline)
00372 #elif PX_GCC_FAMILY
00373 #define PX_NOINLINE __attribute__((noinline))
00374 #else
00375 #define PX_NOINLINE
00376 #endif
00377 
00381 #if defined(__CUDACC__)
00382 #define PX_RESTRICT __restrict__
00383 #else
00384 #define PX_RESTRICT __restrict
00385 #endif
00386 
00390 #if PX_MICROSOFT_FAMILY
00391 #define PX_NOALIAS __declspec(noalias)
00392 #else
00393 #define PX_NOALIAS
00394 #endif
00395 
00407 #ifndef PX_ALIGN
00408 #if PX_MICROSOFT_FAMILY
00409 #define PX_ALIGN(alignment, decl) __declspec(align(alignment)) decl
00410 #define PX_ALIGN_PREFIX(alignment) __declspec(align(alignment))
00411 #define PX_ALIGN_SUFFIX(alignment)
00412 #elif PX_GCC_FAMILY
00413 #define PX_ALIGN(alignment, decl) decl __attribute__((aligned(alignment)))
00414 #define PX_ALIGN_PREFIX(alignment)
00415 #define PX_ALIGN_SUFFIX(alignment) __attribute__((aligned(alignment)))
00416 #elif defined __CUDACC__
00417 #define PX_ALIGN(alignment, decl) __align__(alignment) decl
00418 #define PX_ALIGN_PREFIX(alignment)
00419 #define PX_ALIGN_SUFFIX(alignment) __align__(alignment))
00420 #else
00421 #define PX_ALIGN(alignment, decl)
00422 #define PX_ALIGN_PREFIX(alignment)
00423 #define PX_ALIGN_SUFFIX(alignment)
00424 #endif
00425 #endif
00426 
00437 #define PX_DEPRECATED
00438 
00443 // static assert
00444 #if(defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))) || (PX_PS4) || (PX_APPLE_FAMILY) || (PX_SWITCH) || (PX_CLANG && PX_ARM)
00445 #define PX_COMPILE_TIME_ASSERT(exp) typedef char PX_CONCAT(PxCompileTimeAssert_Dummy, __COUNTER__)[(exp) ? 1 : -1] __attribute__((unused))
00446 #else
00447 #define PX_COMPILE_TIME_ASSERT(exp) typedef char PxCompileTimeAssert_Dummy[(exp) ? 1 : -1]
00448 #endif
00449 
00450 #if PX_GCC_FAMILY
00451 #define PX_OFFSET_OF(X, Y) __builtin_offsetof(X, Y)
00452 #else
00453 #define PX_OFFSET_OF(X, Y) offsetof(X, Y)
00454 #endif
00455 
00456 #define PX_OFFSETOF_BASE 0x100 // casting the null ptr takes a special-case code path, which we don't want
00457 #define PX_OFFSET_OF_RT(Class, Member)                                                                                 \
00458     (reinterpret_cast<size_t>(&reinterpret_cast<Class*>(PX_OFFSETOF_BASE)->Member) - size_t(PX_OFFSETOF_BASE))
00459 
00460 // check that exactly one of NDEBUG and _DEBUG is defined
00461 #if !defined(NDEBUG) ^ defined(_DEBUG)
00462 #error Exactly one of NDEBUG and _DEBUG needs to be defined!
00463 #endif
00464 
00465 // make sure PX_CHECKED is defined in all _DEBUG configurations as well
00466 #if !PX_CHECKED && PX_DEBUG
00467 #error PX_CHECKED must be defined when PX_DEBUG is defined
00468 #endif
00469 
00470 #ifdef __CUDACC__
00471 #define PX_CUDA_CALLABLE __host__ __device__
00472 #else
00473 #define PX_CUDA_CALLABLE
00474 #endif
00475 
00476 // avoid unreferenced parameter warning
00477 // preferred solution: omit the parameter's name from the declaration
00478 template <class T>
00479 PX_CUDA_CALLABLE PX_INLINE void PX_UNUSED(T const&)
00480 {
00481 }
00482 
00483 // Ensure that the application hasn't tweaked the pack value to less than 8, which would break
00484 // matching between the API headers and the binaries
00485 // This assert works on win32/win64, but may need further specialization on other platforms.
00486 // Some GCC compilers need the compiler flag -malign-double to be set.
00487 // Apparently the apple-clang-llvm compiler doesn't support malign-double.
00488 #if PX_PS4 || PX_APPLE_FAMILY || (PX_CLANG && !PX_ARM)
00489 struct PxPackValidation
00490 {
00491     char _;
00492     long a;
00493 };
00494 #elif PX_ANDROID || (PX_CLANG && PX_ARM)
00495 struct PxPackValidation
00496 {
00497     char _;
00498     double a;
00499 };
00500 #else
00501 struct PxPackValidation
00502 {
00503     char _;
00504     long long a;
00505 };
00506 #endif
00507 // clang (as of version 3.9) cannot align doubles on 8 byte boundary  when compiling for Intel 32 bit target
00508 #if !PX_APPLE_FAMILY && !PX_EMSCRIPTEN && !(PX_CLANG && PX_X86)
00509 PX_COMPILE_TIME_ASSERT(PX_OFFSET_OF(PxPackValidation, a) == 8);
00510 #endif
00511 
00512 // use in a cpp file to suppress LNK4221
00513 #if PX_VC
00514 #define PX_DUMMY_SYMBOL                                                                                                \
00515     namespace                                                                                                          \
00516     {                                                                                                                  \
00517     char PxDummySymbol;                                                                                                \
00518     }
00519 #else
00520 #define PX_DUMMY_SYMBOL
00521 #endif
00522 
00523 #if PX_GCC_FAMILY
00524 #define PX_WEAK_SYMBOL __attribute__((weak)) // this is to support SIMD constant merging in template specialization
00525 #else
00526 #define PX_WEAK_SYMBOL
00527 #endif
00528 
00529 // Macro for avoiding default assignment and copy, because doing this by inheritance can increase class size on some
00530 // platforms.
00531 #define PX_NOCOPY(Class)                                                                                               \
00532     \
00533 protected:                                                                                                             \
00534     Class(const Class&);                                                                                               \
00535     Class& operator=(const Class&);
00536 
00537 #ifndef DISABLE_CUDA_PHYSX
00538 //CUDA is currently supported only on windows 
00539 #define PX_SUPPORT_GPU_PHYSX ((PX_WINDOWS_FAMILY) || (PX_LINUX && PX_X64))
00540 #else
00541 #define PX_SUPPORT_GPU_PHYSX 0
00542 #endif
00543 
00544 #define PX_SUPPORT_COMPUTE_PHYSX 0
00545 
00546 #ifndef PX_SUPPORT_EXTERN_TEMPLATE
00547 #define PX_SUPPORT_EXTERN_TEMPLATE ((!PX_ANDROID) && (PX_VC != 11))
00548 #else
00549 #define PX_SUPPORT_EXTERN_TEMPLATE 0
00550 #endif
00551 
00553 #endif // #ifndef PXFOUNDATION_PXPREPROCESSOR_H


Copyright © 2008-2018 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com