Cycles: amd opencl compatibility fixes.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 10 Aug 2011 14:26:51 +0000 (14:26 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 10 Aug 2011 14:26:51 +0000 (14:26 +0000)
intern/cycles/kernel/kernel.cl
intern/cycles/kernel/kernel_shader.h
intern/cycles/kernel/svm/bsdf_ward.h
intern/cycles/kernel/svm/svm_math.h
intern/cycles/kernel/svm/svm_texture.h

index e1a9b3a..007a5f6 100644 (file)
@@ -51,7 +51,6 @@ __kernel void kernel_ocl_path_trace(
 
        int x = sx + get_global_id(0);
        int y = sy + get_global_id(1);
-       int w = kernel_data.cam.width;
 
        if(x < sx + sw && y < sy + sh)
                kernel_path_trace(kg, buffer, rng_state, pass, x, y);
index f1abbda..c4fc655 100644 (file)
@@ -140,14 +140,18 @@ __device void shader_setup_from_sample(KernelGlobals *kg, ShaderData *sd,
 #endif
 
        /* detect instancing, for non-instanced the object index is -object-1 */
+#ifdef __INSTANCING__
        bool instanced = false;
 
        if(sd->prim != ~0) {
                if(sd->object >= 0)
                        instanced = true;
                else
+#endif
                        sd->object = -sd->object-1;
+#ifdef __INSTANCING__
        }
+#endif
 
        /* smooth normal */
        if(sd->shader < 0) {
index 9f857b3..c54418a 100644 (file)
@@ -166,9 +166,7 @@ __device int bsdf_ward_sample(const ShaderData *sd, float randu, float randv, fl
                h = h.x * X + h.y * Y + h.z * m_N;
                // generate the final sample
                float oh = dot(h, sd->I);
-               omega_in->x = 2 * oh * h.x - sd->I.x;
-               omega_in->y = 2 * oh * h.y - sd->I.y;
-               omega_in->z = 2 * oh * h.z - sd->I.z;
+               *omega_in = 2.0f * oh * h - sd->I;
                if(dot(sd->Ng, *omega_in) > 0) {
                        float cosNI = dot(m_N, *omega_in);
                        if(cosNI > 0) {
index 401bd22..bc2f774 100644 (file)
@@ -21,7 +21,7 @@ CCL_NAMESPACE_BEGIN
 __device float safe_asinf(float a)
 {
        if(a <= -1.0f)
-               return -M_PI_2;
+               return -M_PI_2_F;
        else if(a >= 1.0f)
                return M_PI_2_F;
 
@@ -114,15 +114,20 @@ __device float svm_math(NodeMath type, float Fac1, float Fac2)
        return Fac;
 }
 
+__device float average_fac(float3 v)
+{
+       return (fabsf(v.x) + fabsf(v.y) + fabsf(v.z))/3.0f;
+}
+
 __device void svm_vector_math(float *Fac, float3 *Vector, NodeVectorMath type, float3 Vector1, float3 Vector2)
 {
        if(type == NODE_VECTOR_MATH_ADD) {
                *Vector = Vector1 + Vector2;
-               *Fac = (fabsf(Vector->x) + fabsf(Vector->y) + fabsf(Vector->z))/3.0f;
+               *Fac = average_fac(*Vector);
        }
        else if(type == NODE_VECTOR_MATH_SUBTRACT) {
                *Vector = Vector1 - Vector2;
-               *Fac = (fabsf(Vector->x) + fabsf(Vector->y) + fabsf(Vector->z))/3.0f;
+               *Fac = average_fac(*Vector);
        }
        else if(type == NODE_VECTOR_MATH_AVERAGE) {
                *Fac = len(Vector1 + Vector2);
index d4765cc..0bf0cf8 100644 (file)
@@ -194,15 +194,15 @@ __device float noise_wave(NodeWaveType wave, float a)
        return 0.5f + 0.5f*sin(a);
        }
        else if(wave == NODE_WAVE_SAW) {
-               float b = 2*M_PI;
+               float b = 2.0f*M_PI_F;
                int n = (int)(a / b);
                a -= n*b;
-               if(a < 0) a += b;
+               if(a < 0.0f) a += b;
 
                return a / b;
        }
        else if(wave == NODE_WAVE_TRI) {
-               float b = 2*M_PI;
+               float b = 2.0f*M_PI_F;
                float rmax = 1.0f;
 
                return rmax - 2.0f*fabsf(floorf((a*(1.0f/b))+0.5f) - (a*(1.0f/b)));