forked from bartvdbraak/blender
Cycles: Pass BVH builder by const reference to spatial splitters
This commit is contained in:
parent
d9b729e342
commit
e69a0ab5fc
@ -339,7 +339,7 @@ void BVHBuild::thread_build_node(InnerNode *inner, int child, BVHObjectBinning *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BVHBuild::range_within_max_leaf_size(const BVHRange& range)
|
bool BVHBuild::range_within_max_leaf_size(const BVHRange& range) const
|
||||||
{
|
{
|
||||||
size_t size = range.size();
|
size_t size = range.size();
|
||||||
size_t max_leaf_size = max(params.max_triangle_leaf_size, params.max_curve_leaf_size);
|
size_t max_leaf_size = max(params.max_triangle_leaf_size, params.max_curve_leaf_size);
|
||||||
@ -352,7 +352,7 @@ bool BVHBuild::range_within_max_leaf_size(const BVHRange& range)
|
|||||||
size_t num_motion_curves = 0;
|
size_t num_motion_curves = 0;
|
||||||
|
|
||||||
for(int i = 0; i < size; i++) {
|
for(int i = 0; i < size; i++) {
|
||||||
BVHReference& ref = references[range.start() + i];
|
const BVHReference& ref = references[range.start() + i];
|
||||||
|
|
||||||
if(ref.prim_type() & PRIMITIVE_CURVE)
|
if(ref.prim_type() & PRIMITIVE_CURVE)
|
||||||
num_curves++;
|
num_curves++;
|
||||||
@ -424,7 +424,7 @@ BVHNode* BVHBuild::build_node(const BVHRange& range, int level)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* splitting test */
|
/* splitting test */
|
||||||
BVHMixedSplit split(this, &spatial_storage[0], range, level);
|
BVHMixedSplit split(*this, &spatial_storage[0], range, level);
|
||||||
|
|
||||||
if(!(range.size() > 0 && params.top_level && level == 0)) {
|
if(!(range.size() > 0 && params.top_level && level == 0)) {
|
||||||
if(split.no_split) {
|
if(split.no_split) {
|
||||||
|
@ -78,7 +78,7 @@ protected:
|
|||||||
int start,
|
int start,
|
||||||
int nun);
|
int nun);
|
||||||
|
|
||||||
bool range_within_max_leaf_size(const BVHRange& range);
|
bool range_within_max_leaf_size(const BVHRange& range) const;
|
||||||
|
|
||||||
/* threads */
|
/* threads */
|
||||||
enum { THREAD_TASK_SIZE = 4096 };
|
enum { THREAD_TASK_SIZE = 4096 };
|
||||||
|
@ -28,7 +28,7 @@ CCL_NAMESPACE_BEGIN
|
|||||||
|
|
||||||
/* Object Split */
|
/* Object Split */
|
||||||
|
|
||||||
BVHObjectSplit::BVHObjectSplit(BVHBuild *builder,
|
BVHObjectSplit::BVHObjectSplit(const BVHBuild& builder,
|
||||||
BVHSpatialStorage *storage,
|
BVHSpatialStorage *storage,
|
||||||
const BVHRange& range,
|
const BVHRange& range,
|
||||||
float nodeSAH)
|
float nodeSAH)
|
||||||
@ -39,7 +39,7 @@ BVHObjectSplit::BVHObjectSplit(BVHBuild *builder,
|
|||||||
right_bounds(BoundBox::empty),
|
right_bounds(BoundBox::empty),
|
||||||
storage_(storage)
|
storage_(storage)
|
||||||
{
|
{
|
||||||
const BVHReference *ref_ptr = &builder->references[range.start()];
|
const BVHReference *ref_ptr = &builder.references[range.start()];
|
||||||
float min_sah = FLT_MAX;
|
float min_sah = FLT_MAX;
|
||||||
|
|
||||||
storage->spatial_indices.resize(range.size());
|
storage->spatial_indices.resize(range.size());
|
||||||
@ -52,7 +52,7 @@ BVHObjectSplit::BVHObjectSplit(BVHBuild *builder,
|
|||||||
*/
|
*/
|
||||||
bvh_reference_sort_indices(range.start(),
|
bvh_reference_sort_indices(range.start(),
|
||||||
range.end(),
|
range.end(),
|
||||||
&builder->references[0],
|
&builder.references[0],
|
||||||
indices,
|
indices,
|
||||||
dim);
|
dim);
|
||||||
|
|
||||||
@ -72,8 +72,8 @@ BVHObjectSplit::BVHObjectSplit(BVHBuild *builder,
|
|||||||
right_bounds = storage_->spatial_right_bounds[i - 1];
|
right_bounds = storage_->spatial_right_bounds[i - 1];
|
||||||
|
|
||||||
float sah = nodeSAH +
|
float sah = nodeSAH +
|
||||||
left_bounds.safe_area() * builder->params.primitive_cost(i) +
|
left_bounds.safe_area() * builder.params.primitive_cost(i) +
|
||||||
right_bounds.safe_area() * builder->params.primitive_cost(range.size() - i);
|
right_bounds.safe_area() * builder.params.primitive_cost(range.size() - i);
|
||||||
|
|
||||||
if(sah < min_sah) {
|
if(sah < min_sah) {
|
||||||
min_sah = sah;
|
min_sah = sah;
|
||||||
@ -101,7 +101,7 @@ void BVHObjectSplit::split(BVHBuild *builder, BVHRange& left, BVHRange& right, c
|
|||||||
|
|
||||||
/* Spatial Split */
|
/* Spatial Split */
|
||||||
|
|
||||||
BVHSpatialSplit::BVHSpatialSplit(BVHBuild *builder,
|
BVHSpatialSplit::BVHSpatialSplit(const BVHBuild& builder,
|
||||||
BVHSpatialStorage *storage,
|
BVHSpatialStorage *storage,
|
||||||
const BVHRange& range,
|
const BVHRange& range,
|
||||||
float nodeSAH)
|
float nodeSAH)
|
||||||
@ -127,7 +127,7 @@ BVHSpatialSplit::BVHSpatialSplit(BVHBuild *builder,
|
|||||||
|
|
||||||
/* chop references into bins. */
|
/* chop references into bins. */
|
||||||
for(unsigned int refIdx = range.start(); refIdx < range.end(); refIdx++) {
|
for(unsigned int refIdx = range.start(); refIdx < range.end(); refIdx++) {
|
||||||
const BVHReference& ref = builder->references[refIdx];
|
const BVHReference& ref = builder.references[refIdx];
|
||||||
float3 firstBinf = (ref.bounds().min - origin) * invBinSize;
|
float3 firstBinf = (ref.bounds().min - origin) * invBinSize;
|
||||||
float3 lastBinf = (ref.bounds().max - origin) * invBinSize;
|
float3 lastBinf = (ref.bounds().max - origin) * invBinSize;
|
||||||
int3 firstBin = make_int3((int)firstBinf.x, (int)firstBinf.y, (int)firstBinf.z);
|
int3 firstBin = make_int3((int)firstBinf.x, (int)firstBinf.y, (int)firstBinf.z);
|
||||||
@ -174,8 +174,8 @@ BVHSpatialSplit::BVHSpatialSplit(BVHBuild *builder,
|
|||||||
rightNum -= storage_->spatial_bins[dim][i - 1].exit;
|
rightNum -= storage_->spatial_bins[dim][i - 1].exit;
|
||||||
|
|
||||||
float sah = nodeSAH +
|
float sah = nodeSAH +
|
||||||
left_bounds.safe_area() * builder->params.primitive_cost(leftNum) +
|
left_bounds.safe_area() * builder.params.primitive_cost(leftNum) +
|
||||||
storage_->spatial_right_bounds[i - 1].safe_area() * builder->params.primitive_cost(rightNum);
|
storage_->spatial_right_bounds[i - 1].safe_area() * builder.params.primitive_cost(rightNum);
|
||||||
|
|
||||||
if(sah < this->sah) {
|
if(sah < this->sah) {
|
||||||
this->sah = sah;
|
this->sah = sah;
|
||||||
@ -225,7 +225,7 @@ void BVHSpatialSplit::split(BVHBuild *builder, BVHRange& left, BVHRange& right,
|
|||||||
while(left_end < right_start) {
|
while(left_end < right_start) {
|
||||||
/* split reference. */
|
/* split reference. */
|
||||||
BVHReference lref, rref;
|
BVHReference lref, rref;
|
||||||
split_reference(builder, lref, rref, refs[left_end], this->dim, this->pos);
|
split_reference(*builder, lref, rref, refs[left_end], this->dim, this->pos);
|
||||||
|
|
||||||
/* compute SAH for duplicate/unsplit candidates. */
|
/* compute SAH for duplicate/unsplit candidates. */
|
||||||
BoundBox lub = left_bounds; // Unsplit to left: new left-hand bounds.
|
BoundBox lub = left_bounds; // Unsplit to left: new left-hand bounds.
|
||||||
@ -425,7 +425,7 @@ void BVHSpatialSplit::split_object_reference(const Object *object,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BVHSpatialSplit::split_reference(BVHBuild *builder,
|
void BVHSpatialSplit::split_reference(const BVHBuild& builder,
|
||||||
BVHReference& left,
|
BVHReference& left,
|
||||||
BVHReference& right,
|
BVHReference& right,
|
||||||
const BVHReference& ref,
|
const BVHReference& ref,
|
||||||
@ -437,7 +437,7 @@ void BVHSpatialSplit::split_reference(BVHBuild *builder,
|
|||||||
BoundBox right_bounds = BoundBox::empty;
|
BoundBox right_bounds = BoundBox::empty;
|
||||||
|
|
||||||
/* loop over vertices/edges. */
|
/* loop over vertices/edges. */
|
||||||
Object *ob = builder->objects[ref.prim_object()];
|
const Object *ob = builder.objects[ref.prim_object()];
|
||||||
const Mesh *mesh = ob->mesh;
|
const Mesh *mesh = ob->mesh;
|
||||||
|
|
||||||
if(ref.prim_type() & PRIMITIVE_ALL_TRIANGLE) {
|
if(ref.prim_type() & PRIMITIVE_ALL_TRIANGLE) {
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
BoundBox right_bounds;
|
BoundBox right_bounds;
|
||||||
|
|
||||||
BVHObjectSplit() {}
|
BVHObjectSplit() {}
|
||||||
BVHObjectSplit(BVHBuild *builder,
|
BVHObjectSplit(const BVHBuild& builder,
|
||||||
BVHSpatialStorage *storage,
|
BVHSpatialStorage *storage,
|
||||||
const BVHRange& range,
|
const BVHRange& range,
|
||||||
float nodeSAH);
|
float nodeSAH);
|
||||||
@ -61,13 +61,13 @@ public:
|
|||||||
float pos;
|
float pos;
|
||||||
|
|
||||||
BVHSpatialSplit() : sah(FLT_MAX), dim(0), pos(0.0f) {}
|
BVHSpatialSplit() : sah(FLT_MAX), dim(0), pos(0.0f) {}
|
||||||
BVHSpatialSplit(BVHBuild *builder,
|
BVHSpatialSplit(const BVHBuild& builder,
|
||||||
BVHSpatialStorage *storage,
|
BVHSpatialStorage *storage,
|
||||||
const BVHRange& range,
|
const BVHRange& range,
|
||||||
float nodeSAH);
|
float nodeSAH);
|
||||||
|
|
||||||
void split(BVHBuild *builder, BVHRange& left, BVHRange& right, const BVHRange& range);
|
void split(BVHBuild *builder, BVHRange& left, BVHRange& right, const BVHRange& range);
|
||||||
void split_reference(BVHBuild *builder,
|
void split_reference(const BVHBuild& builder,
|
||||||
BVHReference& left,
|
BVHReference& left,
|
||||||
BVHReference& right,
|
BVHReference& right,
|
||||||
const BVHReference& ref,
|
const BVHReference& ref,
|
||||||
@ -137,7 +137,7 @@ public:
|
|||||||
|
|
||||||
bool no_split;
|
bool no_split;
|
||||||
|
|
||||||
__forceinline BVHMixedSplit(BVHBuild *builder,
|
__forceinline BVHMixedSplit(const BVHBuild& builder,
|
||||||
BVHSpatialStorage *storage,
|
BVHSpatialStorage *storage,
|
||||||
const BVHRange& range,
|
const BVHRange& range,
|
||||||
int level)
|
int level)
|
||||||
@ -145,22 +145,22 @@ public:
|
|||||||
/* find split candidates. */
|
/* find split candidates. */
|
||||||
float area = range.bounds().safe_area();
|
float area = range.bounds().safe_area();
|
||||||
|
|
||||||
leafSAH = area * builder->params.primitive_cost(range.size());
|
leafSAH = area * builder.params.primitive_cost(range.size());
|
||||||
nodeSAH = area * builder->params.node_cost(2);
|
nodeSAH = area * builder.params.node_cost(2);
|
||||||
|
|
||||||
object = BVHObjectSplit(builder, storage, range, nodeSAH);
|
object = BVHObjectSplit(builder, storage, range, nodeSAH);
|
||||||
|
|
||||||
if(builder->params.use_spatial_split && level < BVHParams::MAX_SPATIAL_DEPTH) {
|
if(builder.params.use_spatial_split && level < BVHParams::MAX_SPATIAL_DEPTH) {
|
||||||
BoundBox overlap = object.left_bounds;
|
BoundBox overlap = object.left_bounds;
|
||||||
overlap.intersect(object.right_bounds);
|
overlap.intersect(object.right_bounds);
|
||||||
|
|
||||||
if(overlap.safe_area() >= builder->spatial_min_overlap)
|
if(overlap.safe_area() >= builder.spatial_min_overlap)
|
||||||
spatial = BVHSpatialSplit(builder, storage, range, nodeSAH);
|
spatial = BVHSpatialSplit(builder, storage, range, nodeSAH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* leaf SAH is the lowest => create leaf. */
|
/* leaf SAH is the lowest => create leaf. */
|
||||||
minSAH = min(min(leafSAH, object.sah), spatial.sah);
|
minSAH = min(min(leafSAH, object.sah), spatial.sah);
|
||||||
no_split = (minSAH == leafSAH && builder->range_within_max_leaf_size(range));
|
no_split = (minSAH == leafSAH && builder.range_within_max_leaf_size(range));
|
||||||
}
|
}
|
||||||
|
|
||||||
__forceinline void split(BVHBuild *builder, BVHRange& left, BVHRange& right, const BVHRange& range)
|
__forceinline void split(BVHBuild *builder, BVHRange& left, BVHRange& right, const BVHRange& range)
|
||||||
|
Loading…
Reference in New Issue
Block a user