[Bf-blender-cvs] [bb3c8af] strand_nodes: Depsgraph integration for hair strand nodes (horrible).

Lukas Tönne noreply at git.blender.org
Sat Jul 23 17:29:32 CEST 2016


Commit: bb3c8afb77a820c4204c5b8fc296f637b9d2c42a
Author: Lukas Tönne
Date:   Sat Jul 23 17:24:35 2016 +0200
Branches: strand_nodes
https://developer.blender.org/rBbb3c8afb77a820c4204c5b8fc296f637b9d2c42a

Depsgraph integration for hair strand nodes (horrible).

The depsgraph now invalidates the strand shader when the nodes are changed.
As mentioned in the previous commit, this happens through an operation in
the object GEOMETRY component for each strand modifier. This is messy, only
useful until we have truly granular modifier integration in the depsgraph.

Invalidating the shader is currently done just by setting a flag. The actual
freeing and subsequent lazy-rebuild of the shader is done in the drawing
thread, because during the threaded depsgraph update we don't have a valid
OpenGL context. This needs to be sorted out for future viewport recode.

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

M	source/blender/blenkernel/BKE_strands.h
M	source/blender/blenkernel/intern/strands.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
M	source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M	source/blender/depsgraph/intern/depsgraph_type_defines.cc
M	source/blender/depsgraph/intern/depsgraph_types.h
M	source/blender/editors/space_view3d/drawstrands.c
M	source/blender/makesdna/DNA_modifier_types.h

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

diff --git a/source/blender/blenkernel/BKE_strands.h b/source/blender/blenkernel/BKE_strands.h
index cdfb8ef..3a71ed9 100644
--- a/source/blender/blenkernel/BKE_strands.h
+++ b/source/blender/blenkernel/BKE_strands.h
@@ -99,4 +99,13 @@ void BKE_strands_invalidate_shader(struct Strands *strands);
 struct GPUStrandsConverter *BKE_strands_get_gpu_converter(struct Strands *strands, struct DerivedMesh *root_dm,
                                                           int subdiv, int fiber_primitive, bool use_geomshader);
 
+/* ------------------------------------------------------------------------- */
+/* Depsgraph Update */
+
+struct EvaluationContext;
+struct Object;
+struct StrandsModifierData;
+
+void BKE_strands_shader_update(struct EvaluationContext *eval_ctx, struct Object *ob, struct StrandsModifierData *smd);
+
 #endif
diff --git a/source/blender/blenkernel/intern/strands.c b/source/blender/blenkernel/intern/strands.c
index 056c48b..63b1d0f 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -37,6 +37,8 @@
 #include "BLI_math.h"
 #include "BLI_rand.h"
 
+#include "DNA_modifier_types.h"
+
 #include "BKE_DerivedMesh.h"
 #include "BKE_mesh_sample.h"
 #include "BKE_strands.h"
@@ -582,7 +584,6 @@ void BKE_strands_invalidate_shader(Strands *strands)
 	}
 }
 
-
 /* gpu buffer conversion */
 
 typedef struct DNAStrandsConverter {
@@ -737,3 +738,12 @@ GPUStrandsConverter *BKE_strands_get_gpu_converter(Strands *strands, struct Deri
 	conv->strands = strands;
 	return (GPUStrandsConverter *)conv;
 }
+
+/* ------------------------------------------------------------------------- */
+
+void BKE_strands_shader_update(struct EvaluationContext *UNUSED(eval_ctx), struct Object *UNUSED(ob), StrandsModifierData *smd)
+{
+	if (smd->strands) {
+		smd->tag |= MOD_STRANDS_TAG_UPDATE_SHADER;
+	}
+}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 9f5741b..8376a6f 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5269,6 +5269,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
 				direct_link_strands(fd, smd->strands);
 			}
 			
+			smd->tag = 0;
 			smd->edit = NULL;
 			smd->gpu_buffer = NULL;
 			
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
index 9c0f88a..80e7d20 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
@@ -88,6 +88,7 @@ extern "C" {
 #include "BKE_particle.h"
 #include "BKE_rigidbody.h"
 #include "BKE_sound.h"
+#include "BKE_strands.h"
 #include "BKE_texture.h"
 #include "BKE_tracking.h"
 #include "BKE_world.h"
@@ -1035,6 +1036,14 @@ void DepsgraphNodeBuilder::build_obdata_geom(Main *bmain, Scene *scene, Object *
 				NodeBuilderHandle handle(this);
 				mti->updateDepsgraph(md, bmain, scene, ob, &handle.base);
 			}
+			
+			/* XXX placeholder operation until the future granularity design is sorted out */
+			if (md->type == eModifierType_Strands) {
+				StrandsModifierData *smd = (StrandsModifierData *)md;
+				add_operation_node(&ob->id, DEPSNODE_TYPE_GEOMETRY,
+				                   DEPSOP_TYPE_EXEC, function_bind(BKE_strands_shader_update, _1, ob, smd),
+				                   DEG_OPCODE_GEOMETRY_STRANDS_SHADER, md->name);
+			}
 		}
 	}
 
@@ -1135,6 +1144,7 @@ void DepsgraphNodeBuilder::build_obdata_geom(Main *bmain, Scene *scene, Object *
 
 	if (ob->nodetree) {
 		NodeBuilderHandle handle(this);
+		BVM_nodetree_compile_dependencies(ob->nodetree, &handle.base);
 		BVM_nodetree_eval_dependencies(ob->nodetree, &handle.base);
 	}
 
@@ -1230,10 +1240,12 @@ void DepsgraphNodeBuilder::build_nodetree(DepsNode *owner_node, bNodeTree *ntree
 
 	// TODO: link from nodetree to owner_component?
 
+#if 0
 	add_operation_node(ntree_id, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_POST, function_bind(BVM_function_bvm_cache_remove, ntree),
 	                   DEG_OPCODE_NTREE_BVM_FUNCTION_INVALIDATE, "BVM function invalidate");
 	NodeBuilderHandle handle(this);
 	BVM_nodetree_compile_dependencies(ntree, &handle.base);
+#endif
 }
 
 /* Recursively build graph for material */
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
index 17d36c9..31124f5 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
@@ -1753,6 +1753,29 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje
 				}
 			}
 
+			/* XXX placeholder operation until the future granularity design is sorted out */
+			if (md->type == eModifierType_Strands) {
+				OperationKey shader_update_key(&ob->id, DEPSNODE_TYPE_GEOMETRY,
+				                               DEG_OPCODE_GEOMETRY_STRANDS_SHADER, md->name);
+				RelationBuilderHandle strands_handle(this, find_node(shader_update_key));
+				
+				if (ob->nodetree) {
+					bNode *node;
+					for (node = (bNode *)ob->nodetree->nodes.first; node; node = node->next) {
+						if (STREQ(node->idname, "HairNode") && node->id) {
+							bNodeTree *hair_ntree = (bNodeTree *)node->id;
+							ComponentKey node_key(&hair_ntree->id, DEPSNODE_TYPE_PARAMETERS);
+							
+							/* invalidate the strands shader when nodes are changed */
+							add_relation(node_key, shader_update_key,
+							             DEPSREL_TYPE_COMPONENT_ORDER, "NTree Invalidation");
+							/* custom invalidation through internal dependencies */
+							BVM_nodetree_compile_dependencies(hair_ntree, &strands_handle.base);
+						}
+					}
+				}
+			}
+
 			prev_mod_key = mod_key;
 		}
 	}
@@ -1879,9 +1902,14 @@ void DepsgraphRelationBuilder::build_obdata_geom(Main *bmain, Scene *scene, Obje
 		 * not the overall object node tree!
 		 * Currently there is no good way of accessing these internal nodes.
 		 */
+#if 0
 		OperationKey bvm_invalidate_key(&ob->nodetree->id, DEPSNODE_TYPE_PARAMETERS,
 		                                DEG_OPCODE_NTREE_BVM_FUNCTION_INVALIDATE, "BVM function invalidate");
 		add_relation(bvm_invalidate_key, obdata_geom_eval_key, DEPSREL_TYPE_GEOMETRY_EVAL, "NTree->Object Geometry");
+#else
+		ComponentKey nodetree_key(&ob->nodetree->id, DEPSNODE_TYPE_PARAMETERS);
+		add_relation(nodetree_key, obdata_geom_eval_key, DEPSREL_TYPE_GEOMETRY_EVAL, "NTree->Object Geometry");
+#endif
 		RelationBuilderHandle handle(this, find_node(obdata_geom_eval_key));
 		BVM_nodetree_eval_dependencies(ob->nodetree, &handle.base);
 	}
@@ -1988,6 +2016,7 @@ void DepsgraphRelationBuilder::build_nodetree(ID *owner, bNodeTree *ntree)
 		             DEPSREL_TYPE_COMPONENT_ORDER, "NTree Parameters");
 	}
 
+#if 0
 	OperationKey bvm_invalidate_key(ntree_id,
 	                                DEPSNODE_TYPE_PARAMETERS,
 	                                DEG_OPCODE_NTREE_BVM_FUNCTION_INVALIDATE,
@@ -1998,6 +2027,7 @@ void DepsgraphRelationBuilder::build_nodetree(ID *owner, bNodeTree *ntree)
 	/* custom invalidation through internal dependencies */
 	RelationBuilderHandle handle(this, find_node(bvm_invalidate_key));
 	BVM_nodetree_compile_dependencies(ntree, &handle.base);
+#endif
 
 	// TODO: link from nodetree to owner_component?
 }
diff --git a/source/blender/depsgraph/intern/depsgraph_type_defines.cc b/source/blender/depsgraph/intern/depsgraph_type_defines.cc
index 4ce9151..d33bd7a 100644
--- a/source/blender/depsgraph/intern/depsgraph_type_defines.cc
+++ b/source/blender/depsgraph/intern/depsgraph_type_defines.cc
@@ -116,6 +116,7 @@ static const char *stringify_opcode(eDepsOperation_Code opcode)
 		STRINGIFY_OPCODE(GEOMETRY_UBEREVAL);
 		STRINGIFY_OPCODE(GEOMETRY_MODIFIER);
 		STRINGIFY_OPCODE(GEOMETRY_PATH);
+		STRINGIFY_OPCODE(GEOMETRY_STRANDS_SHADER);
 		STRINGIFY_OPCODE(POSE_INIT);
 		STRINGIFY_OPCODE(POSE_DONE);
 		STRINGIFY_OPCODE(POSE_IK_SOLVER);
@@ -129,6 +130,10 @@ static const char *stringify_opcode(eDepsOperation_Code opcode)
 		STRINGIFY_OPCODE(BONE_READY);
 		STRINGIFY_OPCODE(BONE_DONE);
 		STRINGIFY_OPCODE(PSYS_EVAL);
+		STRINGIFY_OPCODE(TEXTURE_INIT);
+		STRINGIFY_OPCODE(TEXTURE_INVALIDATE);
+		STRINGIFY_OPCODE(IMAGE_INIT);
+		STRINGIFY_OPCODE(NTREE_BVM_FUNCTION_INVALIDATE);
 
 		case DEG_NUM_OPCODES: return "SpecialCase";
 #undef STRINGIFY_OPCODE
diff --git a/source/blender/depsgraph/intern/depsgraph_types.h b/source/blender/depsgraph/intern/depsgraph_types.h
index a015719..44333b7 100644
--- a/source/blender/depsgraph/intern/depsgraph_types.h
+++ b/source/blender/depsgraph/intern/depsgraph_types.h
@@ -192,6 +192,7 @@ typedef enum eDepsOperation_Code {
 
 	/* Modifier */
 	DEG_OPCODE_GEOMETRY_MODIFIER,
+	DEG_OPCODE_GEOMETRY_STRANDS_SHADER,
 
 	/* Curve Objects - Path Calculation (used for path-following tools, */
 	DEG_OPCODE_GEOMETRY_PATH,
diff --git a/source/blender/editors/space_view3d/drawstrands.c b/source/blender/editors/space_view3d/drawstrands.c
index 3dfe049..a74361c 100644
--- a/source/blender/editors/space_view3d/drawstrands.c
+++ b/source/blender/editors/space_view3d/drawstrands.c
@@ -140,6 +140,8 @@ void draw_strands(Scene *scene, View3D *UNUSED(v3d), RegionView3D *rv3d,
 		smd->gpu_buffer = GPU_strands_buffer_create(converter);
 	GPUDrawStrands *buffer = smd->gpu_buffer;
 	
+	if (smd->tag & MOD_STRANDS_TAG_UPDATE_SHADER)
+		BKE_strands_invalidate_shader(smd->strands);
 	if (!strands->gpu_shader) {
 		GPUStrandsShaderParams shader_params;
 		shader_params.fiber_primitive = fiber_primitive;
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index bf607f6..5024e8c 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1547,6 +1547,7 @@ typedef struct StrandsModifierData {
 	ModifierData modifier;
 	
 	int flag;
+	int tag;
 	int num_fibers;
 	int seed;
 	int subdiv;
@@ -1554,7 +1555,6 @@ typedef struct StrandsModifierData {
 	int shader_model;
 	int fiber_primitive;
 	float ribbon_width;
-	int pad;
 	
 	struct Strands *strands;
 	
@@ -1578,6 +1578,11 @@ enum {
 	MOD_STRANDS_USE_GEO

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list