Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/bvh/bvh_traversal.h
| Show All 20 Lines | |||||
| # include "kernel/bvh/qbvh_traversal.h" | # include "kernel/bvh/qbvh_traversal.h" | ||||
| #endif | #endif | ||||
| #ifdef __KERNEL_AVX2__ | #ifdef __KERNEL_AVX2__ | ||||
| # include "kernel/bvh/obvh_traversal.h" | # include "kernel/bvh/obvh_traversal.h" | ||||
| #endif | #endif | ||||
| #if BVH_FEATURE(BVH_HAIR) | #if BVH_FEATURE(BVH_HAIR) | ||||
| # define NODE_INTERSECT bvh_node_intersect | # define NODE_INTERSECT bvh_node_intersect | ||||
| # define NODE_INTERSECT_ROBUST bvh_node_intersect_robust | |||||
| #else | #else | ||||
| # define NODE_INTERSECT bvh_aligned_node_intersect | # define NODE_INTERSECT bvh_aligned_node_intersect | ||||
| # define NODE_INTERSECT_ROBUST bvh_aligned_node_intersect_robust | |||||
| #endif | #endif | ||||
| /* This is a template BVH traversal function, where various features can be | /* This is a template BVH traversal function, where various features can be | ||||
| * enabled/disabled. This way we can compile optimized versions for each case | * enabled/disabled. This way we can compile optimized versions for each case | ||||
| * without new features slowing things down. | * without new features slowing things down. | ||||
| * | * | ||||
| * BVH_INSTANCING: object instancing | * BVH_INSTANCING: object instancing | ||||
| * BVH_HAIR: hair curve rendering | * BVH_HAIR: hair curve rendering | ||||
| * BVH_HAIR_MINIMUM_WIDTH: hair curve rendering with minimum width | |||||
| * BVH_MOTION: motion blur rendering | * BVH_MOTION: motion blur rendering | ||||
| */ | */ | ||||
| ccl_device_noinline bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg, | ccl_device_noinline bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg, | ||||
| const Ray *ray, | const Ray *ray, | ||||
| Intersection *isect, | Intersection *isect, | ||||
| const uint visibility | const uint visibility) | ||||
| #if BVH_FEATURE(BVH_HAIR_MINIMUM_WIDTH) | |||||
| , uint *lcg_state, | |||||
| float difl, | |||||
| float extmax | |||||
| #endif | |||||
| ) | |||||
| { | { | ||||
| /* todo: | /* todo: | ||||
| * - test if pushing distance on the stack helps (for non shadow rays) | * - test if pushing distance on the stack helps (for non shadow rays) | ||||
| * - separate version for shadow rays | * - separate version for shadow rays | ||||
| * - likely and unlikely for if() statements | * - likely and unlikely for if() statements | ||||
| * - test restrict attribute for pointers | * - test restrict attribute for pointers | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | do { | ||||
| do { | do { | ||||
| /* traverse internal nodes */ | /* traverse internal nodes */ | ||||
| while(node_addr >= 0 && node_addr != ENTRYPOINT_SENTINEL) { | while(node_addr >= 0 && node_addr != ENTRYPOINT_SENTINEL) { | ||||
| int node_addr_child1, traverse_mask; | int node_addr_child1, traverse_mask; | ||||
| float dist[2]; | float dist[2]; | ||||
| float4 cnodes = kernel_tex_fetch(__bvh_nodes, node_addr+0); | float4 cnodes = kernel_tex_fetch(__bvh_nodes, node_addr+0); | ||||
| #if !defined(__KERNEL_SSE2__) | #if !defined(__KERNEL_SSE2__) | ||||
| # if BVH_FEATURE(BVH_HAIR_MINIMUM_WIDTH) | |||||
| if(difl != 0.0f) { | |||||
| traverse_mask = NODE_INTERSECT_ROBUST(kg, | |||||
| P, | |||||
| # if BVH_FEATURE(BVH_HAIR) | |||||
| dir, | |||||
| # endif | |||||
| idir, | |||||
| isect->t, | |||||
| difl, | |||||
| extmax, | |||||
| node_addr, | |||||
| visibility, | |||||
| dist); | |||||
| } | |||||
| else | |||||
| # endif | |||||
| { | { | ||||
| traverse_mask = NODE_INTERSECT(kg, | traverse_mask = NODE_INTERSECT(kg, | ||||
| P, | P, | ||||
| # if BVH_FEATURE(BVH_HAIR) | # if BVH_FEATURE(BVH_HAIR) | ||||
| dir, | dir, | ||||
| # endif | # endif | ||||
| idir, | idir, | ||||
| isect->t, | isect->t, | ||||
| node_addr, | node_addr, | ||||
| visibility, | visibility, | ||||
| dist); | dist); | ||||
| } | } | ||||
| #else // __KERNEL_SSE2__ | #else // __KERNEL_SSE2__ | ||||
| # if BVH_FEATURE(BVH_HAIR_MINIMUM_WIDTH) | |||||
| if(difl != 0.0f) { | |||||
| traverse_mask = NODE_INTERSECT_ROBUST(kg, | |||||
| P, | |||||
| dir, | |||||
| # if BVH_FEATURE(BVH_HAIR) | |||||
| tnear, | |||||
| tfar, | |||||
| # endif | |||||
| tsplat, | |||||
| Psplat, | |||||
| idirsplat, | |||||
| shufflexyz, | |||||
| difl, | |||||
| extmax, | |||||
| node_addr, | |||||
| visibility, | |||||
| dist); | |||||
| } | |||||
| else | |||||
| # endif | |||||
| { | { | ||||
| traverse_mask = NODE_INTERSECT(kg, | traverse_mask = NODE_INTERSECT(kg, | ||||
| P, | P, | ||||
| dir, | dir, | ||||
| # if BVH_FEATURE(BVH_HAIR) | # if BVH_FEATURE(BVH_HAIR) | ||||
| tnear, | tnear, | ||||
| tfar, | tfar, | ||||
| # endif | # endif | ||||
| ▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | #if BVH_FEATURE(BVH_HAIR) | ||||
| hit = cardinal_curve_intersect(kg, | hit = cardinal_curve_intersect(kg, | ||||
| isect, | isect, | ||||
| P, | P, | ||||
| dir, | dir, | ||||
| visibility, | visibility, | ||||
| object, | object, | ||||
| prim_addr, | prim_addr, | ||||
| ray->time, | ray->time, | ||||
| curve_type, | curve_type); | ||||
| lcg_state, | |||||
| difl, | |||||
| extmax); | |||||
| } | } | ||||
| else { | else { | ||||
| hit = curve_intersect(kg, | hit = curve_intersect(kg, | ||||
| isect, | isect, | ||||
| P, | P, | ||||
| dir, | dir, | ||||
| visibility, | visibility, | ||||
| object, | object, | ||||
| prim_addr, | prim_addr, | ||||
| ray->time, | ray->time, | ||||
| curve_type, | curve_type); | ||||
| lcg_state, | |||||
| difl, | |||||
| extmax); | |||||
| } | } | ||||
| if(hit) { | if(hit) { | ||||
| /* shadow ray early termination */ | /* shadow ray early termination */ | ||||
| # if defined(__KERNEL_SSE2__) | # if defined(__KERNEL_SSE2__) | ||||
| if(visibility & PATH_RAY_SHADOW_OPAQUE) | if(visibility & PATH_RAY_SHADOW_OPAQUE) | ||||
| return true; | return true; | ||||
| tsplat = ssef(0.0f, 0.0f, -isect->t, -isect->t); | tsplat = ssef(0.0f, 0.0f, -isect->t, -isect->t); | ||||
| # if BVH_FEATURE(BVH_HAIR) | # if BVH_FEATURE(BVH_HAIR) | ||||
| ▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | #endif /* FEATURE(BVH_INSTANCING) */ | ||||
| } while(node_addr != ENTRYPOINT_SENTINEL); | } while(node_addr != ENTRYPOINT_SENTINEL); | ||||
| return (isect->prim != PRIM_NONE); | return (isect->prim != PRIM_NONE); | ||||
| } | } | ||||
| ccl_device_inline bool BVH_FUNCTION_NAME(KernelGlobals *kg, | ccl_device_inline bool BVH_FUNCTION_NAME(KernelGlobals *kg, | ||||
| const Ray *ray, | const Ray *ray, | ||||
| Intersection *isect, | Intersection *isect, | ||||
| const uint visibility | const uint visibility) | ||||
| #if BVH_FEATURE(BVH_HAIR_MINIMUM_WIDTH) | |||||
| , uint *lcg_state, | |||||
| float difl, | |||||
| float extmax | |||||
| #endif | |||||
| ) | |||||
| { | { | ||||
| switch(kernel_data.bvh.bvh_layout) { | switch(kernel_data.bvh.bvh_layout) { | ||||
| #ifdef __KERNEL_AVX2__ | #ifdef __KERNEL_AVX2__ | ||||
| case BVH_LAYOUT_BVH8: | case BVH_LAYOUT_BVH8: | ||||
| return BVH_FUNCTION_FULL_NAME(OBVH)(kg, | return BVH_FUNCTION_FULL_NAME(OBVH)(kg, | ||||
| ray, | ray, | ||||
| isect, | isect, | ||||
| visibility | visibility); | ||||
| # if BVH_FEATURE(BVH_HAIR_MINIMUM_WIDTH) | |||||
| , lcg_state, | |||||
| difl, | |||||
| extmax | |||||
| # endif | |||||
| ); | |||||
| #endif | #endif | ||||
| #ifdef __QBVH__ | #ifdef __QBVH__ | ||||
| case BVH_LAYOUT_BVH4: | case BVH_LAYOUT_BVH4: | ||||
| return BVH_FUNCTION_FULL_NAME(QBVH)(kg, | return BVH_FUNCTION_FULL_NAME(QBVH)(kg, | ||||
| ray, | ray, | ||||
| isect, | isect, | ||||
| visibility | visibility); | ||||
| # if BVH_FEATURE(BVH_HAIR_MINIMUM_WIDTH) | |||||
| , lcg_state, | |||||
| difl, | |||||
| extmax | |||||
| # endif | |||||
| ); | |||||
| #endif /* __QBVH__ */ | #endif /* __QBVH__ */ | ||||
| case BVH_LAYOUT_BVH2: | case BVH_LAYOUT_BVH2: | ||||
| return BVH_FUNCTION_FULL_NAME(BVH)(kg, | return BVH_FUNCTION_FULL_NAME(BVH)(kg, | ||||
| ray, | ray, | ||||
| isect, | isect, | ||||
| visibility | visibility); | ||||
| #if BVH_FEATURE(BVH_HAIR_MINIMUM_WIDTH) | |||||
| , lcg_state, | |||||
| difl, | |||||
| extmax | |||||
| #endif | |||||
| ); | |||||
| } | } | ||||
| kernel_assert(!"Should not happen"); | kernel_assert(!"Should not happen"); | ||||
| return false; | return false; | ||||
| } | } | ||||
| #undef BVH_FUNCTION_NAME | #undef BVH_FUNCTION_NAME | ||||
| #undef BVH_FUNCTION_FEATURES | #undef BVH_FUNCTION_FEATURES | ||||
| #undef NODE_INTERSECT | #undef NODE_INTERSECT | ||||
| #undef NODE_INTERSECT_ROBUST | |||||