[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31763] branches/particles-2010/source/ blender: Implemented GetData and SetData nodes.

Lukas Toenne lukas.toenne at googlemail.com
Sun Sep 5 11:50:24 CEST 2010


Revision: 31763
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31763
Author:   lukastoenne
Date:     2010-09-05 11:50:24 +0200 (Sun, 05 Sep 2010)

Log Message:
-----------
Implemented GetData and SetData nodes. SetData still needs to update the rna properties after writing data, this will require a better place for calling the tree execution, so it can be passed a scene pointer.

Modified Paths:
--------------
    branches/particles-2010/source/blender/blenkernel/BKE_node.h
    branches/particles-2010/source/blender/modifiers/CMakeLists.txt
    branches/particles-2010/source/blender/modifiers/intern/MOD_nodetree.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_get_data.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_if.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_program.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_set_data.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

Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-09-05 07:08:21 UTC (rev 31762)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-09-05 09:50:24 UTC (rev 31763)
@@ -64,6 +64,7 @@
 struct Tex;
 struct uiLayout;
 
+struct SimDataContext;
 struct SimExecData;
 struct SimNodeStack;
 struct SimSocketStack;
@@ -120,7 +121,8 @@
 	int (*sim_opexecfunc)(struct SimNodeThreadContext *ctx, struct bNode *node, int level, int *r_opsock);
 
 	const char *cl_source;
-	int (*enqueue)(struct SimExecData *execdata, struct SimNodeStack *node, int oplevel);
+	void (*enqueue)(struct SimExecData *execdata, struct SimNodeStack *node, struct SimDataContext *self);
+	void (*enqueue_op)(struct SimExecData *execdata, struct SimNodeStack *node, struct SimDataContext *self, int execlevel, int *pushop);
 } bNodeType;
 
 /* node->exec, now in use for composites (#define for break is same as ready yes) */
@@ -560,9 +562,7 @@
 #define SIM_NODE_DEBUGPRINT			801
 
 /* API */
-/* can't use RNA in modifiers, stupid ... */
-//void ntreeSimulationExecTree(struct bNodeTree *ntree, struct PointerRNA *self, float frame, float dframe, float time, float dtime);
-void ntreeSimulationExecTree(struct bNodeTree *ntree, struct ID *self, float frame, float dframe, float time, float dtime);
+void ntreeSimulationExecTree(struct bNodeTree *ntree, struct PointerRNA *self, float frame, float dframe, float time, float dtime);
 
 struct StructRNA *simnode_getdata_get_type(struct bNode *node);
 void simnode_getdata_set_type(struct bNodeTree *ntree, struct bNode *node, struct StructRNA *type);

Modified: branches/particles-2010/source/blender/modifiers/CMakeLists.txt
===================================================================
--- branches/particles-2010/source/blender/modifiers/CMakeLists.txt	2010-09-05 07:08:21 UTC (rev 31762)
+++ branches/particles-2010/source/blender/modifiers/CMakeLists.txt	2010-09-05 09:50:24 UTC (rev 31763)
@@ -30,6 +30,7 @@
 	. ./intern
 	../blenlib
 	../makesdna
+	../makesrna
 	../blenkernel
 	../blenkernel/intern
 	../render/extern/include

Modified: branches/particles-2010/source/blender/modifiers/intern/MOD_nodetree.c
===================================================================
--- branches/particles-2010/source/blender/modifiers/intern/MOD_nodetree.c	2010-09-05 07:08:21 UTC (rev 31762)
+++ branches/particles-2010/source/blender/modifiers/intern/MOD_nodetree.c	2010-09-05 09:50:24 UTC (rev 31763)
@@ -43,9 +43,8 @@
 #include "MOD_modifiertypes.h"
 #include "MEM_guardedalloc.h"
 
-/* TODO why is RNA access prohibited for modifiers? */
-//#include "RNA_access.h"
-//#include "RNA_types.h"
+#include "RNA_access.h"
+#include "RNA_types.h"
 
 static void initData(ModifierData *md)
 {
@@ -90,11 +89,10 @@
 		return;
 	
 	if(ob->data && ntmd->nodetree) {
-//		PointerRNA self;
+		PointerRNA self;
 		
-//		RNA_id_pointer_create((ID*)ob->data, &self);
-//		ntreeSimulationExecTree(ntmd->nodetree, self, md->scene->r.cfra, 1.0f, md->scene->r.cfra, 1.0f);
-		ntreeSimulationExecTree(ntmd->nodetree, (ID*)ob->data, md->scene->r.cfra, 1.0f, md->scene->r.cfra, 1.0f);
+		RNA_id_pointer_create((ID*)ob->data, &self);
+		ntreeSimulationExecTree(ntmd->nodetree, &self, md->scene->r.cfra, 1.0f, md->scene->r.cfra, 1.0f);
 	}
 
 #if 0

Modified: branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_get_data.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_get_data.c	2010-09-05 07:08:21 UTC (rev 31762)
+++ branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_get_data.c	2010-09-05 09:50:24 UTC (rev 31763)
@@ -129,16 +129,14 @@
 	bNodeSocket *pathsock= node->inputs.first;
 	
 	if (pathsock->link == 0) {
-		PointerRNA curptr, ptr;
-		PropertyRNA *prop;
-		int index, resolved;
+		SimDataContext ctx;
+		int resolved;
 		
 		/* The "self" pointer is only defined at runtime, so we can only check absolute paths here */
-		RNA_main_pointer_create(G.main, &curptr);
+		resolved = sim_context_path_resolve(NULL, pathsock->default_string, &ctx);
 		
-		resolved = RNA_path_resolve_full(&curptr, pathsock->default_string, &ptr, &prop, &index);
-		if (resolved && !prop) {
-			simnode_getdata_set_type(ntree, node, ptr.type);
+		if (resolved) {
+			simnode_getdata_set_type(ntree, node, sim_context_type(&ctx));
 		}
 		else {
 			/* assuming the path is relative to self context */
@@ -152,26 +150,155 @@
 //static const char *cl_source= OPENCL_STRINGIFY(
 //);
 
-static int cl_enqueue(SimExecData *execdata, SimNodeStack *node, int execlevel)
+static void enqueue_output(SimExecData *execdata, SimDataContext *ctx, SimSocketStack *out)
 {
 	cl_int res;
+	int datasize = sim_get_data_size(out->type);
+
+	/* set the context
+	 * Note: the context for GetData node sockets is set by the path explicitely
+	 */
+	out->context = *ctx;
+	
+	if (sim_context_is_collection(ctx)) {
+		int totdata = RNA_property_collection_length(&ctx->ptr, ctx->prop);
+		CollectionPropertyIterator iter;
+		cl_mem pinned_outmem;
+		void *outbuf, *cur;
+		
+		/* create output data buffer */
+		out->data = clCreateBuffer(execdata->context, CL_MEM_READ_ONLY, totdata * datasize, NULL, &res);
+		
+		/* TODO this intermediate buffer prevents us from enqueueing a big pile of single copy kernels.
+		 * It would be better to make use of raw arrays to copy data, but this does not work for paged data (particles!)
+		 * More flexible support for paged data collections (and other partially arrayed data) would be helpful.
+		 * See also SetData node
+		 */
+		
+		/* create intermediate pinned-memory buffer (see NVIDIA OpenCL best practices guide, section 3.1.1) */
+		pinned_outmem = clCreateBuffer(execdata->context, CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR, totdata * datasize, NULL, &res);
+		/* map to host memory pointer */
+		outbuf = clEnqueueMapBuffer(execdata->queue, pinned_outmem, CL_TRUE, CL_MAP_WRITE, 0, totdata * datasize, 0, NULL, NULL, &res);
+		/* iterate over collection and copy data */
+		RNA_property_collection_begin(&ctx->ptr, ctx->prop, &iter);
+		cur = outbuf;
+		switch (out->type) {
+		case SOCK_FLOAT:
+			while (iter.valid) {
+				*(float*)cur = RNA_property_float_get(&iter.ptr, (PropertyRNA*)out->base->nodedata);
+				cur = (char*)cur + datasize;
+				RNA_property_collection_next(&iter);
+			}
+			break;
+		case SOCK_INT:
+			while (iter.valid) {
+				*(int*)cur = RNA_property_int_get(&iter.ptr, (PropertyRNA*)out->base->nodedata);
+				cur = (char*)cur + datasize;
+				RNA_property_collection_next(&iter);
+			}
+			break;
+		case SOCK_BOOL:
+			while (iter.valid) {
+				*(char*)cur = (char)RNA_property_boolean_get(&iter.ptr, (PropertyRNA*)out->base->nodedata);
+				cur = (char*)cur + datasize;
+				RNA_property_collection_next(&iter);
+			}
+			break;
+		case SOCK_VECTOR:
+			while (iter.valid) {
+				RNA_property_float_get_array(&iter.ptr, (PropertyRNA*)out->base->nodedata, (float*)cur);
+				cur = (char*)cur + datasize;
+				RNA_property_collection_next(&iter);
+			}
+			break;
+		case SOCK_RGBA:
+			while (iter.valid) {
+				RNA_property_float_get_array(&iter.ptr, (PropertyRNA*)out->base->nodedata, (float*)cur);
+				cur = (char*)cur + datasize;
+				RNA_property_collection_next(&iter);
+			}
+			break;
+		case SOCK_STRING:
+			while (iter.valid) {
+				RNA_property_string_get(&iter.ptr, (PropertyRNA*)out->base->nodedata, (char*)cur);
+				cur = (char*)cur + datasize;
+				RNA_property_collection_next(&iter);
+			}
+			break;
+		}
+		RNA_property_collection_end(&iter);
+		clEnqueueUnmapMemObject(execdata->queue, pinned_outmem, outbuf, 0, NULL, NULL);
+		res = clReleaseMemObject(pinned_outmem);
+	}
+	else {
+		char buf[SIM_MAXDATASIZE];
+		
+		/* create output data buffer */
+		out->data = clCreateBuffer(execdata->context, CL_MEM_READ_ONLY, datasize, NULL, &res);
+		
+		switch (out->type) {
+		case SOCK_FLOAT:
+			*(float*)buf = RNA_property_float_get(&ctx->ptr, (PropertyRNA*)out->base->nodedata);
+			break;
+		case SOCK_INT:
+			*(int*)buf = RNA_property_int_get(&ctx->ptr, (PropertyRNA*)out->base->nodedata);
+			break;
+		case SOCK_BOOL:
+			*(char*)buf = (char)RNA_property_boolean_get(&ctx->ptr, (PropertyRNA*)out->base->nodedata);
+			break;
+		case SOCK_VECTOR:
+			RNA_property_float_get_array(&ctx->ptr, (PropertyRNA*)out->base->nodedata, (float*)buf);
+			break;
+		case SOCK_RGBA:
+			RNA_property_float_get_array(&ctx->ptr, (PropertyRNA*)out->base->nodedata, (float*)buf);
+			break;
+		case SOCK_STRING:
+			RNA_property_string_get(&ctx->ptr, (PropertyRNA*)out->base->nodedata, (char*)buf);
+			break;
+		}
+		
+		res = clEnqueueWriteBuffer(execdata->queue, out->data, CL_FALSE, 0, datasize, buf, 0, NULL, &out->event);
+	}
+}
+
+static void cl_enqueue(SimExecData *execdata, SimNodeStack *node, SimDataContext *self)
+{
+	cl_int res;
+	size_t stringsize= sim_get_data_size(SOCK_STRING);
 	char path[SIM_STRINGLENGTH];
-	size_t stringsize= sim_get_data_size(SOCK_STRING);
+	SimDataContext ctx;
+	int resolved;
 	
-	/* read the path input to determine the data context (blocking read!) */
+	/* copy the path socket to the output */
+	node->outstack[0].data = clCreateBuffer(execdata->context, CL_MEM_READ_WRITE, stringsize, NULL, &res);
+	if (res != CL_SUCCESS)
+		printf("Error creating data path output buffer in %s: %s\n", node->base->name, BKE_opencl_message(res));
+	res = clEnqueueCopyBuffer(execdata->queue, node->instack[0]->data, node->outstack[0].data, 0, 0, stringsize, node->totin, node->event_wait_list, &node->outstack[0].event);
+	if (res != CL_SUCCESS)
+		printf("Error copying data path in %s: %s\n", node->base->name, BKE_opencl_message(res));
+	
+	/* read the path input to determine the data context (blocking read, we immediately need the path!) */
 	res = clEnqueueReadBuffer(execdata->queue, node->instack[0]->data, CL_TRUE, 0, stringsize, path, 0, NULL, NULL);
 	if (res != CL_SUCCESS)
 		printf("Error reading data path in %s: %s\n", node->base->name, BKE_opencl_message(res));
 	
-	node->outstack[0].data = clCreateBuffer(execdata->context, CL_MEM_READ_WRITE, stringsize, NULL, &res);
-	if (res == CL_SUCCESS) {
-		res = clEnqueueCopyBuffer(execdata->queue, node->instack[0]->data, node->outstack[0].data, 0, 0, stringsize, node->totin, node->event_wait_list, &node->outstack[0].event);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list