From 57d235d9f496fd71f5b57cef36d34fae5bf9d9ce Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 23 Dec 2014 00:58:19 +0500 Subject: 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. --- intern/cycles/bvh/bvh.cpp | 6 ++---- intern/cycles/bvh/bvh.h | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'intern') diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp index 57bc6db1d72..3f14c0d15c4 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 58faaccee7d..ef4575ad7ee 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 -- cgit v1.2.3