Blender V2.61 - r43446

kernel_compat_opencl.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 __KERNEL_COMPAT_OPENCL_H__
00020 #define __KERNEL_COMPAT_OPENCL_H__
00021 
00022 #define __KERNEL_GPU__
00023 #define __KERNEL_OPENCL__
00024 
00025 /* no namespaces in opencl */
00026 #define CCL_NAMESPACE_BEGIN
00027 #define CCL_NAMESPACE_END
00028 
00029 #ifdef __CL_NO_FLOAT3__
00030 #define float3 float4
00031 #endif
00032 
00033 #ifdef __CL_NOINLINE__
00034 #define __noinline __attribute__((noinline))
00035 #else
00036 #define __noinline
00037 #endif
00038 
00039 /* in opencl all functions are device functions, so leave this empty */
00040 #define __device
00041 #define __device_inline __device
00042 #define __device_noinline  __device __noinline
00043 
00044 /* no assert in opencl */
00045 #define kernel_assert(cond)
00046 
00047 /* manual implementation of interpolated 1D lookup */
00048 __device float kernel_tex_interp_(__global float *data, int width, float x)
00049 {
00050     x = clamp(x, 0.0f, 1.0f)*width;
00051 
00052     int index = min((int)x, width-1);
00053     int nindex = min(index+1, width-1);
00054     float t = x - index;
00055 
00056     return (1.0f - t)*data[index] + t*data[nindex];
00057 }
00058 
00059 /* make_type definitions with opencl style element initializers */
00060 #ifdef make_float2
00061 #undef make_float2
00062 #endif
00063 #ifdef make_float3
00064 #undef make_float3
00065 #endif
00066 #ifdef make_float4
00067 #undef make_float4
00068 #endif
00069 #ifdef make_int2
00070 #undef make_int2
00071 #endif
00072 #ifdef make_int3
00073 #undef make_int3
00074 #endif
00075 #ifdef make_int4
00076 #undef make_int4
00077 #endif
00078 
00079 #define make_float2(x, y) ((float2)(x, y))
00080 #ifdef __CL_NO_FLOAT3__
00081 #define make_float3(x, y, z) ((float4)(x, y, z, 0.0))
00082 #else
00083 #define make_float3(x, y, z) ((float3)(x, y, z))
00084 #endif
00085 #define make_float4(x, y, z, w) ((float4)(x, y, z, w))
00086 #define make_int2(x, y) ((int2)(x, y))
00087 #define make_int3(x, y, z) ((int3)(x, y, z))
00088 #define make_int4(x, y, z, w) ((int4)(x, y, z, w))
00089 
00090 /* math functions */
00091 #define __uint_as_float(x) as_float(x)
00092 #define __float_as_uint(x) as_uint(x)
00093 #define __int_as_float(x) as_float(x)
00094 #define __float_as_int(x) as_int(x)
00095 #define sqrtf(x) sqrt(((float)x))
00096 #define cosf(x) cos(((float)x))
00097 #define sinf(x) sin(((float)x))
00098 #define powf(x, y) pow(((float)x), ((float)y))
00099 #define fabsf(x) fabs(((float)x))
00100 #define copysignf(x, y) copysign(((float)x), ((float)y))
00101 #define cosf(x) cos(((float)x))
00102 #define asinf(x) asin(((float)x))
00103 #define acosf(x) acos(((float)x))
00104 #define atanf(x) atan(((float)x))
00105 #define tanf(x) tan(((float)x))
00106 #define logf(x) log(((float)x))
00107 #define floorf(x) floor(((float)x))
00108 #define expf(x) exp(((float)x))
00109 #define hypotf(x, y) hypot(((float)x), ((float)y))
00110 #define atan2f(x, y) atan2(((float)x), ((float)y))
00111 #define fmaxf(x, y) fmax(((float)x), ((float)y))
00112 #define fminf(x, y) fmin(((float)x), ((float)y))
00113 
00114 /* data lookup defines */
00115 #define kernel_data (*kg->data)
00116 #define kernel_tex_interp(t, x, size) kernel_tex_interp_(kg->t, size, x)
00117 #define kernel_tex_fetch(t, index) kg->t[index]
00118 
00119 /* define NULL */
00120 #define NULL 0
00121 
00122 #include "util_types.h"
00123 
00124 #endif /* __KERNEL_COMPAT_OPENCL_H__ */
00125