[Bf-blender-cvs] [1d90072] cycles_bvh: Cycles: Prepare some utility funcitons for regular BVH traversal

Sergey Sharybin noreply at git.blender.org
Wed Jun 15 17:56:17 CEST 2016


Commit: 1d90072315f15bbd5aaa3cd5ab383287e345949b
Author: Sergey Sharybin
Date:   Wed Jun 15 17:55:23 2016 +0200
Branches: cycles_bvh
https://developer.blender.org/rB1d90072315f15bbd5aaa3cd5ab383287e345949b

Cycles: Prepare some utility funcitons for regular BVH traversal

The idea is to use utility function for node intersection, just like
it's done in QBVH. Would make it easier to choose between aligned and
unaligned node intersection here.

===================================================================

M	intern/cycles/kernel/CMakeLists.txt
M	intern/cycles/kernel/geom/geom_bvh.h
D	intern/cycles/kernel/geom/geom_bvh_curve.h
A	intern/cycles/kernel/geom/geom_bvh_nodes.h

===================================================================

diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt
index fc0614e..188d774 100644
--- a/intern/cycles/kernel/CMakeLists.txt
+++ b/intern/cycles/kernel/CMakeLists.txt
@@ -138,7 +138,7 @@ set(SRC_GEOM_HEADERS
 	geom/geom.h
 	geom/geom_attribute.h
 	geom/geom_bvh.h
-	geom/geom_bvh_curve.h
+	geom/geom_bvh_nodes.h
 	geom/geom_bvh_shadow.h
 	geom/geom_bvh_subsurface.h
 	geom/geom_bvh_traversal.h
diff --git a/intern/cycles/kernel/geom/geom_bvh.h b/intern/cycles/kernel/geom/geom_bvh.h
index 5b2c4df..f8d563f 100644
--- a/intern/cycles/kernel/geom/geom_bvh.h
+++ b/intern/cycles/kernel/geom/geom_bvh.h
@@ -77,6 +77,8 @@ CCL_NAMESPACE_BEGIN
 
 /* Regular BVH traversal */
 
+#include "geom_bvh_nodes.h"
+
 #define BVH_FUNCTION_NAME bvh_intersect
 #define BVH_FUNCTION_FEATURES 0
 #include "geom_bvh_traversal.h"
diff --git a/intern/cycles/kernel/geom/geom_bvh_curve.h b/intern/cycles/kernel/geom/geom_bvh_curve.h
deleted file mode 100644
index 054aaed..0000000
--- a/intern/cycles/kernel/geom/geom_bvh_curve.h
+++ /dev/null
@@ -1,329 +0,0 @@
-/*
- * Copyright 2011-2016, Blender Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-ccl_device_inline Transform bvh_curve_fetch_aligned_space(KernelGlobals *kg,
-                                                          int nodeAddr,
-                                                          int child)
-{
-	Transform aligned_space;
-	if(child == 0) {
-		aligned_space.x = kernel_tex_fetch(__bvh_nodes, nodeAddr+0);
-		aligned_space.y = kernel_tex_fetch(__bvh_nodes, nodeAddr+1);
-		aligned_space.z = kernel_tex_fetch(__bvh_nodes, nodeAddr+2);
-		aligned_space.w = kernel_tex_fetch(__bvh_nodes, nodeAddr+3);
-	}
-	else {
-		aligned_space.x = kernel_tex_fetch(__bvh_nodes, nodeAddr+4);
-		aligned_space.y = kernel_tex_fetch(__bvh_nodes, nodeAddr+5);
-		aligned_space.z = kernel_tex_fetch(__bvh_nodes, nodeAddr+6);
-		aligned_space.w = kernel_tex_fetch(__bvh_nodes, nodeAddr+7);
-	}
-	return aligned_space;
-}
-
-#if !defined(__KERNEL_SSE2__)
-ccl_device_inline bool bvh_curve_intersect_unaligned_child(KernelGlobals *kg,
-                                                           const float3 P,
-                                                           const float3 dir,
-                                                           const float t,
-                                                           const float difl,
-                                                           int nodeAddr,
-                                                           int child,
-                                                           float *dist)
-{
-	Transform aligned_space  = bvh_curve_fetch_aligned_space(kg, nodeAddr, child);
-	float3 aligned_dir = transform_direction(&aligned_space, dir);
-	float3 aligned_P = transform_point(&aligned_space, P);
-	float3 nrdir = -1.0f * bvh_inverse_direction(aligned_dir);
-	/* TODO(sergey): Do we need NO_EXTENDED_PRECISION here as well? */
-	float3 tLowerXYZ = make_float3(aligned_P.x * nrdir.x,
-	                               aligned_P.y * nrdir.y,
-	                               aligned_P.z * nrdir.z);
-	float3 tUpperXYZ = tLowerXYZ - nrdir;
-	NO_EXTENDED_PRECISION const float tNearX = min(tLowerXYZ.x, tUpperXYZ.x);
-	NO_EXTENDED_PRECISION const float tNearY = min(tLowerXYZ.y, tUpperXYZ.y);
-	NO_EXTENDED_PRECISION const float tNearZ = min(tLowerXYZ.z, tUpperXYZ.z);
-	NO_EXTENDED_PRECISION const float tFarX  = max(tLowerXYZ.x, tUpperXYZ.x);
-	NO_EXTENDED_PRECISION const float tFarY  = max(tLowerXYZ.y, tUpperXYZ.y);
-	NO_EXTENDED_PRECISION const float tFarZ  = max(tLowerXYZ.z, tUpperXYZ.z);
-	NO_EXTENDED_PRECISION const float tNear  = max4(0.0f, tNearX, tNearY, tNearZ);
-	NO_EXTENDED_PRECISION const float tFar   = min4(t, tFarX, tFarY, tFarZ);
-	*dist = tNear;
-	if(difl != 0.0f) {
-		/* TODO(sergey): Same as for QBVH, needs a proper use. */
-		const float round_down = 1.0f - difl;
-		const float round_up = 1.0f + difl;
-		return round_down*tNear <= round_up*tFar;
-	}
-	else {
-		return tNear <= tFar;
-	}
-}
-
-ccl_device_inline int bvh_curve_intersect_aligned(KernelGlobals *kg,
-                                                  const float3 P,
-                                                  const float3 idir,
-                                                  const float t,
-                                                  const float difl,
-                                                  int nodeAddr,
-                                                  const uint visibility,
-                                                  float *dist)
-{
-
-	/* fetch node data */
-	float4 node0 = kernel_tex_fetch(__bvh_nodes, nodeAddr+0);
-	float4 node1 = kernel_tex_fetch(__bvh_nodes, nodeAddr+1);
-	float4 node2 = kernel_tex_fetch(__bvh_nodes, nodeAddr+2);
-	float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+8);
-
-	/* intersect ray against child nodes */
-	NO_EXTENDED_PRECISION float c0lox = (node0.x - P.x) * idir.x;
-	NO_EXTENDED_PRECISION float c0hix = (node0.z - P.x) * idir.x;
-	NO_EXTENDED_PRECISION float c0loy = (node1.x - P.y) * idir.y;
-	NO_EXTENDED_PRECISION float c0hiy = (node1.z - P.y) * idir.y;
-	NO_EXTENDED_PRECISION float c0loz = (node2.x - P.z) * idir.z;
-	NO_EXTENDED_PRECISION float c0hiz = (node2.z - P.z) * idir.z;
-	NO_EXTENDED_PRECISION float c0min = max4(min(c0lox, c0hix), min(c0loy, c0hiy), min(c0loz, c0hiz), 0.0f);
-	NO_EXTENDED_PRECISION float c0max = min4(max(c0lox, c0hix), max(c0loy, c0hiy), max(c0loz, c0hiz), t);
-
-	NO_EXTENDED_PRECISION float c1lox = (node0.y - P.x) * idir.x;
-	NO_EXTENDED_PRECISION float c1hix = (node0.w - P.x) * idir.x;
-	NO_EXTENDED_PRECISION float c1loy = (node1.y - P.y) * idir.y;
-	NO_EXTENDED_PRECISION float c1hiy = (node1.w - P.y) * idir.y;
-	NO_EXTENDED_PRECISION float c1loz = (node2.y - P.z) * idir.z;
-	NO_EXTENDED_PRECISION float c1hiz = (node2.w - P.z) * idir.z;
-	NO_EXTENDED_PRECISION float c1min = max4(min(c1lox, c1hix), min(c1loy, c1hiy), min(c1loz, c1hiz), 0.0f);
-	NO_EXTENDED_PRECISION float c1max = min4(max(c1lox, c1hix), max(c1loy, c1hiy), max(c1loz, c1hiz), t);
-
-	if(difl != 0.0f) {
-		float hdiff = 1.0f + difl;
-		float ldiff = 1.0f - difl;
-		if(__float_as_int(cnodes.z) & PATH_RAY_CURVE) {
-			c0min *= ldiff;
-			c0max *= hdiff;
-		}
-		if(__float_as_int(cnodes.w) & PATH_RAY_CURVE) {
-			c1min *= ldiff;
-			c1max *= hdiff;
-		}
-	}
-
-	dist[0] = c0min;
-	dist[1] = c1min;
-
-#ifdef __VISIBILITY_FLAG__
-	/* this visibility test gives a 5% performance hit, how to solve? */
-	return (((c0max >= c0min) && (__float_as_uint(cnodes.z) & visibility))? 1: 0) |
-	       (((c1max >= c1min) && (__float_as_uint(cnodes.w) & visibility))? 2: 0);
-#else
-	return ((c0max >= c0min)? 1: 0) |
-	       ((c1max >= c1min)? 2: 0);
-#endif
-}
-
-int ccl_device bvh_curve_intersect_node(KernelGlobals *kg,
-                                        const float3 P,
-                                        const float3 dir,
-                                        const float3 idir,
-                                        const float t,
-                                        const float difl,
-                                        const uint visibility,
-                                        int nodeAddr,
-                                        float dist[2])
-{
-	int mask = 0;
-	float4 node = kernel_tex_fetch(__bvh_nodes, nodeAddr+7);
-	if(node.w != 0.0f) {
-		float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+8);
-		if(bvh_curve_intersect_unaligned_child(kg, P, dir, t, difl, nodeAddr, 0, &dist[0])) {
-			if((__float_as_uint(cnodes.z) & visibility)) {
-				mask |= 1;
-			}
-		}
-		if(bvh_curve_intersect_unaligned_child(kg, P, dir, t, difl, nodeAddr, 1, &dist[1])) {
-			if((__float_as_uint(cnodes.w) & visibility)) {
-				mask |= 2;
-			}
-		}
-	}
-	else {
-		return bvh_curve_intersect_aligned(kg,
-		                                   P,
-		                                   idir,
-		                                   t,
-		                                   difl,
-		                                   nodeAddr,
-		                                   visibility,
-		                                   dist);
-	}
-	return mask;
-}
-#else  /* !defined(__KERNEL_SSE2__) */
-int ccl_device bvh_curve_intersect_node_unaligned(KernelGlobals *kg,
-                                                  const float3 P,
-                                                  const float3 dir,
-                                                  const ssef& tnear,
-                                                  const ssef& tfar,
-                                                  const float difl,
-                                                  const uint visibility,
-                                                  int nodeAddr,
-                                                  float dist[2])
-{
-	Transform aligned_space0 = bvh_curve_fetch_aligned_space(kg, nodeAddr, 0);
-	Transform aligned_space1 = bvh_curve_fetch_aligned_space(kg, nodeAddr, 1);
-
-	float3 aligned_dir0 = transform_direction(&aligned_space0, dir),
-	       aligned_dir1 = transform_direction(&aligned_space1, dir);;
-	float3 aligned_P0 = transform_point(&aligned_space0, P),
-	       aligned_P1 = transform_point(&aligned_space1, P);
-	float3 nrdir0 = -1.0f * bvh_inverse_direction(aligned_dir0),
-	       nrdir1 = -1.0f * bvh_inverse_direction(aligned_dir1);
-
-	ssef tLowerX = ssef(aligned_P0.x * nrdir0.x,
-	                    aligned_P1.x * nrdir1.x,
-	                    0.0f, 0.0f),
-	     tLowerY = ssef(aligned_P0.y * nrdir0.y,
-	                    aligned_P1.y * nrdir1.y,
-	                    0.0f,
-	                    0.0f),
-	     tLowerZ = ssef(aligned_P0.z * n

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list