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