Depsgraph: Remove function bindings with collections

Use single function to evaluate all the collections for the given view layer.

This way we avoid need to get scene ID sub-data. Similar to pchan index, this
allows us to avoid build-time scene expansion, which also simplifies update of
the scene datablock.

Well, sort of. There is still work to be done to get rid of build-time scene
datablock expansion, which includes:

- Need to pass view layer by index.

  Annoying part would be to get actual view layer for that index. In practice
  doing list lookup might not be such a bad idea, since such lookup will not
  happen very often, and it is unlikely to have more than handful of view
  layer anyway.

  Other idea could be to use view layer from evaluation context.
  Or maybe from depsgraph, which is supposed to be in the context. Can have
  some assert statements to make sure everything is good.

- Need to get id of base binding for flags flush.

  We can replace that with index-based lookup from an array created by view
  layer evaluation.

Reviewers: dfelinto

Differential Revision: https://developer.blender.org/D3141
This commit is contained in:
Sergey Sharybin
2018-04-10 15:07:39 +02:00
parent c1680902ac
commit ca2484e090
15 changed files with 48 additions and 328 deletions

View File

@@ -169,14 +169,9 @@ void BKE_collection_engine_property_value_set_bool(struct IDProperty *props, con
/* evaluation */
void BKE_layer_eval_layer_collection_pre(const struct EvaluationContext *eval_ctx,
struct ID *owner_id,
struct ViewLayer *view_layer);
void BKE_layer_eval_layer_collection(const struct EvaluationContext *eval_ctx,
struct LayerCollection *layer_collection,
struct LayerCollection *parent_layer_collection);
void BKE_layer_eval_layer_collection_post(const struct EvaluationContext *eval_ctx,
struct ViewLayer *view_layer);
void BKE_layer_eval_view_layer(const struct EvaluationContext *eval_ctx,
struct ID *owner_id,
struct ViewLayer *view_layer);
/* iterators */

View File

@@ -381,33 +381,9 @@ void BKE_group_handle_recalc_and_update(const struct EvaluationContext *eval_ctx
/* ******** Dependency graph evaluation ******** */
static void group_eval_layer_collections(
const struct EvaluationContext *eval_ctx,
Group *group,
ListBase *layer_collections,
LayerCollection *parent_layer_collection)
{
LISTBASE_FOREACH (LayerCollection *, layer_collection, layer_collections) {
/* Evaluate layer collection itself. */
BKE_layer_eval_layer_collection(eval_ctx,
layer_collection,
parent_layer_collection);
/* Evaluate nested collections. */
group_eval_layer_collections(eval_ctx,
group,
&layer_collection->layer_collections,
layer_collection);
}
}
void BKE_group_eval_view_layers(const struct EvaluationContext *eval_ctx,
Group *group)
{
DEG_debug_print_eval(__func__, group->id.name, group);
BKE_layer_eval_layer_collection_pre(eval_ctx, &group->id, group->view_layer);
group_eval_layer_collections(eval_ctx,
group,
&group->view_layer->layer_collections,
NULL);
BKE_layer_eval_layer_collection_post(eval_ctx, group->view_layer);
BKE_layer_eval_view_layer(eval_ctx, &group->id, group->view_layer);
}

View File

@@ -2253,8 +2253,7 @@ static void idproperty_reset(IDProperty **props, IDProperty *props_ref)
}
}
void BKE_layer_eval_layer_collection_pre(const struct EvaluationContext *UNUSED(eval_ctx),
ID *owner_id, ViewLayer *view_layer)
static void layer_eval_layer_collection_pre(ID *owner_id, ViewLayer *view_layer)
{
DEG_debug_print_eval(__func__, view_layer->name, view_layer);
Scene *scene = (GS(owner_id->name) == ID_SCE) ? (Scene *)owner_id : NULL;
@@ -2296,9 +2295,9 @@ static bool layer_collection_visible_get(const EvaluationContext *eval_ctx, Laye
}
}
void BKE_layer_eval_layer_collection(const EvaluationContext *eval_ctx,
LayerCollection *layer_collection,
LayerCollection *parent_layer_collection)
static void layer_eval_layer_collection(const EvaluationContext *eval_ctx,
LayerCollection *layer_collection,
LayerCollection *parent_layer_collection)
{
if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) {
/* TODO)sergey): Try to make it more generic and handled by depsgraph messaging. */
@@ -2356,8 +2355,7 @@ void BKE_layer_eval_layer_collection(const EvaluationContext *eval_ctx,
}
}
void BKE_layer_eval_layer_collection_post(const struct EvaluationContext *UNUSED(eval_ctx),
ViewLayer *view_layer)
static void layer_eval_layer_collection_post(ViewLayer *view_layer)
{
DEG_debug_print_eval(__func__, view_layer->name, view_layer);
/* if base is not selectabled, clear select */
@@ -2368,6 +2366,34 @@ void BKE_layer_eval_layer_collection_post(const struct EvaluationContext *UNUSED
}
}
static void layer_eval_collections_recurse(const EvaluationContext *eval_ctx,
ListBase *layer_collections,
LayerCollection *parent_layer_collection)
{
for (LayerCollection *layer_collection = layer_collections->first;
layer_collection != NULL;
layer_collection = layer_collection->next)
{
layer_eval_layer_collection(eval_ctx,
layer_collection,
parent_layer_collection);
layer_eval_collections_recurse(eval_ctx,
&layer_collection->layer_collections,
layer_collection);
}
}
void BKE_layer_eval_view_layer(const struct EvaluationContext *eval_ctx,
struct ID *owner_id,
struct ViewLayer *view_layer)
{
layer_eval_layer_collection_pre(owner_id, view_layer);
layer_eval_collections_recurse(eval_ctx,
&view_layer->layer_collections,
NULL);
layer_eval_layer_collection_post(view_layer);
}
/**
* Free any static allocated memory.
*/

View File

@@ -44,13 +44,11 @@ set(SRC
intern/builder/deg_builder_cycle.cc
intern/builder/deg_builder_map.cc
intern/builder/deg_builder_nodes.cc
intern/builder/deg_builder_nodes_layer_collection.cc
intern/builder/deg_builder_nodes_rig.cc
intern/builder/deg_builder_nodes_view_layer.cc
intern/builder/deg_builder_pchanmap.cc
intern/builder/deg_builder_relations.cc
intern/builder/deg_builder_relations_keys.cc
intern/builder/deg_builder_relations_layer_collection.cc
intern/builder/deg_builder_relations_rig.cc
intern/builder/deg_builder_relations_view_layer.cc
intern/builder/deg_builder_transitive.cc

View File

@@ -414,7 +414,7 @@ void DepsgraphNodeBuilder::build_group(Group *group)
function_bind(BKE_group_eval_view_layers,
_1,
group_cow),
DEG_OPCODE_VIEW_LAYER_DONE);
DEG_OPCODE_VIEW_LAYER_EVAL);
}
void DepsgraphNodeBuilder::build_object(Base *base,

View File

@@ -214,17 +214,6 @@ struct DepsgraphNodeBuilder {
void build_movieclip(MovieClip *clip);
void build_lightprobe(Object *object);
struct LayerCollectionState {
int index;
LayerCollection *parent;
};
void build_layer_collection(ID *owner_id,
LayerCollection *layer_collection,
LayerCollectionState *state);
void build_layer_collections(ID *owner_id,
ListBase *layer_collections,
LayerCollectionState *state);
void build_view_layer_collections(ID *owner_id, ViewLayer *view_layer);
protected:
struct SavedEntryTag {
ID *id;

View File

@@ -1,126 +0,0 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2013 Blender Foundation.
* All rights reserved.
*
* Original Author: Joshua Leung
* Contributor(s): Based on original depsgraph.c code - Blender Foundation (2005-2013)
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/depsgraph/intern/builder/deg_builder_nodes_layer_collection.cc
* \ingroup depsgraph
*
* Methods for constructing depsgraph's nodes
*/
#include "intern/builder/deg_builder_nodes.h"
#include <stdio.h>
#include <stdlib.h>
#include "MEM_guardedalloc.h"
extern "C" {
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BKE_layer.h"
#include "DNA_scene_types.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
} /* extern "C" */
#include "intern/builder/deg_builder.h"
#include "intern/eval/deg_eval_copy_on_write.h"
#include "intern/nodes/deg_node.h"
#include "intern/nodes/deg_node_component.h"
#include "intern/nodes/deg_node_operation.h"
#include "intern/depsgraph_types.h"
#include "intern/depsgraph_intern.h"
#include "util/deg_util_foreach.h"
namespace DEG {
void DepsgraphNodeBuilder::build_layer_collection(
ID *owner_id,
LayerCollection *layer_collection,
LayerCollectionState *state)
{
/* TODO(sergey): This will attempt to create component for each collection.
* Harmless but could be optimized.
*/
ComponentDepsNode *comp = add_component_node(
owner_id,
DEG_NODE_TYPE_LAYER_COLLECTIONS);
add_operation_node(comp,
function_bind(BKE_layer_eval_layer_collection,
_1,
layer_collection,
state->parent),
DEG_OPCODE_VIEW_LAYER_EVAL,
layer_collection->scene_collection->name,
state->index);
++state->index;
/* Recurs into nested layer collections. */
LayerCollection *parent = state->parent;
state->parent = layer_collection;
build_layer_collections(owner_id, &layer_collection->layer_collections, state);
state->parent = parent;
}
void DepsgraphNodeBuilder::build_layer_collections(ID *owner_id,
ListBase *layer_collections,
LayerCollectionState *state)
{
LISTBASE_FOREACH (LayerCollection *, layer_collection, layer_collections) {
build_layer_collection(owner_id, layer_collection, state);
}
}
void DepsgraphNodeBuilder::build_view_layer_collections(
ID *owner_id,
ViewLayer *view_layer)
{
LayerCollectionState state;
state.index = 0;
ComponentDepsNode *comp = add_component_node(
owner_id,
DEG_NODE_TYPE_LAYER_COLLECTIONS);
add_operation_node(comp,
function_bind(BKE_layer_eval_layer_collection_pre,
_1,
owner_id,
view_layer),
DEG_OPCODE_VIEW_LAYER_INIT);
add_operation_node(comp,
function_bind(BKE_layer_eval_layer_collection_post,
_1,
view_layer),
DEG_OPCODE_VIEW_LAYER_DONE);
state.parent = NULL;
build_layer_collections(owner_id, &view_layer->layer_collections, &state);
}
} // namespace DEG

View File

@@ -157,7 +157,13 @@ void DepsgraphNodeBuilder::build_view_layer(
build_movieclip(clip);
}
/* Collections. */
build_view_layer_collections(&scene->id, view_layer_cow);
add_operation_node(&scene->id,
DEG_NODE_TYPE_LAYER_COLLECTIONS,
function_bind(BKE_layer_eval_view_layer,
_1,
&scene_cow->id,
view_layer_cow),
DEG_OPCODE_VIEW_LAYER_EVAL);
/* Parameters evaluation for scene relations mainly. */
add_operation_node(&scene->id,
DEG_NODE_TYPE_PARAMETERS,

View File

@@ -505,7 +505,7 @@ void DepsgraphRelationBuilder::build_object_flags(Base *base, Object *object)
}
OperationKey view_layer_done_key(&scene_->id,
DEG_NODE_TYPE_LAYER_COLLECTIONS,
DEG_OPCODE_VIEW_LAYER_DONE);
DEG_OPCODE_VIEW_LAYER_EVAL);
OperationKey object_flags_key(&object->id,
DEG_NODE_TYPE_LAYER_COLLECTIONS,
DEG_OPCODE_OBJECT_BASE_FLAGS);

View File

@@ -264,20 +264,6 @@ struct DepsgraphRelationBuilder
EffectorWeights *eff,
bool add_absorption, const char *name);
struct LayerCollectionState {
int index;
OperationKey init_key;
OperationKey done_key;
OperationKey prev_key;
};
void build_layer_collection(ID *owner_id,
LayerCollection *layer_collection,
LayerCollectionState *state);
void build_layer_collections(ID *owner_id,
ListBase *layer_collections,
LayerCollectionState *state);
void build_view_layer_collections(struct ID *owner_id, ViewLayer *view_layer);
void build_copy_on_write_relations();
void build_copy_on_write_relations(IDDepsNode *id_node);

View File

@@ -1,124 +0,0 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2013 Blender Foundation.
* All rights reserved.
*
* Original Author: Joshua Leung
* Contributor(s): Based on original depsgraph.c code - Blender Foundation (2005-2013)
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/depsgraph/intern/builder/deg_builder_relations_layer_collection.cc
* \ingroup depsgraph
*
* Methods for constructing depsgraph
*/
#include "intern/builder/deg_builder_relations.h"
#include <stdio.h>
#include <stdlib.h>
#include <cstring> /* required for STREQ later on. */
#include "MEM_guardedalloc.h"
extern "C" {
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
} /* extern "C" */
#include "intern/builder/deg_builder.h"
#include "intern/builder/deg_builder_pchanmap.h"
#include "intern/nodes/deg_node.h"
#include "intern/nodes/deg_node_component.h"
#include "intern/nodes/deg_node_operation.h"
#include "intern/depsgraph_intern.h"
#include "intern/depsgraph_types.h"
#include "util/deg_util_foreach.h"
namespace DEG {
void DepsgraphRelationBuilder::build_layer_collection(
ID *owner_id,
LayerCollection *layer_collection,
LayerCollectionState *state)
{
OperationKey layer_key(owner_id,
DEG_NODE_TYPE_LAYER_COLLECTIONS,
DEG_OPCODE_VIEW_LAYER_EVAL,
layer_collection->scene_collection->name,
state->index);
add_relation(state->prev_key, layer_key, "Layer collection order");
++state->index;
state->prev_key = layer_key;
/* Recurs into nested layer collections. */
build_layer_collections(owner_id, &layer_collection->layer_collections, state);
}
void DepsgraphRelationBuilder::build_layer_collections(
ID *owner_id,
ListBase *layer_collections,
LayerCollectionState *state)
{
LISTBASE_FOREACH (LayerCollection *, layer_collection, layer_collections) {
/* Recurs into the layer. */
build_layer_collection(owner_id, layer_collection, state);
}
}
void DepsgraphRelationBuilder::build_view_layer_collections(
ID *owner_id,
ViewLayer *view_layer)
{
LayerCollectionState state;
state.index = 0;
OperationKey init_key(owner_id,
DEG_NODE_TYPE_LAYER_COLLECTIONS,
DEG_OPCODE_VIEW_LAYER_INIT);
OperationKey done_key(owner_id,
DEG_NODE_TYPE_LAYER_COLLECTIONS,
DEG_OPCODE_VIEW_LAYER_DONE);
state.init_key = init_key;
state.done_key = done_key;
state.prev_key = init_key;
build_layer_collections(owner_id, &view_layer->layer_collections, &state);
add_relation(state.prev_key, done_key, "Layer collection order");
}
} // namespace DEG

View File

@@ -112,8 +112,6 @@ void DepsgraphRelationBuilder::build_view_layer(Scene *scene, ViewLayer *view_la
LISTBASE_FOREACH (MovieClip *, clip, &bmain_->movieclip) {
build_movieclip(clip);
}
/* Collections. */
build_view_layer_collections(&scene_->id, view_layer);
/* TODO(sergey): Do this flush on CoW object? */
foreach (OperationDepsNode *node, graph_->operations) {
IDDepsNode *id_node = node->owner->owner;

View File

@@ -136,7 +136,7 @@ void depsgraph_select_tag_to_component_opcode(
* road.
*/
*component_type = DEG_NODE_TYPE_LAYER_COLLECTIONS;
*operation_code = DEG_OPCODE_VIEW_LAYER_DONE;
*operation_code = DEG_OPCODE_VIEW_LAYER_EVAL;
}
else if (id_type == ID_OB) {
*component_type = DEG_NODE_TYPE_LAYER_COLLECTIONS;
@@ -156,7 +156,7 @@ void depsgraph_base_flags_tag_to_component_opcode(
const ID_Type id_type = GS(id->name);
if (id_type == ID_SCE) {
*component_type = DEG_NODE_TYPE_LAYER_COLLECTIONS;
*operation_code = DEG_OPCODE_VIEW_LAYER_INIT;
*operation_code = DEG_OPCODE_VIEW_LAYER_EVAL;
}
else if (id_type == ID_OB) {
*component_type = DEG_NODE_TYPE_LAYER_COLLECTIONS;

View File

@@ -127,9 +127,7 @@ static const char *stringify_opcode(eDepsOperation_Code opcode)
STRINGIFY_OPCODE(MASK_ANIMATION);
STRINGIFY_OPCODE(MASK_EVAL);
/* Collections. */
STRINGIFY_OPCODE(VIEW_LAYER_INIT);
STRINGIFY_OPCODE(VIEW_LAYER_EVAL);
STRINGIFY_OPCODE(VIEW_LAYER_DONE);
/* Copy on write. */
STRINGIFY_OPCODE(COPY_ON_WRITE);
/* Shading. */

View File

@@ -245,9 +245,7 @@ typedef enum eDepsOperation_Code {
DEG_OPCODE_POINT_CACHE_RESET,
/* Collections. ------------------------------------- */
DEG_OPCODE_VIEW_LAYER_INIT,
DEG_OPCODE_VIEW_LAYER_EVAL,
DEG_OPCODE_VIEW_LAYER_DONE,
/* Copy on Write. ------------------------------------ */
DEG_OPCODE_COPY_ON_WRITE,