[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24242] branches/bmesh/blender/source/ blender: bmesh compile fixes
Joseph Eagar
joeedh at gmail.com
Mon Nov 2 15:45:12 CET 2009
Revision: 24242
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24242
Author: joeedh
Date: 2009-11-02 15:45:12 +0100 (Mon, 02 Nov 2009)
Log Message:
-----------
bmesh compile fixes
Modified Paths:
--------------
branches/bmesh/blender/source/blender/blenkernel/BKE_key.h
branches/bmesh/blender/source/blender/blenkernel/intern/key.c
branches/bmesh/blender/source/blender/blenkernel/intern/node.c
branches/bmesh/blender/source/blender/editors/mesh/bmeshutils.c
Added Paths:
-----------
branches/bmesh/blender/source/blender/render/intern/source/rayobject_blibvh.c
branches/bmesh/blender/source/blender/render/intern/source/rayobject_instance.c
branches/bmesh/blender/source/blender/render/intern/source/rayobject_octree.c
branches/bmesh/blender/source/blender/render/intern/source/rayobject_raycounter.c
Modified: branches/bmesh/blender/source/blender/blenkernel/BKE_key.h
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/BKE_key.h 2009-11-02 14:03:13 UTC (rev 24241)
+++ branches/bmesh/blender/source/blender/blenkernel/BKE_key.h 2009-11-02 14:45:12 UTC (rev 24242)
@@ -47,8 +47,10 @@
#endif
void free_key(struct Key *sc);
+void free_key_nolib(struct Key *key);
struct Key *add_key(struct ID *id);
struct Key *copy_key(struct Key *key);
+struct Key *copy_key_nolib(struct Key *key);
void make_local_key(struct Key *key);
void sort_keys(struct Key *key);
Modified: branches/bmesh/blender/source/blender/blenkernel/intern/key.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/key.c 2009-11-02 14:03:13 UTC (rev 24241)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/key.c 2009-11-02 14:45:12 UTC (rev 24242)
@@ -96,6 +96,20 @@
}
+void free_key_nolib(Key *key)
+{
+ KeyBlock *kb;
+
+ while( (kb= key->block.first) ) {
+
+ if(kb->data) MEM_freeN(kb->data);
+
+ BLI_remlink(&key->block, kb);
+ MEM_freeN(kb);
+ }
+
+}
+
/* GS reads the memory pointed at in a specific ordering. There are,
* however two definitions for it. I have jotted them down here, both,
* but I think the first one is actually used. The thing is that
@@ -182,6 +196,32 @@
return keyn;
}
+
+Key *copy_key_nolib(Key *key)
+{
+ Key *keyn;
+ KeyBlock *kbn, *kb;
+
+ if(key==0) return 0;
+
+ keyn= MEM_dupallocN(key);
+
+ BLI_duplicatelist(&keyn->block, &key->block);
+
+ kb= key->block.first;
+ kbn= keyn->block.first;
+ while(kbn) {
+
+ if(kbn->data) kbn->data= MEM_dupallocN(kbn->data);
+ if(kb==key->refkey) keyn->refkey= kbn;
+
+ kbn= kbn->next;
+ kb= kb->next;
+ }
+
+ return keyn;
+}
+
void make_local_key(Key *key)
{
Modified: branches/bmesh/blender/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/node.c 2009-11-02 14:03:13 UTC (rev 24241)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/node.c 2009-11-02 14:45:12 UTC (rev 24242)
@@ -1927,4 +1927,1247 @@
bNode *node;
bNodeSocket *sock;
- for(node= ntree->
\ No newline at end of file
+ for(node= ntree->nodes.first; node; node= node->next) {
+
+ /* initialize needed for groups */
+ node->exec= 0;
+
+ if(is_group==0) {
+ for(sock= node->outputs.first; sock; sock= sock->next) {
+ bNodeStack *ns= ntree->stack + sock->stack_index;
+
+ if(sock->ns.data) {
+ ns->data= sock->ns.data;
+ sock->ns.data= NULL;
+ }
+ }
+ }
+ /* cannot initialize them while using in threads */
+ if(ELEM3(node->type, CMP_NODE_TIME, CMP_NODE_CURVE_VEC, CMP_NODE_CURVE_RGB)) {
+ curvemapping_initialize(node->storage);
+ if(node->type==CMP_NODE_CURVE_RGB)
+ curvemapping_premultiply(node->storage, 0);
+ }
+ if(node->type==NODE_GROUP)
+ composit_begin_exec((bNodeTree *)node->id, 1);
+
+ }
+}
+
+/* copy stack compbufs to sockets */
+static void composit_end_exec(bNodeTree *ntree, int is_group)
+{
+ extern void print_compbuf(char *str, struct CompBuf *cbuf);
+ bNode *node;
+ bNodeStack *ns;
+ int a;
+
+ for(node= ntree->nodes.first; node; node= node->next) {
+ if(is_group==0) {
+ bNodeSocket *sock;
+
+ for(sock= node->outputs.first; sock; sock= sock->next) {
+ ns= ntree->stack + sock->stack_index;
+ if(ns->data) {
+ sock->ns.data= ns->data;
+ ns->data= NULL;
+ }
+ }
+ }
+ if(node->type==CMP_NODE_CURVE_RGB)
+ curvemapping_premultiply(node->storage, 1);
+
+ if(node->type==NODE_GROUP)
+ composit_end_exec((bNodeTree *)node->id, 1);
+
+ node->need_exec= 0;
+ }
+
+ if(is_group==0) {
+ /* internally, group buffers are not stored */
+ for(ns= ntree->stack, a=0; a<ntree->stacksize; a++, ns++) {
+ if(ns->data) {
+ printf("freed leftover buffer from stack\n");
+ free_compbuf(ns->data);
+ ns->data= NULL;
+ }
+ }
+ }
+}
+
+static void group_tag_used_outputs(bNode *gnode, bNodeStack *stack)
+{
+ bNodeTree *ntree= (bNodeTree *)gnode->id;
+ bNode *node;
+
+ stack+= gnode->stack_index;
+
+ for(node= ntree->nodes.first; node; node= node->next) {
+ if(node->typeinfo->execfunc) {
+ bNodeSocket *sock;
+
+ for(sock= node->inputs.first; sock; sock= sock->next) {
+ if(sock->intern) {
+ if(sock->link) {
+ bNodeStack *ns= stack + sock->link->fromsock->stack_index;
+ ns->hasoutput= 1;
+ ns->sockettype= sock->link->fromsock->type;
+ }
+ else
+ sock->ns.sockettype= sock->type;
+ }
+ }
+ }
+ }
+}
+
+/* notes below are ancient! (ton) */
+/* stack indices make sure all nodes only write in allocated data, for making it thread safe */
+/* only root tree gets the stack, to enable instances to have own stack entries */
+/* per tree (and per group) unique indices are created */
+/* the index_ext we need to be able to map from groups to the group-node own stack */
+
+typedef struct bNodeThreadStack {
+ struct bNodeThreadStack *next, *prev;
+ bNodeStack *stack;
+ int used;
+} bNodeThreadStack;
+
+static bNodeThreadStack *ntreeGetThreadStack(bNodeTree *ntree, int thread)
+{
+ ListBase *lb= &ntree->threadstack[thread];
+ bNodeThreadStack *nts;
+
+ for(nts=lb->first; nts; nts=nts->next) {
+ if(!nts->used) {
+ nts->used= 1;
+ return nts;
+ }
+ }
+ nts= MEM_callocN(sizeof(bNodeThreadStack), "bNodeThreadStack");
+ nts->stack= MEM_dupallocN(ntree->stack);
+ nts->used= 1;
+ BLI_addtail(lb, nts);
+
+ return nts;
+}
+
+static void ntreeReleaseThreadStack(bNodeThreadStack *nts)
+{
+ nts->used= 0;
+}
+
+/* free texture delegates */
+static void tex_end_exec(bNodeTree *ntree)
+{
+ bNodeThreadStack *nts;
+ bNodeStack *ns;
+ int th, a;
+
+ if(ntree->threadstack)
+ for(th=0; th<BLENDER_MAX_THREADS; th++)
+ for(nts=ntree->threadstack[th].first; nts; nts=nts->next)
+ for(ns= nts->stack, a=0; a<ntree->stacksize; a++, ns++)
+ if(ns->data)
+ MEM_freeN(ns->data);
+
+}
+
+void ntreeBeginExecTree(bNodeTree *ntree)
+{
+ /* let's make it sure */
+ if(ntree->init & NTREE_EXEC_INIT)
+ return;
+
+ /* allocate the thread stack listbase array */
+ if(ntree->type!=NTREE_COMPOSIT)
+ ntree->threadstack= MEM_callocN(BLENDER_MAX_THREADS*sizeof(ListBase), "thread stack array");
+
+ /* goes recursive over all groups */
+ ntree->stacksize= ntree_begin_exec_tree(ntree);
+
+ if(ntree->stacksize) {
+ bNode *node;
+ bNodeStack *ns;
+ int a;
+
+ /* allocate the base stack */
+ ns=ntree->stack= MEM_callocN(ntree->stacksize*sizeof(bNodeStack), "node stack");
+
+ /* tag inputs, the get_stack() gives own socket stackdata if not in use */
+ for(a=0; a<ntree->stacksize; a++, ns++) ns->hasinput= 1;
+
+ /* tag used outputs, so we know when we can skip operations */
+ for(node= ntree->nodes.first; node; node= node->next) {
+ bNodeSocket *sock;
+
+ /* composite has own need_exec tag handling */
+ if(ntree->type!=NTREE_COMPOSIT)
+ node->need_exec= 1;
+
+ for(sock= node->inputs.first; sock; sock= sock->next) {
+ if(sock->link) {
+ ns= ntree->stack + sock->link->fromsock->stack_index;
+ ns->hasoutput= 1;
+ ns->sockettype= sock->link->fromsock->type;
+ }
+ else
+ sock->ns.sockettype= sock->type;
+
+ if(sock->link) {
+ bNodeLink *link= sock->link;
+ /* this is the test for a cyclic case */
+ if(link->fromnode && link->tonode) {
+ if(link->fromnode->level >= link->tonode->level && link->tonode->level!=0xFFF);
+ else {
+ node->need_exec= 0;
+ }
+ }
+ }
+ }
+
+ if(node->type==NODE_GROUP && node->id)
+ group_tag_used_outputs(node, ntree->stack);
+
+ }
+
+ if(ntree->type==NTREE_COMPOSIT)
+ composit_begin_exec(ntree, 0);
+ }
+
+ ntree->init |= NTREE_EXEC_INIT;
+}
+
+void ntreeEndExecTree(bNodeTree *ntree)
+{
+
+ if(ntree->init & NTREE_EXEC_INIT) {
+ bNodeThreadStack *nts;
+ int a;
+
+ /* another callback candidate! */
+ if(ntree->type==NTREE_COMPOSIT)
+ composit_end_exec(ntree, 0);
+ else if(ntree->type==NTREE_TEXTURE)
+ tex_end_exec(ntree);
+
+ if(ntree->stack) {
+ MEM_freeN(ntree->stack);
+ ntree->stack= NULL;
+ }
+
+ if(ntree->threadstack) {
+ for(a=0; a<BLENDER_MAX_THREADS; a++) {
+ for(nts=ntree->threadstack[a].first; nts; nts=nts->next)
+ if (nts->stack) MEM_freeN(nts->stack);
+ BLI_freelistN(&ntree->threadstack[a]);
+ }
+
+ MEM_freeN(ntree->threadstack);
+ ntree->threadstack= NULL;
+ }
+
+ ntree->init &= ~NTREE_EXEC_INIT;
+ }
+}
+
+static void node_get_stack(bNode *node, bNodeStack *stack, bNodeStack **in, bNodeStack **out)
+{
+ bNodeSocket *sock;
+
+ /* build pointer stack */
+ for(sock= node->inputs.first; sock; sock= sock->next) {
+ if(sock->link)
+ *(in++)= stack + sock->link->fromsock->stack_index;
+ else
+ *(in++)= &sock->ns;
+ }
+
+ for(sock= node->outputs.first; sock; sock= sock->next) {
+ *(out++)= stack + sock->stack_index;
+ }
+}
+
+/* nodes are presorted, so exec is in order of list */
+void ntreeExecTree(bNodeTree *ntree, void *callerdata, int thread)
+{
+ bNode *node;
+ bNodeStack *nsin[MAX_SOCKET]; /* arbitrary... watch this */
+ bNodeStack *nsout[MAX_SOCKET]; /* arbitrary... watch this */
+ bNodeStack *stack;
+ bNodeThreadStack *nts = NULL;
+
+ /* only when initialized */
+ if((ntree->init & NTREE_EXEC_INIT)==0)
+ ntreeBeginExecTree(ntree);
+
+ /* composite does 1 node per thread, so no multiple stacks needed */
+ if(ntree->type==NTREE_COMPOSIT) {
+ stack= ntree->stack;
+ }
+ else {
+ nts= ntreeGetThreadStack(ntree, thread);
+ stack= nts->stack;
+ }
+
+ for(node= ntree->nodes.first; node; node= node->next) {
+ if(node->need_exec) {
+ if(node->typeinfo->execfunc) {
+ node_get_stack(node, stack, nsin, nsout);
+ node->typeinfo->execfunc(callerdata, node, nsin, nsout);
+ }
+ else if(node->type==NODE_GROUP && node->id) {
+ node_get_stack(node, stack, nsin, nsout);
+ node_group_execute(stack, callerdata, node, nsin, nsout);
+ }
+ }
+ }
+
+ if(nts)
+ ntreeReleaseThreadStack(nts);
+}
+
+
+/* ***************************** threaded version for execute composite nodes ************* */
+/* these are nodes without input, only giving values */
+/* or nodes with only value inputs */
+static int node_only_value(bNode *node)
+{
+ bNodeSocket *sock;
+
+ if(ELEM3(node->type, CMP_NODE_TIME, CMP_NODE_VALUE, CMP_NODE_RGB))
+ return 1;
+
+ /* doing this for all node types goes wrong. memory free errors */
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list