Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/bvh/obvh_nodes.h
| Show First 20 Lines • Show All 222 Lines • ▼ Show 20 Lines | #ifdef __KERNEL_AVX2__ | ||||
| int mask = (int)movemask(vmask); | int mask = (int)movemask(vmask); | ||||
| *dist = tnear; | *dist = tnear; | ||||
| return mask; | return mask; | ||||
| #else | #else | ||||
| return 0; | return 0; | ||||
| #endif | #endif | ||||
| } | } | ||||
| ccl_device_inline int obvh_aligned_node_intersect_robust( | |||||
| KernelGlobals *ccl_restrict kg, | |||||
| const avxf& isect_near, | |||||
| const avxf& isect_far, | |||||
| #ifdef __KERNEL_AVX2__ | |||||
| const avx3f& P_idir, | |||||
| #else | |||||
| const avx3f& P, | |||||
| #endif | |||||
| const avx3f& idir, | |||||
| const int near_x, | |||||
| const int near_y, | |||||
| const int near_z, | |||||
| const int far_x, | |||||
| const int far_y, | |||||
| const int far_z, | |||||
| const int node_addr, | |||||
| const float difl, | |||||
| avxf *ccl_restrict dist) | |||||
| { | |||||
| const int offset = node_addr + 2; | |||||
| #ifdef __KERNEL_AVX2__ | |||||
| const avxf tnear_x = msub(kernel_tex_fetch_avxf(__bvh_nodes, offset + near_x * 2), idir.x, P_idir.x); | |||||
| const avxf tfar_x = msub(kernel_tex_fetch_avxf(__bvh_nodes, offset + far_x * 2), idir.x, P_idir.x); | |||||
| const avxf tnear_y = msub(kernel_tex_fetch_avxf(__bvh_nodes, offset + near_y * 2), idir.y, P_idir.y); | |||||
| const avxf tfar_y = msub(kernel_tex_fetch_avxf(__bvh_nodes, offset + far_y * 2), idir.y, P_idir.y); | |||||
| const avxf tnear_z = msub(kernel_tex_fetch_avxf(__bvh_nodes, offset + near_z * 2), idir.z, P_idir.z); | |||||
| const avxf tfar_z = msub(kernel_tex_fetch_avxf(__bvh_nodes, offset + far_z * 2), idir.z, P_idir.z); | |||||
| const float round_down = 1.0f - difl; | |||||
| const float round_up = 1.0f + difl; | |||||
| const avxf tnear = max4(tnear_x, tnear_y, tnear_z, isect_near); | |||||
| const avxf tfar = min4(tfar_x, tfar_y, tfar_z, isect_far); | |||||
| const avxb vmask = round_down*tnear <= round_up*tfar; | |||||
| int mask = (int)movemask(vmask); | |||||
| *dist = tnear; | |||||
| return mask; | |||||
| #else | |||||
| return 0; | |||||
| #endif | |||||
| } | |||||
| /* Unaligned nodes intersection */ | /* Unaligned nodes intersection */ | ||||
| ccl_device_inline int obvh_unaligned_node_intersect( | ccl_device_inline int obvh_unaligned_node_intersect( | ||||
| KernelGlobals *ccl_restrict kg, | KernelGlobals *ccl_restrict kg, | ||||
| const avxf& isect_near, | const avxf& isect_near, | ||||
| const avxf& isect_far, | const avxf& isect_far, | ||||
| #ifdef __KERNEL_AVX2__ | #ifdef __KERNEL_AVX2__ | ||||
| const avx3f& org_idir, | const avx3f& org_idir, | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | #endif | ||||
| const avxf tfar_z = max(tlower_z, tupper_z); | const avxf tfar_z = max(tlower_z, tupper_z); | ||||
| const avxf tnear = max4(isect_near, tnear_x, tnear_y, tnear_z); | const avxf tnear = max4(isect_near, tnear_x, tnear_y, tnear_z); | ||||
| const avxf tfar = min4(isect_far, tfar_x, tfar_y, tfar_z); | const avxf tfar = min4(isect_far, tfar_x, tfar_y, tfar_z); | ||||
| const avxb vmask = tnear <= tfar; | const avxb vmask = tnear <= tfar; | ||||
| *dist = tnear; | *dist = tnear; | ||||
| return movemask(vmask); | return movemask(vmask); | ||||
| } | } | ||||
| ccl_device_inline int obvh_unaligned_node_intersect_robust( | |||||
| KernelGlobals *ccl_restrict kg, | |||||
| const avxf& isect_near, | |||||
| const avxf& isect_far, | |||||
| #ifdef __KERNEL_AVX2__ | |||||
| const avx3f& P_idir, | |||||
| #endif | |||||
| const avx3f& P, | |||||
| const avx3f& dir, | |||||
| const avx3f& idir, | |||||
| const int near_x, | |||||
| const int near_y, | |||||
| const int near_z, | |||||
| const int far_x, | |||||
| const int far_y, | |||||
| const int far_z, | |||||
| const int node_addr, | |||||
| const float difl, | |||||
| avxf *ccl_restrict dist) | |||||
| { | |||||
| const int offset = node_addr; | |||||
| const avxf tfm_x_x = kernel_tex_fetch_avxf(__bvh_nodes, offset+2); | |||||
| const avxf tfm_x_y = kernel_tex_fetch_avxf(__bvh_nodes, offset+4); | |||||
| const avxf tfm_x_z = kernel_tex_fetch_avxf(__bvh_nodes, offset+6); | |||||
| const avxf tfm_y_x = kernel_tex_fetch_avxf(__bvh_nodes, offset+8); | |||||
| const avxf tfm_y_y = kernel_tex_fetch_avxf(__bvh_nodes, offset+10); | |||||
| const avxf tfm_y_z = kernel_tex_fetch_avxf(__bvh_nodes, offset+12); | |||||
| const avxf tfm_z_x = kernel_tex_fetch_avxf(__bvh_nodes, offset+14); | |||||
| const avxf tfm_z_y = kernel_tex_fetch_avxf(__bvh_nodes, offset+16); | |||||
| const avxf tfm_z_z = kernel_tex_fetch_avxf(__bvh_nodes, offset+18); | |||||
| const avxf tfm_t_x = kernel_tex_fetch_avxf(__bvh_nodes, offset+20); | |||||
| const avxf tfm_t_y = kernel_tex_fetch_avxf(__bvh_nodes, offset+22); | |||||
| const avxf tfm_t_z = kernel_tex_fetch_avxf(__bvh_nodes, offset+24); | |||||
| const avxf aligned_dir_x = dir.x*tfm_x_x + dir.y*tfm_x_y + dir.z*tfm_x_z, | |||||
| aligned_dir_y = dir.x*tfm_y_x + dir.y*tfm_y_y + dir.z*tfm_y_z, | |||||
| aligned_dir_z = dir.x*tfm_z_x + dir.y*tfm_z_y + dir.z*tfm_z_z; | |||||
| const avxf aligned_P_x = P.x*tfm_x_x + P.y*tfm_x_y + P.z*tfm_x_z + tfm_t_x, | |||||
| aligned_P_y = P.x*tfm_y_x + P.y*tfm_y_y + P.z*tfm_y_z + tfm_t_y, | |||||
| aligned_P_z = P.x*tfm_z_x + P.y*tfm_z_y + P.z*tfm_z_z + tfm_t_z; | |||||
| const avxf neg_one(-1.0f); | |||||
| const avxf nrdir_x = neg_one / aligned_dir_x, | |||||
| nrdir_y = neg_one / aligned_dir_y, | |||||
| nrdir_z = neg_one / aligned_dir_z; | |||||
| const avxf tlower_x = aligned_P_x * nrdir_x, | |||||
| tlower_y = aligned_P_y * nrdir_y, | |||||
| tlower_z = aligned_P_z * nrdir_z; | |||||
| const avxf tupper_x = tlower_x - nrdir_x, | |||||
| tupper_y = tlower_y - nrdir_y, | |||||
| tupper_z = tlower_z - nrdir_z; | |||||
| const float round_down = 1.0f - difl; | |||||
| const float round_up = 1.0f + difl; | |||||
| const avxf tnear_x = min(tlower_x, tupper_x); | |||||
| const avxf tnear_y = min(tlower_y, tupper_y); | |||||
| const avxf tnear_z = min(tlower_z, tupper_z); | |||||
| const avxf tfar_x = max(tlower_x, tupper_x); | |||||
| const avxf tfar_y = max(tlower_y, tupper_y); | |||||
| const avxf tfar_z = max(tlower_z, tupper_z); | |||||
| const avxf tnear = max4(isect_near, tnear_x, tnear_y, tnear_z); | |||||
| const avxf tfar = min4(isect_far, tfar_x, tfar_y, tfar_z); | |||||
| const avxb vmask = round_down*tnear <= round_up*tfar; | |||||
| *dist = tnear; | |||||
| return movemask(vmask); | |||||
| } | |||||
| /* Intersectors wrappers. | /* Intersectors wrappers. | ||||
| * | * | ||||
| * They'll check node type and call appropriate intersection code. | * They'll check node type and call appropriate intersection code. | ||||
| */ | */ | ||||
| ccl_device_inline int obvh_node_intersect( | ccl_device_inline int obvh_node_intersect( | ||||
| KernelGlobals *ccl_restrict kg, | KernelGlobals *ccl_restrict kg, | ||||
| const avxf& isect_near, | const avxf& isect_near, | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| #endif | #endif | ||||
| idir, | idir, | ||||
| near_x, near_y, near_z, | near_x, near_y, near_z, | ||||
| far_x, far_y, far_z, | far_x, far_y, far_z, | ||||
| node_addr, | node_addr, | ||||
| dist); | dist); | ||||
| } | } | ||||
| } | } | ||||
| ccl_device_inline int obvh_node_intersect_robust( | |||||
| KernelGlobals *ccl_restrict kg, | |||||
| const avxf& isect_near, | |||||
| const avxf& isect_far, | |||||
| #ifdef __KERNEL_AVX2__ | |||||
| const avx3f& P_idir, | |||||
| #endif | |||||
| const avx3f& P, | |||||
| const avx3f& dir, | |||||
| const avx3f& idir, | |||||
| const int near_x, | |||||
| const int near_y, | |||||
| const int near_z, | |||||
| const int far_x, | |||||
| const int far_y, | |||||
| const int far_z, | |||||
| const int node_addr, | |||||
| const float difl, | |||||
| avxf *ccl_restrict dist) | |||||
| { | |||||
| const int offset = node_addr; | |||||
| const float4 node = kernel_tex_fetch(__bvh_nodes, offset); | |||||
| if(__float_as_uint(node.x) & PATH_RAY_NODE_UNALIGNED) { | |||||
| return obvh_unaligned_node_intersect_robust(kg, | |||||
| isect_near, | |||||
| isect_far, | |||||
| #ifdef __KERNEL_AVX2__ | |||||
| P_idir, | |||||
| #endif | |||||
| P, | |||||
| dir, | |||||
| idir, | |||||
| near_x, near_y, near_z, | |||||
| far_x, far_y, far_z, | |||||
| node_addr, | |||||
| difl, | |||||
| dist); | |||||
| } | |||||
| else { | |||||
| return obvh_aligned_node_intersect_robust(kg, | |||||
| isect_near, | |||||
| isect_far, | |||||
| #ifdef __KERNEL_AVX2__ | |||||
| P_idir, | |||||
| #else | |||||
| P, | |||||
| #endif | |||||
| idir, | |||||
| near_x, near_y, near_z, | |||||
| far_x, far_y, far_z, | |||||
| node_addr, | |||||
| difl, | |||||
| dist); | |||||
| } | |||||
| } | |||||