Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2016-02-21 17:22:48 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2016-03-31 11:06:21 +0300
commit9c420e5e481f00f42eeea42979c140afc8ee4acc (patch)
treeccf7f917c4e9fab0f6a3e4df237e6252c39f7318 /intern/cycles/bvh/bvh_build.cpp
parentffe59c54cb2aa8c45216f37943e7b4f0c4d9d540 (diff)
Cycles: Use stack storage for temporary data on leaf creation
Uses new StackAllocator from util_stack_allocator. Some tweaks to the stack storage size are possible, read notes in the code about this. At this point we might want to rename allocator files to util_allocator_foo.c, so the stay nicely grouped in the folder.
Diffstat (limited to 'intern/cycles/bvh/bvh_build.cpp')
-rw-r--r--intern/cycles/bvh/bvh_build.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/intern/cycles/bvh/bvh_build.cpp b/intern/cycles/bvh/bvh_build.cpp
index 84d036b22bf..ef58bb2357b 100644
--- a/intern/cycles/bvh/bvh_build.cpp
+++ b/intern/cycles/bvh/bvh_build.cpp
@@ -30,6 +30,7 @@
#include "util_foreach.h"
#include "util_logging.h"
#include "util_progress.h"
+#include "util_stack_allocator.h"
#include "util_time.h"
CCL_NAMESPACE_BEGIN
@@ -481,12 +482,26 @@ BVHNode *BVHBuild::create_primitive_leaf_node(const int *p_type,
BVHNode* BVHBuild::create_leaf_node(const BVHRange& range)
{
- /* TODO(sergey): Consider writing own allocator which would
- * not do heap allocation if number of elements is relatively small.
+ const int MAX_ITEMS_PER_LEAF = 16;
+
+ /* This is a bit overallocating here (considering leaf size into account),
+ * but chunk-based re-allocation in vector makes it difficult to use small
+ * size of stack storage here. Some tweaks are possible tho.
+ *
+ * NOTES:
+ * - If the size is too big, we'll have inefficient stack usage,
+ * and lots of cache misses.
+ * - If the size is too small, then we can run out of memory
+ * allowed to be used by vector.
+ * - Optimistic re-allocation in STL could jump us out of stack usage
+ * because re-allocation happens in chunks and size of those chunks we
+ * can not control.
*/
- vector<int> p_type[PRIMITIVE_NUM_TOTAL];
- vector<int> p_index[PRIMITIVE_NUM_TOTAL];
- vector<int> p_object[PRIMITIVE_NUM_TOTAL];
+ typedef StackAllocator<MAX_ITEMS_PER_LEAF * 8, int> LeafStackAllocator;
+
+ vector<int, LeafStackAllocator> p_type[PRIMITIVE_NUM_TOTAL];
+ vector<int, LeafStackAllocator> p_index[PRIMITIVE_NUM_TOTAL];
+ vector<int, LeafStackAllocator> p_object[PRIMITIVE_NUM_TOTAL];
uint visibility[PRIMITIVE_NUM_TOTAL] = {0};
/* NOTE: Keep initializtion in sync with actual number of primitives. */
BoundBox bounds[PRIMITIVE_NUM_TOTAL] = {BoundBox::empty,