[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23035] branches/soc-2009-jaguarandi/ source/blender: *introduced new method for packing/ optimizing trees after building

Andre Susano Pinto andresusanopinto at gmail.com
Sun Sep 6 21:14:06 CEST 2009


Revision: 23035
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23035
Author:   jaguarandi
Date:     2009-09-06 21:14:06 +0200 (Sun, 06 Sep 2009)

Log Message:
-----------
*introduced new method for packing/optimizing trees after building
(this is a generalization of some of the experimental stuff i tried during SoC,
 but only had time to improve a few days ago)
 - it should yield slightly better results
 - the cost model can somehow be tweaked to optimize for diferent trees.

*cleaned up some code
*added counters for number of SIMD BB tests
*added GPL license block on missing files

Modified Paths:
--------------
    branches/soc-2009-jaguarandi/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2009-jaguarandi/source/blender/makesrna/intern/rna_scene.c
    branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h
    branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/bvh.h
    branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_bvh.cpp
    branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_qbvh.cpp
    branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp
    branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_svbvh.cpp
    branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_vbvh.cpp
    branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/reorganize.h
    branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/svbvh.h
    branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/vbvh.h
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayobject_raycounter.c
    branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c

Removed Paths:
-------------
    branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/qbvh.h

Modified: branches/soc-2009-jaguarandi/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/makesdna/DNA_scene_types.h	2009-09-06 16:58:14 UTC (rev 23034)
+++ branches/soc-2009-jaguarandi/source/blender/makesdna/DNA_scene_types.h	2009-09-06 19:14:06 UTC (rev 23035)
@@ -769,16 +769,14 @@
 #define R_YAFRAY	1
 
 /* raytrace structure */
-#define R_RAYSTRUCTURE_HIER_BVH_BVH		0
-#define R_RAYSTRUCTURE_HIER_BVH_OCTREE	1
-#define R_RAYSTRUCTURE_SINGLE_OCTREE	2
-#define R_RAYSTRUCTURE_SINGLE_BVH		3
+#define R_RAYSTRUCTURE_AUTO				0
+#define R_RAYSTRUCTURE_OCTREE			1
+#define R_RAYSTRUCTURE_BLIBVH			2
+#define R_RAYSTRUCTURE_VBVH				3
+#define R_RAYSTRUCTURE_SIMD_SVBVH		4	/* needs SIMD */
+#define R_RAYSTRUCTURE_SIMD_QBVH		5	/* needs SIMD */
+#define R_RAYSTRUCTURE_BIH				6
 
-/* raytrace tree type */
-#define R_RAYTRACE_TREE_BVH		0
-#define R_RAYTRACE_TREE_BLIBVH	1
-#define R_RAYTRACE_TREE_BIH		2
-
 /* scemode (int now) */
 #define R_DOSEQ				0x0001
 #define R_BG_RENDER			0x0002

Modified: branches/soc-2009-jaguarandi/source/blender/makesrna/intern/rna_scene.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/makesrna/intern/rna_scene.c	2009-09-06 16:58:14 UTC (rev 23034)
+++ branches/soc-2009-jaguarandi/source/blender/makesrna/intern/rna_scene.c	2009-09-06 19:14:06 UTC (rev 23035)
@@ -1032,18 +1032,16 @@
 		{0, NULL, 0, NULL, NULL}};
 
 	static EnumPropertyItem raytrace_structure_items[] = {
-		{R_RAYSTRUCTURE_HIER_BVH_BVH, "{R_RAYSTRUCTURE_HIER_BVH_BVH", 0, "BVH of BVH's", "Create a BVH of objects (each object has it own BVH)"},
-		{R_RAYSTRUCTURE_HIER_BVH_OCTREE, "{R_RAYSTRUCTURE_HIER_BVH_OCTREE", 0, "BVH of octree", "Create a BVH of objects (each object has it own octree)"},
-		{R_RAYSTRUCTURE_SINGLE_BVH, "{R_RAYSTRUCTURE_SINGLE_BVH", 0, "Single BVH", "BVH of all primitives (no instance support)"},
-		{R_RAYSTRUCTURE_SINGLE_OCTREE, "{R_RAYSTRUCTURE_SINGLE_OCTREE", 0, "Octree", "Octree of all primitives (no instance support)"},
-		{0, NULL, 0, NULL, NULL}};
+		{R_RAYSTRUCTURE_AUTO, "{R_RAYSTRUCTURE_AUTO", 0, "auto", ""},
+		{R_RAYSTRUCTURE_OCTREE, "R_RAYSTRUCTURE_OCTREE", 0, "octree", "Use old octree structure (no support for instances)"},
+		{R_RAYSTRUCTURE_BLIBVH, "R_RAYSTRUCTURE_BLIBVH", 0, "blibvh", "Use BLI_kdopbvh.c"},
+		{R_RAYSTRUCTURE_VBVH, "R_RAYSTRUCTURE_VBVH", 0, "vBVH", ""},
+		{R_RAYSTRUCTURE_SIMD_SVBVH, "R_RAYSTRUCTURE_SIMD_SVBVH", 0, "SIMD SVBVH", "Requires SIMD"},
+		{R_RAYSTRUCTURE_SIMD_QBVH, "R_RAYSTRUCTURE_SIMD_QBVH", 0, "SIMD QBVH", "Requires SIMD"},
+		{R_RAYSTRUCTURE_BIH, "R_RAYSTRUCTURE_BIH", 0, "BIH", ""},
+		{0, NULL, 0, NULL, NULL}
+		};
 
-	static EnumPropertyItem raytrace_tree_type_items[] = {
-		{R_RAYTRACE_TREE_BVH, "{R_RAYTRACE_TREE_BVH", 0, "BVH", "rayobject_bvh.c"},
-		{R_RAYTRACE_TREE_BLIBVH, "{R_RAYTRACE_TREE_BLIBVH", 0, "BLIbvh", "rayobject_blibvh.c"},
-		{R_RAYTRACE_TREE_BIH, "{R_RAYSTRUCTURE_SINGLE_BVH", 0, "BIH", "rayobject_bih.c"},
-		{0, NULL, 0, NULL, NULL}};
-		
 	static EnumPropertyItem fixed_oversample_items[] = {
 		{5, "OVERSAMPLE_5", 0, "5", ""},
 		{8, "OVERSAMPLE_8", 0, "8", ""},
@@ -1462,12 +1460,6 @@
 	RNA_def_property_ui_text(prop, "Raytrace Acceleration Structure", "Type of raytrace accelerator structure.");
 	RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
 
-	prop= RNA_def_property(srna, "raytrace_tree_type", PROP_ENUM, PROP_NONE);
-	RNA_def_property_enum_sdna(prop, NULL, "raytrace_tree_type");
-	RNA_def_property_enum_items(prop, raytrace_tree_type_items);
-	RNA_def_property_ui_text(prop, "Raytrace tree type", "Type of raytrace accelerator structure.");
-	RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
-	
 	prop= RNA_def_property(srna, "antialiasing", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "mode", R_OSA);
 	RNA_def_property_ui_text(prop, "Anti-Aliasing", "Render and combine multiple samples per pixel to prevent jagged edges.");

Modified: branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h	2009-09-06 16:58:14 UTC (rev 23034)
+++ branches/soc-2009-jaguarandi/source/blender/render/extern/include/RE_raytrace.h	2009-09-06 19:14:06 UTC (rev 23035)
@@ -53,7 +53,7 @@
 	{
 		unsigned long long test, hit;
 		
-	} faces, bb, raycast, raytrace_hint, rayshadow_last_hit;
+	} faces, bb, simd_bb, raycast, raytrace_hint, rayshadow_last_hit;
 };
 
 /* #define RE_RC_INIT(isec, shi) (isec).count = re_rc_counter+(shi).thread */

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/bvh.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/bvh.h	2009-09-06 16:58:14 UTC (rev 23034)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/bvh.h	2009-09-06 19:14:06 UTC (rev 23035)
@@ -241,17 +241,13 @@
 				t_node[i] = t->child;
 			}
 */
-			RE_RC_COUNT(isec->raycounter->bb.test);
-			RE_RC_COUNT(isec->raycounter->bb.test);
-			RE_RC_COUNT(isec->raycounter->bb.test);
-			RE_RC_COUNT(isec->raycounter->bb.test);
-			
+			RE_RC_COUNT(isec->raycounter->simd_bb.test);
 			int res = test_bb_group4( t_bb, isec );
 
 			for(int i=0; i<4; i++)
 			if(res & (1<<i))
 			{
-				RE_RC_COUNT(isec->raycounter->bb.hit);
+				RE_RC_COUNT(isec->raycounter->simd_bb.hit);
 				if(!is_leaf(t_node[i]))
 				{
 					for(Node *t=t_node[i]; t; t=t->sibling)

Deleted: branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/qbvh.h
===================================================================

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_bvh.cpp
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_bvh.cpp	2009-09-06 16:58:14 UTC (rev 23034)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_bvh.cpp	2009-09-06 19:14:06 UTC (rev 23035)
@@ -65,7 +65,6 @@
 	RTBuilder *builder;
 };
 
-
 /*
  * Push nodes (used on dfs)
  */

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_qbvh.cpp
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_qbvh.cpp	2009-09-06 16:58:14 UTC (rev 23034)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_qbvh.cpp	2009-09-06 19:14:06 UTC (rev 23035)
@@ -1,6 +1,33 @@
+/**
+ * $Id$
+ *
+ * ***** 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,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * 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 *****
+ */
 #include "vbvh.h"
 #include "svbvh.h"
-#include "qbvh.h"
 #include "reorganize.h"
 
 #define DFS_STACK_SIZE	256
@@ -17,6 +44,17 @@
 };
 
 
+/*
+ * Cost to test N childs
+ */
+struct PackCost
+{
+	float operator()(int n)
+	{
+		return (n / 4) + ((n % 4) > 2 ? 1 : n%4);
+	}
+};
+
 template<>
 void bvh_done<QBVHTree>(QBVHTree *obj)
 {
@@ -31,10 +69,21 @@
 					   BLI_memarena_use_align(arena2, 16);
 
 	//Build and optimize the tree
-	VBVHNode *root = BuildBinaryVBVH(arena1).transform(obj->builder);	
-	pushup_simd<VBVHNode,4>(root);					   
-	obj->root = Reorganize_SVBVH<VBVHNode>(arena2).transform(root);
 	
+	if(0)
+	{
+		VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1).transform(obj->builder);	
+		pushup_simd<VBVHNode,4>(root);					   
+		obj->root = Reorganize_SVBVH<VBVHNode>(arena2).transform(root);
+	}
+	else
+	{
+		//Finds the optimal packing of this tree using a given cost model
+		OVBVHNode *root = BuildBinaryVBVH<OVBVHNode>(arena1).transform(obj->builder);			
+		VBVH_optimalPackSIMD<OVBVHNode,PackCost>(PackCost()).transform(root);
+		obj->root = Reorganize_SVBVH<OVBVHNode>(arena2).transform(root);
+	}
+	
 	//Cleanup
 	BLI_memarena_free(arena1);	
 	

Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp	2009-09-06 16:58:14 UTC (rev 23034)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp	2009-09-06 19:14:06 UTC (rev 23035)
@@ -1,3 +1,31 @@
+/**
+ * $Id$
+ *
+ * ***** 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,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * 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 *****
+ */
 #include <assert.h>
 #include <math.h>

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list