[Bf-blender-cvs] [57d235d] master: Cycles: Optimize storage of QBVH node by one float4

Sergey Sharybin noreply at git.blender.org
Wed Dec 24 22:56:19 CET 2014


Commit: 57d235d9f496fd71f5b57cef36d34fae5bf9d9ce
Author: Sergey Sharybin
Date:   Tue Dec 23 00:58:19 2014 +0500
Branches: master
https://developer.blender.org/rB57d235d9f496fd71f5b57cef36d34fae5bf9d9ce

Cycles: Optimize storage of QBVH node by one float4

The idea is to store visibility flags for leaf nodes only since visibility check
for inner nodes costs too much for QBVH hence it is not optimal to perform.

Leaf QBVH nodes have plenty of space to store all sort of flags, so we can make
nodes one element smaller, saving noticeable amount of memory.

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

M	intern/cycles/bvh/bvh.cpp
M	intern/cycles/bvh/bvh.h

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

diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp
index 57bc6db..3f14c0d 100644
--- a/intern/cycles/bvh/bvh.cpp
+++ b/intern/cycles/bvh/bvh.cpp
@@ -754,6 +754,7 @@ void QBVH::pack_leaf(const BVHStackEntry& e, const LeafNode *leaf)
 		data[6].x = __int_as_float(leaf->m_lo);
 		data[6].y = __int_as_float(leaf->m_hi);
 	}
+	data[6].z = __uint_as_float(leaf->m_visibility);
 
 	memcpy(&pack.nodes[e.idx * BVH_QNODE_SIZE], data, sizeof(float4)*BVH_QNODE_SIZE);
 }
@@ -774,7 +775,6 @@ void QBVH::pack_inner(const BVHStackEntry& e, const BVHStackEntry *en, int num)
 		data[5][i] = bb_max.z;
 
 		data[6][i] = __int_as_float(en[i].encodeIdx());
-		data[7][i] = 0.0f;
 	}
 
 	for(int i = num; i < 4; i++) {
@@ -787,7 +787,6 @@ void QBVH::pack_inner(const BVHStackEntry& e, const BVHStackEntry *en, int num)
 		data[5][i] = 0.0f;
 
 		data[6][i] = __int_as_float(0);
-		data[7][i] = 0.0f;
 	}
 
 	memcpy(&pack.nodes[e.idx * BVH_QNODE_SIZE], data, sizeof(float4)*BVH_QNODE_SIZE);
@@ -959,7 +958,7 @@ void QBVH::refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility)
 		memset(leaf_data, 0, sizeof(leaf_data));
 		leaf_data[6].x = __int_as_float(c.x);
 		leaf_data[6].y = __int_as_float(c.y);
-		leaf_data[7] = make_float4(__uint_as_float(visibility));
+		leaf_data[6].z = __uint_as_float(visibility);
 		memcpy(&pack.nodes[idx * BVH_QNODE_SIZE],
 		       leaf_data,
 		       sizeof(float4)*BVH_QNODE_SIZE);
@@ -994,7 +993,6 @@ void QBVH::refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility)
 			inner_data[4][i] = bb_min.z;
 			inner_data[5][i] = bb_max.z;
 			inner_data[6][i] = __int_as_float(c[i]);
-			inner_data[7][i] = __uint_as_float(child_visibility[i]);
 		}
 		memcpy(&pack.nodes[idx * BVH_QNODE_SIZE],
 		       inner_data,
diff --git a/intern/cycles/bvh/bvh.h b/intern/cycles/bvh/bvh.h
index 58faacc..ef4575a 100644
--- a/intern/cycles/bvh/bvh.h
+++ b/intern/cycles/bvh/bvh.h
@@ -36,7 +36,7 @@ class Object;
 class Progress;
 
 #define BVH_NODE_SIZE	4
-#define BVH_QNODE_SIZE	8
+#define BVH_QNODE_SIZE	7
 #define BVH_ALIGN		4096
 #define TRI_NODE_SIZE	3




More information about the Bf-blender-cvs mailing list