Blender V2.61 - r43446

util_types.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2011, Blender Foundation.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #ifndef __UTIL_TYPES_H__
00020 #define __UTIL_TYPES_H__
00021 
00022 #ifndef __KERNEL_OPENCL__
00023 
00024 #include <stdlib.h>
00025 
00026 #endif
00027 
00028 /* Qualifiers for kernel code shared by CPU and GPU */
00029 
00030 #ifndef __KERNEL_GPU__
00031 
00032 #define __device static inline
00033 #define __device_noinline static
00034 #define __global
00035 #define __local
00036 #define __shared
00037 #define __constant
00038 
00039 #ifdef __GNUC__
00040 #define __device_inline static inline __attribute__((always_inline))
00041 #else
00042 #define __device_inline static __forceinline
00043 #endif
00044 
00045 #endif
00046 
00047 /* SIMD Types */
00048 
00049 /* not needed yet, will be for qbvh
00050 #ifndef __KERNEL_GPU__
00051 
00052 #include <emmintrin.h>
00053 #include <xmmintrin.h>
00054 
00055 #endif*/
00056 
00057 #ifndef _WIN32
00058 #ifndef __KERNEL_GPU__
00059 
00060 #include <stdint.h>
00061 
00062 #endif
00063 #endif
00064 
00065 CCL_NAMESPACE_BEGIN
00066 
00067 /* Types
00068  *
00069  * Define simpler unsigned type names, and integer with defined number of bits.
00070  * Also vector types, named to be compatible with OpenCL builtin types, while
00071  * working for CUDA and C++ too. */
00072 
00073 /* Shorter Unsigned Names */
00074 
00075 #ifndef __KERNEL_OPENCL__
00076 
00077 typedef unsigned char uchar;
00078 typedef unsigned int uint;
00079 
00080 #endif
00081 
00082 #ifndef __KERNEL_GPU__
00083 
00084 /* Fixed Bits Types */
00085 
00086 #ifdef _WIN32
00087 
00088 typedef signed char int8_t;
00089 typedef unsigned char uint8_t;
00090 
00091 typedef signed short int16_t;
00092 typedef unsigned short uint16_t;
00093 
00094 typedef signed int int32_t;
00095 typedef unsigned int uint32_t;
00096 
00097 typedef long long int64_t;
00098 typedef unsigned long long uint64_t;
00099 
00100 #endif
00101 
00102 /* Generic Memory Pointer */
00103 
00104 typedef uint64_t device_ptr;
00105 
00106 /* Vector Types */
00107 
00108 struct uchar2 {
00109     uchar x, y;
00110 
00111     uchar operator[](int i) const { return *(&x + i); }
00112     uchar& operator[](int i) { return *(&x + i); }
00113 };
00114 
00115 struct uchar3 {
00116     uchar x, y, z;
00117 
00118     uchar operator[](int i) const { return *(&x + i); }
00119     uchar& operator[](int i) { return *(&x + i); }
00120 };
00121 
00122 struct uchar4 {
00123     uchar x, y, z, w;
00124 
00125     uchar operator[](int i) const { return *(&x + i); }
00126     uchar& operator[](int i) { return *(&x + i); }
00127 };
00128 
00129 struct int2 {
00130     int x, y;
00131 
00132     int operator[](int i) const { return *(&x + i); }
00133     int& operator[](int i) { return *(&x + i); }
00134 };
00135 
00136 struct int3 {
00137     int x, y, z;
00138 
00139     int operator[](int i) const { return *(&x + i); }
00140     int& operator[](int i) { return *(&x + i); }
00141 };
00142 
00143 struct int4 {
00144     int x, y, z, w;
00145 
00146     int operator[](int i) const { return *(&x + i); }
00147     int& operator[](int i) { return *(&x + i); }
00148 };
00149 
00150 struct uint2 {
00151     uint x, y;
00152 
00153     uint operator[](int i) const { return *(&x + i); }
00154     uint& operator[](int i) { return *(&x + i); }
00155 };
00156 
00157 struct uint3 {
00158     uint x, y, z;
00159 
00160     uint operator[](int i) const { return *(&x + i); }
00161     uint& operator[](int i) { return *(&x + i); }
00162 };
00163 
00164 struct uint4 {
00165     uint x, y, z, w;
00166 
00167     uint operator[](int i) const { return *(&x + i); }
00168     uint& operator[](int i) { return *(&x + i); }
00169 };
00170 
00171 struct float2 {
00172     float x, y;
00173 
00174     float operator[](int i) const { return *(&x + i); }
00175     float& operator[](int i) { return *(&x + i); }
00176 };
00177 
00178 struct float3 {
00179     float x, y, z;
00180 
00181 #ifdef WITH_OPENCL
00182     float w;
00183 #endif
00184 
00185     float operator[](int i) const { return *(&x + i); }
00186     float& operator[](int i) { return *(&x + i); }
00187 };
00188 
00189 struct float4 {
00190     float x, y, z, w;
00191 
00192     float operator[](int i) const { return *(&x + i); }
00193     float& operator[](int i) { return *(&x + i); }
00194 };
00195 
00196 #endif
00197 
00198 #ifndef __KERNEL_GPU__
00199 
00200 /* Vector Type Constructors
00201  * 
00202  * OpenCL does not support C++ class, so we use these instead. */
00203 
00204 __device uchar2 make_uchar2(uchar x, uchar y)
00205 {
00206     uchar2 a = {x, y};
00207     return a;
00208 }
00209 
00210 __device uchar3 make_uchar3(uchar x, uchar y, uchar z)
00211 {
00212     uchar3 a = {x, y, z};
00213     return a;
00214 }
00215 
00216 __device uchar4 make_uchar4(uchar x, uchar y, uchar z, uchar w)
00217 {
00218     uchar4 a = {x, y, z, w};
00219     return a;
00220 }
00221 
00222 __device int2 make_int2(int x, int y)
00223 {
00224     int2 a = {x, y};
00225     return a;
00226 }
00227 
00228 __device int3 make_int3(int x, int y, int z)
00229 {
00230     int3 a = {x, y, z};
00231     return a;
00232 }
00233 
00234 __device int4 make_int4(int x, int y, int z, int w)
00235 {
00236     int4 a = {x, y, z, w};
00237     return a;
00238 }
00239 
00240 __device uint2 make_uint2(uint x, uint y)
00241 {
00242     uint2 a = {x, y};
00243     return a;
00244 }
00245 
00246 __device uint3 make_uint3(uint x, uint y, uint z)
00247 {
00248     uint3 a = {x, y, z};
00249     return a;
00250 }
00251 
00252 __device uint4 make_uint4(uint x, uint y, uint z, uint w)
00253 {
00254     uint4 a = {x, y, z, w};
00255     return a;
00256 }
00257 
00258 __device float2 make_float2(float x, float y)
00259 {
00260     float2 a = {x, y};
00261     return a;
00262 }
00263 
00264 __device float3 make_float3(float x, float y, float z)
00265 {
00266 #ifdef WITH_OPENCL
00267     float3 a = {x, y, z, 0.0f};
00268 #else
00269     float3 a = {x, y, z};
00270 #endif
00271     return a;
00272 }
00273 
00274 __device float4 make_float4(float x, float y, float z, float w)
00275 {
00276     float4 a = {x, y, z, w};
00277     return a;
00278 }
00279 
00280 #endif
00281 
00282 CCL_NAMESPACE_END
00283 
00284 #endif /* __UTIL_TYPES_H__ */
00285