From d13a0e8f4ac0352de25e76756509e613a9cc6514 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 9 Sep 2015 13:25:56 +0500 Subject: Cycles: Limit triangle magnitude check for only GPU Found a way to make AVX2 CPUs happy by reshuffling instructions a bit, so now there's no weird precision errors happening in there. This solves some render speed regressions on CPU, but unfortunately this doesn't help for GPU rendering. --- intern/cycles/kernel/geom/geom_triangle_intersect.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'intern') diff --git a/intern/cycles/kernel/geom/geom_triangle_intersect.h b/intern/cycles/kernel/geom/geom_triangle_intersect.h index 5f88ef09256..fd521c18cc7 100644 --- a/intern/cycles/kernel/geom/geom_triangle_intersect.h +++ b/intern/cycles/kernel/geom/geom_triangle_intersect.h @@ -140,13 +140,15 @@ ccl_device_inline bool triangle_intersect(KernelGlobals *kg, /* Calculate scaled barycentric coordinates. */ float U = Cx * By - Cy * Bx; - int sign_mask = (__float_as_int(U) & 0x80000000); float V = Ax * Cy - Ay * Cx; - if(sign_mask != (__float_as_int(V) & 0x80000000)) { - return false; - } float W = Bx * Ay - By * Ax; - if(sign_mask != (__float_as_int(W) & 0x80000000)) { + const int sign_mask = (__float_as_int(U) & 0x80000000); + /* TODO(sergey): Check if multiplication plus sign check is faster + * or at least same speed (but robust for endian types). + */ + if(sign_mask != (__float_as_int(V) & 0x80000000) || + sign_mask != (__float_as_int(W) & 0x80000000)) + { return false; } @@ -173,6 +175,7 @@ ccl_device_inline bool triangle_intersect(KernelGlobals *kg, if(kernel_tex_fetch(__prim_visibility, triAddr) & visibility) #endif { +#ifdef __KERNEL_GPU__ float4 a = tri_b - tri_a, b = tri_c - tri_a; if(len_squared(make_float3(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, @@ -180,6 +183,8 @@ ccl_device_inline bool triangle_intersect(KernelGlobals *kg, { return false; } +#endif + /* Normalize U, V, W, and T. */ const float inv_det = 1.0f / det; isect->prim = triAddr; -- cgit v1.2.3