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:
Diffstat (limited to 'source/blender/render/intern/raytrace/reorganize.h')
-rw-r--r--source/blender/render/intern/raytrace/reorganize.h117
1 files changed, 58 insertions, 59 deletions
diff --git a/source/blender/render/intern/raytrace/reorganize.h b/source/blender/render/intern/raytrace/reorganize.h
index a47bd27d11b..1e9a0319b2f 100644
--- a/source/blender/render/intern/raytrace/reorganize.h
+++ b/source/blender/render/intern/raytrace/reorganize.h
@@ -57,13 +57,13 @@ extern int tot_pushdown;
template<class Node>
bool node_fits_inside(Node *a, Node *b)
{
- return bb_fits_inside(b->bb, b->bb+3, a->bb, a->bb+3);
+ return bb_fits_inside(b->bb, b->bb + 3, a->bb, a->bb + 3);
}
template<class Node>
-void reorganize_find_fittest_parent(Node *tree, Node *node, std::pair<float, Node*> &cost)
+void reorganize_find_fittest_parent(Node *tree, Node *node, std::pair<float, Node *> &cost)
{
- std::queue<Node*> q;
+ std::queue<Node *> q;
q.push(tree);
while (!q.empty()) {
@@ -72,8 +72,8 @@ void reorganize_find_fittest_parent(Node *tree, Node *node, std::pair<float, Nod
if (parent == node) continue;
if (node_fits_inside(node, parent) && RE_rayobject_isAligned(parent->child) ) {
- float pcost = bb_area(parent->bb, parent->bb+3);
- cost = std::min( cost, std::make_pair(pcost, parent) );
+ float pcost = bb_area(parent->bb, parent->bb + 3);
+ cost = std::min(cost, std::make_pair(pcost, parent) );
for (Node *child = parent->child; child; child = child->sibling)
q.push(child);
}
@@ -84,11 +84,11 @@ static int tot_moves = 0;
template<class Node>
void reorganize(Node *root)
{
- std::queue<Node*> q;
+ std::queue<Node *> q;
q.push(root);
while (!q.empty()) {
- Node * node = q.front();
+ Node *node = q.front();
q.pop();
if (RE_rayobject_isAligned(node->child)) {
@@ -96,7 +96,7 @@ void reorganize(Node *root)
assert(RE_rayobject_isAligned(*prev));
q.push(*prev);
- std::pair<float, Node*> best(FLT_MAX, root);
+ std::pair<float, Node *> best(FLT_MAX, root);
reorganize_find_fittest_parent(root, *prev, best);
if (best.second == node) {
@@ -129,7 +129,7 @@ void reorganize(Node *root)
template<class Node>
void remove_useless(Node *node, Node **new_node)
{
- if ( RE_rayobject_isAligned(node->child) ) {
+ if (RE_rayobject_isAligned(node->child) ) {
for (Node **prev = &node->child; *prev; ) {
Node *next = (*prev)->sibling;
@@ -160,12 +160,12 @@ void pushup(Node *parent)
{
if (is_leaf(parent)) return;
- float p_area = bb_area(parent->bb, parent->bb+3);
+ float p_area = bb_area(parent->bb, parent->bb + 3);
Node **prev = &parent->child;
for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; ) {
const float c_area = bb_area(child->bb, child->bb + 3);
const int nchilds = count_childs(child);
- float original_cost = ((p_area != 0.0f)? (c_area / p_area)*nchilds: 1.0f) + 1;
+ float original_cost = ((p_area != 0.0f) ? (c_area / p_area) * nchilds : 1.0f) + 1;
float flatten_cost = nchilds;
if (flatten_cost < original_cost && nchilds >= 2) {
append_sibling(child, child->child);
@@ -201,7 +201,7 @@ void pushup_simd(Node *parent)
Node **prev = &parent->child;
for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; ) {
int cn = count_childs(child);
- if (cn-1 <= (SSize - (n%SSize) ) % SSize && RE_rayobject_isAligned(child->child) ) {
+ if (cn - 1 <= (SSize - (n % SSize) ) % SSize && RE_rayobject_isAligned(child->child) ) {
n += (cn - 1);
append_sibling(child, child->child);
child = child->sibling;
@@ -227,7 +227,7 @@ template<class Node>
void pushdown(Node *parent)
{
Node **s_child = &parent->child;
- Node * child = parent->child;
+ Node *child = parent->child;
while (child && RE_rayobject_isAligned(child)) {
Node *next = child->sibling;
@@ -236,18 +236,18 @@ void pushdown(Node *parent)
//assert(bb_fits_inside(parent->bb, parent->bb+3, child->bb, child->bb+3));
for (Node *i = parent->child; RE_rayobject_isAligned(i) && i; i = i->sibling)
- if (child != i && bb_fits_inside(i->bb, i->bb+3, child->bb, child->bb+3) && RE_rayobject_isAligned(i->child)) {
+ if (child != i && bb_fits_inside(i->bb, i->bb + 3, child->bb, child->bb + 3) && RE_rayobject_isAligned(i->child)) {
// todo optimize (should the one with the smallest area?)
// float ia = bb_area(i->bb, i->bb+3)
// if (child->i)
- *s_child = child->sibling;
- child->sibling = i->child;
- i->child = child;
- next_s_child = s_child;
+ *s_child = child->sibling;
+ child->sibling = i->child;
+ i->child = child;
+ next_s_child = s_child;
- tot_pushdown++;
- break;
- }
+ tot_pushdown++;
+ break;
+ }
child = next;
s_child = next_s_child;
}
@@ -273,13 +273,13 @@ float bvh_refit(Node *node)
for (Node *child = node->child; child; child = child->sibling)
total += bvh_refit(child);
- float old_area = bb_area(node->bb, node->bb+3);
- INIT_MINMAX(node->bb, node->bb+3);
+ float old_area = bb_area(node->bb, node->bb + 3);
+ INIT_MINMAX(node->bb, node->bb + 3);
for (Node *child = node->child; child; child = child->sibling) {
DO_MIN(child->bb, node->bb);
- DO_MAX(child->bb+3, node->bb+3);
+ DO_MAX(child->bb + 3, node->bb + 3);
}
- total += old_area - bb_area(node->bb, node->bb+3);
+ total += old_area - bb_area(node->bb, node->bb + 3);
return total;
}
@@ -289,12 +289,11 @@ float bvh_refit(Node *node)
* with the purpose to reduce the expected cost (eg.: number of BB tests).
*/
#include <vector>
-#define MAX_CUT_SIZE 4 /* svbvh assumes max 4 children! */
-#define MAX_OPTIMIZE_CHILDS MAX_CUT_SIZE
+#define MAX_CUT_SIZE 4 /* svbvh assumes max 4 children! */
+#define MAX_OPTIMIZE_CHILDS MAX_CUT_SIZE
-struct OVBVHNode
-{
- float bb[6];
+struct OVBVHNode {
+ float bb[6];
OVBVHNode *child;
OVBVHNode *sibling;
@@ -306,7 +305,7 @@ struct OVBVHNode
float cut_cost[MAX_CUT_SIZE];
float get_cost(int cutsize)
{
- return cut_cost[cutsize-1];
+ return cut_cost[cutsize - 1];
}
/*
@@ -316,7 +315,7 @@ struct OVBVHNode
int cut_size[MAX_CUT_SIZE];
int get_cut_size(int parent_cut_size)
{
- return cut_size[parent_cut_size-1];
+ return cut_size[parent_cut_size - 1];
}
/*
@@ -327,19 +326,21 @@ struct OVBVHNode
{
if (cutsize == 1) {
**cut = this;
- *cut = &(**cut)->sibling;
+ *cut = &(**cut)->sibling;
}
else {
if (cutsize > MAX_CUT_SIZE) {
for (OVBVHNode *child = this->child; child && RE_rayobject_isAligned(child); child = child->sibling) {
- child->set_cut( 1, cut );
+ child->set_cut(1, cut);
cutsize--;
}
assert(cutsize == 0);
}
- else
- for (OVBVHNode *child = this->child; child && RE_rayobject_isAligned(child); child = child->sibling)
- child->set_cut( child->get_cut_size( cutsize ), cut );
+ else {
+ for (OVBVHNode *child = this->child; child && RE_rayobject_isAligned(child); child = child->sibling) {
+ child->set_cut(child->get_cut_size(cutsize), cut);
+ }
+ }
}
}
@@ -365,8 +366,7 @@ struct OVBVHNode
*
*/
template<class Node, class TestCost>
-struct VBVH_optimalPackSIMD
-{
+struct VBVH_optimalPackSIMD {
TestCost testcost;
VBVH_optimalPackSIMD(TestCost testcost)
@@ -377,8 +377,7 @@ struct VBVH_optimalPackSIMD
/*
* calc best cut on a node
*/
- struct calc_best
- {
+ struct calc_best {
Node *child[MAX_OPTIMIZE_CHILDS];
float child_hit_prob[MAX_OPTIMIZE_CHILDS];
@@ -387,10 +386,10 @@ struct VBVH_optimalPackSIMD
int nchilds = 0;
//Fetch childs and needed data
{
- float parent_area = bb_area(node->bb, node->bb+3);
+ float parent_area = bb_area(node->bb, node->bb + 3);
for (Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) {
this->child[nchilds] = child;
- this->child_hit_prob[nchilds] = (parent_area != 0.0f)? bb_area(child->bb, child->bb+3) / parent_area: 1.0f;
+ this->child_hit_prob[nchilds] = (parent_area != 0.0f) ? bb_area(child->bb, child->bb + 3) / parent_area : 1.0f;
nchilds++;
}
@@ -399,7 +398,7 @@ struct VBVH_optimalPackSIMD
//Build DP table to find minimum cost to represent this node with a given cutsize
- int bt [MAX_OPTIMIZE_CHILDS + 1][MAX_CUT_SIZE + 1]; //backtrace table
+ int bt[MAX_OPTIMIZE_CHILDS + 1][MAX_CUT_SIZE + 1]; //backtrace table
float cost[MAX_OPTIMIZE_CHILDS + 1][MAX_CUT_SIZE + 1]; //cost table (can be reduced to float[2][MAX_CUT_COST])
for (int i = 0; i <= nchilds; i++) {
@@ -410,13 +409,13 @@ struct VBVH_optimalPackSIMD
cost[0][0] = 0;
- for (int i = 1; i<=nchilds; i++) {
- for (int size = i - 1; size/*+(nchilds-i)*/<=MAX_CUT_SIZE; size++) {
- for (int cut = 1; cut+size/*+(nchilds-i)*/<=MAX_CUT_SIZE; cut++) {
+ for (int i = 1; i <= nchilds; i++) {
+ for (int size = i - 1; size /*+(nchilds-i)*/ <= MAX_CUT_SIZE; size++) {
+ for (int cut = 1; cut + size /*+(nchilds-i)*/ <= MAX_CUT_SIZE; cut++) {
float new_cost = cost[i - 1][size] + child_hit_prob[i - 1] * child[i - 1]->get_cost(cut);
- if (new_cost < cost[i][size+cut]) {
- cost[i][size+cut] = new_cost;
- bt[i][size+cut] = cut;
+ if (new_cost < cost[i][size + cut]) {
+ cost[i][size + cut] = new_cost;
+ bt[i][size + cut] = cut;
}
}
}
@@ -424,11 +423,11 @@ struct VBVH_optimalPackSIMD
//Save the ways to archieve the minimum cost with a given cutsize
for (int i = nchilds; i <= MAX_CUT_SIZE; i++) {
- node->cut_cost[i-1] = cost[nchilds][i];
+ node->cut_cost[i - 1] = cost[nchilds][i];
if (cost[nchilds][i] < INFINITY) {
int current_size = i;
- for (int j=nchilds; j>0; j--) {
- child[j-1]->cut_size[i-1] = bt[j][current_size];
+ for (int j = nchilds; j > 0; j--) {
+ child[j - 1]->cut_size[i - 1] = bt[j][current_size];
current_size -= bt[j][current_size];
}
}
@@ -439,23 +438,23 @@ struct VBVH_optimalPackSIMD
void calc_costs(Node *node)
{
- if ( RE_rayobject_isAligned(node->child) ) {
+ if (RE_rayobject_isAligned(node->child) ) {
int nchilds = 0;
for (Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) {
calc_costs(child);
nchilds++;
}
- for (int i=0; i<MAX_CUT_SIZE; i++)
+ for (int i = 0; i < MAX_CUT_SIZE; i++)
node->cut_cost[i] = INFINITY;
//We are not allowed to look on nodes with with so many childs
if (nchilds > MAX_CUT_SIZE) {
float cost = 0;
- float parent_area = bb_area(node->bb, node->bb+3);
+ float parent_area = bb_area(node->bb, node->bb + 3);
for (Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) {
- cost += ((parent_area != 0.0f)? ( bb_area(child->bb, child->bb+3) / parent_area ): 1.0f) * child->get_cost(1);
+ cost += ((parent_area != 0.0f) ? (bb_area(child->bb, child->bb + 3) / parent_area) : 1.0f) * child->get_cost(1);
}
cost += testcost(nchilds);
@@ -466,7 +465,7 @@ struct VBVH_optimalPackSIMD
calc_best calc(node);
//calc expected cost if we optimaly pack this node
- for (int cutsize=nchilds; cutsize<=MAX_CUT_SIZE; cutsize++) {
+ for (int cutsize = nchilds; cutsize <= MAX_CUT_SIZE; cutsize++) {
float m = node->get_cost(cutsize) + testcost(cutsize);
if (m < node->cut_cost[0]) {
node->cut_cost[0] = m;
@@ -491,7 +490,7 @@ struct VBVH_optimalPackSIMD
if (num == 0) { num++; first = true; }
calc_costs(node);
- if ((G.debug & G_DEBUG) && first) printf("expected cost = %f (%d)\n", node->cut_cost[0], node->best_cutsize );
+ if ((G.debug & G_DEBUG) && first) printf("expected cost = %f (%d)\n", node->cut_cost[0], node->best_cutsize);
node->optimize();
}
return node;