From 65d01def80a4fec855360b5e52d5d9724464ba17 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 21 Nov 2018 11:28:49 +0100 Subject: Cycles: Cleanup, CUDA code path is not possible inside AVX2 --- .../cycles/kernel/geom/geom_triangle_intersect.h | 64 ++++++++++------------ 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/intern/cycles/kernel/geom/geom_triangle_intersect.h b/intern/cycles/kernel/geom/geom_triangle_intersect.h index 6b4fbcbbb7c..368ea25d941 100644 --- a/intern/cycles/kernel/geom/geom_triangle_intersect.h +++ b/intern/cycles/kernel/geom/geom_triangle_intersect.h @@ -71,28 +71,23 @@ ccl_device_inline bool triangle_intersect(KernelGlobals *kg, } #ifdef __KERNEL_AVX2__ - #define cross256(A,B, C,D) _mm256_fmsub_ps(A,B, _mm256_mul_ps(C,D)) -#if defined(__KERNEL_CUDA__) && __CUDA_ARCH__ < 300 -ccl_device_inline -#else -ccl_device_forceinline -#endif -int ray_triangle_intersect8(KernelGlobals *kg, - float3 ray_P, - float3 ray_dir, - Intersection **isect, - uint visibility, - int object, - __m256 *triA, - __m256 *triB, - __m256 *triC, - int prim_addr, - int prim_num, - uint *num_hits, - uint max_hits, - int *num_hits_in_instance, - float isec_t) +ccl_device_inline int ray_triangle_intersect8( + KernelGlobals *kg, + float3 ray_P, + float3 ray_dir, + Intersection **isect, + uint visibility, + int object, + __m256 *triA, + __m256 *triB, + __m256 *triC, + int prim_addr, + int prim_num, + uint *num_hits, + uint max_hits, + int *num_hits_in_instance, + float isec_t) { const unsigned char prim_num_mask = (1 << prim_num) - 1; @@ -425,20 +420,19 @@ int ray_triangle_intersect8(KernelGlobals *kg, } -//vz static -ccl_device_inline -int triangle_intersect8(KernelGlobals *kg, - Intersection **isect, - float3 P, - float3 dir, - uint visibility, - int object, - int prim_addr, - int prim_num, - uint *num_hits, - uint max_hits, - int *num_hits_in_instance, - float isec_t) +ccl_device_inline int triangle_intersect8( + KernelGlobals *kg, + Intersection **isect, + float3 P, + float3 dir, + uint visibility, + int object, + int prim_addr, + int prim_num, + uint *num_hits, + uint max_hits, + int *num_hits_in_instance, + float isec_t) { __m128 tri_a[8], tri_b[8], tri_c[8]; __m256 tritmp[12], tri[12]; -- cgit v1.2.3 From 700330afe839897a3a87497385326e2b39748fd8 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 21 Nov 2018 11:33:11 +0100 Subject: Cycles: Cleanup, comments and dead code --- .../cycles/kernel/geom/geom_triangle_intersect.h | 119 ++++++--------------- 1 file changed, 34 insertions(+), 85 deletions(-) diff --git a/intern/cycles/kernel/geom/geom_triangle_intersect.h b/intern/cycles/kernel/geom/geom_triangle_intersect.h index 368ea25d941..9f3ea2c596c 100644 --- a/intern/cycles/kernel/geom/geom_triangle_intersect.h +++ b/intern/cycles/kernel/geom/geom_triangle_intersect.h @@ -103,10 +103,6 @@ ccl_device_inline int ray_triangle_intersect8( const __m256 dirz256 = _mm256_set1_ps(ray_dir.z); /* Calculate vertices relative to ray origin. */ - /* const float3 v0 = tri_c - P; - const float3 v1 = tri_a - P; - const float3 v2 = tri_b - P; */ - __m256 v0_x_256 = _mm256_sub_ps(triC[0], Px256); __m256 v0_y_256 = _mm256_sub_ps(triC[1], Py256); __m256 v0_z_256 = _mm256_sub_ps(triC[2], Pz256); @@ -131,11 +127,7 @@ ccl_device_inline int ray_triangle_intersect8( __m256 v1_v2_y_256 = _mm256_add_ps(v1_y_256, v2_y_256); __m256 v1_v2_z_256 = _mm256_add_ps(v1_z_256, v2_z_256); - /* Calculate triangle edges. - const float3 e0 = v2 - v0; - const float3 e1 = v0 - v1; - const float3 e2 = v1 - v2;*/ - + /* Calculate triangle edges. */ __m256 e0_x_256 = _mm256_sub_ps(v2_x_256, v0_x_256); __m256 e0_y_256 = _mm256_sub_ps(v2_y_256, v0_y_256); __m256 e0_z_256 = _mm256_sub_ps(v2_z_256, v0_z_256); @@ -148,48 +140,32 @@ ccl_device_inline int ray_triangle_intersect8( __m256 e2_y_256 = _mm256_sub_ps(v1_y_256, v2_y_256); __m256 e2_z_256 = _mm256_sub_ps(v1_z_256, v2_z_256); - /* Perform edge tests. - const float U = dot(cross(v2 + v0, e0), ray_dir); - const float V = dot(cross(v0 + v1, e1), ray_dir); - const float W = dot(cross(v1 + v2, e2), ray_dir);*/ - - //cross (AyBz - AzBy, AzBx -AxBz, AxBy - AyBx) + /* Perform edge tests. */ + /* cross (AyBz - AzBy, AzBx -AxBz, AxBy - AyBx) */ __m256 U_x_256 = cross256(v0_v2_y_256, e0_z_256, v0_v2_z_256, e0_y_256); __m256 U_y_256 = cross256(v0_v2_z_256, e0_x_256, v0_v2_x_256, e0_z_256); __m256 U_z_256 = cross256(v0_v2_x_256, e0_y_256, v0_v2_y_256, e0_x_256); - //vertical dot + /* vertical dot */ __m256 U_256 = _mm256_mul_ps(U_x_256, dirx256); - U_256 = _mm256_fmadd_ps(U_y_256, diry256, U_256); //_mm256_add_ps(U_256, _mm256_mul_ps(U_y_256, diry256)); - U_256 = _mm256_fmadd_ps(U_z_256, dirz256, U_256); //_mm256_add_ps(U_256, _mm256_mul_ps(U_z_256, dirz256)); + U_256 = _mm256_fmadd_ps(U_y_256, diry256, U_256); + U_256 = _mm256_fmadd_ps(U_z_256, dirz256, U_256); __m256 V_x_256 = cross256(v0_v1_y_256, e1_z_256, v0_v1_z_256, e1_y_256); __m256 V_y_256 = cross256(v0_v1_z_256, e1_x_256, v0_v1_x_256, e1_z_256); __m256 V_z_256 = cross256(v0_v1_x_256, e1_y_256, v0_v1_y_256, e1_x_256); - //vertical dot + /* vertical dot */ __m256 V_256 = _mm256_mul_ps(V_x_256, dirx256); - V_256 = _mm256_fmadd_ps(V_y_256, diry256, V_256);// _mm256_add_ps(V_256, _mm256_mul_ps(V_y_256, diry256)); - V_256 = _mm256_fmadd_ps(V_z_256, dirz256, V_256);// _mm256_add_ps(V_256, _mm256_mul_ps(V_z_256, dirz256)); + V_256 = _mm256_fmadd_ps(V_y_256, diry256, V_256); + V_256 = _mm256_fmadd_ps(V_z_256, dirz256, V_256); __m256 W_x_256 = cross256(v1_v2_y_256, e2_z_256, v1_v2_z_256, e2_y_256); __m256 W_y_256 = cross256(v1_v2_z_256, e2_x_256, v1_v2_x_256, e2_z_256); __m256 W_z_256 = cross256(v1_v2_x_256, e2_y_256, v1_v2_y_256, e2_x_256); - //vertical dot + /* vertical dot */ __m256 W_256 = _mm256_mul_ps(W_x_256, dirx256); - W_256 = _mm256_fmadd_ps(W_y_256, diry256,W_256);//_mm256_add_ps(W_256, _mm256_mul_ps(W_y_256, diry256)); - W_256 = _mm256_fmadd_ps(W_z_256, dirz256,W_256);//_mm256_add_ps(W_256, _mm256_mul_ps(W_z_256, dirz256)); - - //const float minUVW = min(U, min(V, W)); - //const float maxUVW = max(U, max(V, W)); -#if 0 - __m256 minUVW_256 = _mm256_min_ps(U_256, _mm256_min_ps(V_256, W_256)); - __m256 maxUVW_256 = _mm256_max_ps(U_256, _mm256_max_ps(V_256, W_256)); - - //if(minUVW < 0.0f && maxUVW > 0.0f) - __m256i mask_minmaxUVW_256 = _mm256_and_si256( - _mm256_cmpgt_epi32(zero256, _mm256_castps_si256(minUVW_256)), - //_mm256_castps_si256(minUVW_256), - _mm256_cmpgt_epi32(_mm256_castps_si256(maxUVW_256), zero256)); -#else + W_256 = _mm256_fmadd_ps(W_y_256, diry256,W_256); + W_256 = _mm256_fmadd_ps(W_z_256, dirz256,W_256); + __m256i U_256_1 = _mm256_srli_epi32(_mm256_castps_si256(U_256), 31); __m256i V_256_1 = _mm256_srli_epi32(_mm256_castps_si256(V_256), 31); __m256i W_256_1 = _mm256_srli_epi32(_mm256_castps_si256(W_256), 31); @@ -199,9 +175,8 @@ ccl_device_inline int ray_triangle_intersect8( const __m256i two256 = _mm256_set1_epi32(2); __m256i mask_minmaxUVW_256 = _mm256_or_si256( - _mm256_cmpeq_epi32(one256, UVW_256_1), - _mm256_cmpeq_epi32(two256, UVW_256_1) ); -#endif + _mm256_cmpeq_epi32(one256, UVW_256_1), + _mm256_cmpeq_epi32(two256, UVW_256_1)); unsigned char mask_minmaxUVW_pos = _mm256_movemask_ps(_mm256_castsi256_ps(mask_minmaxUVW_256)); if((mask_minmaxUVW_pos & prim_num_mask) == prim_num_mask) { //all bits set @@ -209,81 +184,56 @@ ccl_device_inline int ray_triangle_intersect8( } /* Calculate geometry normal and denominator. */ - // const float3 Ng1 = cross(e1, e0); - //const Vec3vfM Ng1 = stable_triangle_normal(e2,e1,e0); - __m256 Ng1_x_256 = cross256(e1_y_256, e0_z_256, e1_z_256, e0_y_256); __m256 Ng1_y_256 = cross256(e1_z_256, e0_x_256, e1_x_256, e0_z_256); __m256 Ng1_z_256 = cross256(e1_x_256, e0_y_256, e1_y_256, e0_x_256); - //const float3 Ng = Ng1 + Ng1; Ng1_x_256 = _mm256_add_ps(Ng1_x_256, Ng1_x_256); Ng1_y_256 = _mm256_add_ps(Ng1_y_256, Ng1_y_256); Ng1_z_256 = _mm256_add_ps(Ng1_z_256, Ng1_z_256); - //const float den = dot3(Ng, dir); - //vertical dot + /* vertical dot */ __m256 den_256 = _mm256_mul_ps(Ng1_x_256, dirx256); - den_256 = _mm256_fmadd_ps(Ng1_y_256, diry256,den_256);//_mm256_add_ps(den_256, _mm256_mul_ps(Ng1_y_256, diry256)); - den_256 = _mm256_fmadd_ps(Ng1_z_256, dirz256,den_256);//_mm256_add_ps(den_256, _mm256_mul_ps(Ng1_z_256, dirz256)); - - // __m256i maskden256 = _mm256_cmpeq_epi32(_mm256_castps_si256(den_256), zero256); + den_256 = _mm256_fmadd_ps(Ng1_y_256, diry256,den_256); + den_256 = _mm256_fmadd_ps(Ng1_z_256, dirz256,den_256); /* Perform depth test. */ - //const float T = dot3(v0, Ng); __m256 T_256 = _mm256_mul_ps(Ng1_x_256, v0_x_256); - T_256 = _mm256_fmadd_ps(Ng1_y_256, v0_y_256,T_256);//_mm256_add_ps(T_256, _mm256_mul_ps(Ng1_y_256, v0_y_256)); - T_256 = _mm256_fmadd_ps(Ng1_z_256, v0_z_256,T_256);//_mm256_add_ps(T_256, _mm256_mul_ps(Ng1_z_256, v0_z_256)); + T_256 = _mm256_fmadd_ps(Ng1_y_256, v0_y_256,T_256); + T_256 = _mm256_fmadd_ps(Ng1_z_256, v0_z_256,T_256); - //const int sign_den = (__float_as_int(den) & 0x80000000); const __m256i c0x80000000 = _mm256_set1_epi32(0x80000000); __m256i sign_den_256 = _mm256_and_si256(_mm256_castps_si256(den_256), c0x80000000); - //const float sign_T = xor_signmask(T, sign_den); __m256 sign_T_256 = _mm256_castsi256_ps(_mm256_xor_si256(_mm256_castps_si256(T_256), sign_den_256)); - /*if((sign_T < 0.0f) || mask_minmaxUVW_pos { return false;} */ unsigned char mask_sign_T = _mm256_movemask_ps(sign_T_256); if(((mask_minmaxUVW_pos | mask_sign_T) & prim_num_mask) == prim_num_mask) { return false; - } /**/ + } __m256 xor_signmask_256 = _mm256_castsi256_ps(_mm256_xor_si256(_mm256_castps_si256(den_256), sign_den_256)); - ccl_align(32) float den8[8], U8[8], V8[8], T8[8], sign_T8[8], xor_signmask8[8]; ccl_align(32) unsigned int mask_minmaxUVW8[8]; if(visibility == PATH_RAY_SHADOW_OPAQUE){ - __m256i mask_final_256 = _mm256_cmpeq_epi32(mask_minmaxUVW_256, zero256);//~mask_minmaxUVW_256 - + __m256i mask_final_256 = _mm256_cmpeq_epi32(mask_minmaxUVW_256, zero256); __m256i maskden256 = _mm256_cmpeq_epi32(_mm256_castps_si256(den_256), zero256); - __m256i mask0 = _mm256_cmpgt_epi32(zero256, _mm256_castps_si256(sign_T_256)); __m256 rayt_256 = _mm256_set1_ps((*isect)->t); - __m256i mask1 = _mm256_cmpgt_epi32(_mm256_castps_si256(sign_T_256), _mm256_castps_si256( _mm256_mul_ps(_mm256_castsi256_ps(_mm256_xor_si256(_mm256_castps_si256(den_256), sign_den_256)), rayt_256) ) ); - /* __m256i mask1 = _mm256_castps_si256(_mm256_cmp_ps(sign_T_256, - _mm256_mul_ps(_mm256_castsi256_ps(_mm256_xor_si256(_mm256_castps_si256(den_256), sign_den_256)), rayt_256), - _CMP_GT_OS - ) );*/ - mask0 = _mm256_or_si256(mask1, mask0); - //unsigned char mask = _mm256_movemask_ps(_mm256_castsi256_ps(mask0)); - //unsigned char maskden = _mm256_movemask_ps(_mm256_castsi256_ps(maskden256)); - //unsigned char mask_final = ((~mask) & (~maskden) & (~mask_minmaxUVW_pos)); mask_final_256 = _mm256_andnot_si256(mask0, mask_final_256); //(~mask_minmaxUVW_pos) &(~mask) mask_final_256 = _mm256_andnot_si256(maskden256, mask_final_256); //(~mask_minmaxUVW_pos) &(~mask) & (~maskden) - unsigned char mask_final = _mm256_movemask_ps(_mm256_castsi256_ps(mask_final_256)); - if((mask_final & prim_num_mask) == 0) { //all bits NOT set + if((mask_final & prim_num_mask) == 0) { return false; - } /**/ - + } unsigned long i = 0; #if defined(_MSC_VER) unsigned char res = _BitScanForward(&i, (unsigned long)mask_final); @@ -291,17 +241,17 @@ ccl_device_inline int ray_triangle_intersect8( i = __builtin_ffs(mask_final)-1; #endif - den_256 = _mm256_rcp_ps(den_256); //inv_den - U_256 = _mm256_mul_ps(U_256, den_256); //*inv_den - V_256 = _mm256_mul_ps(V_256, den_256); //*inv_den - T_256 = _mm256_mul_ps(T_256, den_256); //*inv_den + __m256 inv_den_256 = _mm256_rcp_ps(den_256); + U_256 = _mm256_mul_ps(U_256, inv_den_256); + V_256 = _mm256_mul_ps(V_256, inv_den_256); + T_256 = _mm256_mul_ps(T_256, inv_den_256); _mm256_store_ps(U8, U_256); _mm256_store_ps(V8, V_256); _mm256_store_ps(T8, T_256); - - //here we assume (kernel_tex_fetch(__prim_visibility, (prim_addr +i)) & visibility) is always true + /* NOTE: Here we assume visibility for all triangles in the node is + * the same. */ (*isect)->u = U8[i]; (*isect)->v = V8[i]; @@ -363,11 +313,11 @@ ccl_device_inline int ray_triangle_intersect8( #endif int flag = kernel_tex_fetch(__shaders, (shader & SHADER_MASK)).flags; - /* if no transparent shadows, all light is blocked */ + /* if no transparent shadows, all light is blocked. */ if(!(flag & SD_HAS_TRANSPARENT_SHADOW)) { return 2; } - /* if maximum number of hits reached, block all light */ + /* if maximum number of hits reached, block all light. */ else if(*num_hits == max_hits) { return 2; } @@ -415,9 +365,8 @@ ccl_device_inline int ray_triangle_intersect8( }//if mask } //for } //default - return ret; -}// else PATH_RAY_SHADOW_OPAQUE - + return ret; + }// else PATH_RAY_SHADOW_OPAQUE } ccl_device_inline int triangle_intersect8( -- cgit v1.2.3 From 65143542af499c026645823d3e5e0f0302fae636 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 21 Nov 2018 12:23:54 +0100 Subject: Cycles: Cleanup, reduce indentation level --- .../cycles/kernel/geom/geom_triangle_intersect.h | 258 ++++++++++----------- 1 file changed, 123 insertions(+), 135 deletions(-) diff --git a/intern/cycles/kernel/geom/geom_triangle_intersect.h b/intern/cycles/kernel/geom/geom_triangle_intersect.h index 9f3ea2c596c..558f08205a2 100644 --- a/intern/cycles/kernel/geom/geom_triangle_intersect.h +++ b/intern/cycles/kernel/geom/geom_triangle_intersect.h @@ -87,7 +87,7 @@ ccl_device_inline int ray_triangle_intersect8( uint *num_hits, uint max_hits, int *num_hits_in_instance, - float isec_t) + float isect_t) { const unsigned char prim_num_mask = (1 << prim_num) - 1; @@ -217,156 +217,144 @@ ccl_device_inline int ray_triangle_intersect8( ccl_align(32) float den8[8], U8[8], V8[8], T8[8], sign_T8[8], xor_signmask8[8]; ccl_align(32) unsigned int mask_minmaxUVW8[8]; - if(visibility == PATH_RAY_SHADOW_OPAQUE){ - __m256i mask_final_256 = _mm256_cmpeq_epi32(mask_minmaxUVW_256, zero256); - __m256i maskden256 = _mm256_cmpeq_epi32(_mm256_castps_si256(den_256), zero256); - __m256i mask0 = _mm256_cmpgt_epi32(zero256, _mm256_castps_si256(sign_T_256)); - __m256 rayt_256 = _mm256_set1_ps((*isect)->t); - __m256i mask1 = _mm256_cmpgt_epi32(_mm256_castps_si256(sign_T_256), - _mm256_castps_si256( - _mm256_mul_ps(_mm256_castsi256_ps(_mm256_xor_si256(_mm256_castps_si256(den_256), sign_den_256)), rayt_256) - ) - ); - mask0 = _mm256_or_si256(mask1, mask0); - mask_final_256 = _mm256_andnot_si256(mask0, mask_final_256); //(~mask_minmaxUVW_pos) &(~mask) - mask_final_256 = _mm256_andnot_si256(maskden256, mask_final_256); //(~mask_minmaxUVW_pos) &(~mask) & (~maskden) - unsigned char mask_final = _mm256_movemask_ps(_mm256_castsi256_ps(mask_final_256)); - if((mask_final & prim_num_mask) == 0) { - return false; - } - unsigned long i = 0; + if(visibility == PATH_RAY_SHADOW_OPAQUE) { + __m256i mask_final_256 = _mm256_cmpeq_epi32(mask_minmaxUVW_256, zero256); + __m256i maskden256 = _mm256_cmpeq_epi32(_mm256_castps_si256(den_256), zero256); + __m256i mask0 = _mm256_cmpgt_epi32(zero256, _mm256_castps_si256(sign_T_256)); + __m256 rayt_256 = _mm256_set1_ps((*isect)->t); + __m256i mask1 = _mm256_cmpgt_epi32(_mm256_castps_si256(sign_T_256), + _mm256_castps_si256( + _mm256_mul_ps(_mm256_castsi256_ps(_mm256_xor_si256(_mm256_castps_si256(den_256), sign_den_256)), rayt_256) + ) + ); + mask0 = _mm256_or_si256(mask1, mask0); + mask_final_256 = _mm256_andnot_si256(mask0, mask_final_256); //(~mask_minmaxUVW_pos) &(~mask) + mask_final_256 = _mm256_andnot_si256(maskden256, mask_final_256); //(~mask_minmaxUVW_pos) &(~mask) & (~maskden) + unsigned char mask_final = _mm256_movemask_ps(_mm256_castsi256_ps(mask_final_256)); + if((mask_final & prim_num_mask) == 0) { + return false; + } + unsigned long i = 0; #if defined(_MSC_VER) - unsigned char res = _BitScanForward(&i, (unsigned long)mask_final); + unsigned char res = _BitScanForward(&i, (unsigned long)mask_final); #else - i = __builtin_ffs(mask_final)-1; + i = __builtin_ffs(mask_final)-1; #endif - - __m256 inv_den_256 = _mm256_rcp_ps(den_256); - U_256 = _mm256_mul_ps(U_256, inv_den_256); - V_256 = _mm256_mul_ps(V_256, inv_den_256); - T_256 = _mm256_mul_ps(T_256, inv_den_256); - - _mm256_store_ps(U8, U_256); - _mm256_store_ps(V8, V_256); - _mm256_store_ps(T8, T_256); - - /* NOTE: Here we assume visibility for all triangles in the node is - * the same. */ - - (*isect)->u = U8[i]; - (*isect)->v = V8[i]; - (*isect)->t = T8[i]; - - (*isect)->prim = (prim_addr + i); - (*isect)->object = object; - (*isect)->type = PRIMITIVE_TRIANGLE; - - return true; - } + __m256 inv_den_256 = _mm256_rcp_ps(den_256); + U_256 = _mm256_mul_ps(U_256, inv_den_256); + V_256 = _mm256_mul_ps(V_256, inv_den_256); + T_256 = _mm256_mul_ps(T_256, inv_den_256); + _mm256_store_ps(U8, U_256); + _mm256_store_ps(V8, V_256); + _mm256_store_ps(T8, T_256); + /* NOTE: Here we assume visibility for all triangles in the node is + * the same. */ + (*isect)->u = U8[i]; + (*isect)->v = V8[i]; + (*isect)->t = T8[i]; + (*isect)->prim = (prim_addr + i); + (*isect)->object = object; + (*isect)->type = PRIMITIVE_TRIANGLE; + return true; + } else { - _mm256_store_ps(den8, den_256); - _mm256_store_ps(U8, U_256); - _mm256_store_ps(V8, V_256); - _mm256_store_ps(T8, T_256); + _mm256_store_ps(den8, den_256); + _mm256_store_ps(U8, U_256); + _mm256_store_ps(V8, V_256); + _mm256_store_ps(T8, T_256); - _mm256_store_ps(sign_T8, sign_T_256); - _mm256_store_ps(xor_signmask8, xor_signmask_256); - _mm256_store_si256((__m256i*)mask_minmaxUVW8, mask_minmaxUVW_256); + _mm256_store_ps(sign_T8, sign_T_256); + _mm256_store_ps(xor_signmask8, xor_signmask_256); + _mm256_store_si256((__m256i*)mask_minmaxUVW8, mask_minmaxUVW_256); - int ret = false; + int ret = false; - if(visibility == PATH_RAY_SHADOW) { - for(int i = 0; i < prim_num; i++) { - if(!mask_minmaxUVW8[i]) { + if(visibility == PATH_RAY_SHADOW) { + for(int i = 0; i < prim_num; i++) { + if(mask_minmaxUVW8[i]) { + continue; + } #ifdef __VISIBILITY_FLAG__ - if(kernel_tex_fetch(__prim_visibility, (prim_addr + i)) & visibility) + if((kernel_tex_fetch(__prim_visibility, (prim_addr + i)) & visibility) == 0) { + continue; + } #endif - { - if((sign_T8[i] >= 0.0f) && - (sign_T8[i] <= (*isect)->t * xor_signmask8[i])) - { - if(den8[i]) { - const float inv_den = 1.0f / den8[i]; - - (*isect)->u = U8[i] * inv_den; - (*isect)->v = V8[i] * inv_den; - (*isect)->t = T8[i] * inv_den; - - (*isect)->prim = (prim_addr + i); - (*isect)->object = object; - (*isect)->type = PRIMITIVE_TRIANGLE; - - int prim = kernel_tex_fetch(__prim_index, (*isect)->prim); - int shader = 0; - + if((sign_T8[i] < 0.0f) || + (sign_T8[i] > (*isect)->t * xor_signmask8[i])) + { + continue; + } + if(!den8[i]) { + continue; + } + const float inv_den = 1.0f / den8[i]; + (*isect)->u = U8[i] * inv_den; + (*isect)->v = V8[i] * inv_den; + (*isect)->t = T8[i] * inv_den; + (*isect)->prim = (prim_addr + i); + (*isect)->object = object; + (*isect)->type = PRIMITIVE_TRIANGLE; + const int prim = kernel_tex_fetch(__prim_index, (*isect)->prim); + int shader = 0; #ifdef __HAIR__ - if(kernel_tex_fetch(__prim_type, (*isect)->prim) & PRIMITIVE_ALL_TRIANGLE) + if(kernel_tex_fetch(__prim_type, (*isect)->prim) & PRIMITIVE_ALL_TRIANGLE) #endif - { - shader = kernel_tex_fetch(__tri_shader, prim); - } + { + shader = kernel_tex_fetch(__tri_shader, prim); + } #ifdef __HAIR__ - else { - float4 str = kernel_tex_fetch(__curves, prim); - shader = __float_as_int(str.z); - } + else { + float4 str = kernel_tex_fetch(__curves, prim); + shader = __float_as_int(str.z); + } #endif - int flag = kernel_tex_fetch(__shaders, (shader & SHADER_MASK)).flags; - - /* if no transparent shadows, all light is blocked. */ - if(!(flag & SD_HAS_TRANSPARENT_SHADOW)) { - return 2; - } - /* if maximum number of hits reached, block all light. */ - else if(*num_hits == max_hits) { - return 2; - } - /* move on to next entry in intersections array */ - ret = true; - - (*isect)++; - (*num_hits)++; - - (*num_hits_in_instance)++; - - (*isect)->t = isec_t; - - } //den - } //if sign - } //vis - }//if mask - } //for + const int flag = kernel_tex_fetch(__shaders, (shader & SHADER_MASK)).flags; + /* If no transparent shadows, all light is blocked. */ + if(!(flag & SD_HAS_TRANSPARENT_SHADOW)) { + return 2; + } + /* If maximum number of hits reached, block all light. */ + else if(*num_hits == max_hits) { + return 2; + } + /* Move on to next entry in intersections array. */ + ret = true; + (*isect)++; + (*num_hits)++; + (*num_hits_in_instance)++; + (*isect)->t = isect_t; + } } - else { //default case + else { for(int i = 0; i < prim_num; i++) { - if(!mask_minmaxUVW8[i]) { + if(mask_minmaxUVW8[i]) { + continue; + } #ifdef __VISIBILITY_FLAG__ - if(kernel_tex_fetch(__prim_visibility, (prim_addr + i)) & visibility) + if((kernel_tex_fetch(__prim_visibility, (prim_addr + i)) & visibility) == 0) { + continue; + } #endif - { - if((sign_T8[i] >= 0.0f) && - (sign_T8[i] <= (*isect)->t * xor_signmask8[i])) - { - if(den8[i]) { - const float inv_den = 1.0f / den8[i]; - - (*isect)->u = U8[i] * inv_den; - (*isect)->v = V8[i] * inv_den; - (*isect)->t = T8[i] * inv_den; - - (*isect)->prim = (prim_addr + i); - (*isect)->object = object; - (*isect)->type = PRIMITIVE_TRIANGLE; - - ret = true; - } //den - } //if sign - } //vis - }//if mask - } //for - } //default + if((sign_T8[i] < 0.0f) || + (sign_T8[i] > (*isect)->t * xor_signmask8[i])) + { + continue; + } + if(!den8[i]) { + continue; + } + const float inv_den = 1.0f / den8[i]; + (*isect)->u = U8[i] * inv_den; + (*isect)->v = V8[i] * inv_den; + (*isect)->t = T8[i] * inv_den; + (*isect)->prim = (prim_addr + i); + (*isect)->object = object; + (*isect)->type = PRIMITIVE_TRIANGLE; + ret = true; + } + } return ret; - }// else PATH_RAY_SHADOW_OPAQUE + } } ccl_device_inline int triangle_intersect8( @@ -381,7 +369,7 @@ ccl_device_inline int triangle_intersect8( uint *num_hits, uint max_hits, int *num_hits_in_instance, - float isec_t) + float isect_t) { __m128 tri_a[8], tri_b[8], tri_c[8]; __m256 tritmp[12], tri[12]; @@ -483,7 +471,7 @@ ccl_device_inline int triangle_intersect8( num_hits, max_hits, num_hits_in_instance, - isec_t); + isect_t); return result; } -- cgit v1.2.3 From 6f48bfc7a872c106e631cda0e23d2f61d6d944d2 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 21 Nov 2018 13:51:18 +0100 Subject: Cycles: Cleanup, use utility function Replaces inlined platform-specific code. --- intern/cycles/kernel/geom/geom_triangle_intersect.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/intern/cycles/kernel/geom/geom_triangle_intersect.h b/intern/cycles/kernel/geom/geom_triangle_intersect.h index 558f08205a2..fa686d8a223 100644 --- a/intern/cycles/kernel/geom/geom_triangle_intersect.h +++ b/intern/cycles/kernel/geom/geom_triangle_intersect.h @@ -234,12 +234,7 @@ ccl_device_inline int ray_triangle_intersect8( if((mask_final & prim_num_mask) == 0) { return false; } - unsigned long i = 0; -#if defined(_MSC_VER) - unsigned char res = _BitScanForward(&i, (unsigned long)mask_final); -#else - i = __builtin_ffs(mask_final)-1; -#endif + const int i = __bsf(mask_final); __m256 inv_den_256 = _mm256_rcp_ps(den_256); U_256 = _mm256_mul_ps(U_256, inv_den_256); V_256 = _mm256_mul_ps(V_256, inv_den_256); -- cgit v1.2.3 From 968bf0df148c6fac7567860a64433daa97d042c9 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 21 Nov 2018 14:17:26 +0100 Subject: Fix T57811: Render crashes in certain scenes when AO Bounces are used --- intern/cycles/kernel/geom/geom_triangle_intersect.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intern/cycles/kernel/geom/geom_triangle_intersect.h b/intern/cycles/kernel/geom/geom_triangle_intersect.h index fa686d8a223..57f4c86d403 100644 --- a/intern/cycles/kernel/geom/geom_triangle_intersect.h +++ b/intern/cycles/kernel/geom/geom_triangle_intersect.h @@ -309,7 +309,7 @@ ccl_device_inline int ray_triangle_intersect8( return 2; } /* If maximum number of hits reached, block all light. */ - else if(*num_hits == max_hits) { + else if(num_hits == NULL || *num_hits == max_hits) { return 2; } /* Move on to next entry in intersections array. */ -- cgit v1.2.3 From c66570f519fb24e0c3fb724d7b6d38f4b6fd7ffc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 22 Nov 2018 14:57:41 +1100 Subject: Fix T57989: File loaded as startup The file contents was used to check if the file was a startup file. Now pass in an argument from startup loading code instead. --- source/blender/blenkernel/BKE_blendfile.h | 12 ++++--- source/blender/blenkernel/intern/blender_undo.c | 6 +++- source/blender/blenkernel/intern/blendfile.c | 37 +++++++++++++--------- source/blender/blenloader/BLO_readfile.h | 14 ++++++-- source/blender/blenloader/intern/readblenentry.c | 9 ++++-- source/blender/blenloader/intern/undofile.c | 2 +- source/blender/editors/render/render_preview.c | 2 +- source/blender/windowmanager/intern/wm_files.c | 21 +++++++++--- .../BlenderRoutines/BL_KetsjiEmbedStart.cpp | 3 +- source/gameengine/GamePlayer/ghost/GPG_ghost.cpp | 2 +- 10 files changed, 74 insertions(+), 34 deletions(-) diff --git a/source/blender/blenkernel/BKE_blendfile.h b/source/blender/blenkernel/BKE_blendfile.h index 9ff164f60be..74fdde93d9a 100644 --- a/source/blender/blenkernel/BKE_blendfile.h +++ b/source/blender/blenkernel/BKE_blendfile.h @@ -34,6 +34,7 @@ struct Main; struct MemFile; struct ReportList; struct UserDef; +struct BlendFileReadParams; enum { BKE_BLENDFILE_READ_FAIL = 0, /* no load */ @@ -43,13 +44,16 @@ enum { int BKE_blendfile_read( struct bContext *C, const char *filepath, - struct ReportList *reports, int skip_flag); + const struct BlendFileReadParams *params, + struct ReportList *reports); bool BKE_blendfile_read_from_memory( - struct bContext *C, const void *filebuf, int filelength, - struct ReportList *reports, int skip_flag, bool update_defaults); + struct bContext *C, const void *filebuf, int filelength, bool update_defaults, + const struct BlendFileReadParams *params, + struct ReportList *reports); bool BKE_blendfile_read_from_memfile( struct bContext *C, struct MemFile *memfile, - struct ReportList *reports, int skip_flag); + const struct BlendFileReadParams *params, + struct ReportList *reports); void BKE_blendfile_read_make_empty(struct bContext *C); struct UserDef *BKE_blendfile_userdef_read( diff --git a/source/blender/blenkernel/intern/blender_undo.c b/source/blender/blenkernel/intern/blender_undo.c index df2caba0208..441687c1c01 100644 --- a/source/blender/blenkernel/intern/blender_undo.c +++ b/source/blender/blenkernel/intern/blender_undo.c @@ -55,6 +55,7 @@ #include "BKE_main.h" #include "BLO_undofile.h" +#include "BLO_readfile.h" #include "BLO_writefile.h" /* -------------------------------------------------------------------- */ @@ -79,7 +80,10 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu, bContext *C) success = (BKE_blendfile_read(C, mfu->filename, NULL, 0) != BKE_BLENDFILE_READ_FAIL); } else { - success = BKE_blendfile_read_from_memfile(C, &mfu->memfile, NULL, 0); + success = BKE_blendfile_read_from_memfile( + C, &mfu->memfile, + &(const struct BlendFileReadParams){0}, + NULL); } /* Restore, bmain has been re-allocated. */ diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c index c92648da67c..c6cb8a412fe 100644 --- a/source/blender/blenkernel/intern/blendfile.c +++ b/source/blender/blenkernel/intern/blendfile.c @@ -111,11 +111,12 @@ static bool wm_scene_is_visible(wmWindowManager *wm, Scene *scene) */ static void setup_app_data( bContext *C, BlendFileData *bfd, - const char *filepath, ReportList *reports) + const char *filepath, + const bool is_startup, + ReportList *reports) { Main *bmain = G_MAIN; Scene *curscene = NULL; - const bool is_startup = (bfd->filename[0] == '\0'); const bool recover = (G.fileflags & G_FILE_RECOVER) != 0; enum { LOAD_UI = 1, @@ -296,7 +297,7 @@ static void setup_app_data( bmain->recovered = 0; /* startup.blend or recovered startup */ - if (bfd->filename[0] == 0) { + if (is_startup) { bmain->name[0] = '\0'; } else if (recover && G.relbase_valid) { @@ -351,7 +352,8 @@ static int handle_subversion_warning(Main *main, ReportList *reports) int BKE_blendfile_read( bContext *C, const char *filepath, - ReportList *reports, int skip_flags) + const struct BlendFileReadParams *params, + ReportList *reports) { BlendFileData *bfd; int retval = BKE_BLENDFILE_READ_OK; @@ -361,7 +363,7 @@ int BKE_blendfile_read( printf("Read blend: %s\n", filepath); } - bfd = BLO_read_from_file(filepath, reports, skip_flags); + bfd = BLO_read_from_file(filepath, params->skip_flags, reports); if (bfd) { if (bfd->user) { retval = BKE_BLENDFILE_READ_OK_USERPREFS; @@ -374,7 +376,7 @@ int BKE_blendfile_read( retval = BKE_BLENDFILE_READ_FAIL; } else { - setup_app_data(C, bfd, filepath, reports); + setup_app_data(C, bfd, filepath, params->is_startup, reports); } } else @@ -384,16 +386,17 @@ int BKE_blendfile_read( } bool BKE_blendfile_read_from_memory( - bContext *C, const void *filebuf, int filelength, - ReportList *reports, int skip_flags, bool update_defaults) + bContext *C, const void *filebuf, int filelength, bool update_defaults, + const struct BlendFileReadParams *params, + ReportList *reports) { BlendFileData *bfd; - bfd = BLO_read_from_memory(filebuf, filelength, reports, skip_flags); + bfd = BLO_read_from_memory(filebuf, filelength, params->skip_flags, reports); if (bfd) { if (update_defaults) BLO_update_defaults_startup_blend(bfd->main); - setup_app_data(C, bfd, "", reports); + setup_app_data(C, bfd, "", params->is_startup, reports); } else { BKE_reports_prepend(reports, "Loading failed: "); @@ -405,12 +408,13 @@ bool BKE_blendfile_read_from_memory( /* memfile is the undo buffer */ bool BKE_blendfile_read_from_memfile( bContext *C, struct MemFile *memfile, - ReportList *reports, int skip_flags) + const struct BlendFileReadParams *params, + ReportList *reports) { Main *bmain = CTX_data_main(C); BlendFileData *bfd; - bfd = BLO_read_from_memfile(bmain, BKE_main_blendfile_path(bmain), memfile, reports, skip_flags); + bfd = BLO_read_from_memfile(bmain, BKE_main_blendfile_path(bmain), memfile, params->skip_flags, reports); if (bfd) { /* remove the unused screens and wm */ while (bfd->main->wm.first) @@ -418,7 +422,7 @@ bool BKE_blendfile_read_from_memfile( while (bfd->main->screen.first) BKE_libblock_free(bfd->main, bfd->main->screen.first); - setup_app_data(C, bfd, "", reports); + setup_app_data(C, bfd, "", params->is_startup, reports); } else { BKE_reports_prepend(reports, "Loading failed: "); @@ -459,7 +463,7 @@ UserDef *BKE_blendfile_userdef_read(const char *filepath, ReportList *reports) BlendFileData *bfd; UserDef *userdef = NULL; - bfd = BLO_read_from_file(filepath, reports, BLO_READ_SKIP_ALL & ~BLO_READ_SKIP_USERDEF); + bfd = BLO_read_from_file(filepath, BLO_READ_SKIP_ALL & ~BLO_READ_SKIP_USERDEF, reports); if (bfd) { if (bfd->user) { userdef = bfd->user; @@ -479,7 +483,10 @@ UserDef *BKE_blendfile_userdef_read_from_memory( BlendFileData *bfd; UserDef *userdef = NULL; - bfd = BLO_read_from_memory(filebuf, filelength, reports, BLO_READ_SKIP_ALL & ~BLO_READ_SKIP_USERDEF); + bfd = BLO_read_from_memory( + filebuf, filelength, + BLO_READ_SKIP_ALL & ~BLO_READ_SKIP_USERDEF, + reports); if (bfd) { if (bfd->user) { userdef = bfd->user; diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h index 11f34732cfc..5a1c479f450 100644 --- a/source/blender/blenloader/BLO_readfile.h +++ b/source/blender/blenloader/BLO_readfile.h @@ -48,6 +48,7 @@ struct View3D; struct bContext; struct BHead; struct FileData; +struct BlendFileReadParams; typedef struct BlendHandle BlendHandle; @@ -71,6 +72,10 @@ typedef struct BlendFileData { eBlenFileType type; } BlendFileData; +struct BlendFileReadParams { + uint skip_flags : 2; /* eBLOReadSkip */ + uint is_startup : 1; +}; /* skip reading some data-block types (may want to skip screen data too). */ typedef enum eBLOReadSkip { @@ -83,13 +88,16 @@ typedef enum eBLOReadSkip { BlendFileData *BLO_read_from_file( const char *filepath, - struct ReportList *reports, eBLOReadSkip skip_flag); + eBLOReadSkip skip_flags, + struct ReportList *reports); BlendFileData *BLO_read_from_memory( const void *mem, int memsize, - struct ReportList *reports, eBLOReadSkip skip_flag); + eBLOReadSkip skip_flags, + struct ReportList *reports); BlendFileData *BLO_read_from_memfile( struct Main *oldmain, const char *filename, struct MemFile *memfile, - struct ReportList *reports, eBLOReadSkip skip_flag); + eBLOReadSkip skip_flags, + struct ReportList *reports); void BLO_blendfiledata_free(BlendFileData *bfd); diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c index 7488d62bb3c..b2bcf745eac 100644 --- a/source/blender/blenloader/intern/readblenentry.c +++ b/source/blender/blenloader/intern/readblenentry.c @@ -319,7 +319,8 @@ void BLO_blendhandle_close(BlendHandle *bh) */ BlendFileData *BLO_read_from_file( const char *filepath, - ReportList *reports, eBLOReadSkip skip_flags) + eBLOReadSkip skip_flags, + ReportList *reports) { BlendFileData *bfd = NULL; FileData *fd; @@ -346,7 +347,8 @@ BlendFileData *BLO_read_from_file( */ BlendFileData *BLO_read_from_memory( const void *mem, int memsize, - ReportList *reports, eBLOReadSkip skip_flags) + eBLOReadSkip skip_flags, + ReportList *reports) { BlendFileData *bfd = NULL; FileData *fd; @@ -370,7 +372,8 @@ BlendFileData *BLO_read_from_memory( */ BlendFileData *BLO_read_from_memfile( Main *oldmain, const char *filename, MemFile *memfile, - ReportList *reports, eBLOReadSkip skip_flags) + eBLOReadSkip skip_flags, + ReportList *reports) { BlendFileData *bfd = NULL; FileData *fd; diff --git a/source/blender/blenloader/intern/undofile.c b/source/blender/blenloader/intern/undofile.c index 614a3be559b..37cd69b72f2 100644 --- a/source/blender/blenloader/intern/undofile.c +++ b/source/blender/blenloader/intern/undofile.c @@ -130,7 +130,7 @@ void memfile_chunk_add( struct Main *BLO_memfile_main_get(struct MemFile *memfile, struct Main *oldmain, struct Scene **r_scene) { struct Main *bmain_undo = NULL; - BlendFileData *bfd = BLO_read_from_memfile(oldmain, BKE_main_blendfile_path(oldmain), memfile, NULL, BLO_READ_SKIP_NONE); + BlendFileData *bfd = BLO_read_from_memfile(oldmain, BKE_main_blendfile_path(oldmain), memfile, BLO_READ_SKIP_NONE, NULL); if (bfd) { bmain_undo = bfd->main; diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index e1042f17229..a8069b01026 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -196,7 +196,7 @@ static Main *load_main_from_memory(const void *blend, int blend_size) BlendFileData *bfd; G.fileflags |= G_FILE_NO_UI; - bfd = BLO_read_from_memory(blend, blend_size, NULL, BLO_READ_SKIP_NONE); + bfd = BLO_read_from_memory(blend, blend_size, BLO_READ_SKIP_NONE, NULL); if (bfd) { bmain = bfd->main; diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index ef951010ba5..acb954a4b05 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -569,7 +569,10 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) /* confusing this global... */ G.relbase_valid = 1; - retval = BKE_blendfile_read(C, filepath, reports, 0); + retval = BKE_blendfile_read( + C, filepath, + &(const struct BlendFileReadParams){0}, + reports); /* BKE_file_read sets new Main into context. */ Main *bmain = CTX_data_main(C); @@ -804,7 +807,13 @@ int wm_homefile_read( if (!use_factory_settings || (filepath_startup[0] != '\0')) { if (BLI_access(filepath_startup, R_OK) == 0) { - success = (BKE_blendfile_read(C, filepath_startup, NULL, skip_flags) != BKE_BLENDFILE_READ_FAIL); + success = BKE_blendfile_read( + C, filepath_startup, + &(const struct BlendFileReadParams){ + .is_startup = true, + .skip_flags = skip_flags, + }, + NULL) != BKE_BLENDFILE_READ_FAIL; } if (BLI_listbase_is_empty(&U.themes)) { if (G.debug & G_DEBUG) @@ -820,8 +829,12 @@ int wm_homefile_read( if (success == false) { success = BKE_blendfile_read_from_memory( - C, datatoc_startup_blend, datatoc_startup_blend_size, - NULL, skip_flags, true); + C, datatoc_startup_blend, datatoc_startup_blend_size, true, + &(const struct BlendFileReadParams){ + .is_startup = true, + .skip_flags = skip_flags, + }, + NULL); if (success) { if (use_userdef) { if ((skip_flags & BLO_READ_SKIP_USERDEF) == 0) { diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 22616458b54..84cbf4bf85b 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -110,7 +110,8 @@ static BlendFileData *load_game_data(const char *filename) BlendFileData *bfd; BKE_reports_init(&reports, RPT_STORE); - bfd= BLO_read_from_file(filename, &reports, BLO_READ_SKIP_USERDEF); + bfd= BLO_read_from_file(filename, BLO_READ_SKIP_USERDEF, &reports); + if (!bfd) { printf("Loading %s failed: ", filename); diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index 42b603f8980..46b477a6da5 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -355,7 +355,7 @@ static BlendFileData *load_game_data(const char *progname, char *filename = NULL BLI_strncpy(bfd->main->name, progname, sizeof(bfd->main->name)); } } else { - bfd= BLO_read_from_file(progname, &reports, BLO_READ_SKIP_NONE); + bfd= BLO_read_from_file(progname, BLO_READ_SKIP_NONE, &reports); } if (!bfd && filename) { -- cgit v1.2.3