[Bf-blender-cvs] [0fdc0f8bbdd] blender2.8: Depsgraph: Introduce hash of dependency graphs in the scene level

Sergey Sharybin noreply at git.blender.org
Fri Oct 20 12:48:50 CEST 2017


Commit: 0fdc0f8bbddf2913e784f4abc75972c76cabcc3a
Author: Sergey Sharybin
Date:   Fri Oct 20 12:28:25 2017 +0200
Branches: blender2.8
https://developer.blender.org/rB0fdc0f8bbddf2913e784f4abc75972c76cabcc3a

Depsgraph: Introduce hash of dependency graphs in the scene level

The idea is following: we do need to have multiple dependency graphs to denote
different scene layers (depsgraph should only contain objects from a specific
scene layer), and we also want to support same scene layer to be evaluated to
a different state in different windows. In order to achieve that we do need to
have a list or hash (for faster lookup presumably) somewhere. To keep things
easier for now, it will be a scene which owns that hash. This seems to make
sense anyway, since dependency graph only points to data which is owned by
scene.

This commit only introduces some basic API and hash itself stored in DNA, there
is no changes in behavior. See this as a first step towards getting rid of
scene-global dependency graph.

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

M	source/blender/blenkernel/BKE_scene.h
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/makesdna/DNA_scene_types.h

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

diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h
index b31cd1742a2..8e2e37bf39a 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -215,6 +215,10 @@ void        BKE_scene_multiview_videos_dimensions_get(const struct RenderData *r
 int         BKE_scene_multiview_num_videos_get(const struct RenderData *rd);
 
 /* depsgraph */
+void BKE_scene_allocate_depsgraph_hash(struct Scene *scene);
+void BKE_scene_ensure_depsgraph_hash(struct Scene *scene);
+void BKE_scene_free_depsgraph_hash(struct Scene *scene);
+
 struct Depsgraph *BKE_scene_get_depsgraph(struct Scene *scene, struct SceneLayer *scene_layer);
 
 #ifdef __cplusplus
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index c320f3d2a6c..8b53425d343 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -238,6 +238,7 @@ void BKE_scene_copy_data(Main *bmain, Scene *sce_dst, const Scene *sce_src, cons
 
 	sce_dst->ed = NULL;
 	sce_dst->depsgraph_legacy = NULL;
+	sce_dst->depsgraph_hash = NULL;
 	sce_dst->obedit = NULL;
 	sce_dst->fps_info = NULL;
 
@@ -661,7 +662,7 @@ void BKE_scene_free_ex(Scene *sce, const bool do_id_user)
 		sce->toolsettings = NULL;
 	}
 	
-	DEG_scene_graph_free(sce);
+	BKE_scene_free_depsgraph_hash(sce);
 
 	MEM_SAFE_FREE(sce->fps_info);
 
@@ -2401,6 +2402,72 @@ int BKE_scene_multiview_num_videos_get(const RenderData *rd)
 	}
 }
 
+/* Manipulation of depsgraph storage. */
+
+/* This is a key which identifies depsgraph. */
+typedef struct DepsgraphKey {
+	SceneLayer *scene_layer;
+	/* TODO(sergey): Need to include window somehow (same layer might be in a
+	 * different states in different windows).
+	 */
+} DepsgraphKey;
+
+static unsigned int depsgraph_key_hash(const void *key_v)
+{
+	const DepsgraphKey *key = key_v;
+	unsigned int hash = BLI_ghashutil_ptrhash(key->scene_layer);
+	/* TODO(sergey): Include hash from other fields in the key. */
+	return hash;
+}
+
+static bool depsgraph_key_compare(const void *key_a_v, const void *key_b_v)
+{
+	const DepsgraphKey *key_a = key_a_v;
+	const DepsgraphKey *key_b = key_b_v;
+	/* TODO(sergey): Compare rest of  */
+	return !(key_a->scene_layer == key_b->scene_layer);
+}
+
+static void depsgraph_key_free(void *key_v)
+{
+	DepsgraphKey *key = key_v;
+	MEM_freeN(key);
+}
+
+static void depsgraph_key_value_free(void *value)
+{
+	Depsgraph *depsgraph = value;
+	DEG_graph_free(depsgraph);
+}
+
+void BKE_scene_allocate_depsgraph_hash(Scene *scene)
+{
+	scene->depsgraph_hash = BLI_ghash_new(depsgraph_key_hash,
+	                                      depsgraph_key_compare,
+	                                      "Scene Depsgraph Hash");
+}
+
+void BKE_scene_ensure_depsgraph_hash(Scene *scene)
+{
+	if (scene->depsgraph_hash == NULL) {
+		BKE_scene_allocate_depsgraph_hash(scene);
+	}
+}
+
+void BKE_scene_free_depsgraph_hash(Scene *scene)
+{
+	/* TODO(sergey): Keep this for until we get rid of depsgraph_legacy. */
+	DEG_scene_graph_free(scene);
+	if (scene->depsgraph_hash == NULL) {
+		return;
+	}
+	BLI_ghash_free(scene->depsgraph_hash,
+	               depsgraph_key_free,
+	               depsgraph_key_value_free);
+}
+
+/* Query depsgraph for a specific contexts. */
+
 Depsgraph *BKE_scene_get_depsgraph(Scene *scene, SceneLayer *scene_layer)
 {
 	(void) scene_layer;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index e56218b7c90..c0580660e2b 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6095,6 +6095,7 @@ static void direct_link_scene(FileData *fd, Scene *sce, Main *bmain)
 	SceneRenderLayer *srl;
 	
 	sce->depsgraph_legacy = NULL;
+	sce->depsgraph_hash = NULL;
 	sce->obedit = NULL;
 	sce->fps_info = NULL;
 	sce->customdata_mask_modal = 0;
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index ec885cb198c..68599a10a3e 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1655,7 +1655,9 @@ typedef struct Scene {
 	
 	/* none of the dependency graph  vars is mean to be saved */
 	struct Depsgraph *depsgraph_legacy;
-	float pad3;
+	struct GHash *depsgraph_hash;
+	void *pad3;
+	int pad7;
 
 	/* User-Defined KeyingSets */
 	int active_keyingset;			/* index of the active KeyingSet. first KeyingSet has index 1, 'none' active is 0, 'add new' is -1 */



More information about the Bf-blender-cvs mailing list