OptiX  3.9
NVIDIA OptiX Acceleration Engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
optix_sizet.h
1 
2 /*
3  * Copyright (c) 2010 NVIDIA Corporation. All rights reserved.
4  *
5  * NVIDIA Corporation and its licensors retain all intellectual property and proprietary
6  * rights in and to this software, related documentation and any modifications thereto.
7  * Any use, reproduction, disclosure or distribution of this software and related
8  * documentation without an express license agreement from NVIDIA Corporation is strictly
9  * prohibited.
10  *
11  * TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED *AS IS*
12  * AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS OR IMPLIED,
13  * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14  * PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS BE LIABLE FOR ANY
15  * SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT
16  * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF
17  * BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
18  * INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF
19  * SUCH DAMAGES
20  */
21 
22 #ifndef __optix_sizet_h__
23 #define __optix_sizet_h__
24 
25 #if !defined(_WIN32)
26  #include <sys/types.h>
27 #endif
28 
29 #include "internal/optix_declarations.h" /* For RT_HOSTDEVICE */
30 
31 #ifdef __cplusplus
32 # define RT_SIZET_INLINE inline
33 #else
34 # ifdef _MSC_VER
35 # define RT_SIZET_INLINE __inline
36 # else
37 # define RT_SIZET_INLINE static inline
38 # endif
39 #endif
40 
41 #ifdef __cplusplus
42 namespace optix {
43 #endif
44 
45 #if defined(__x86_64) || defined(AMD64) || defined(_M_AMD64)
46 
47  typedef struct {
48  size_t x;
49  } size_t1;
50 
51  // 16 byte alignment to match CUDA's ulong2 type for 64 bit longs
52  typedef struct __align__(16) size_t2 {
53 #ifdef __cplusplus
54  RT_HOSTDEVICE size_t2() { }
55  RT_HOSTDEVICE explicit size_t2( size_t s ) { x = y = s; }
56  RT_HOSTDEVICE size_t2( uint2 u ) { x = u.x; y = u.y; }
57 #endif
58  size_t x,y;
59  } size_t2;
60 
61  typedef struct size_t3 {
62 #ifdef __cplusplus
63  RT_HOSTDEVICE size_t3() { }
64  RT_HOSTDEVICE explicit size_t3( size_t s ) { x = y = z = s; }
65  RT_HOSTDEVICE size_t3( uint3 u ) { x = u.x; y = u.y; z = u.z; }
66 #endif
67  size_t x,y,z;
68  } size_t3;
69 
70  // 16 byte alignment to match CUDA's ulong4 type for 64 bit longs
71  typedef struct __align__(16) size_t4 {
72 #ifdef __cplusplus
73  RT_HOSTDEVICE size_t4() { }
74  RT_HOSTDEVICE explicit size_t4( size_t s ) { x = y = z = w = s; }
75  RT_HOSTDEVICE size_t4( uint4 u ) { x = u.x; y = u.y; z = u.z; w = u.w; }
76 #endif
77  size_t x,y,z,w;
78  } size_t4;
79 
80  RT_SIZET_INLINE RT_HOSTDEVICE size_t2 make_size_t2( size_t x, size_t y ) {
81  size_t2 ret;
82  ret.x = x;
83  ret.y = y;
84  return ret;
85  }
86  RT_SIZET_INLINE RT_HOSTDEVICE size_t3 make_size_t3( size_t x, size_t y, size_t z ) {
87  size_t3 ret;
88  ret.x = x;
89  ret.y = y;
90  ret.z = z;
91  return ret;
92  }
93  RT_SIZET_INLINE RT_HOSTDEVICE size_t4 make_size_t4( size_t x, size_t y, size_t z, size_t w ) {
94  size_t4 ret;
95  ret.x = x;
96  ret.y = y;
97  ret.z = z;
98  ret.w = w;
99  return ret;
100  }
101 
102 #ifdef __cplusplus
103  /* additional constructors */
104  RT_SIZET_INLINE RT_HOSTDEVICE size_t4 make_size_t4(unsigned int s)
105  {
106  return make_size_t4(s, s, s, s);
107  }
108  RT_SIZET_INLINE RT_HOSTDEVICE size_t3 make_size_t3(unsigned int s)
109  {
110  return make_size_t3(s, s, s);
111  }
112  RT_SIZET_INLINE RT_HOSTDEVICE size_t2 make_size_t2(unsigned int s)
113  {
114  return make_size_t2(s, s);
115  }
116  RT_SIZET_INLINE RT_HOSTDEVICE size_t3 make_size_t3(size_t4 st)
117  {
118  return make_size_t3(st.x, st.y, st.z);
119  }
120  RT_SIZET_INLINE RT_HOSTDEVICE size_t2 make_size_t2(size_t4 st)
121  {
122  return make_size_t2(st.x, st.y);
123  }
124  RT_SIZET_INLINE RT_HOSTDEVICE size_t make_size_t(size_t4 v0)
125  {
126  return (size_t) v0.x;
127  }
128 
129  RT_SIZET_INLINE RT_HOSTDEVICE size_t4 make_size_t4(uint4 s)
130  {
131  return make_size_t4(s.x, s.y, s.z, s.w);
132  }
133 
134  RT_SIZET_INLINE RT_HOSTDEVICE float2 make_float2(size_t2 st)
135  {
136  float2 ret;
137  ret.x = (float)st.x;
138  ret.y = (float)st.y;
139  return ret;
140  }
141 #endif
142 
143 #else
144  typedef uint1 size_t1;
145  typedef uint2 size_t2;
146  typedef uint3 size_t3;
147  typedef uint4 size_t4;
148  #define make_size_t4 make_uint4
149  #define make_size_t3 make_uint3
150  #define make_size_t2 make_uint2
151  #define make_size_t1 make_uint1
152 #endif
153 
154 #ifdef __cplusplus
155 }
156 #endif
157 
158 #undef RT_SIZET_INLINE
159 
160 #endif /* __optix_sizet_h__ */
OptiX public API declarations.