[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32148] branches/particles-2010/source/ blender/nodes/intern/simulation: As the default execution method (no OpenCL ) the simulation trees now have a custom command queue implementation.
Lukas Toenne
lukas.toenne at googlemail.com
Mon Sep 27 12:36:02 CEST 2010
Revision: 32148
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32148
Author: lukastoenne
Date: 2010-09-27 12:36:02 +0200 (Mon, 27 Sep 2010)
Log Message:
-----------
As the default execution method (no OpenCL) the simulation trees now have a custom command queue implementation. the host threads is responsible for enqueueing tasks into the command queue. worker threads then pick a task from the queue and perform work for a number of work items of this task. this is hidden beneath a set of wrapper functions to allow node coders creating nodes for both CPU and OpenCL with minimal effort.
Also added 2 new files to keep internals out of the way of node coders (only SIM_util.h should be necessary).
Modified Paths:
--------------
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
Added Paths:
-----------
branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.c
branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.h
Added: branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.c (rev 0)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.c 2010-09-27 10:36:02 UTC (rev 32148)
@@ -0,0 +1,166 @@
+/**
+ *
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "SIM_internal.h"
+
+#include <assert.h>
+#include <ctype.h>
+
+#include "DNA_ID.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_node_types.h"
+
+#include "BLI_threads.h"
+
+#include "BKE_main.h"
+#include "BKE_node.h"
+#include "BKE_particleset.h"
+
+#include "RNA_access.h"
+
+#ifdef WITH_OPENCL
+
+const char *cl_string_funcs = STRINGIFY(
+//size_t strlen(const char *str)
+//{
+// const char *end= str;
+// while (*end != '\0')
+// ++end;
+// return (end - str);
+//}
+
+//char *strcpy(char *destination, const char *source)
+//{
+// while (*source != '\0') {
+// *destination = *source;
+// ++source;
+// ++destination;
+// }
+// *destination = '\0';
+// return destination;
+//}
+);
+
+/* note: can't use stringify here because of precompiler definitions */
+const char *cl_socket_macros =
+"#define CONVERT_FLOAT_FLOAT(x) (x)\n"
+"#define CONVERT_FLOAT_INT(x) (float)(x)\n"
+"#define CONVERT_FLOAT_BOOL(x) (float)(x)\n"
+"#define CONVERT_INT_FLOAT(x) (int)(x)\n"
+"#define CONVERT_INT_INT(x) (x)\n"
+"#define CONVERT_INT_BOOL(x) (int)(x)\n"
+"#define CONVERT_BOOL_FLOAT(x) (char)((int)(x) % 2)\n"
+"#define CONVERT_BOOL_INT(x) (char)((x) % 2)\n"
+"#define CONVERT_BOOL_BOOL(x) (x)\n"
+"#define CONVERT_VECTOR_VECTOR(x) (x)\n"
+"#define CONVERT_RGBA_RGBA(x) (x)\n"
+"#define CONVERT_STRING_STRING(x) (x)\n";
+
+const char *cl_socket_funcs = STRINGIFY(
+size_t get_socket_id(int size)
+{
+ return (get_global_id(0) % (size_t)size);
+}
+);
+
+#endif
+
+void sim_init_event(SimEvent *event)
+{
+ event->impl = MEM_callocN(sizeof(SimTaskEvent), "SimTaskEvent");
+ event->impl->status = SIM_QUEUED;
+}
+
+void sim_free_event(SimEvent *event)
+{
+ if (event->impl)
+ MEM_freeN(event->impl);
+}
+
+static int task_ready(SimTask *task)
+{
+ int i;
+ for (i=0; i < task->num_wait_events; ++i)
+ if (sim_get_event_status(task->wait_events + i) != SIM_COMPLETE)
+ break;
+ return (i >= task->num_wait_events);
+}
+
+SimTask *sim_enqueue_task(SimExecData *execdata, SimTaskFunction execfunc, void *data, int totitems, int workgroupsize, int num_wait_events, SimEvent *wait_events, SimEvent *event)
+{
+ SimTask *task= MEM_callocN(sizeof(SimTask), "SimTask");
+ task->data = data;
+ task->execfunc = execfunc;
+ task->totitems = totitems;
+ task->workgroupsize = (workgroupsize > 0 ? workgroupsize : execdata->default_workgroupsize);
+ task->startitem = 0;
+ task->num_wait_events = num_wait_events;
+ if (num_wait_events > 0) {
+ task->wait_events = MEM_callocN(num_wait_events*sizeof(SimEvent), "wait events");
+ memcpy(task->wait_events, wait_events, num_wait_events*sizeof(SimEvent));
+ }
+ else
+ task->wait_events = NULL;
+ sim_init_event(&task->event);
+ if (event)
+ *event = task->event;
+
+ if (task_ready(task))
+ task->event.impl->status = SIM_SUBMITTED;
+ else
+ task->event.impl->status = SIM_QUEUED;
+ BLI_addtail(&execdata->queue, task);
+
+ pthread_cond_signal(&execdata->workercond);
+
+ return task;
+}
+
+void sim_finish_task(SimExecData *execdata, SimTask *task)
+{
+ task->event.impl->status = SIM_COMPLETE;
+ for (task=task->next; task; task = task->next) {
+ if (sim_get_event_status(&task->event) == SIM_QUEUED && task_ready(task)) {
+ /* activate the task */
+ task->event.impl->status = SIM_SUBMITTED;
+ }
+ }
+}
+
+void sim_free_task(SimExecData *execdata, SimTask *task)
+{
+ BLI_remlink(&execdata->queue, task);
+ sim_free_event(&task->event);
+ if (task->wait_events)
+ MEM_freeN(task->wait_events);
+ if (task->data)
+ MEM_freeN(task->data);
+ MEM_freeN(task);
+}
Added: branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.h
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.h (rev 0)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/SIM_internal.h 2010-09-27 10:36:02 UTC (rev 32148)
@@ -0,0 +1,101 @@
+/**
+ *
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef SIM_INTERNAL_H
+#define SIM_INTERNAL_H
+
+#include <math.h>
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_ID.h"
+#include "DNA_node_types.h"
+#include "DNA_particle_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "BKE_blender.h"
+#include "BKE_global.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_node.h"
+#include "BKE_opencl.h"
+#include "BKE_utildefines.h"
+
+#include "BLI_math.h"
+#include "BLI_blenlib.h"
+#include "BLI_gsqueue.h"
+#include "BLI_rand.h"
+#include "BLI_threads.h"
+
+#include "RNA_types.h"
+
+#include "SIM_util.h"
+
+
+/* common OpenCL helper functions */
+extern const char *cl_string_funcs;
+extern const char *cl_socket_funcs;
+extern const char *cl_socket_macros;
+
+struct SimExecData;
+
+typedef struct SimTaskEvent {
+ SimEventStatus status;
+} SimTaskEvent;
+
+typedef void (*SimTaskFunction)(void *data, int start, int total);
+typedef struct SimTask {
+ struct SimTask *next, *prev;
+ int active; /* number of threads working on this task */
+
+ SimEvent *wait_events;
+ int num_wait_events;
+ SimEvent event;
+
+ int totitems, workgroupsize;
+ int startitem; /* starting index for the next worker thread */
+
+ void *data;
+ SimTaskFunction execfunc;
+} SimTask;
+
+typedef struct SimWorkerThread {
+ struct SimExecData *execdata;
+ int num;
+} SimWorkerThread;
+
+void sim_init_event(struct SimEvent *event);
+void sim_free_event(struct SimEvent *event);
+
+struct SimTask *sim_enqueue_task(struct SimExecData *execdata, SimTaskFunction execfunc, void *data, int totitems, int workgroupsize, int num_wait_events, struct SimEvent *wait_events, struct SimEvent *event);
+void sim_finish_task(struct SimExecData *execdata, struct SimTask *task);
+void sim_free_task(struct SimExecData *execdata, struct SimTask *task);
+
+#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-09-27 09:58:37 UTC (rev 32147)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/SIM_util.c 2010-09-27 10:36:02 UTC (rev 32148)
@@ -27,6 +27,7 @@
*/
#include "SIM_util.h"
+#include "SIM_internal.h"
#include <assert.h>
#include <ctype.h>
@@ -37,59 +38,14 @@
#include "DNA_modifier_types.h"
#include "DNA_node_types.h"
+#include "BLI_threads.h"
+
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_particleset.h"
#include "RNA_access.h"
-#ifdef WITH_OPENCL
-
-const char *cl_string_funcs = STRINGIFY(
-//size_t strlen(const char *str)
-//{
-// const char *end= str;
-// while (*end != '\0')
-// ++end;
-// return (end - str);
-//}
-
-//char *strcpy(char *destination, const char *source)
-//{
-// while (*source != '\0') {
-// *destination = *source;
-// ++source;
-// ++destination;
-// }
-// *destination = '\0';
-// return destination;
-//}
-);
-
-/* note: can't use stringify here because of precompiler definitions */
-const char *cl_socket_macros =
-"#define CONVERT_FLOAT_FLOAT(x) (x)\n"
-"#define CONVERT_FLOAT_INT(x) (float)(x)\n"
-"#define CONVERT_FLOAT_BOOL(x) (float)(x)\n"
-"#define CONVERT_INT_FLOAT(x) (int)(x)\n"
-"#define CONVERT_INT_INT(x) (x)\n"
-"#define CONVERT_INT_BOOL(x) (int)(x)\n"
-"#define CONVERT_BOOL_FLOAT(x) (char)((int)(x) % 2)\n"
-"#define CONVERT_BOOL_INT(x) (char)((x) % 2)\n"
-"#define CONVERT_BOOL_BOOL(x) (x)\n"
-"#define CONVERT_VECTOR_VECTOR(x) (x)\n"
-"#define CONVERT_RGBA_RGBA(x) (x)\n"
-"#define CONVERT_STRING_STRING(x) (x)\n";
-
-const char *cl_socket_funcs = STRINGIFY(
-size_t get_socket_id(int size)
-{
- return (get_global_id(0) % (size_t)size);
-}
-);
-
-#endif
-
size_t sim_get_data_size(int datatype)
{
#ifdef WITH_OPENCL
@@ -277,7 +233,65 @@
return 1;
}
+SimEventStatus sim_get_event_status(SimEvent *event)
+{
+#ifdef WITH_OPENCL
+ if (BKE_opencl_is_active()) {
+ cl_int status;
+ clGetEventInfo(event->impl_cl, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(cl_int), &status, NULL);
+ return status;
+ }
+ else
+#endif
+ {
+ return event->impl->status;
+ }
+}
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list