[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30924] branches/particles-2010/source/ blender: Major overhaul of the simulation node execution process.

Lukas Toenne lukas.toenne at googlemail.com
Sat Jul 31 16:47:41 CEST 2010


Revision: 30924
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30924
Author:   lukastoenne
Date:     2010-07-31 16:47:41 +0200 (Sat, 31 Jul 2010)

Log Message:
-----------
Major overhaul of the simulation node execution process.
1) Data calculations are fully threaded now. Threads are currently created by the tree execution function, but could be inserted outside if necessary. Data will be generated in batches, with each batch being handled by one thread (per node). SIMD can later be implemented too using this feature.
2) This now uses a completely custom "instance stack" (roughly equivalent to bNodeStack). It completely flattens node groups, which should make it easier to implement nested groups later. Also the operator nodes now return from from their execution function before the next operator node on the call stack is executed. Cleaner procedure and less ways to mess it up by node type coders.
Previous functionality is not yet fully restored, this is merely an intermediate step.

Modified Paths:
--------------
    branches/particles-2010/source/blender/blenkernel/BKE_node.h
    branches/particles-2010/source/blender/blenkernel/intern/node.c
    branches/particles-2010/source/blender/makesdna/DNA_node_types.h
    branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c
    branches/particles-2010/source/blender/makesrna/intern/rna_nodetree_types.h
    branches/particles-2010/source/blender/modifiers/intern/MOD_nodetree.c
    branches/particles-2010/source/blender/nodes/SIM_node.h
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_debugprint.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_for.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_get_object_data.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_if.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_math.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_pass.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_program.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_set_object_data.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_subprogram.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_timestep.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_vector_compose.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_vector_decompose.c
    branches/particles-2010/source/blender/nodes/intern/SIM_util.c
    branches/particles-2010/source/blender/nodes/intern/SIM_util.h
    branches/particles-2010/source/blender/nodes/intern/node_tree_simulation.c

Added Paths:
-----------
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_get_vertex_data.c

Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-07-31 10:58:10 UTC (rev 30923)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-07-31 14:47:41 UTC (rev 30924)
@@ -56,6 +56,7 @@
 struct GPUNode;
 struct GPUNodeStack;
 struct SimulationContext;
+struct SimNodeJob;
 struct PointerRNA;
 struct bContext;
 
@@ -108,25 +109,11 @@
 	/* gpu */
 	int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out);
 
+	/* simulation nodes */
+	int (*sim_exec)(struct SimulationContext *sim, struct bNode *node, struct SimNodeJob *job);
+	int (*sim_opexec)(struct SimulationContext *sim, struct bNode *node, int level, int *r_opsock);
 } bNodeType;
 
-typedef void (*bNodeTreeCallback)(void *calldata, struct ID *owner_id, struct bNodeTree *ntree);
-typedef struct bNodeTreeTypeInfo
-{
-	int type;						/* type identifier */
-	char id_name[24];				/* id name for RNA identification */
-	
-	ListBase node_types;			/* type definitions */
-	
-	/* callbacks */
-	void (*freeCache)(struct bNodeTree *ntree);
-	void (*freeNodeCache)(struct bNodeTree *ntree, struct bNode *node);
-	void (*foreachNodeTree)(void *calldata, bNodeTreeCallback func);		/* iteration over all node trees */
-	void (*beginExec)(struct bNodeTree *ntree);
-	void (*endExec)(struct bNodeTree *ntree);
-	void (*exec)(struct bNodeTree *ntree, void *callerdata, int thread);
-} bNodeTreeTypeInfo;
-
 /* node->exec, now in use for composites (#define for break is same as ready yes) */
 #define NODE_PROCESSING	1
 #define NODE_READY		2
@@ -135,6 +122,10 @@
 #define NODE_FREEBUFS	8
 #define NODE_SKIPPED	16
 
+/* sim_exec return value */
+#define NODE_EXEC_FINISHED	0
+#define NODE_EXEC_SUSPEND	1
+
 /* nodetype->nclass, for add-menu and themes */
 #define NODE_CLASS_INPUT		0
 #define NODE_CLASS_OUTPUT		1
@@ -152,6 +143,23 @@
 #define NODE_CLASS_SIMULATION	14
 #define NODE_CLASS_MATH			15
 
+typedef void (*bNodeTreeCallback)(void *calldata, struct ID *owner_id, struct bNodeTree *ntree);
+typedef struct bNodeTreeTypeInfo
+{
+	int type;						/* type identifier */
+	char id_name[24];				/* id name for RNA identification */
+	
+	ListBase node_types;			/* type definitions */
+	
+	/* callbacks */
+	void (*freeCache)(struct bNodeTree *ntree);
+	void (*freeNodeCache)(struct bNodeTree *ntree, struct bNode *node);
+	void (*foreachNodeTree)(void *calldata, bNodeTreeCallback func);		/* iteration over all node trees */
+	void (*beginExec)(struct bNodeTree *ntree);
+	void (*endExec)(struct bNodeTree *ntree);
+	void (*exec)(struct bNodeTree *ntree, void *callerdata, int thread);
+} bNodeTreeTypeInfo;
+
 /* ************** GENERIC API, TREES *************** */
 
 bNodeTreeTypeInfo	*ntreeGetTypeInfo(int type);
@@ -508,16 +516,14 @@
 #define SIM_NODE_TIMESTEP			750
 #define SIM_NODE_GETOBJECTDATA		751
 #define SIM_NODE_SETOBJECTDATA		752
+#define SIM_NODE_GETVERTEXDATA		753
 
 /* TO BE REMOVED: debugging stuff, testing, etc. */
 #define SIM_NODE_DEBUGPRINT			801
 
 /* API */
-void ntreeSimulationExecTree(struct SimulationContext *sim, int thread);
+void ntreeSimulationExecTree(struct SimulationContext *sim);
 
-/* Note: this function should only be called from within other nodes execution functions! */
-void ntreeSimulationExecOperator(struct SimulationContext *sim, struct bNodeOperatorContext *ctx);
-
 /**/
 
 void init_nodesystem(void);

Modified: branches/particles-2010/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/particles-2010/source/blender/blenkernel/intern/node.c	2010-07-31 10:58:10 UTC (rev 30923)
+++ branches/particles-2010/source/blender/blenkernel/intern/node.c	2010-07-31 14:47:41 UTC (rev 30924)
@@ -1893,7 +1893,8 @@
 		return;
 
 	treetype = ntreeGetTypeInfo(ntree->type);
-	treetype->beginExec(ntree);
+	if (treetype->beginExec)
+		treetype->beginExec(ntree);
 	
 	ntree->init |= NTREE_EXEC_INIT;
 }
@@ -1904,7 +1905,8 @@
 	
 	if(ntree->init & NTREE_EXEC_INIT) {
 		treetype = ntreeGetTypeInfo(ntree->type);
-		treetype->endExec(ntree);
+		if (treetype->endExec)
+			treetype->endExec(ntree);
 		
 		ntree->init &= ~NTREE_EXEC_INIT;
 	}
@@ -1915,7 +1917,8 @@
 {
 	bNodeTreeTypeInfo *treetype= ntreeGetTypeInfo(ntree->type);
 	
-	treetype->exec(ntree, callerdata, thread);
+	if (treetype->exec)
+		treetype->exec(ntree, callerdata, thread);
 }
 
 
@@ -2614,6 +2617,7 @@
 	nodeRegisterType(ntypelist, &sim_node_timestep);
 	nodeRegisterType(ntypelist, &sim_node_getobjectdata);
 	nodeRegisterType(ntypelist, &sim_node_setobjectdata);
+	nodeRegisterType(ntypelist, &sim_node_getvertexdata);
 
 	nodeRegisterType(ntypelist, &sim_node_debugprint);
 }

Modified: branches/particles-2010/source/blender/makesdna/DNA_node_types.h
===================================================================
--- branches/particles-2010/source/blender/makesdna/DNA_node_types.h	2010-07-31 10:58:10 UTC (rev 30923)
+++ branches/particles-2010/source/blender/makesdna/DNA_node_types.h	2010-07-31 14:47:41 UTC (rev 30924)
@@ -47,23 +47,41 @@
 #define NODE_MAXSTR 32
 
 
+
 /* Defines execution context for nodes in an operator socket.
  * This allows calling node executions from within a node tree or group node.
  */
-typedef struct bNodeOperatorContext {
-	struct bNodeTree *ntree;
-	struct bNode *node;
-	struct bNodeStack *stack;
-} bNodeOperatorContext;
+//typedef struct bNodeOperatorContext {
+//	struct bNodeTree *ntree;
+//	struct bNode *node;
+//	struct bNodeStack *stack;
+//	struct bNodeStackInfo *nsinfo;
+//} bNodeOperatorContext;
 
 /*
  */
-typedef struct bNodeDataContext {
-	void* (*init)(struct bNodeDataContext *ctx);
-	void* (*next)(struct bNodeDataContext *ctx, void *current);
-	int (*end)(struct bNodeDataContext *ctx);
-} bNodeDataContext;
+typedef struct bNodeDataCollection {
+	int type;
+	char pad[4];
+	void *source;
+} bNodeDataCollection;
 
+typedef enum eNodeDataCollectionType {
+	NDC_SINGLETON = 0,
+	NDC_NODE,
+	NDC_PARTICLE,
+	NDC_VERTEX,
+	NDC_EDGE,
+	NDC_FACE
+} eNodeDataCollectionType;
+
+typedef struct bNodeDataCollectionIterator {
+	void *internal;
+	int valid;
+	
+	char pad[4];
+} bNodeDataCollectionIterator;
+
 typedef struct bNodeStack {
 	float vec[4];
 	float min, max;			/* min/max for values (UI writes it, execute might use it) */
@@ -75,7 +93,6 @@
 	short hasoutput;		/* when output is linked, tagged before executing */
 	short datatype;			/* type of data pointer */
 	short sockettype;		/* type of socket stack comes from, to remap linking different sockets */
-	bNodeOperatorContext ctx;	/* context for execution, only used for operator sockets */
 } bNodeStack;
 
 /* ns->datatype, shadetree only */
@@ -93,23 +110,25 @@
 	short intern;				/* intern = tag for group nodes */
 	short stack_index_ext;		/* for groups, to find the caller stack index */
 	
+	int pad1;
+	
 	float locx, locy;
 	
 	/* internal data to retrieve relations and groups */
 	
 	int own_index, to_index;	/* group socket identifiers, to find matching pairs after reading files */
 	
-	char pad[4];
+//	struct PointerRNA collection_ptr;
+//	struct PropertyRNA *collection_prop;
+	struct bNodeDataCollection collection;
 	
-	struct bNodeDataContext *context;
-	
 	/* group-node sockets point to the internal group counterpart sockets, set after read file  */
 	struct bNode *tonode;
 	struct bNodeSocket *tosock;	
 	
 	struct bNodeLink *link;		/* a link pointer, set in nodeSolveOrder() */
 	
-	struct bNodeSocketType *stype;	/* socket type, needed because list sockets make 1:1 lookup impossible */
+	struct bNodeSocketType *stype;	/* socket type pointer */
 } bNodeSocket;
 
 /* sock->type */

Modified: branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c	2010-07-31 10:58:10 UTC (rev 30923)
+++ branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c	2010-07-31 14:47:41 UTC (rev 30924)
@@ -31,8 +31,10 @@
 #include "rna_internal.h"
 
 #include "DNA_material_types.h"
+#include "DNA_mesh_types.h"
 #include "DNA_node_types.h"
-#include "DNA_particle_types.h"
+#include "DNA_object_types.h"
+#include "DNA_particleset_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_texture_types.h"
 
@@ -289,6 +291,31 @@
 	rna_Node_update(bmain, scene, ptr);
 }
 
+static void rna_Node_get_vertex_data_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+	bNodeTree *ntree= (bNodeTree*)ptr->id.data;
+	bNode *node= (bNode*)ptr->data;
+	bNodeSocket *out_pos = node->outputs.first;
+	Object *ob = (Object*)node->id;
+	
+	if (ob && ob->type==OB_MESH) {
+		Mesh *mesh = (Mesh*)ob->data;
+		
+		out_pos->collection.type = NDC_VERTEX;
+		out_pos->collection.source = mesh;
+//		RNA_id_pointer_create(&mesh->id, &out_pos->collection_ptr);
+//		out_pos->collection_prop = RNA_struct_find_property(&out_pos->collection_ptr, "verts");
+	}
+	else {
+		out_pos->collection.type = NDC_SINGLETON;
+		out_pos->collection.source = NULL;
+//		RNA_id_pointer_create(NULL, &out_pos->collection_ptr);
+//		out_pos->collection_prop = NULL;
+	}
+	
+	node_update(bmain, scene, ntree, node);
+}
+
 static EnumPropertyItem *renderresult_layers_add_enum(RenderLayer *rl)
 {
 	EnumPropertyItem *item= NULL;
@@ -2095,6 +2122,18 @@
 	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
 }
 
+static void def_sim_getvertexdata(StructRNA *srna)
+{
+	PropertyRNA *prop;
+
+	prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
+	RNA_def_property_pointer_sdna(prop, NULL, "id");
+	RNA_def_property_struct_type(prop, "Object");
+	RNA_def_property_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Object", "");
+	RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_get_vertex_data_update");
+}
+
 /* -------------------------------------------------------------------------- */
 
 static EnumPropertyItem shader_node_type_items[MaxNodes];

Modified: branches/particles-2010/source/blender/makesrna/intern/rna_nodetree_types.h
===================================================================
--- branches/particles-2010/source/blender/makesrna/intern/rna_nodetree_types.h	2010-07-31 10:58:10 UTC (rev 30923)
+++ branches/particles-2010/source/blender/makesrna/intern/rna_nodetree_types.h	2010-07-31 14:47:41 UTC (rev 30924)
@@ -159,5 +159,6 @@

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list