[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32228] branches/particles-2010/source/ blender/nodes/intern/simulation: Simplification: removed the SimBuffer struct that wrapped the OpenCL buffers.
Lukas Toenne
lukas.toenne at googlemail.com
Fri Oct 1 14:50:49 CEST 2010
Revision: 32228
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32228
Author: lukastoenne
Date: 2010-10-01 14:50:49 +0200 (Fri, 01 Oct 2010)
Log Message:
-----------
Simplification: removed the SimBuffer struct that wrapped the OpenCL buffers. These are now directly in the socket instance structs, which simplifies code a lot by avoiding duplicate socket type read/write functions. Access to buffers outside of kernels can use higher level functions now, which streamlines node definitions.
Modified Paths:
--------------
branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.c
branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.h
branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.c
branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.h
branches/particles-2010/source/blender/nodes/intern/simulation/node_tree_simulation.c
branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_get_data.c
branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_if.c
branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_math.c
branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_set_data.c
branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_subprogram.c
Modified: branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.c 2010-10-01 12:25:18 UTC (rev 32227)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.c 2010-10-01 12:50:49 UTC (rev 32228)
@@ -117,3 +117,20 @@
MEM_freeN(task->data);
MEM_freeN(task);
}
+
+#ifdef WITH_OPENCL
+cl_event *sim_create_cl_event_list(int num_events, struct SimEvent *events)
+{
+
+ if (num_events > 0) {
+ cl_event *events_cl;
+ int i;
+ events_cl = MEM_callocN(num_events * sizeof(cl_event), "events_cl");
+ for (i=0; i < num_events; ++i)
+ events_cl[i] = events[i].impl_cl;
+ return events_cl;
+ }
+ else
+ return NULL;
+}
+#endif
Modified: branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.h
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.h 2010-10-01 12:25:18 UTC (rev 32227)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.h 2010-10-01 12:50:49 UTC (rev 32228)
@@ -93,4 +93,8 @@
void sim_finish_task(struct SimExecData *execdata, struct SimTask *task);
void sim_free_task(struct SimExecData *execdata, struct SimTask *task);
+#ifdef WITH_OPENCL
+cl_event *sim_create_cl_event_list(int num_events, struct SimEvent *events);
#endif
+
+#endif
Modified: branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.c 2010-10-01 12:25:18 UTC (rev 32227)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.c 2010-10-01 12:50:49 UTC (rev 32228)
@@ -264,6 +264,52 @@
return 1;
}
+int sim_node_get_max_context(struct SimSocketStack **instack, int totin, struct SimDataContext *r_max)
+{
+ SimDataContext res, *ctx;
+ int i;
+
+ res.scene = NULL;
+ RNA_pointer_create(NULL, NULL, NULL, &res.ptr);
+ res.prop = NULL;
+ res.key = 0;
+ res.size = 0;
+
+ for (i=0; i < totin; ++i) {
+ ctx = &instack[i]->context;
+ if (ctx->prop && RNA_property_type(ctx->prop) == PROP_COLLECTION) {
+ if (res.prop && RNA_property_type(res.prop) == PROP_COLLECTION) {
+ if (ctx->scene == res.scene
+ && ctx->ptr.data == res.ptr.data
+ && ctx->prop == res.prop
+ && ctx->key == res.key) {
+ res = *ctx;
+ }
+ else {
+ r_max->scene = NULL;
+ RNA_pointer_create(NULL, NULL, NULL, &r_max->ptr);
+ r_max->prop = NULL;
+ r_max->key = 0;
+ r_max->size = 0;
+ return 0;
+ }
+ }
+ else {
+ res = *ctx;
+ }
+ }
+ else {
+ if (res.prop && RNA_property_type(res.prop) == PROP_COLLECTION) {
+ }
+ else {
+ res = *ctx;
+ }
+ }
+ }
+ *r_max = res;
+ return 1;
+}
+
SimEventStatus sim_get_event_status(SimEvent *event)
{
#ifdef WITH_OPENCL
@@ -323,625 +369,556 @@
}
}
-int sim_buffer_valid(struct SimBuffer *buffer)
+#if 0 /* OpenCL 1.1 specs */
+SimEvent sim_create_user_event(struct SimExecData *execdata)
{
-#ifdef WITH_OPENCL
- if (BKE_opencl_is_active()) {
- cl_mem_object_type buftype;
- cl_int res= clGetMemObjectInfo(buffer->data_cl, CL_MEM_TYPE, sizeof(cl_mem_object_type), &buftype, NULL);
- if (res == CL_SUCCESS)
- return 1;
- else if (res == CL_INVALID_MEM_OBJECT)
- return 0;
- else {
- printf("Error querying OpenCL buffer info: %s", BKE_opencl_message(res));
- return 0;
- }
+ cl_int res;
+ SimEvent event;
+
+ if (execdata->error)
+ return;
+
+ event = clCreateUserEvent(execdata->context, &res);
+ if (res != CL_SUCCESS) {
+ execdata->error = 1;
+ sprintf(execdata->error_string, "Error creating OpenCL user event: %s", BKE_opencl_message(res));
}
- else {
-#endif
- return (buffer->data != NULL && buffer->stride > 0);
-#ifdef WITH_OPENCL
- }
-#endif
+ return event;
}
-SimBuffer sim_create_buffer(SimExecData *execdata, SimBufferMode mode, int datatype, int total)
+void sim_set_user_event_status(SimEvent event, SimEventStatus status)
{
- SimBuffer buf;
+ cl_int res;
+
if (execdata->error)
- return buf;
+ return;
+ res = clSetUserEventStatus(event, status);
+ if (res != CL_SUCCESS) {
+ execdata->error = 1;
+ sprintf(execdata->error_string, "Error setting OpenCL user event status: %s", BKE_opencl_message(res));
+ }
+}
+#endif
+
+
+static void init_socket_buffer(SimExecData *execdata, SimSocketStack *sock)
+{
#ifdef WITH_OPENCL
if (BKE_opencl_is_active()) {
cl_int res;
- size_t datasize = sim_get_data_size(datatype);
- buf.datatype = datatype;
- buf.stride = datasize;
-
- if (datasize > 0 && total > 0) {
- buf.data_cl = clCreateBuffer(execdata->opencl_context, mode, total * datasize, NULL, &res);
+ size_t datasize = sim_get_data_size(sock->type);
+ if (datasize > 0 && sock->context.size > 0) {
+ sock->data_cl = clCreateBuffer(execdata->opencl_context, CL_MEM_READ_WRITE, sock->context.size * datasize, NULL, &res);
if (res != CL_SUCCESS) {
execdata->error = 1;
sprintf(execdata->error_string, "Error creating OpenCL buffer: %s", BKE_opencl_message(res));
}
}
-
- return buf;
}
else
#endif
{
- int datasize = sim_get_data_size(datatype);
- buf.datatype = datatype;
- buf.stride = datasize;
-
- if (datasize > 0 && total > 0) {
- buf.data = MEM_callocN(datasize * total, "SimBuffer data");
+ size_t datasize = sim_get_data_size(sock->type);
+ if (datasize > 0 && sock->context.size > 0) {
+ sock->data = MEM_callocN(datasize * sock->context.size, "socket data");
}
else {
- buf.data = NULL;
-
- execdata->error = 1;
- sprintf(execdata->error_string, "Error creating buffer: zero datasize or number of elements.");
+ sock->data = NULL;
}
-
- return buf;
}
}
-SimBuffer sim_create_buffer_copy(SimExecData *execdata, SimBufferMode mode, int datatype, int total, void *src)
+static void free_socket_buffer(SimExecData *execdata, SimSocketStack *sock)
{
- SimBuffer buf;
if (execdata->error)
- return buf;
+ return;
#ifdef WITH_OPENCL
if (BKE_opencl_is_active()) {
cl_int res;
- size_t datasize = sim_get_data_size(datatype);
- buf.datatype = datatype;
- buf.stride = datasize;
-
- if (datasize > 0 && total > 0) {
- buf.data_cl = clCreateBuffer(execdata->opencl_context, mode | CL_MEM_COPY_HOST_PTR, total * datasize, src, &res);
+ cl_uint refcount;
+ res = clGetMemObjectInfo(sock->data_cl, CL_MEM_REFERENCE_COUNT, sizeof(cl_uint), &refcount, NULL);
+ if (res == CL_SUCCESS && refcount > 0) {
+ clReleaseMemObject(sock->data_cl);
if (res != CL_SUCCESS) {
execdata->error = 1;
- sprintf(execdata->error_string, "Error creating OpenCL buffer copy: %s", BKE_opencl_message(res));
+ sprintf(execdata->error_string, "Error releasing OpenCL buffer: %s", BKE_opencl_message(res));
}
}
-
- return buf;
}
else
#endif
{
- int datasize = sim_get_data_size(datatype);
- buf.datatype = datatype;
- buf.stride = datasize;
-
- if (datasize > 0 && total > 0) {
- buf.data = MEM_callocN(datasize * total, "SimBuffer data");
-
- memcpy(buf.data, src, datasize * total);
+ if (sock->data) {
+ MEM_freeN(sock->data);
}
- else {
- buf.data = NULL;
-
- execdata->error = 1;
- sprintf(execdata->error_string, "Error creating buffer copy: zero datasize or number of elements.");
- }
-
- return buf;
}
}
-SimBuffer sim_create_host_buffer(SimExecData *execdata, SimBufferMode mode, int datatype, int total)
+void sim_node_init_default_data(SimExecData *execdata, SimSocketStack *input, SimDataContext *ctx)
{
- SimBuffer buf;
if (execdata->error)
- return buf;
+ return;
-#ifdef WITH_OPENCL
- if (BKE_opencl_is_active()) {
- cl_int res;
- size_t datasize = sim_get_data_size(datatype);
- buf.datatype = datatype;
- buf.stride = datasize;
-
- if (datasize > 0 && total > 0) {
- buf.data_cl = clCreateBuffer(execdata->opencl_context, mode | CL_MEM_ALLOC_HOST_PTR, total * datasize, NULL, &res);
- if (res != CL_SUCCESS) {
- execdata->error = 1;
- sprintf(execdata->error_string, "Error creating OpenCL host buffer: %s", BKE_opencl_message(res));
- }
- }
-
- return buf;
- }
- else
-#endif
- {
- int datasize = sim_get_data_size(datatype);
- buf.datatype = datatype;
- buf.stride = datasize;
-
- if (datasize > 0 && total > 0) {
- buf.data = MEM_callocN(datasize * total, "SimBuffer data");
- }
- else {
- buf.data = NULL;
-
- execdata->error = 1;
- sprintf(execdata->error_string, "Error creating host buffer: zero datasize or number of elements.");
- }
-
- return buf;
- }
+ input->context = *ctx;
+
+ init_socket_buffer(execdata, input);
}
-void sim_release_buffer(SimExecData *execdata, SimBuffer *buffer)
+void sim_node_free_default_data(SimExecData *execdata, SimSocketStack *input)
{
if (execdata->error)
return;
-
-#ifdef WITH_OPENCL
- if (BKE_opencl_is_active()) {
- cl_int res;
- res = clReleaseMemObject(buffer->data_cl);
- if (res != CL_SUCCESS) {
- execdata->error = 1;
- sprintf(execdata->error_string, "Error releasing OpenCL buffer: %s", BKE_opencl_message(res));
- }
- }
- else
-#endif
- {
- if (buffer->data) {
- MEM_freeN(buffer->data);
- buffer->data = NULL;
- }
- }
+ free_socket_buffer(execdata, input);
}
-void *sim_enqueue_map_buffer(SimExecData *execdata, SimBuffer *buffer, int blocking, SimMapMode mode, int start, int num, int num_wait_events, SimEvent *wait_events, SimEvent *event)
+int sim_node_init_output(SimExecData *execdata, SimSocketStack *output, SimDataContext *ctx)
{
if (execdata->error)
- return NULL;
+ return 0;
+ output->context = *ctx;
+
+ if (output->branches == 0)
+ return 0;
+
+ init_socket_buffer(execdata, output);
+ return 1;
+}
+
+void sim_node_free_output(SimExecData *execdata, SimSocketStack *output)
+{
+ if (execdata->error)
+ return;
+ free_socket_buffer(execdata, output);
+}
+
+void sim_input_begin(SimExecData *execdata, SimSocketStack *sock, SimSocketIterator *iter)
+{
+ iter->valid = 1;
+ if (execdata->error) {
+ iter->valid = 0;
+ return;
+ }
+ iter->sock = sock;
+ iter->stride = sim_get_data_size(sock->type);
+ /* total = -1 for singleton context is used for validity check */
+ iter->total = (sim_context_is_collection(&sock->context) ? sock->context.size : -1);
+ if (iter->stride > 0) {
#ifdef WITH_OPENCL
- if (BKE_opencl_is_active()) {
- cl_int res;
- cl_event *wait_events_cl;
- void *mapped;
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list