diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-05 23:44:33 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-05 23:44:33 +0400 |
commit | 8103381ded923a097eae5a0ba012ae41847a83ad (patch) | |
tree | b2d224fac3262dea4eca154480f26bdd10662c81 /intern/cycles/bvh | |
parent | c53fe94bb4973362278b488ef26384a029d3cc69 (diff) |
Cycles: threading optimizations
* Multithreaded image loading, each thread can load a separate image.
* Better multithreading for multiple instanced meshes, different threads can now
build BVH's for different meshes, rather than all cooperating on the same mesh.
Especially noticeable for dynamic BVH building for the viewport, gave about
2x faster build on 8 core in fairly complex scene with many objects.
* The main thread waiting for worker threads can now also work itself, so
(num_cores + 1) threads will be working, this supposedly gives better
performance on some operating systems, but did not measure performance for
this very detailed yet.
Diffstat (limited to 'intern/cycles/bvh')
-rw-r--r-- | intern/cycles/bvh/bvh_build.cpp | 30 | ||||
-rw-r--r-- | intern/cycles/bvh/bvh_build.h | 5 |
2 files changed, 18 insertions, 17 deletions
diff --git a/intern/cycles/bvh/bvh_build.cpp b/intern/cycles/bvh/bvh_build.cpp index d865426304a..28237aea611 100644 --- a/intern/cycles/bvh/bvh_build.cpp +++ b/intern/cycles/bvh/bvh_build.cpp @@ -36,12 +36,12 @@ CCL_NAMESPACE_BEGIN class BVHBuildTask : public Task { public: - BVHBuildTask(InnerNode *node_, int child_, BVHObjectBinning& range_, int level_) - : node(node_), child(child_), level(level_), range(range_) {} + BVHBuildTask(BVHBuild *build, InnerNode *node, int child, BVHObjectBinning& range_, int level) + : range(range_) + { + run = function_bind(&BVHBuild::thread_build_node, build, node, child, &range, level); + } - InnerNode *node; - int child; - int level; BVHObjectBinning range; }; @@ -55,8 +55,7 @@ BVHBuild::BVHBuild(const vector<Object*>& objects_, prim_object(prim_object_), params(params_), progress(progress_), - progress_start_time(0.0), - task_pool(function_bind(&BVHBuild::thread_build_node, this, _1, _2)) + progress_start_time(0.0) { spatial_min_overlap = 0.0f; } @@ -177,7 +176,7 @@ BVHNode* BVHBuild::run() /* multithreaded binning build */ BVHObjectBinning rootbin(root, (references.size())? &references[0]: NULL); rootnode = build_node(rootbin, 0); - task_pool.wait(); + task_pool.wait_work(); } /* delete if we cancelled */ @@ -210,25 +209,24 @@ void BVHBuild::progress_update() progress_start_time = time_dt(); } -void BVHBuild::thread_build_node(Task *task_, int thread_id) +void BVHBuild::thread_build_node(InnerNode *inner, int child, BVHObjectBinning *range, int level) { if(progress.get_cancel()) return; /* build nodes */ - BVHBuildTask *task = (BVHBuildTask*)task_; - BVHNode *node = build_node(task->range, task->level); + BVHNode *node = build_node(*range, level); /* set child in inner node */ - task->node->children[task->child] = node; + inner->children[child] = node; /* update progress */ - if(task->range.size() < THREAD_TASK_SIZE) { + if(range->size() < THREAD_TASK_SIZE) { /*rotate(node, INT_MAX, 5);*/ thread_scoped_lock lock(build_mutex); - progress_count += task->range.size(); + progress_count += range->size(); progress_update(); } } @@ -262,8 +260,8 @@ BVHNode* BVHBuild::build_node(const BVHObjectBinning& range, int level) /* threaded build */ inner = new InnerNode(range.bounds()); - task_pool.push(new BVHBuildTask(inner, 0, left, level + 1), true); - task_pool.push(new BVHBuildTask(inner, 1, right, level + 1), true); + task_pool.push(new BVHBuildTask(this, inner, 0, left, level + 1), true); + task_pool.push(new BVHBuildTask(this, inner, 1, right, level + 1), true); } return inner; diff --git a/intern/cycles/bvh/bvh_build.h b/intern/cycles/bvh/bvh_build.h index 84e14632b4b..44ef918b326 100644 --- a/intern/cycles/bvh/bvh_build.h +++ b/intern/cycles/bvh/bvh_build.h @@ -29,7 +29,9 @@ CCL_NAMESPACE_BEGIN +class BVHBuildTask; class BVHParams; +class InnerNode; class Mesh; class Object; class Progress; @@ -54,6 +56,7 @@ protected: friend class BVHMixedSplit; friend class BVHObjectSplit; friend class BVHSpatialSplit; + friend class BVHBuildTask; /* adding references */ void add_reference_mesh(BoundBox& root, BoundBox& center, Mesh *mesh, int i); @@ -68,7 +71,7 @@ protected: /* threads */ enum { THREAD_TASK_SIZE = 4096 }; - void thread_build_node(Task *task_, int thread_id); + void thread_build_node(InnerNode *node, int child, BVHObjectBinning *range, int level); thread_mutex build_mutex; /* progress */ |