Cycles: Resolve ridiculous amount of memory used by spatial split builder

This was only visible on systems with lots of threads and root of the issue
was that we've been pre-allocating too much memory for all the threads.

Now we only pre-allocate data for the main thread and rest of the threads
does allocation on-demand.

This brings down memory usage from 36Gig to 6.9Gig when building spatial
split for the Bunny.blend file on our Intel beast.

Originally regression was happened by the threaded spacial split builder
commit.
This commit is contained in:
Sergey Sharybin
2016-04-13 14:22:53 +02:00
parent 9604db7650
commit bbcb9c68c9
2 changed files with 3 additions and 1 deletions

View File

@@ -280,8 +280,8 @@ BVHNode* BVHBuild::run()
size_t num_bins = max(root.size(), (int)BVHParams::NUM_SPATIAL_BINS) - 1; size_t num_bins = max(root.size(), (int)BVHParams::NUM_SPATIAL_BINS) - 1;
foreach(BVHSpatialStorage &storage, spatial_storage) { foreach(BVHSpatialStorage &storage, spatial_storage) {
storage.right_bounds.clear(); storage.right_bounds.clear();
storage.right_bounds.resize(num_bins);
} }
spatial_storage[0].right_bounds.resize(num_bins);
} }
spatial_free_index = 0; spatial_free_index = 0;

View File

@@ -54,6 +54,7 @@ BVHObjectSplit::BVHObjectSplit(BVHBuild *builder,
/* sweep right to left and determine bounds. */ /* sweep right to left and determine bounds. */
BoundBox right_bounds = BoundBox::empty; BoundBox right_bounds = BoundBox::empty;
storage_->right_bounds.resize(range.size());
for(int i = range.size() - 1; i > 0; i--) { for(int i = range.size() - 1; i > 0; i--) {
right_bounds.grow(ref_ptr[i].bounds()); right_bounds.grow(ref_ptr[i].bounds());
storage_->right_bounds[i - 1] = right_bounds; storage_->right_bounds[i - 1] = right_bounds;
@@ -160,6 +161,7 @@ BVHSpatialSplit::BVHSpatialSplit(const BVHBuild& builder,
/* sweep right to left and determine bounds. */ /* sweep right to left and determine bounds. */
BoundBox right_bounds = BoundBox::empty; BoundBox right_bounds = BoundBox::empty;
storage_->right_bounds.resize(BVHParams::NUM_SPATIAL_BINS);
for(int i = BVHParams::NUM_SPATIAL_BINS - 1; i > 0; i--) { for(int i = BVHParams::NUM_SPATIAL_BINS - 1; i > 0; i--) {
right_bounds.grow(storage_->bins[dim][i].bounds); right_bounds.grow(storage_->bins[dim][i].bounds);
storage_->right_bounds[i - 1] = right_bounds; storage_->right_bounds[i - 1] = right_bounds;