[Bf-blender-cvs] [71772f5] cycles_bvh: Cycles BVH: Lazily allocate aligned transform in BVH node

Sergey Sharybin noreply at git.blender.org
Wed Jul 6 13:55:46 CEST 2016


Commit: 71772f5ae7d38f22984531fd3aa99a86fab8e90e
Author: Sergey Sharybin
Date:   Wed Jul 6 13:54:57 2016 +0200
Branches: cycles_bvh
https://developer.blender.org/rB71772f5ae7d38f22984531fd3aa99a86fab8e90e

Cycles BVH: Lazily allocate aligned transform in BVH node

This is an attempt to save up memory for oriented nodes during BVH build.

Will likely introduce some slowdown to construct hair BVH, but that we can
optimize later by using specialized allocator.

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

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

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

diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp
index f127e26..e92526a 100644
--- a/intern/cycles/bvh/bvh.cpp
+++ b/intern/cycles/bvh/bvh.cpp
@@ -489,8 +489,8 @@ void RegularBVH::pack_unaligned_inner(const BVHStackEntry& e,
                                       const BVHStackEntry& e1)
 {
 	pack_unaligned_node(e.idx,
-	                    e0.node->m_aligned_space,
-	                    e1.node->m_aligned_space,
+	                    e0.node->get_aligned_space(),
+	                    e1.node->get_aligned_space(),
 	                    e0.node->m_bounds,
 	                    e1.node->m_bounds,
 	                    e0.encodeIdx(), e1.encodeIdx(),
@@ -849,7 +849,7 @@ void QBVH::pack_unaligned_inner(const BVHStackEntry& e,
 	for(int i = 0; i < num; i++) {
 		Transform space = BVHUnaligned::compute_node_transform(
 		        en[i].node->m_bounds,
-		        en[i].node->m_aligned_space);
+		        en[i].node->get_aligned_space());
 
 		data[1][i] = space.x.x;
 		data[2][i] = space.x.y;
diff --git a/intern/cycles/bvh/bvh_node.h b/intern/cycles/bvh/bvh_node.h
index 53f85f7..5c5d7ca 100644
--- a/intern/cycles/bvh/bvh_node.h
+++ b/intern/cycles/bvh/bvh_node.h
@@ -46,12 +46,16 @@ class BVHParams;
 class BVHNode
 {
 public:
-	BVHNode() : m_is_unaligned(false)
+	BVHNode() : m_is_unaligned(false),
+	            m_aligned_space(NULL)
 	{
-		m_aligned_space = transform_identity();
 	}
 
-	virtual ~BVHNode() {}
+	virtual ~BVHNode()
+	{
+		delete m_aligned_space;
+	}
+
 	virtual bool is_leaf() const = 0;
 	virtual int num_children() const = 0;
 	virtual BVHNode *get_child(int i) const = 0;
@@ -59,10 +63,18 @@ public:
 	virtual void print(int depth = 0) const = 0;
 	bool is_unaligned() const { return m_is_unaligned; }
 
-	void set_aligned_space(const Transform& aligned_space)
+	inline void set_aligned_space(const Transform& aligned_space)
 	{
 		m_is_unaligned = true;
-		m_aligned_space = aligned_space;
+		m_aligned_space = new Transform(aligned_space);
+	}
+
+	inline Transform get_aligned_space() const
+	{
+		if(m_aligned_space == NULL) {
+			return transform_identity();
+		}
+		return *m_aligned_space;
 	}
 
 	BoundBox m_bounds;
@@ -76,7 +88,7 @@ public:
 	uint update_visibility();
 
 	bool m_is_unaligned;
-	Transform m_aligned_space;
+	Transform *m_aligned_space;
 };
 
 class InnerNode : public BVHNode




More information about the Bf-blender-cvs mailing list