1/*
2 * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NVIDIA CORPORATION and its licensors retain all intellectual property
5 * and proprietary rights in and to this software, related documentation
6 * and any modifications thereto. Any use, reproduction, disclosure or
7 * distribution of this software and related documentation without an express
8 * license agreement from NVIDIA CORPORATION is strictly prohibited.
9 */
10// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12
13
14#ifndef PX_FOUNDATION_PX_PREPROCESSOR_H
15#define PX_FOUNDATION_PX_PREPROCESSOR_H
16
17#include <stddef.h>
18
19/** \addtogroup foundation
20 @{
21*/
22
23
24/**
25List of preprocessor defines used to configure the SDK
26- PX_DEBUG: enable asserts (exactly one needs to be defined)
27- PX_CHECKED: enable run time checks, mostly unused or equiv. to PX_DEBUG
28- PX_SUPPORT_VISUAL_DEBUGGER: ...
29- AG_PERFMON: ... (Deprecated)
30*/
31
32/**
33Compiler define
34*/
35#ifdef _MSC_VER
36# define PX_VC
37# if _MSC_VER >= 1900
38# define PX_VC14
39# elif _MSC_VER >= 1800
40# define PX_VC12
41# elif _MSC_VER >= 1700
42# define PX_VC11
43# elif _MSC_VER >= 1600
44# define PX_VC10
45# elif _MSC_VER >= 1500
46# define PX_VC9
47# elif _MSC_VER >= 1400
48# define PX_VC8
49# elif _MSC_VER >= 1300
50# define PX_VC7
51# else
52# define PX_VC6
53# endif
54#elif defined(__ghs__)
55# define PX_GHS
56#elif __GNUC__ || __SNC__
57# define PX_GNUC
58#else
59# error "Unknown compiler"
60#endif
61
62/**
63Platform define
64*/
65#ifdef PX_VC
66# ifdef XBOXONE
67# define PX_XBOXONE
68# define PX_X64
69# elif defined(_M_IX86)
70# define PX_X86
71# define PX_WINDOWS
72# elif defined(_M_X64)
73# define PX_X64
74# define PX_WINDOWS
75# elif defined(_M_PPC)
76# define PX_PPC
77# define PX_X360
78# define PX_VMX
79# elif defined(_M_ARM)
80# define PX_ARM
81# define PX_ARM_NEON
82# else
83# error "Unknown platform"
84# endif
85# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_PARTITION_APP)
86# define PX_WINMODERN
87# endif
88#elif defined PX_GNUC
89# ifdef __CELLOS_LV2__
90# define PX_PS3
91# define PX_VMX
92# elif defined(__arm__)
93# define PX_ARM
94# if defined(__SNC__)
95# define PX_PSP2
96# endif
97# if defined(__ARM_NEON__)
98# define PX_ARM_NEON
99# endif
100# elif defined(__arm64__)
101# define PX_A64
102# if defined(__ARM_NEON__)
103# define PX_ARM_NEON
104# endif
105# elif defined(__i386__)
106# define PX_X86
107# define PX_VMX
108# elif defined(__x86_64__)
109# ifdef __ORBIS__
110# define PX_PS4
111# define PX_X64
112# else
113# define PX_X64
114# endif
115# elif defined(__ppc__)
116# define PX_PPC
117# elif defined(__ppc64__)
118# define PX_PPC
119# define PX_PPC64
120# else
121# error "Unknown platform"
122# endif
123# if defined(ANDROID)
124# define PX_ANDROID
125# define PX_UNIX
126# elif defined(__linux__)
127# define PX_LINUX
128# define PX_UNIX
129# elif defined(__APPLE__)
130# define PX_APPLE
131# define PX_UNIX
132# if defined(__arm__) || defined(__arm64__)
133# define PX_APPLE_IOS
134# else
135# define PX_OSX
136# endif
137# elif defined(__CYGWIN__)
138# define PX_CYGWIN
139# define PX_LINUX
140# define PX_UNIX
141# endif
142#elif defined PX_GHS
143# define PX_WIIU
144#endif
145
146#if defined(PX_X64) || defined(PX_A64)
147#define PX_P64 // pointers are 64 bit
148#endif
149
150/**
151DLL export macros
152*/
153#if !defined(PX_C_EXPORT)
154# if defined(PX_WINDOWS) || defined(PX_WINMODERN) || defined(PX_LINUX)
155# define PX_C_EXPORT extern "C"
156# else
157# define PX_C_EXPORT
158# endif
159#endif
160
161#if (defined(PX_UNIX) && (__GNUC__ >= 4))
162# define PX_UNIX_EXPORT __attribute__ ((visibility ("default")))
163#else
164# define PX_UNIX_EXPORT
165#endif
166
167/**
168Define API function declaration
169
170PX_FOUNDATION_EXPORTS - used by the DLL library (PhysXCommon) to export the API
171PX_FOUNDATION_NO_EXPORTS - exists because there are windows configurations where
172 the PX_FOUNDATION_API is linked through standard static linking
173no definition - this will allow DLLs and libraries to use the exported API from PhysXCommon
174
175*/
176#if (defined(PX_WINDOWS) || defined(PX_WINMODERN) ) && !defined(__CUDACC__)
177 #if defined PX_FOUNDATION_EXPORTS
178 #define PX_FOUNDATION_API __declspec(dllexport)
179 #elif defined PX_FOUNDATION_NO_EXPORTS
180 #define PX_FOUNDATION_API
181 #else
182 #define PX_FOUNDATION_API __declspec(dllimport)
183 #endif
184#elif defined(PX_UNIX)
185 #define PX_FOUNDATION_API PX_UNIX_EXPORT
186#else
187 #define PX_FOUNDATION_API
188#endif
189
190/**
191Calling convention
192*/
193#ifndef PX_CALL_CONV
194# if defined PX_WINDOWS
195# define PX_CALL_CONV __cdecl
196# else
197# define PX_CALL_CONV
198# endif
199#endif
200
201/**
202Pack macros - disabled on SPU because they are not supported
203*/
204#if defined(PX_VC)
205# define PX_PUSH_PACK_DEFAULT __pragma( pack(push, 8) )
206# define PX_POP_PACK __pragma( pack(pop) )
207#elif (defined(PX_GNUC) && !defined(__SPU__)) || defined(PX_GHS)
208# define PX_PUSH_PACK_DEFAULT _Pragma("pack(push, 8)")
209# define PX_POP_PACK _Pragma("pack(pop)")
210#else
211# define PX_PUSH_PACK_DEFAULT
212# define PX_POP_PACK
213#endif
214
215/**
216Inline macro
217*/
218#if defined(PX_WINDOWS) || defined(PX_X360) || defined(PX_WINMODERN) || defined(PX_XBOXONE)
219# define PX_INLINE inline
220# pragma inline_depth( 255 )
221#else
222# define PX_INLINE inline
223#endif
224
225/**
226Force inline macro
227*/
228#if defined(PX_VC)
229 #define PX_FORCE_INLINE __forceinline
230#elif defined(PX_LINUX) // Workaround; Fedora Core 3 do not agree with force inline and PxcPool
231 #define PX_FORCE_INLINE inline
232#elif defined(PX_GNUC) || defined(PX_GHS)
233 #define PX_FORCE_INLINE inline __attribute__((always_inline))
234#else
235 #define PX_FORCE_INLINE inline
236#endif
237
238/**
239Noinline macro
240*/
241#if defined PX_WINDOWS || defined PX_XBOXONE
242# define PX_NOINLINE __declspec(noinline)
243#elif defined(PX_GNUC) || defined(PX_GHS)
244# define PX_NOINLINE __attribute__ ((noinline))
245#else
246# define PX_NOINLINE
247#endif
248
249/*! restrict macro */
250#if defined(__CUDACC__)
251# define PX_RESTRICT __restrict__
252#else
253//PX_GNUC, PX_VC and PX_GHS all support restrict. If adding support for a compiler which does not like restrict, please add an exception for it by in that case defining PX_RESTRICT to naught.
254# define PX_RESTRICT __restrict
255#endif
256
257#if defined(PX_WINDOWS) || defined(PX_X360) || defined(PX_WINMODERN) || defined(PX_XBOXONE)
258#define PX_NOALIAS __declspec(noalias)
259#else
260#define PX_NOALIAS
261#endif
262
263
264/**
265Alignment macros
266
267PX_ALIGN_PREFIX and PX_ALIGN_SUFFIX can be used for type alignment instead of aligning individual variables as follows:
268PX_ALIGN_PREFIX(16)
269struct A {
270...
271} PX_ALIGN_SUFFIX(16);
272This declaration style is parsed correctly by Visual Assist.
273
274*/
275#ifndef PX_ALIGN
276 #if defined(PX_VC)
277 #define PX_ALIGN(alignment, decl) __declspec(align(alignment)) decl
278 #define PX_ALIGN_PREFIX(alignment) __declspec(align(alignment))
279 #define PX_ALIGN_SUFFIX(alignment)
280 #elif defined(PX_GNUC) || defined(PX_GHS) || defined(PX_APPLE_IOS)
281 #define PX_ALIGN(alignment, decl) decl __attribute__ ((aligned(alignment)))
282 #define PX_ALIGN_PREFIX(alignment)
283 #define PX_ALIGN_SUFFIX(alignment) __attribute__ ((aligned(alignment)))
284 #else
285 #define PX_ALIGN(alignment, decl)
286 #define PX_ALIGN_PREFIX(alignment)
287 #define PX_ALIGN_SUFFIX(alignment)
288 #endif
289#endif
290
291/**
292Deprecated macro
293- To deprecate a function: Place PX_DEPRECATED at the start of the function header (leftmost word).
294- To deprecate a 'typedef', a 'struct' or a 'class': Place PX_DEPRECATED directly after the keywords ('typdef', 'struct', 'class').
295*/
296#if 0 // set to 1 to create warnings for deprecated functions
297# define PX_DEPRECATED __declspec(deprecated)
298#else
299# define PX_DEPRECATED
300#endif
301
302// VC6 no '__FUNCTION__' workaround
303#if defined PX_VC6 && !defined __FUNCTION__
304# define __FUNCTION__ "Undefined"
305#endif
306
307/**
308General defines
309*/
310
311// static assert
312#if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)))
313#define PX_COMPILE_TIME_ASSERT(exp) typedef char PxCompileTimeAssert_Dummy[(exp) ? 1 : -1] __attribute__((unused))
314#else
315#define PX_COMPILE_TIME_ASSERT(exp) typedef char PxCompileTimeAssert_Dummy[(exp) ? 1 : -1]
316#endif
317
318#if defined(PX_GNUC)
319#define PX_OFFSET_OF(X, Y) __builtin_offsetof(X, Y)
320#else
321#define PX_OFFSET_OF(X, Y) offsetof(X, Y)
322#endif
323
324#define PX_SIZE_OF(Class, Member) sizeof(((Class*)0)->Member)
325
326// check that exactly one of NDEBUG and _DEBUG is defined
327#if !(defined NDEBUG ^ defined _DEBUG)
328 #error Exactly one of NDEBUG and _DEBUG needs to be defined by preprocessor
329#endif
330
331// make sure PX_CHECKED is defined in all _DEBUG configurations as well
332#if !defined(PX_CHECKED) && defined _DEBUG
333#define PX_CHECKED
334#endif
335
336#ifdef __CUDACC__
337#define PX_CUDA_CALLABLE __host__ __device__
338#else
339#define PX_CUDA_CALLABLE
340#endif
341
342// Support GPU PhysX
343#if (defined(PX_WINDOWS) && !defined(PX_WINMODERN) && !defined(PX_VC14)) || defined(PX_LINUX)
344#define PX_SUPPORT_GPU_PHYSX 1
345#else
346#define PX_SUPPORT_GPU_PHYSX 0
347#endif
348
349// avoid unreferenced parameter warning (why not just disable it?)
350// PT: or why not just omit the parameter's name from the declaration????
351template <class T> PX_CUDA_CALLABLE PX_INLINE void PX_UNUSED(T const&) {}
352
353 // Ensure that the application hasn't tweaked the pack value to less than 8, which would break
354 // matching between the API headers and the binaries
355 // This assert works on win32/win64/360/ps3, but may need further specialization on other platforms.
356 // Some GCC compilers need the compiler flag -malign-double to be set.
357 // Apparently the apple-clang-llvm compiler doesn't support malign-double.
358
359struct PxPackValidation { char _; long long a; };
360
361#if !defined(PX_APPLE)
362PX_COMPILE_TIME_ASSERT(PX_OFFSET_OF(PxPackValidation, a) == 8);
363#endif
364
365// use in a cpp file to suppress LNK4221
366#if defined(PX_VC)
367#define PX_DUMMY_SYMBOL namespace { char PxDummySymbol; }
368#else
369#define PX_DUMMY_SYMBOL
370#endif
371
372#ifdef __SPU__
373#define PX_IS_SPU 1
374#else
375#define PX_IS_SPU 0
376#endif
377
378#ifdef PX_X64
379#define PX_IS_X64 1
380#else
381#define PX_IS_X64 0
382#endif
383
384#ifdef PX_WINDOWS
385#define PX_IS_WINDOWS 1
386#else
387#define PX_IS_WINDOWS 0
388#endif
389
390#ifdef PX_X86
391#define PX_IS_X86 1
392#else
393#define PX_IS_X86 0
394#endif
395
396#ifdef PX_X64
397#define PX_IS_X64 1
398#else
399#define PX_IS_X64 0
400#endif
401
402#if defined(PX_X86) || defined(PX_X64)
403#define PX_IS_INTEL 1
404#else
405#define PX_IS_INTEL 0
406#endif
407
408#ifdef PX_X360
409#define PX_IS_X360 1
410#else
411#define PX_IS_X360 0
412#endif
413
414#ifdef PX_PS3
415#define PX_IS_PS3 1
416#else
417#define PX_IS_PS3 0
418#endif
419
420#ifdef PX_NVTX
421#define PX_NVTX 1
422#else
423#define PX_NVTX 0
424#endif
425
426#define PX_IS_PPU (PX_IS_PS3 && !PX_IS_SPU) // PS3 PPU
427
428#ifdef PX_GNUC
429#define PX_WEAK_SYMBOL __attribute__((weak)) // this is to support SIMD constant merging in template specialization
430#else
431#define PX_WEAK_SYMBOL
432#endif
433
434/** @} */
435#endif // PX_FOUNDATION_PX_PREPROCESSOR_H
436