2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-08-11 00:33:51 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-08-11 00:33:51 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2009 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): André Pinto.
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
|
2011-02-27 19:31:27 +00:00
|
|
|
/** \file blender/render/intern/raytrace/svbvh.h
|
|
|
|
|
* \ingroup render
|
|
|
|
|
*/
|
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#ifndef __SVBVH_H__
|
|
|
|
|
#define __SVBVH_H__
|
2009-08-11 00:33:51 +00:00
|
|
|
|
2012-10-09 13:36:42 +00:00
|
|
|
#ifdef __SSE__
|
|
|
|
|
|
2009-08-11 00:33:51 +00:00
|
|
|
#include "bvh.h"
|
2009-08-29 17:24:45 +00:00
|
|
|
#include "BLI_memarena.h"
|
|
|
|
|
#include <algorithm>
|
2009-08-11 00:33:51 +00:00
|
|
|
|
2012-05-15 18:45:20 +00:00
|
|
|
struct SVBVHNode {
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
float child_bb[24];
|
|
|
|
|
SVBVHNode *child[4];
|
2009-08-11 00:33:51 +00:00
|
|
|
int nchilds;
|
|
|
|
|
};
|
|
|
|
|
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
static int svbvh_bb_intersect_test_simd4(const Isect *isec, const __m128 *bb_group)
|
|
|
|
|
{
|
|
|
|
|
const __m128 tmin0 = _mm_setzero_ps();
|
|
|
|
|
const __m128 tmax0 = _mm_set_ps1(isec->dist);
|
|
|
|
|
|
|
|
|
|
const __m128 start0 = _mm_set_ps1(isec->start[0]);
|
|
|
|
|
const __m128 start1 = _mm_set_ps1(isec->start[1]);
|
|
|
|
|
const __m128 start2 = _mm_set_ps1(isec->start[2]);
|
|
|
|
|
const __m128 sub0 = _mm_sub_ps(bb_group[isec->bv_index[0]], start0);
|
|
|
|
|
const __m128 sub1 = _mm_sub_ps(bb_group[isec->bv_index[1]], start0);
|
|
|
|
|
const __m128 sub2 = _mm_sub_ps(bb_group[isec->bv_index[2]], start1);
|
|
|
|
|
const __m128 sub3 = _mm_sub_ps(bb_group[isec->bv_index[3]], start1);
|
|
|
|
|
const __m128 sub4 = _mm_sub_ps(bb_group[isec->bv_index[4]], start2);
|
|
|
|
|
const __m128 sub5 = _mm_sub_ps(bb_group[isec->bv_index[5]], start2);
|
|
|
|
|
const __m128 idot_axis0 = _mm_set_ps1(isec->idot_axis[0]);
|
|
|
|
|
const __m128 idot_axis1 = _mm_set_ps1(isec->idot_axis[1]);
|
|
|
|
|
const __m128 idot_axis2 = _mm_set_ps1(isec->idot_axis[2]);
|
|
|
|
|
const __m128 mul0 = _mm_mul_ps(sub0, idot_axis0);
|
|
|
|
|
const __m128 mul1 = _mm_mul_ps(sub1, idot_axis0);
|
|
|
|
|
const __m128 mul2 = _mm_mul_ps(sub2, idot_axis1);
|
|
|
|
|
const __m128 mul3 = _mm_mul_ps(sub3, idot_axis1);
|
|
|
|
|
const __m128 mul4 = _mm_mul_ps(sub4, idot_axis2);
|
|
|
|
|
const __m128 mul5 = _mm_mul_ps(sub5, idot_axis2);
|
|
|
|
|
const __m128 tmin1 = _mm_max_ps(tmin0, mul0);
|
|
|
|
|
const __m128 tmax1 = _mm_min_ps(tmax0, mul1);
|
|
|
|
|
const __m128 tmin2 = _mm_max_ps(tmin1, mul2);
|
|
|
|
|
const __m128 tmax2 = _mm_min_ps(tmax1, mul3);
|
|
|
|
|
const __m128 tmin3 = _mm_max_ps(tmin2, mul4);
|
|
|
|
|
const __m128 tmax3 = _mm_min_ps(tmax2, mul5);
|
|
|
|
|
|
|
|
|
|
return _mm_movemask_ps(_mm_cmpge_ps(tmax3, tmin3));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int svbvh_bb_intersect_test(const Isect *isec, const float *_bb)
|
2009-08-11 00:33:51 +00:00
|
|
|
{
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
const float *bb = _bb;
|
|
|
|
|
|
|
|
|
|
float t1x = (bb[isec->bv_index[0]] - isec->start[0]) * isec->idot_axis[0];
|
|
|
|
|
float t2x = (bb[isec->bv_index[1]] - isec->start[0]) * isec->idot_axis[0];
|
|
|
|
|
float t1y = (bb[isec->bv_index[2]] - isec->start[1]) * isec->idot_axis[1];
|
|
|
|
|
float t2y = (bb[isec->bv_index[3]] - isec->start[1]) * isec->idot_axis[1];
|
|
|
|
|
float t1z = (bb[isec->bv_index[4]] - isec->start[2]) * isec->idot_axis[2];
|
|
|
|
|
float t2z = (bb[isec->bv_index[5]] - isec->start[2]) * isec->idot_axis[2];
|
|
|
|
|
|
|
|
|
|
RE_RC_COUNT(isec->raycounter->bb.test);
|
|
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
if (t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0;
|
2012-11-04 10:20:16 +00:00
|
|
|
if (t2x < 0.0f || t2y < 0.0f || t2z < 0.0f) return 0;
|
2012-04-28 06:31:57 +00:00
|
|
|
if (t1x > isec->dist || t1y > isec->dist || t1z > isec->dist) return 0;
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
|
2012-10-21 05:46:41 +00:00
|
|
|
RE_RC_COUNT(isec->raycounter->bb.hit);
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
|
2009-08-11 00:33:51 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
static bool svbvh_node_is_leaf(const SVBVHNode *node)
|
2009-08-11 00:33:51 +00:00
|
|
|
{
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
return !RE_rayobject_isAligned(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<int MAX_STACK_SIZE, bool SHADOW>
|
|
|
|
|
static int svbvh_node_stack_raycast(SVBVHNode *root, Isect *isec)
|
|
|
|
|
{
|
|
|
|
|
SVBVHNode *stack[MAX_STACK_SIZE], *node;
|
|
|
|
|
int hit = 0, stack_pos = 0;
|
|
|
|
|
|
|
|
|
|
stack[stack_pos++] = root;
|
|
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
while (stack_pos) {
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
node = stack[--stack_pos];
|
|
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
if (!svbvh_node_is_leaf(node)) {
|
2012-05-15 18:45:20 +00:00
|
|
|
int nchilds = node->nchilds;
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
if (nchilds == 4) {
|
2012-05-15 18:45:20 +00:00
|
|
|
float *child_bb = node->child_bb;
|
|
|
|
|
int res = svbvh_bb_intersect_test_simd4(isec, ((__m128 *) (child_bb)));
|
|
|
|
|
SVBVHNode **child = node->child;
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
|
|
|
|
|
RE_RC_COUNT(isec->raycounter->simd_bb.test);
|
|
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
if (res & 1) { stack[stack_pos++] = child[0]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); }
|
|
|
|
|
if (res & 2) { stack[stack_pos++] = child[1]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); }
|
|
|
|
|
if (res & 4) { stack[stack_pos++] = child[2]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); }
|
|
|
|
|
if (res & 8) { stack[stack_pos++] = child[3]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); }
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-15 18:45:20 +00:00
|
|
|
float *child_bb = node->child_bb;
|
|
|
|
|
SVBVHNode **child = node->child;
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
int i;
|
|
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
for (i = 0; i < nchilds; i++) {
|
|
|
|
|
if (svbvh_bb_intersect_test(isec, (float *)child_bb + 6 * i)) {
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
stack[stack_pos++] = child[i];
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
|
|
|
|
}
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-04-28 06:31:57 +00:00
|
|
|
else {
|
2012-05-15 18:45:20 +00:00
|
|
|
hit |= RE_rayobject_intersect((RayObject *)node, isec);
|
2012-04-28 06:31:57 +00:00
|
|
|
if (SHADOW && hit) break;
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
}
|
2009-08-11 00:33:51 +00:00
|
|
|
}
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
|
|
|
|
|
return hit;
|
2009-08-11 00:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
|
2009-08-11 17:28:58 +00:00
|
|
|
template<>
|
2012-05-12 22:34:20 +00:00
|
|
|
inline void bvh_node_merge_bb<SVBVHNode>(SVBVHNode *node, float min[3], float max[3])
|
2009-08-11 17:28:58 +00:00
|
|
|
{
|
2012-04-28 06:31:57 +00:00
|
|
|
if (is_leaf(node)) {
|
2012-05-15 18:45:20 +00:00
|
|
|
RE_rayobject_merge_bb((RayObject *)node, min, max);
|
2009-08-11 17:28:58 +00:00
|
|
|
}
|
2012-04-28 06:31:57 +00:00
|
|
|
else {
|
2012-05-12 22:34:20 +00:00
|
|
|
int i;
|
|
|
|
|
for (i = 0; i + 4 <= node->nchilds; i += 4) {
|
|
|
|
|
float *res = node->child_bb + 6 * i;
|
2012-04-28 06:31:57 +00:00
|
|
|
for (int j = 0; j < 3; j++) {
|
2013-12-12 15:29:17 +11:00
|
|
|
min[j] = min_ff(min[j],
|
|
|
|
|
min_ffff(res[4 * j + 0],
|
|
|
|
|
res[4 * j + 1],
|
|
|
|
|
res[4 * j + 2],
|
|
|
|
|
res[4 * j + 3]));
|
2009-08-11 17:28:58 +00:00
|
|
|
}
|
2012-04-28 06:31:57 +00:00
|
|
|
for (int j = 0; j < 3; j++) {
|
2013-12-12 15:29:17 +11:00
|
|
|
max[j] = max_ff(max[j],
|
2014-02-14 07:44:53 +09:00
|
|
|
max_ffff(res[4 * (j + 3) + 0],
|
|
|
|
|
res[4 * (j + 3) + 1],
|
|
|
|
|
res[4 * (j + 3) + 2],
|
|
|
|
|
res[4 * (j + 3) + 3]));
|
2009-08-11 17:28:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-15 18:45:20 +00:00
|
|
|
for (; i < node->nchilds; i++) {
|
2012-04-28 06:31:57 +00:00
|
|
|
DO_MIN(node->child_bb + 6 * i, min);
|
|
|
|
|
DO_MAX(node->child_bb + 3 + 6 * i, max);
|
2009-08-11 17:28:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-11 00:33:51 +00:00
|
|
|
|
|
|
|
|
|
2009-08-29 17:24:45 +00:00
|
|
|
/*
|
|
|
|
|
* Builds a SVBVH tree form a VBVHTree
|
|
|
|
|
*/
|
|
|
|
|
template<class OldNode>
|
2012-05-15 18:45:20 +00:00
|
|
|
struct Reorganize_SVBVH {
|
2009-08-29 17:24:45 +00:00
|
|
|
MemArena *arena;
|
2009-08-11 00:33:51 +00:00
|
|
|
|
|
|
|
|
float childs_per_node;
|
|
|
|
|
int nodes_with_childs[16];
|
2009-08-13 20:35:53 +00:00
|
|
|
int useless_bb;
|
2009-08-11 00:33:51 +00:00
|
|
|
int nodes;
|
|
|
|
|
|
2009-08-29 17:24:45 +00:00
|
|
|
Reorganize_SVBVH(MemArena *a)
|
2009-08-11 00:33:51 +00:00
|
|
|
{
|
2009-08-29 17:24:45 +00:00
|
|
|
arena = a;
|
2009-08-11 00:33:51 +00:00
|
|
|
nodes = 0;
|
|
|
|
|
childs_per_node = 0;
|
2009-08-13 20:35:53 +00:00
|
|
|
useless_bb = 0;
|
2009-08-11 00:33:51 +00:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
for (int i = 0; i < 16; i++) {
|
2009-08-11 00:33:51 +00:00
|
|
|
nodes_with_childs[i] = 0;
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
2009-08-11 00:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~Reorganize_SVBVH()
|
|
|
|
|
{
|
2014-03-01 21:47:46 +11:00
|
|
|
#if 0
|
2013-12-12 15:29:17 +11:00
|
|
|
{
|
2010-01-12 19:45:01 +00:00
|
|
|
printf("%f childs per node\n", childs_per_node / nodes);
|
|
|
|
|
printf("%d childs BB are useless\n", useless_bb);
|
2012-04-28 06:31:57 +00:00
|
|
|
for (int i = 0; i < 16; i++) {
|
2012-05-15 18:45:20 +00:00
|
|
|
printf("%i childs per node: %d/%d = %f\n", i, nodes_with_childs[i], nodes, nodes_with_childs[i] / float(nodes));
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
2010-01-12 19:45:01 +00:00
|
|
|
}
|
2013-12-12 15:29:17 +11:00
|
|
|
#endif
|
2009-08-11 00:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SVBVHNode *create_node(int nchilds)
|
|
|
|
|
{
|
2012-05-15 18:45:20 +00:00
|
|
|
SVBVHNode *node = (SVBVHNode *)BLI_memarena_alloc(arena, sizeof(SVBVHNode));
|
2009-08-11 00:33:51 +00:00
|
|
|
node->nchilds = nchilds;
|
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-14 13:18:32 +00:00
|
|
|
void copy_bb(float bb[6], const float old_bb[6])
|
2009-08-11 00:33:51 +00:00
|
|
|
{
|
2012-05-15 18:45:20 +00:00
|
|
|
std::copy(old_bb, old_bb + 6, bb);
|
2009-08-11 00:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void prepare_for_simd(SVBVHNode *node)
|
|
|
|
|
{
|
2012-05-15 18:45:20 +00:00
|
|
|
int i = 0;
|
2012-04-28 06:31:57 +00:00
|
|
|
while (i + 4 <= node->nchilds) {
|
2012-05-15 18:45:20 +00:00
|
|
|
float vec_tmp[4 * 6];
|
|
|
|
|
float *res = node->child_bb + 6 * i;
|
|
|
|
|
std::copy(res, res + 6 * 4, vec_tmp);
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < 6; j++) {
|
|
|
|
|
res[4 * j + 0] = vec_tmp[6 * 0 + j];
|
|
|
|
|
res[4 * j + 1] = vec_tmp[6 * 1 + j];
|
|
|
|
|
res[4 * j + 2] = vec_tmp[6 * 2 + j];
|
|
|
|
|
res[4 * j + 3] = vec_tmp[6 * 3 + j];
|
2009-08-11 00:33:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i += 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-13 20:35:53 +00:00
|
|
|
/* amt must be power of two */
|
|
|
|
|
inline int padup(int num, int amt)
|
|
|
|
|
{
|
2012-05-15 18:45:20 +00:00
|
|
|
return ((num + (amt - 1)) & ~(amt - 1));
|
2009-08-13 20:35:53 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-11 00:33:51 +00:00
|
|
|
SVBVHNode *transform(OldNode *old)
|
|
|
|
|
{
|
2012-04-28 06:31:57 +00:00
|
|
|
if (is_leaf(old))
|
2012-05-15 18:45:20 +00:00
|
|
|
return (SVBVHNode *)old;
|
2012-04-28 06:31:57 +00:00
|
|
|
if (is_leaf(old->child))
|
2012-05-15 18:45:20 +00:00
|
|
|
return (SVBVHNode *)old->child;
|
2009-08-11 00:33:51 +00:00
|
|
|
|
|
|
|
|
int nchilds = count_childs(old);
|
2009-08-13 20:35:53 +00:00
|
|
|
int alloc_childs = nchilds;
|
2012-04-28 06:31:57 +00:00
|
|
|
if (nchilds % 4 > 2)
|
2009-08-13 20:35:53 +00:00
|
|
|
alloc_childs = padup(nchilds, 4);
|
|
|
|
|
|
|
|
|
|
SVBVHNode *node = create_node(alloc_childs);
|
2009-08-11 00:33:51 +00:00
|
|
|
|
|
|
|
|
childs_per_node += nchilds;
|
|
|
|
|
nodes++;
|
2012-04-28 06:31:57 +00:00
|
|
|
if (nchilds < 16)
|
2009-08-11 00:33:51 +00:00
|
|
|
nodes_with_childs[nchilds]++;
|
|
|
|
|
|
2012-05-15 18:45:20 +00:00
|
|
|
useless_bb += alloc_childs - nchilds;
|
2012-04-28 06:31:57 +00:00
|
|
|
while (alloc_childs > nchilds) {
|
2012-10-14 13:18:32 +00:00
|
|
|
const static float def_bb[6] = {FLT_MAX, FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX};
|
2009-08-13 20:35:53 +00:00
|
|
|
alloc_childs--;
|
2012-03-26 08:58:17 +00:00
|
|
|
node->child[alloc_childs] = NULL;
|
2012-05-15 18:45:20 +00:00
|
|
|
copy_bb(node->child_bb + alloc_childs * 6, def_bb);
|
2009-08-13 20:35:53 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-15 18:45:20 +00:00
|
|
|
int i = nchilds;
|
2012-04-28 06:31:57 +00:00
|
|
|
for (OldNode *o_child = old->child; o_child; o_child = o_child->sibling) {
|
2009-08-11 00:33:51 +00:00
|
|
|
i--;
|
|
|
|
|
node->child[i] = transform(o_child);
|
2012-04-28 06:31:57 +00:00
|
|
|
if (is_leaf(o_child)) {
|
2009-08-11 00:33:51 +00:00
|
|
|
float bb[6];
|
2012-05-15 18:45:20 +00:00
|
|
|
INIT_MINMAX(bb, bb + 3);
|
|
|
|
|
RE_rayobject_merge_bb((RayObject *)o_child, bb, bb + 3);
|
|
|
|
|
copy_bb(node->child_bb + i * 6, bb);
|
2009-08-11 00:33:51 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2012-04-28 06:31:57 +00:00
|
|
|
else {
|
2012-05-15 18:45:20 +00:00
|
|
|
copy_bb(node->child_bb + i * 6, o_child->bb);
|
2009-08-11 00:33:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
assert(i == 0);
|
2009-08-11 00:33:51 +00:00
|
|
|
|
2009-08-29 17:24:45 +00:00
|
|
|
prepare_for_simd(node);
|
2009-08-11 00:33:51 +00:00
|
|
|
|
|
|
|
|
return node;
|
2012-10-21 05:46:41 +00:00
|
|
|
}
|
2009-08-11 00:33:51 +00:00
|
|
|
};
|
|
|
|
|
|
2012-10-09 13:36:42 +00:00
|
|
|
#endif /* __SSE__ */
|
Raytrace modifications from the Render Branch.
These should not have any effect on render results, except in some cases with
you have overlapping faces, where the noise seems to be slightly reduced.
There are some performance improvements, for simple scenes I wouldn't expect
more than 5-10% to be cut off the render time, for sintel scenes we got about
50% on average, that's with millions of polygons on intel quad cores. This
because memory access / cache misses were the main bottleneck for those scenes,
and the optimizations improve that.
Interal changes:
* Remove RE_raytrace.h, raytracer is now only used by render engine again.
* Split non-public parts rayobject.h into rayobject_internal.h, hopefully
makes it clearer how the API is used.
* Added rayintersection.h to contain some of the stuff from RE_raytrace.h
* Change Isect.vec/labda to Isect.dir/dist, previously vec was sometimes
normalized and sometimes not, confusing... now dir is always normalized
and dist contains the distance.
* Change VECCOPY and similar to BLI_math functions.
* Force inlining of auxiliary functions for ray-triangle/quad intersection,
helps a few percentages.
* Reorganize svbvh code so all the traversal functions are in one file
* Don't do test for root so that push_childs can be inlined
* Make shadow a template parameter so it doesn't need to be runtime checked
* Optimization in raytree building, was computing bounding boxes more often
than necessary.
* Leave out logf() factor in SAH, makes tree build quicker with no
noticeable influence on raytracing on performance?
* Set max childs to 4, simplifies traversal code a bit, but also seems
to help slightly in general.
* Store child pointers and child bb just as fixed arrays of size 4 in nodes,
nearly all nodes have this many children, so overall it actually reduces
memory usage a bit and avoids a pointer indirection.
2011-02-05 13:41:29 +00:00
|
|
|
|
2012-10-09 13:36:42 +00:00
|
|
|
#endif /* __SVBVH_H__ */
|