[Bf-blender-cvs] [bed76fe] object_nodes: Removed global data from the compile process, this should only be needed for eval.

Lukas Tönne noreply at git.blender.org
Thu Dec 10 15:21:37 CET 2015


Commit: bed76fe57069c3585e862a9db428d7e72426da8c
Author: Lukas Tönne
Date:   Thu Dec 10 15:17:54 2015 +0100
Branches: object_nodes
https://developer.blender.org/rBbed76fe57069c3585e862a9db428d7e72426da8c

Removed global data from the compile process, this should only be needed for eval.

Global data is used primarily for blend_data pointers (objects primarily).
These should not be stored directly inside the function instructions,
but should be stored by a key (hash value) and resolved at eval time.

===================================================================

M	release/scripts/nodes/common_nodes.py
M	release/scripts/nodes/node_compiler.py
M	source/blender/blenkernel/intern/DerivedMesh.c
M	source/blender/blenkernel/intern/effect.c
M	source/blender/blenvm/BVM_api.h
M	source/blender/blenvm/intern/bvm_api.cc
M	source/blender/makesrna/intern/rna_blenvm.c
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/makesrna/intern/rna_object_api.c
M	source/blender/makesrna/intern/rna_texture_api.c

===================================================================

diff --git a/release/scripts/nodes/common_nodes.py b/release/scripts/nodes/common_nodes.py
index 7b752f7..75f53f5 100644
--- a/release/scripts/nodes/common_nodes.py
+++ b/release/scripts/nodes/common_nodes.py
@@ -42,8 +42,8 @@ def enum_property_value_prop(name):
 ###############################################################################
 
 class NodeTreeBase():
-    def bvm_compile(self, context, graph):
-        compiler = NodeCompiler(context, graph)
+    def bvm_compile(self, graph):
+        compiler = NodeCompiler(graph)
         self.compile_nodes(compiler)
 
     def compile_nodes(self, compiler):
diff --git a/release/scripts/nodes/node_compiler.py b/release/scripts/nodes/node_compiler.py
index 2f5e596..e084f31 100644
--- a/release/scripts/nodes/node_compiler.py
+++ b/release/scripts/nodes/node_compiler.py
@@ -79,8 +79,7 @@ class NodeWrapper:
 
 # Compiler class for converting nodes
 class NodeCompiler:
-    def __init__(self, context, graph):
-        self.context = context
+    def __init__(self, graph):
         self.graph = graph
         self.bnode_stack = []
 
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index aaf6e56..4b09247 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -1708,20 +1708,18 @@ static DerivedMesh *mesh_calc_modifier_nodes(Scene *UNUSED(scene), Object *ob, b
 	Mesh *me = ob->data;
 	DerivedMesh *dm, *result;
 	
-	struct BVMEvalGlobals *globals = BVM_globals_create();
-	
-	struct BVMFunction *fn = BVM_gen_modifier_function(globals, ob, ntree, NULL);
+	struct BVMFunction *fn = BVM_gen_modifier_function(ob, ntree, NULL);
 	
 	{
+		struct BVMEvalGlobals *globals = BVM_globals_create();
 		struct BVMEvalContext *context = BVM_context_create();
-		dm = BVM_eval_modifier(context, fn, me);
+		dm = BVM_eval_modifier(globals, context, fn, me);
 		BVM_context_free(context);
+		BVM_globals_free(globals);
 	}
 	
 	BVM_function_free(fn);
 	
-	BVM_globals_free(globals);
-	
 	/* XXX this is stupid, but currently required because of
 	 * the unreliability of dm->needsFree ...
 	 * This flag gets set in places to force freeing of meshes, can't expect this to work
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index 683d404..4083d60 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -213,7 +213,7 @@ static void add_object_nodes_to_effectors(EffectorContext *effctx, Scene *scene,
 				
 				if (ff_ntree) {
 					EffectorCache *eff = new_effector_cache(effctx, scene, ob, NULL, ob->pd);
-					eff->function = BVM_gen_forcefield_function(effctx->eval_globals, ff_ntree);
+					eff->function = BVM_gen_forcefield_function(ff_ntree, NULL);
 				}
 				
 				break;
diff --git a/source/blender/blenvm/BVM_api.h b/source/blender/blenvm/BVM_api.h
index d1e64b1..e9e1b0b 100644
--- a/source/blender/blenvm/BVM_api.h
+++ b/source/blender/blenvm/BVM_api.h
@@ -52,15 +52,12 @@ void BVM_function_free(struct BVMFunction *fn);
 
 /* ------------------------------------------------------------------------- */
 
-struct BVMCompileContext;
 struct BVMNodeGraph;
 struct BVMNodeInstance;
 struct BVMNodeInput;
 struct BVMNodeOutput;
 struct BVMTypeDesc;
 
-int BVM_compile_get_object_index(struct BVMCompileContext *context, struct Object *ob);
-
 struct BVMNodeInstance *BVM_nodegraph_add_node(struct BVMNodeGraph *graph, const char *type, const char *name);
 
 void BVM_nodegraph_get_input(struct BVMNodeGraph *graph, const char *name,
@@ -112,7 +109,7 @@ struct bNodeTree;
 struct Object;
 struct EffectedPoint;
 
-struct BVMFunction *BVM_gen_forcefield_function(const struct BVMEvalGlobals *globals, struct bNodeTree *btree);
+struct BVMFunction *BVM_gen_forcefield_function(struct bNodeTree *btree, FILE *debug_file);
 
 void BVM_eval_forcefield(struct BVMEvalGlobals *globals, struct BVMEvalContext *context, struct BVMFunction *fn,
                          struct Object *effob, const struct EffectedPoint *point, float force[3], float impulse[3]);
@@ -122,8 +119,7 @@ void BVM_eval_forcefield(struct BVMEvalGlobals *globals, struct BVMEvalContext *
 struct Tex;
 struct TexResult;
 
-struct BVMFunction *BVM_gen_texture_function(const struct BVMEvalGlobals *globals, struct Tex *tex,
-                                                 struct bNodeTree *btree, FILE *debug_file);
+struct BVMFunction *BVM_gen_texture_function(struct Tex *tex, struct bNodeTree *btree, FILE *debug_file);
 
 void BVM_eval_texture(struct BVMEvalContext *context, struct BVMFunction *fn,
                       struct TexResult *target,
@@ -140,11 +136,9 @@ void BVM_texture_cache_clear(void);
 struct DerivedMesh;
 struct Mesh;
 
-struct BVMFunction *BVM_gen_modifier_function(const struct BVMEvalGlobals *globals,
-                                              struct Object *ob, struct bNodeTree *btree,
-                                              FILE *debug_file);
+struct BVMFunction *BVM_gen_modifier_function(struct Object *ob, struct bNodeTree *btree, FILE *debug_file);
 
-struct DerivedMesh *BVM_eval_modifier(struct BVMEvalContext *context, struct BVMFunction *fn, struct Mesh *base_mesh);
+struct DerivedMesh *BVM_eval_modifier(struct BVMEvalGlobals *globals, struct BVMEvalContext *context, struct BVMFunction *fn, struct Mesh *base_mesh);
 
 /* ------------------------------------------------------------------------- */
 
diff --git a/source/blender/blenvm/intern/bvm_api.cc b/source/blender/blenvm/intern/bvm_api.cc
index e1c4639..89f7965 100644
--- a/source/blender/blenvm/intern/bvm_api.cc
+++ b/source/blender/blenvm/intern/bvm_api.cc
@@ -237,47 +237,11 @@ void BVM_context_free(struct BVMEvalContext *ctx)
 
 /* ------------------------------------------------------------------------- */
 
-struct CompileContext {
-	typedef std::map<struct Object *, int> ObjectPtrMap;
-	
-	ObjectPtrMap obmap;
-	
-	CompileContext(const bvm::EvalGlobals *globals)
-	{
-		for (int i = 0; i < globals->objects.size(); ++i)
-			obmap[globals->objects[i]] = i;
-	}
-	
-	int get_object_index(Object *ob)
-	{
-		ObjectPtrMap::const_iterator it = obmap.find(ob);
-		if (it != obmap.end())
-			return it->second;
-		else
-			return -1;
-	}
-
-	MEM_CXX_CLASS_ALLOC_FUNCS("BVM:CompileContext")
-};
-
-inline static CompileContext *_COMP(BVMCompileContext *c)
-{
-	return (CompileContext *)c;
-}
-
-int BVM_compile_get_object_index(BVMCompileContext *context, Object *ob)
-{
-	return _COMP(context)->get_object_index(ob);
-}
-
-/* ------------------------------------------------------------------------- */
-
-static void parse_py_nodes(CompileContext *_context, bNodeTree *btree, bvm::NodeGraph *graph)
+static void parse_py_nodes(bNodeTree *btree, bvm::NodeGraph *graph)
 {
 	PointerRNA ptr;
 	ParameterList list;
 	FunctionRNA *func;
-	BVMCompileContext *context = (BVMCompileContext *)_context;
 	
 	RNA_id_pointer_create((ID *)btree, &ptr);
 	
@@ -286,14 +250,13 @@ static void parse_py_nodes(CompileContext *_context, bNodeTree *btree, bvm::Node
 		return;
 	
 	RNA_parameter_list_create(&list, &ptr, func);
-	RNA_parameter_set_lookup(&list, "context", &context);
 	RNA_parameter_set_lookup(&list, "graph", &graph);
 	btree->typeinfo->ext.call(NULL, &ptr, func, &list);
 	
 	RNA_parameter_list_free(&list);
 }
 
-struct BVMFunction *BVM_gen_forcefield_function(const struct BVMEvalGlobals *globals, bNodeTree *btree)
+struct BVMFunction *BVM_gen_forcefield_function(bNodeTree *btree, FILE *debug_file)
 {
 	using namespace bvm;
 	
@@ -308,10 +271,13 @@ struct BVMFunction *BVM_gen_forcefield_function(const struct BVMEvalGlobals *glo
 		graph.add_output("impulse", BVM_FLOAT3, zero);
 	}
 	
-	CompileContext comp(_GLOBALS(globals));
-	parse_py_nodes(&comp, btree, &graph);
+	parse_py_nodes(btree, &graph);
 	graph.finalize();
 	
+	if (debug_file) {
+		debug::dump_graphviz(debug_file, &graph, "Force Field Graph");
+	}
+	
 	BVMCompiler compiler;
 	Function *fn = compiler.compile_function(graph);
 	
@@ -776,7 +742,7 @@ static void convert_tex_node(bNodeCompiler *comp, PointerRNA *bnode_ptr)
 
 } /* namespace bvm */
 
-static void parse_tex_nodes(CompileContext */*_context*/, bNodeTree *btree, bvm::NodeGraph *graph)
+static void parse_tex_nodes(bNodeTree *btree, bvm::NodeGraph *graph)
 {
 	using namespace bvm;
 	
@@ -803,8 +769,7 @@ static void parse_tex_nodes(CompileContext */*_context*/, bNodeTree *btree, bvm:
 }
 
 
-struct BVMFunction *BVM_gen_texture_function(const struct BVMEvalGlobals *globals, struct Tex */*tex*/,
-                                                 bNodeTree *btree, FILE *debug_file)
+struct BVMFunction *BVM_gen_texture_function(struct Tex */*tex*/, bNodeTree *btree, FILE *debug_file)
 {
 	using namespace bvm;
 	
@@ -821,8 +786,7 @@ struct BVMFunction *BVM_gen_texture_function(const struct BVMEvalGlobals *global
 		graph.add_output("color", BVM_FLOAT4, C);
 		graph.add_output("normal", BVM_FLOAT3, N);
 	}
-	CompileContext comp(_GLOBALS(globals));
-	parse_tex_nodes(&comp, btree, &graph);
+	parse_tex_nodes(btree, &graph);
 	graph.finalize();
 	
 	if (debug_file) {
@@ -885,9 +849,7 @@ struct BVMFunction *BVM_texture_cache_acquire(Tex *tex)
 		return (BVMFunction *)it->second;
 	}
 	else if (tex->use_nodes && tex->nodetree) {
-		EvalGlobals globals;
-		
-		BVMFunction *fn = BVM_gen_texture_function((BVMEvalGlobals *)(&globals), tex, tex->nodetree, NULL);
+		BVMFunction *fn = BVM_gen_texture_function(tex, tex->nodetree, NULL);
 		
 		bvm_tex_cache[tex] = _FUNC(fn);
 		
@@ -929,9 +891,7 @@ void BVM_texture_cache_clear(void)
 
 /* ------------------------------------------------------------------------- */
 
-struct BVMFunction *BVM_gen_modifier_function(const struct BVMEvalGlobals *globals,
-                                              struct Object *ob, struct bNodeTree *btree,
-                                              FILE *debug_file)
+struct BVMFunction *BVM_gen_modifier_function(struct Object */*ob*/, struct bNodeTree *btree, FILE *debug_file)
 {
 	using namespace bvm;
 	
@@ -942,8 +902,7 @@ struct BVMFunction *BVM_gen_modifier_function(const struct BVMEvalGlobals *globa
 	graph.add_input("modifier

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list