Depsgraph: Avoid hash lookup for every evaluated scene query

Cache pointer to evaluated scene datablock on relations build time,
that pointer never changes after that.
This commit is contained in:
2018-04-25 14:58:19 +02:00
parent a9d3f9f54d
commit 09da47b67a
4 changed files with 11 additions and 4 deletions

View File

@@ -102,7 +102,8 @@ Depsgraph::Depsgraph(Scene *scene,
scene(scene),
view_layer(view_layer),
mode(mode),
ctime(BKE_scene_frame_get(scene))
ctime(BKE_scene_frame_get(scene)),
scene_cow(NULL)
{
BLI_spin_init(&lock);
id_hash = BLI_ghash_ptr_new("Depsgraph id hash");

View File

@@ -197,6 +197,11 @@ struct Depsgraph {
/* Time at which dependency graph is being or was last evaluated. */
float ctime;
/* Evaluated version of datablocks we access a lot.
* Stored here to save us form doing hash lookup.
*/
Scene *scene_cow;
};
} // namespace DEG

View File

@@ -260,6 +260,9 @@ void DEG_graph_build_from_view_layer(Depsgraph *graph,
/* Relations are up to date. */
deg_graph->need_update = false;
/* Store pointers to commonly used valuated datablocks. */
deg_graph->scene_cow = (Scene *)deg_graph->get_cow_id(&deg_graph->scene->id);
if (need_on_visible_update) {
DEG_graph_on_visible_update(bmain, graph);
}

View File

@@ -105,9 +105,7 @@ Scene *DEG_get_evaluated_scene(const Depsgraph *graph)
{
const DEG::Depsgraph *deg_graph =
reinterpret_cast<const DEG::Depsgraph *>(graph);
Scene *scene_orig = deg_graph->scene;
Scene *scene_cow =
reinterpret_cast<Scene *>(deg_graph->get_cow_id(&scene_orig->id));
Scene *scene_cow = deg_graph->scene_cow;
/* TODO(sergey): Shall we expand datablock here? Or is it OK to assume
* that calleer is OK with just a pointer in case scene is not up[dated
* yet?