[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23622] branches/soc-2009-jaguarandi/ source/blender/render/intern: Added some test_break during the build process.
Andre Susano Pinto
andresusanopinto at gmail.com
Sun Oct 4 18:56:01 CEST 2009
Revision: 23622
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23622
Author: jaguarandi
Date: 2009-10-04 18:56:00 +0200 (Sun, 04 Oct 2009)
Log Message:
-----------
Added some test_break during the build process.
(Maybe later this should be done with some thread_cancel function instead of doing variable/callbacks tests)
Modified Paths:
--------------
branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h
branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject.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_rtbuild.h
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/vbvh.h
branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c
Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h 2009-10-04 01:21:33 UTC (rev 23621)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/include/rayobject.h 2009-10-04 16:56:00 UTC (rev 23622)
@@ -93,16 +93,35 @@
#define RE_rayobject_isVlakPrimitive(o) ((((intptr_t)o)&3) == 3)
+
/*
+ * This class is intended as a place holder for control, configuration of the rayobject like:
+ * - stop building (TODO maybe when porting build to threads this could be implemented with some thread_cancel function)
+ * - max number of threads and threads callback to use during build
+ * ...
+ */
+typedef int (*RE_rayobjectcontrol_test_break_callback)(void *data);
+typedef struct RayObjectControl RayObjectControl;
+struct RayObjectControl
+{
+ void *data;
+ RE_rayobjectcontrol_test_break_callback test_break;
+};
+
+/*
* This rayobject represents a generic object. With it's own callbacks for raytrace operations.
* It's suitable to implement things like LOD.
*/
struct RayObject
{
struct RayObjectAPI *api;
+
+ struct RayObjectControl control;
};
+
+
typedef int (*RE_rayobject_raycast_callback)(RayObject *, Isect *);
typedef void (*RE_rayobject_add_callback)(RayObject *raytree, RayObject *rayobject);
typedef void (*RE_rayobject_done_callback)(RayObject *);
@@ -144,6 +163,11 @@
float RE_rayobject_cost(RayObject *r);
+/*
+ * Returns true if for some reason a heavy processing function should stop
+ * (eg.: user asked to stop during a tree a build)
+ */
+int RE_rayobjectcontrol_test_break(RayObjectControl *c);
#define ISECT_EPSILON ((float)FLT_EPSILON)
Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject.cpp
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject.cpp 2009-10-04 01:21:33 UTC (rev 23621)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject.cpp 2009-10-04 16:56:00 UTC (rev 23622)
@@ -528,3 +528,10 @@
else assert(0);
}
+int RE_rayobjectcontrol_test_break(RayObjectControl *control)
+{
+ if(control->test_break)
+ return control->test_break( control->data );
+
+ return 0;
+}
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-10-04 01:21:33 UTC (rev 23621)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_qbvh.cpp 2009-10-04 16:56:00 UTC (rev 23622)
@@ -47,7 +47,7 @@
template<>
void bvh_done<QBVHTree>(QBVHTree *obj)
{
- rtbuild_done(obj->builder);
+ rtbuild_done(obj->builder, &obj->rayobj.control);
//TODO find a away to exactly calculate the needed memory
MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE);
@@ -59,7 +59,15 @@
//Build and optimize the tree
//TODO do this in 1 pass (half memory usage during building)
- VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1).transform(obj->builder);
+ VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1, &obj->rayobj.control).transform(obj->builder);
+
+ if(RE_rayobjectcontrol_test_break(&obj->rayobj.control))
+ {
+ BLI_memarena_free(arena1);
+ BLI_memarena_free(arena2);
+ return;
+ }
+
pushup_simd<VBVHNode,4>(root);
obj->root = Reorganize_SVBVH<VBVHNode>(arena2).transform(root);
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-10-04 01:21:33 UTC (rev 23621)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp 2009-10-04 16:56:00 UTC (rev 23622)
@@ -130,11 +130,14 @@
assert(false);
}
-void rtbuild_done(RTBuilder *b)
+void rtbuild_done(RTBuilder *b, RayObjectControl* ctrl)
{
for(int i=0; i<3; i++)
if(b->sorted_begin[i])
+ {
+ if(RE_rayobjectcontrol_test_break(ctrl)) break;
object_sort( b->sorted_begin[i], b->sorted_end[i], i );
+ }
}
RayObject* rtbuild_get_primitive(RTBuilder *b, int index)
Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_rtbuild.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_rtbuild.h 2009-10-04 01:21:33 UTC (rev 23621)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_rtbuild.h 2009-10-04 16:56:00 UTC (rev 23622)
@@ -85,7 +85,7 @@
RTBuilder* rtbuild_create(int size);
void rtbuild_free(RTBuilder *b);
void rtbuild_add(RTBuilder *b, RayObject *o);
-void rtbuild_done(RTBuilder *b);
+void rtbuild_done(RTBuilder *b, RayObjectControl *c);
void rtbuild_merge_bb(RTBuilder *b, float *min, float *max);
int rtbuild_size(RTBuilder *b);
Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_svbvh.cpp
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_svbvh.cpp 2009-10-04 01:21:33 UTC (rev 23621)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_svbvh.cpp 2009-10-04 16:56:00 UTC (rev 23622)
@@ -58,7 +58,7 @@
template<>
void bvh_done<SVBVHTree>(SVBVHTree *obj)
{
- rtbuild_done(obj->builder);
+ rtbuild_done(obj->builder, &obj->rayobj.control);
//TODO find a away to exactly calculate the needed memory
MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE);
@@ -71,7 +71,14 @@
//Build and optimize the tree
if(0)
{
- VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1).transform(obj->builder);
+ VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1,&obj->rayobj.control).transform(obj->builder);
+ if(RE_rayobjectcontrol_test_break(&obj->rayobj.control))
+ {
+ BLI_memarena_free(arena1);
+ BLI_memarena_free(arena2);
+ return;
+ }
+
reorganize(root);
remove_useless(root, &root);
bvh_refit(root);
@@ -86,7 +93,14 @@
{
//Finds the optimal packing of this tree using a given cost model
//TODO this uses quite a lot of memory, find ways to reduce memory usage during building
- OVBVHNode *root = BuildBinaryVBVH<OVBVHNode>(arena1).transform(obj->builder);
+ OVBVHNode *root = BuildBinaryVBVH<OVBVHNode>(arena1,&obj->rayobj.control).transform(obj->builder);
+ if(RE_rayobjectcontrol_test_break(&obj->rayobj.control))
+ {
+ BLI_memarena_free(arena1);
+ BLI_memarena_free(arena2);
+ return;
+ }
+
VBVH_optimalPackSIMD<OVBVHNode,PackCost>(PackCost()).transform(root);
obj->root = Reorganize_SVBVH<OVBVHNode>(arena2).transform(root);
}
Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_vbvh.cpp
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_vbvh.cpp 2009-10-04 01:21:33 UTC (rev 23621)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/rayobject_vbvh.cpp 2009-10-04 16:56:00 UTC (rev 23622)
@@ -72,7 +72,7 @@
template<>
void bvh_done<VBVHTree>(VBVHTree *obj)
{
- rtbuild_done(obj->builder);
+ rtbuild_done(obj->builder, &obj->rayobj.control);
//TODO find a away to exactly calculate the needed memory
MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE);
@@ -81,7 +81,12 @@
//Build and optimize the tree
if(1)
{
- VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1).transform(obj->builder);
+ VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1,&obj->rayobj.control).transform(obj->builder);
+ if(RE_rayobjectcontrol_test_break(&obj->rayobj.control))
+ {
+ BLI_memarena_free(arena1);
+ return;
+ }
reorganize(root);
remove_useless(root, &root);
Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/vbvh.h
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/vbvh.h 2009-10-04 01:21:33 UTC (rev 23621)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/raytrace/vbvh.h 2009-10-04 16:56:00 UTC (rev 23622)
@@ -107,10 +107,18 @@
struct BuildBinaryVBVH
{
MemArena *arena;
+ RayObjectControl *control;
- BuildBinaryVBVH(MemArena *a)
+ void test_break()
{
+ if(RE_rayobjectcontrol_test_break(control))
+ throw "Stop";
+ }
+
+ BuildBinaryVBVH(MemArena *a, RayObjectControl *c)
+ {
arena = a;
+ control = c;
}
Node *create_node()
@@ -131,6 +139,18 @@
Node *transform(RTBuilder *builder)
{
+ try
+ {
+ return _transform(builder);
+
+ } catch(...)
+ {
+ }
+ return NULL;
+ }
+
+ Node *_transform(RTBuilder *builder)
+ {
int size = rtbuild_size(builder);
if(size == 1)
@@ -143,6 +163,8 @@
}
else
{
+ test_break();
+
Node *node = create_node();
INIT_MINMAX(node->bb, node->bb+3);
@@ -157,7 +179,7 @@
RTBuilder tmp;
rtbuild_get_child(builder, i, &tmp);
- *child = transform(&tmp);
+ *child = _transform(&tmp);
child = &((*child)->sibling);
}
Modified: branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c
===================================================================
--- branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c 2009-10-04 01:21:33 UTC (rev 23621)
+++ branches/soc-2009-jaguarandi/source/blender/render/intern/source/rayshade.c 2009-10-04 16:56:00 UTC (rev 23622)
@@ -72,8 +72,26 @@
/* only to be used here in this file, it's for speed */
extern struct Render R;
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-RayObject * RE_rayobject_create(int type, int size)
+static int test_break(void *data)
{
+ Render *re = (Render*)data;
+ return re->test_break(re->tbh);
+}
+
+static RE_rayobject_config_control(RayObject *r, Render *re)
+{
+ if(RE_rayobject_isRayAPI(r))
+ {
+ r = RE_rayobject_align( r );
+ r->control.data = re;
+ r->control.test_break = test_break;
+ }
+}
+
+RayObject* RE_rayobject_create(Render *re, int type, int size)
+{
+ RayObject * res = NULL;
+
if(type == R_RAYSTRUCTURE_AUTO)
{
//TODO
@@ -83,30 +101,21 @@
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list