Cycles: more opencl fixes.

This commit is contained in:
Brecht Van Lommel 2011-05-31 11:31:00 +00:00
parent eedcba7ed5
commit 64c2d5e90e
5 changed files with 40 additions and 20 deletions

@ -22,10 +22,10 @@
#define __KERNEL_GPU__
#define __KERNEL_OPENCL__
#include "util_types.h"
CCL_NAMESPACE_BEGIN
#pragma OPENCL EXTENSION cl_khr_byte_addressable_store: enable
#define __device
#define __device_inline
@ -42,12 +42,26 @@ __device float kernel_tex_interp_(__global float *data, int width, float x)
return (1.0f - t)*data[index] + t*data[nindex];
}
#define make_float3(x, y, z) ((float3)(x, y, z)) /* todo 1.1 */
#define make_float2(x, y) ((float2)(x, y))
#define make_float3(x, y, z) ((float3)(x, y, z, 0.0f))
#define make_float4(x, y, z, w) ((float4)(x, y, z, w))
#define make_int2(x, y) ((int2)(x, y))
#define make_int3(x, y, z) ((int3)(x, y, z, 0))
#define make_int4(x, y, z, w) ((int4)(x, y, z, w))
typedef float4 float3;
typedef int4 int3;
#define __uint_as_float(x) as_float(x)
#define __float_as_uint(x) as_uint(x)
#define __int_as_float(x) as_float(x)
#define __float_as_int(x) as_int(x)
#define sqrtf(x) sqrt(((float)x))
#define cosf(x) cos(((float)x))
#define sinf(x) sin(((float)x))
#define powf(x, y) pow(((float)x), ((float)y))
#define fabsf(x) fabs(((float)x))
#define copysignf(x, y) copysign(((float)x), ((float)y))
#define kernel_data (*kg->data)
#define kernel_tex_interp(t, x) \
@ -57,6 +71,8 @@ __device float kernel_tex_interp_(__global float *data, int width, float x)
#define NULL 0
#include "util_types.h"
CCL_NAMESPACE_END
#endif /* __KERNEL_COMPAT_OPENCL_H__ */

@ -46,7 +46,10 @@ void Attribute::reserve(int numverts, int numtris)
size_t Attribute::data_sizeof()
{
return type.size();
if(type == TypeDesc::TypeFloat)
return sizeof(float);
else
return sizeof(float3);
}
size_t Attribute::element_size(int numverts, int numtris)

@ -45,6 +45,7 @@ Shader::Shader()
has_displacement = false;
need_update = true;
need_update_attributes = true;
}
Shader::~Shader()

@ -345,56 +345,56 @@ __device_inline float average(const float3 a)
__device_inline float3 operator-(const float3 a)
{
float3 r = {-a.x, -a.y, -a.z};
float3 r = make_float3(-a.x, -a.y, -a.z);
return r;
}
__device_inline float3 operator*(const float3 a, const float3 b)
{
float3 r = {a.x*b.x, a.y*b.y, a.z*b.z};
float3 r = make_float3(a.x*b.x, a.y*b.y, a.z*b.z);
return r;
}
__device_inline float3 operator*(const float3 a, float f)
{
float3 r = {a.x*f, a.y*f, a.z*f};
float3 r = make_float3(a.x*f, a.y*f, a.z*f);
return r;
}
__device_inline float3 operator*(float f, const float3 a)
{
float3 r = {a.x*f, a.y*f, a.z*f};
float3 r = make_float3(a.x*f, a.y*f, a.z*f);
return r;
}
__device_inline float3 operator/(float f, const float3 a)
{
float3 r = {f/a.x, f/a.y, f/a.z};
float3 r = make_float3(f/a.x, f/a.y, f/a.z);
return r;
}
__device_inline float3 operator/(const float3 a, float f)
{
float invf = 1.0f/f;
float3 r = {a.x*invf, a.y*invf, a.z*invf};
float3 r = make_float3(a.x*invf, a.y*invf, a.z*invf);
return r;
}
__device_inline float3 operator/(const float3 a, const float3 b)
{
float3 r = {a.x/b.x, a.y/b.y, a.z/b.z};
float3 r = make_float3(a.x/b.x, a.y/b.y, a.z/b.z);
return r;
}
__device_inline float3 operator+(const float3 a, const float3 b)
{
float3 r = {a.x+b.x, a.y+b.y, a.z+b.z};
float3 r = make_float3(a.x+b.x, a.y+b.y, a.z+b.z);
return r;
}
__device_inline float3 operator-(const float3 a, const float3 b)
{
float3 r = {a.x-b.x, a.y-b.y, a.z-b.z};
float3 r = make_float3(a.x-b.x, a.y-b.y, a.z-b.z);
return r;
}
@ -446,7 +446,7 @@ __device_inline float dot(const float3 a, const float3 b)
__device_inline float3 cross(const float3 a, const float3 b)
{
float3 r = {a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x};
float3 r = make_float3(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x);
return r;
}
@ -486,13 +486,13 @@ __device_inline bool operator!=(const float3 a, const float3 b)
__device_inline float3 min(float3 a, float3 b)
{
float3 r = {min(a.x, b.x), min(a.y, b.y), min(a.z, b.z)};
float3 r = make_float3(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z));
return r;
}
__device_inline float3 max(float3 a, float3 b)
{
float3 r = {max(a.x, b.x), max(a.y, b.y), max(a.z, b.z)};
float3 r = make_float3(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z));
return r;
}

@ -34,16 +34,16 @@ typedef struct Transform {
__device_inline float3 transform(const Transform *t, const float3 a)
{
float4 b = {a.x, a.y, a.z, 1.0f};
float3 c = {dot(t->x, b), dot(t->y, b), dot(t->z, b)};
float4 b = make_float4(a.x, a.y, a.z, 1.0f);
float3 c = make_float3(dot(t->x, b), dot(t->y, b), dot(t->z, b));
return c/dot(t->w, b);
}
__device_inline float3 transform_direction(const Transform *t, const float3 a)
{
float4 b = {a.x, a.y, a.z, 0.0f};
float3 c = {dot(t->x, b), dot(t->y, b), dot(t->z, b)};
float4 b = make_float4(a.x, a.y, a.z, 0.0f);
float3 c = make_float3(dot(t->x, b), dot(t->y, b), dot(t->z, b));
return c;
}