Depsgraph: simplify build API

Reviewers: sergey, sybren

Differential Revision: https://developer.blender.org/D8611
This commit is contained in:
2020-08-18 15:51:32 +02:00
parent d9f7cbb8af
commit 6a4f5e6a8c
31 changed files with 61 additions and 122 deletions

View File

@@ -1485,7 +1485,7 @@ static void scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain, bool on
for (int pass = 0; pass < 2; pass++) {
/* (Re-)build dependency graph if needed. */
DEG_graph_relations_update(depsgraph, bmain, scene, view_layer);
DEG_graph_relations_update(depsgraph);
/* Uncomment this to check if graph was properly tagged for update. */
// DEG_debug_graph_relations_validate(depsgraph, bmain, scene);
/* Flush editing data if needed. */
@@ -1512,7 +1512,7 @@ static void scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain, bool on
* be tagged for an update anyway.
*
* If there are no relations changed by the callback this call will do nothing. */
DEG_graph_relations_update(depsgraph, bmain, scene, view_layer);
DEG_graph_relations_update(depsgraph);
}
/* Inform editors about possible changes. */
DEG_ids_check_recalc(bmain, depsgraph, scene, view_layer, false);
@@ -1556,7 +1556,7 @@ void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph)
*/
BKE_image_editors_update_frame(bmain, scene->r.cfra);
BKE_sound_set_cfra(scene->r.cfra);
DEG_graph_relations_update(depsgraph, bmain, scene, view_layer);
DEG_graph_relations_update(depsgraph);
/* Update all objects: drivers, matrices, displists, etc. flags set
* by depgraph or manual, no layer check here, gets correct flushed.
*
@@ -1579,7 +1579,7 @@ void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph)
/* NOTE: Similar to this case in scene_graph_update_tagged(). Need to ensure that
* DEG_ids_clear_recalc() doesn't access freed memory of possibly removed ID. */
DEG_graph_relations_update(depsgraph, bmain, scene, view_layer);
DEG_graph_relations_update(depsgraph);
}
/* Inform editors about possible changes. */

View File

@@ -220,7 +220,7 @@ static void seq_prefetch_init_depsgraph(PrefetchJob *pfjob)
DEG_debug_name_set(pfjob->depsgraph, "SEQUENCER PREFETCH");
/* Make sure there is a correct evaluated scene pointer. */
DEG_graph_build_for_render_pipeline(pfjob->depsgraph, bmain, scene, view_layer);
DEG_graph_build_for_render_pipeline(pfjob->depsgraph);
/* Update immediately so we have proper evaluated scene. */
seq_prefetch_update_depsgraph(pfjob);

View File

@@ -148,7 +148,7 @@ void BlendfileLoadingBaseTest::depsgraph_create(eEvaluationMode depsgraph_evalua
{
depsgraph = DEG_graph_new(
bfile->main, bfile->curscene, bfile->cur_view_layer, depsgraph_evaluation_mode);
DEG_graph_build_from_view_layer(depsgraph, bfile->main, bfile->curscene, bfile->cur_view_layer);
DEG_graph_build_from_view_layer(depsgraph);
BKE_scene_graph_update_tagged(depsgraph, bfile->main);
}

View File

@@ -51,50 +51,29 @@ extern "C" {
/* Graph Building -------------------------------- */
/* Build depsgraph for the given scene, and dump results in given graph container. */
void DEG_graph_build_from_view_layer(struct Depsgraph *graph,
struct Main *bmain,
struct Scene *scene,
struct ViewLayer *view_layer);
void DEG_graph_build_from_view_layer(struct Depsgraph *graph);
/* Build depsgraph for all objects (so also invisible ones) in the given view layer. */
void DEG_graph_build_for_all_objects(struct Depsgraph *graph,
struct Main *bmain,
struct Scene *scene,
struct ViewLayer *view_layer);
void DEG_graph_build_for_all_objects(struct Depsgraph *graph);
/* Special version of builder which produces dependency graph suitable for the render pipeline.
* It will contain sequencer and compositor (if needed) and all their dependencies. */
void DEG_graph_build_for_render_pipeline(struct Depsgraph *graph,
struct Main *bmain,
struct Scene *scene,
struct ViewLayer *view_layer);
void DEG_graph_build_for_render_pipeline(struct Depsgraph *graph);
/* Builds minimal dependency graph for compositor preview.
*
* Note that compositor editor might have pinned node tree, which is different from scene's node
* tree.
*/
void DEG_graph_build_for_compositor_preview(struct Depsgraph *graph,
struct Main *bmain,
struct Scene *scene,
struct ViewLayer *view_layer,
struct bNodeTree *nodetree);
void DEG_graph_build_for_compositor_preview(struct Depsgraph *graph, struct bNodeTree *nodetree);
void DEG_graph_build_from_ids(struct Depsgraph *graph,
struct Main *bmain,
struct Scene *scene,
struct ViewLayer *view_layer,
struct ID **ids,
const int num_ids);
void DEG_graph_build_from_ids(struct Depsgraph *graph, struct ID **ids, const int num_ids);
/* Tag relations from the given graph for update. */
void DEG_graph_tag_relations_update(struct Depsgraph *graph);
/* Create or update relations in the specified graph. */
void DEG_graph_relations_update(struct Depsgraph *graph,
struct Main *bmain,
struct Scene *scene,
struct ViewLayer *view_layer);
void DEG_graph_relations_update(struct Depsgraph *graph);
/* Tag all relations in the database for update.*/
void DEG_relations_tag_update(struct Main *bmain);

View File

@@ -33,14 +33,11 @@
namespace blender {
namespace deg {
AbstractBuilderPipeline::AbstractBuilderPipeline(::Depsgraph *graph,
Main *bmain,
Scene *scene,
ViewLayer *view_layer)
AbstractBuilderPipeline::AbstractBuilderPipeline(::Depsgraph *graph)
: deg_graph_(reinterpret_cast<Depsgraph *>(graph)),
bmain_(bmain),
scene_(scene),
view_layer_(view_layer),
bmain_(deg_graph_->bmain),
scene_(deg_graph_->scene),
view_layer_(deg_graph_->view_layer),
builder_cache_()
{
}

View File

@@ -49,7 +49,7 @@ class DepsgraphRelationBuilder;
*/
class AbstractBuilderPipeline {
public:
AbstractBuilderPipeline(::Depsgraph *graph, Main *bmain, Scene *scene, ViewLayer *view_layer);
AbstractBuilderPipeline(::Depsgraph *graph);
virtual ~AbstractBuilderPipeline();
void build();

View File

@@ -58,11 +58,8 @@ class AllObjectsRelationBuilder : public DepsgraphRelationBuilder {
} // namespace
AllObjectsBuilderPipeline::AllObjectsBuilderPipeline(::Depsgraph *graph,
Main *bmain,
Scene *scene,
ViewLayer *view_layer)
: ViewLayerBuilderPipeline(graph, bmain, scene, view_layer)
AllObjectsBuilderPipeline::AllObjectsBuilderPipeline(::Depsgraph *graph)
: ViewLayerBuilderPipeline(graph)
{
}

View File

@@ -33,7 +33,7 @@ namespace deg {
* (and their dependencies). */
class AllObjectsBuilderPipeline : public ViewLayerBuilderPipeline {
public:
AllObjectsBuilderPipeline(::Depsgraph *graph, Main *bmain, Scene *scene, ViewLayer *view_layer);
AllObjectsBuilderPipeline(::Depsgraph *graph);
protected:
virtual unique_ptr<DepsgraphNodeBuilder> construct_node_builder() override;

View File

@@ -26,9 +26,8 @@
namespace blender {
namespace deg {
CompositorBuilderPipeline::CompositorBuilderPipeline(
::Depsgraph *graph, Main *bmain, Scene *scene, ViewLayer *view_layer, bNodeTree *nodetree)
: AbstractBuilderPipeline(graph, bmain, scene, view_layer), nodetree_(nodetree)
CompositorBuilderPipeline::CompositorBuilderPipeline(::Depsgraph *graph, bNodeTree *nodetree)
: AbstractBuilderPipeline(graph), nodetree_(nodetree)
{
deg_graph_->is_render_pipeline_depsgraph = true;
}

View File

@@ -32,8 +32,7 @@ namespace deg {
class CompositorBuilderPipeline : public AbstractBuilderPipeline {
public:
CompositorBuilderPipeline(
::Depsgraph *graph, Main *bmain, Scene *scene, ViewLayer *view_layer, bNodeTree *nodetree);
CompositorBuilderPipeline(::Depsgraph *graph, bNodeTree *nodetree);
protected:
virtual void build_nodes(DepsgraphNodeBuilder &node_builder) override;

View File

@@ -114,9 +114,8 @@ class DepsgraphFromIDsRelationBuilder : public DepsgraphRelationBuilder {
} // namespace
FromIDsBuilderPipeline::FromIDsBuilderPipeline(
::Depsgraph *graph, Main *bmain, Scene *scene, ViewLayer *view_layer, Span<ID *> ids)
: AbstractBuilderPipeline(graph, bmain, scene, view_layer), ids_(ids)
FromIDsBuilderPipeline::FromIDsBuilderPipeline(::Depsgraph *graph, Span<ID *> ids)
: AbstractBuilderPipeline(graph), ids_(ids)
{
}

View File

@@ -43,8 +43,7 @@ namespace deg {
class FromIDsBuilderPipeline : public AbstractBuilderPipeline {
public:
FromIDsBuilderPipeline(
::Depsgraph *graph, Main *bmain, Scene *scene, ViewLayer *view_layer, Span<ID *> ids);
FromIDsBuilderPipeline(::Depsgraph *graph, Span<ID *> ids);
protected:
virtual unique_ptr<DepsgraphNodeBuilder> construct_node_builder() override;

View File

@@ -26,11 +26,7 @@
namespace blender {
namespace deg {
RenderBuilderPipeline::RenderBuilderPipeline(::Depsgraph *graph,
Main *bmain,
Scene *scene,
ViewLayer *view_layer)
: AbstractBuilderPipeline(graph, bmain, scene, view_layer)
RenderBuilderPipeline::RenderBuilderPipeline(::Depsgraph *graph) : AbstractBuilderPipeline(graph)
{
deg_graph_->is_render_pipeline_depsgraph = true;
}

View File

@@ -30,7 +30,7 @@ namespace deg {
class RenderBuilderPipeline : public AbstractBuilderPipeline {
public:
RenderBuilderPipeline(::Depsgraph *graph, Main *bmain, Scene *scene, ViewLayer *view_layer);
RenderBuilderPipeline(::Depsgraph *graph);
protected:
virtual void build_nodes(DepsgraphNodeBuilder &node_builder) override;

View File

@@ -26,11 +26,8 @@
namespace blender {
namespace deg {
ViewLayerBuilderPipeline::ViewLayerBuilderPipeline(::Depsgraph *graph,
Main *bmain,
Scene *scene,
ViewLayer *view_layer)
: AbstractBuilderPipeline(graph, bmain, scene, view_layer)
ViewLayerBuilderPipeline::ViewLayerBuilderPipeline(::Depsgraph *graph)
: AbstractBuilderPipeline(graph)
{
}

View File

@@ -30,7 +30,7 @@ namespace deg {
class ViewLayerBuilderPipeline : public AbstractBuilderPipeline {
public:
ViewLayerBuilderPipeline(::Depsgraph *graph, Main *bmain, Scene *scene, ViewLayer *view_layer);
ViewLayerBuilderPipeline(::Depsgraph *graph);
protected:
virtual void build_nodes(DepsgraphNodeBuilder &node_builder) override;

View File

@@ -210,49 +210,33 @@ struct Depsgraph *DEG_get_graph_from_handle(struct DepsNodeHandle *node_handle)
/* Graph Building API's */
/* Build depsgraph for the given scene layer, and dump results in given graph container. */
void DEG_graph_build_from_view_layer(Depsgraph *graph,
Main *bmain,
Scene *scene,
ViewLayer *view_layer)
void DEG_graph_build_from_view_layer(Depsgraph *graph)
{
deg::ViewLayerBuilderPipeline builder(graph, bmain, scene, view_layer);
deg::ViewLayerBuilderPipeline builder(graph);
builder.build();
}
void DEG_graph_build_for_all_objects(struct Depsgraph *graph,
struct Main *bmain,
struct Scene *scene,
struct ViewLayer *view_layer)
void DEG_graph_build_for_all_objects(struct Depsgraph *graph)
{
deg::AllObjectsBuilderPipeline builder(graph, bmain, scene, view_layer);
deg::AllObjectsBuilderPipeline builder(graph);
builder.build();
}
void DEG_graph_build_for_render_pipeline(Depsgraph *graph,
Main *bmain,
Scene *scene,
ViewLayer *view_layer)
void DEG_graph_build_for_render_pipeline(Depsgraph *graph)
{
deg::RenderBuilderPipeline builder(graph, bmain, scene, view_layer);
deg::RenderBuilderPipeline builder(graph);
builder.build();
}
void DEG_graph_build_for_compositor_preview(
Depsgraph *graph, Main *bmain, Scene *scene, struct ViewLayer *view_layer, bNodeTree *nodetree)
void DEG_graph_build_for_compositor_preview(Depsgraph *graph, bNodeTree *nodetree)
{
deg::CompositorBuilderPipeline builder(graph, bmain, scene, view_layer, nodetree);
deg::CompositorBuilderPipeline builder(graph, nodetree);
builder.build();
}
void DEG_graph_build_from_ids(Depsgraph *graph,
Main *bmain,
Scene *scene,
ViewLayer *view_layer,
ID **ids,
const int num_ids)
void DEG_graph_build_from_ids(Depsgraph *graph, ID **ids, const int num_ids)
{
deg::FromIDsBuilderPipeline builder(
graph, bmain, scene, view_layer, blender::Span(ids, num_ids));
deg::FromIDsBuilderPipeline builder(graph, blender::Span(ids, num_ids));
builder.build();
}
@@ -275,14 +259,14 @@ void DEG_graph_tag_relations_update(Depsgraph *graph)
}
/* Create or update relations in the specified graph. */
void DEG_graph_relations_update(Depsgraph *graph, Main *bmain, Scene *scene, ViewLayer *view_layer)
void DEG_graph_relations_update(Depsgraph *graph)
{
deg::Depsgraph *deg_graph = (deg::Depsgraph *)graph;
if (!deg_graph->need_update) {
/* Graph is up to date, nothing to do. */
return;
}
DEG_graph_build_from_view_layer(graph, bmain, scene, view_layer);
DEG_graph_build_from_view_layer(graph);
}
/* Tag all relations for update. */

View File

@@ -93,7 +93,7 @@ bool DEG_debug_graph_relations_validate(Depsgraph *graph,
{
Depsgraph *temp_depsgraph = DEG_graph_new(bmain, scene, view_layer, DEG_get_mode(graph));
bool valid = true;
DEG_graph_build_from_view_layer(temp_depsgraph, bmain, scene, view_layer);
DEG_graph_build_from_view_layer(temp_depsgraph);
if (!DEG_debug_compare(temp_depsgraph, graph)) {
fprintf(stderr, "ERROR! Depsgraph wasn't tagged for update when it should have!\n");
BLI_assert(!"This should not happen!");

View File

@@ -1302,7 +1302,7 @@ void EEVEE_lightbake_job(void *custom_data, short *stop, short *do_update, float
EEVEE_LightBake *lbake = (EEVEE_LightBake *)custom_data;
Depsgraph *depsgraph = lbake->depsgraph;
DEG_graph_relations_update(depsgraph, lbake->bmain, lbake->scene, lbake->view_layer_input);
DEG_graph_relations_update(depsgraph);
DEG_evaluate_on_framechange(lbake->bmain, depsgraph, lbake->frame);
lbake->view_layer = DEG_get_evaluated_view_layer(depsgraph);

View File

@@ -91,7 +91,7 @@ Depsgraph *animviz_depsgraph_build(Main *bmain,
}
/* Build graph from all requested IDs. */
DEG_graph_build_from_ids(depsgraph, bmain, scene, view_layer, ids, num_ids);
DEG_graph_build_from_ids(depsgraph, ids, num_ids);
MEM_freeN(ids);
/* Update once so we can access pointers of evaluated animation data. */

View File

@@ -745,7 +745,7 @@ static int bake(Render *re,
/* We build a depsgraph for the baking,
* so we don't need to change the original data to adjust visibility and modifiers. */
Depsgraph *depsgraph = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_RENDER);
DEG_graph_build_from_view_layer(depsgraph, bmain, scene, view_layer);
DEG_graph_build_from_view_layer(depsgraph);
int op_result = OPERATOR_CANCELLED;
bool ok = false;

View File

@@ -119,7 +119,7 @@ void ED_scene_change_update(Main *bmain, Scene *scene, ViewLayer *layer)
Depsgraph *depsgraph = BKE_scene_get_depsgraph(bmain, scene, layer, true);
BKE_scene_set_background(bmain, scene);
DEG_graph_relations_update(depsgraph, bmain, scene, layer);
DEG_graph_relations_update(depsgraph);
DEG_on_visible_update(bmain, false);
ED_render_engine_changed(bmain, false);

View File

@@ -207,8 +207,7 @@ static void compo_initjob(void *cjv)
ViewLayer *view_layer = cj->view_layer;
cj->compositor_depsgraph = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_RENDER);
DEG_graph_build_for_compositor_preview(
cj->compositor_depsgraph, bmain, scene, view_layer, cj->ntree);
DEG_graph_build_for_compositor_preview(cj->compositor_depsgraph, cj->ntree);
/* NOTE: Don't update animation to preserve unkeyed changes, this means can not use
* evaluate_on_framechange. */

View File

@@ -357,7 +357,7 @@ static void set_trans_object_base_flags(TransInfo *t)
/* Makes sure base flags and object flags are identical. */
BKE_scene_base_flag_to_objects(t->view_layer);
/* Make sure depsgraph is here. */
DEG_graph_relations_update(depsgraph, bmain, scene, view_layer);
DEG_graph_relations_update(depsgraph);
/* Clear all flags we need. It will be used to detect dependencies. */
trans_object_base_deps_flag_prepare(view_layer);
/* Traverse all bases and set all possible flags. */

View File

@@ -869,8 +869,7 @@ Render *BlenderStrokeRenderer::RenderScene(Render * /*re*/, bool render)
#endif
Render *freestyle_render = RE_NewSceneRender(freestyle_scene);
ViewLayer *view_layer = (ViewLayer *)freestyle_scene->view_layers.first;
DEG_graph_relations_update(freestyle_depsgraph, freestyle_bmain, freestyle_scene, view_layer);
DEG_graph_relations_update(freestyle_depsgraph);
RE_RenderFreestyleStrokes(
freestyle_render, freestyle_bmain, freestyle_scene, render && get_stroke_count() > 0);

View File

@@ -67,16 +67,13 @@ namespace io {
namespace alembic {
// Construct the depsgraph for exporting.
static void build_depsgraph(Depsgraph *depsgraph, Main *bmain, const bool visible_objects_only)
static void build_depsgraph(Depsgraph *depsgraph, const bool visible_objects_only)
{
Scene *scene = DEG_get_input_scene(depsgraph);
ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
if (visible_objects_only) {
DEG_graph_build_from_view_layer(depsgraph, bmain, scene, view_layer);
DEG_graph_build_from_view_layer(depsgraph);
}
else {
DEG_graph_build_for_all_objects(depsgraph, bmain, scene, view_layer);
DEG_graph_build_for_all_objects(depsgraph);
}
}
@@ -97,7 +94,7 @@ static void export_startjob(void *customdata,
*progress = 0.0f;
*do_update = true;
build_depsgraph(data->depsgraph, data->bmain, data->params.visible_objects_only);
build_depsgraph(data->depsgraph, data->params.visible_objects_only);
SubdivModifierDisabler subdiv_disabler(data->depsgraph);
if (!data->params.apply_subdiv) {
subdiv_disabler.disable_modifiers();

View File

@@ -328,8 +328,7 @@ class AbstractHierarchyIteratorInvisibleTest : public AbstractHierarchyIteratorT
{
depsgraph = DEG_graph_new(
bfile->main, bfile->curscene, bfile->cur_view_layer, depsgraph_evaluation_mode);
DEG_graph_build_for_all_objects(
depsgraph, bfile->main, bfile->curscene, bfile->cur_view_layer);
DEG_graph_build_for_all_objects(depsgraph);
BKE_scene_graph_update_tagged(depsgraph, bfile->main);
}
};

View File

@@ -75,12 +75,11 @@ static void export_startjob(void *customdata,
// Construct the depsgraph for exporting.
Scene *scene = DEG_get_input_scene(data->depsgraph);
ViewLayer *view_layer = DEG_get_input_view_layer(data->depsgraph);
if (data->params.visible_objects_only) {
DEG_graph_build_from_view_layer(data->depsgraph, data->bmain, scene, view_layer);
DEG_graph_build_from_view_layer(data->depsgraph);
}
else {
DEG_graph_build_for_all_objects(data->depsgraph, data->bmain, scene, view_layer);
DEG_graph_build_for_all_objects(data->depsgraph);
}
BKE_scene_graph_update_tagged(data->depsgraph, data->bmain);

View File

@@ -609,7 +609,7 @@ static void engine_depsgraph_init(RenderEngine *engine, ViewLayer *view_layer)
if (engine->re->r.scemode & R_BUTS_PREVIEW) {
Depsgraph *depsgraph = engine->depsgraph;
DEG_graph_relations_update(depsgraph, bmain, scene, view_layer);
DEG_graph_relations_update(depsgraph);
DEG_evaluate_on_framechange(bmain, depsgraph, CFRA);
DEG_ids_check_recalc(bmain, depsgraph, scene, view_layer, true);
DEG_ids_clear_recalc(bmain, depsgraph);

View File

@@ -1977,7 +1977,7 @@ static void render_init_depsgraph(Render *re)
DEG_debug_name_set(re->pipeline_depsgraph, "RENDER PIPELINE");
/* Make sure there is a correct evaluated scene pointer. */
DEG_graph_build_for_render_pipeline(re->pipeline_depsgraph, re->main, scene, view_layer);
DEG_graph_build_for_render_pipeline(re->pipeline_depsgraph);
/* Update immediately so we have proper evaluated scene. */
render_update_depsgraph(re);

View File

@@ -352,7 +352,7 @@ void wm_event_do_depsgraph(bContext *C, bool is_after_open_file)
*/
Depsgraph *depsgraph = BKE_scene_get_depsgraph(bmain, scene, view_layer, true);
if (is_after_open_file) {
DEG_graph_relations_update(depsgraph, bmain, scene, view_layer);
DEG_graph_relations_update(depsgraph);
DEG_graph_on_visible_update(bmain, depsgraph, true);
}
DEG_make_active(depsgraph);