Depsgraph: store mode and time in depsgraph, add view layer / scene accessors.

Scene, view layer and mode are now set in the constructor and never changed.
Time is updated on frame changes to indicate which frame is being or has been
evaluated last.

This is a step towards making EvaluationContext obsolete.

Differential Revision: https://developer.blender.org/D3144
This commit is contained in:
Brecht Van Lommel 2018-04-06 09:17:53 +02:00
parent 5d7952d9c7
commit 340bfdef2e
15 changed files with 96 additions and 45 deletions

View File

@ -2193,7 +2193,7 @@ Depsgraph *BKE_scene_get_depsgraph(Scene *scene,
{
*key_ptr = MEM_mallocN(sizeof(DepsgraphKey), __func__);
**key_ptr = key;
*depsgraph_ptr = DEG_graph_new();
*depsgraph_ptr = DEG_graph_new(scene, view_layer, DAG_EVAL_VIEWPORT);
}
depsgraph = *depsgraph_ptr;
}

View File

@ -118,7 +118,9 @@ void DEG_depsgraph_enable_copy_on_write(void);
/* Create new Depsgraph instance */
// TODO: what args are needed here? What's the building-graph entry point?
Depsgraph *DEG_graph_new(void);
Depsgraph *DEG_graph_new(struct Scene *scene,
struct ViewLayer *view_layer,
eEvaluationMode mode);
/* Free Depsgraph itself and all its data */
void DEG_graph_free(Depsgraph *graph);

View File

@ -49,6 +49,22 @@ struct ViewLayer;
extern "C" {
#endif
/* *********************** DEG input data ********************* */
/* Get scene that depsgraph was built for. */
struct Scene *DEG_get_input_scene(const Depsgraph *graph);
/* Get view layer that depsgraph was built for. */
struct ViewLayer *DEG_get_input_view_layer(const Depsgraph *graph);
/* Get evaluation mode that depsgraph was built for. */
eEvaluationMode DEG_get_mode(const Depsgraph *graph);
/* Get time that depsgraph is being evaluated or was last evaluated at. */
float DEG_get_ctime(const Depsgraph *graph);
/* ********************* DEG evaluated data ******************* */
/* Check if given ID type was tagged for update. */
bool DEG_id_type_tagged(struct Main *bmain, short id_type);

View File

@ -127,8 +127,8 @@ void DepsgraphRelationBuilder::build_view_layer(Scene *scene, ViewLayer *view_la
build_view_layer(scene->set, set_view_layer);
}
graph_->scene = scene;
graph_->view_layer = view_layer;
BLI_assert(graph_->scene == scene);
BLI_assert(graph_->view_layer == view_layer);
}
} // namespace DEG

View File

@ -49,6 +49,8 @@ extern "C" {
#include "DNA_sequence_types.h"
#include "RNA_access.h"
#include "BKE_scene.h"
}
#include <algorithm>
@ -92,11 +94,15 @@ static void remove_from_vector(vector<T> *vector, const T& value)
vector->end());
}
Depsgraph::Depsgraph()
Depsgraph::Depsgraph(Scene *scene,
ViewLayer *view_layer,
eEvaluationMode mode)
: time_source(NULL),
need_update(true),
scene(NULL),
view_layer(NULL)
scene(scene),
view_layer(view_layer),
mode(mode),
ctime(BKE_scene_frame_get(scene))
{
BLI_spin_init(&lock);
id_hash = BLI_ghash_ptr_new("Depsgraph id hash");
@ -559,9 +565,14 @@ string deg_color_end(void)
/* Public Graph API */
/* Initialize a new Depsgraph */
Depsgraph *DEG_graph_new()
Depsgraph *DEG_graph_new(Scene *scene,
ViewLayer *view_layer,
eEvaluationMode mode)
{
DEG::Depsgraph *deg_depsgraph = OBJECT_GUARDED_NEW(DEG::Depsgraph);
DEG::Depsgraph *deg_depsgraph = OBJECT_GUARDED_NEW(DEG::Depsgraph,
scene,
view_layer,
mode);
return reinterpret_cast<Depsgraph *>(deg_depsgraph);
}

View File

@ -38,6 +38,8 @@
#include "BLI_threads.h" /* for SpinLock */
#include "DEG_depsgraph.h"
#include "intern/depsgraph_types.h"
struct ID;
@ -100,7 +102,9 @@ struct Depsgraph {
typedef vector<OperationDepsNode *> OperationNodes;
typedef vector<IDDepsNode *> IDDepsNodes;
Depsgraph();
Depsgraph(Scene *scene,
ViewLayer *view_layer,
eEvaluationMode mode);
~Depsgraph();
/**
@ -187,9 +191,13 @@ struct Depsgraph {
*/
SpinLock lock;
/* Scene and layer this dependency graph is built for. */
/* Scene, layer, mode this dependency graph is built for. */
Scene *scene;
ViewLayer *view_layer;
eEvaluationMode mode;
/* Time at which dependency graph is being or was last evaluated. */
float ctime;
};
} // namespace DEG

View File

@ -37,9 +37,12 @@ extern "C" {
#include "DNA_scene_types.h"
} /* extern "C" */
#include "DNA_object_types.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_debug.h"
#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph_query.h"
#include "intern/depsgraph_intern.h"
#include "intern/nodes/deg_node_id.h"
@ -72,7 +75,7 @@ bool DEG_debug_graph_relations_validate(Depsgraph *graph,
Scene *scene,
ViewLayer *view_layer)
{
Depsgraph *temp_depsgraph = DEG_graph_new();
Depsgraph *temp_depsgraph = DEG_graph_new(scene, view_layer, DEG_get_mode(graph));
bool valid = true;
DEG_graph_build_from_view_layer(temp_depsgraph, bmain, scene, view_layer);
if (!DEG_debug_compare(temp_depsgraph, graph)) {

View File

@ -134,9 +134,10 @@ void DEG_evaluate_on_refresh(EvaluationContext *eval_ctx,
Depsgraph *graph)
{
DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
deg_graph->ctime = BKE_scene_frame_get(deg_graph->scene);
/* Update time on primary timesource. */
DEG::TimeSourceDepsNode *tsrc = deg_graph->find_time_source();
tsrc->cfra = BKE_scene_frame_get(deg_graph->scene);
tsrc->cfra = deg_graph->ctime;
DEG::deg_evaluate_on_refresh(eval_ctx, deg_graph);
}
@ -147,6 +148,7 @@ void DEG_evaluate_on_framechange(EvaluationContext *eval_ctx,
float ctime)
{
DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
deg_graph->ctime = ctime;
/* Update time on primary timesource. */
DEG::TimeSourceDepsNode *tsrc = deg_graph->find_time_source();
tsrc->cfra = ctime;

View File

@ -49,6 +49,31 @@ extern "C" {
#include "intern/depsgraph_intern.h"
#include "intern/nodes/deg_node_id.h"
struct Scene *DEG_get_input_scene(const Depsgraph *graph)
{
const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
return deg_graph->scene;
}
struct ViewLayer *DEG_get_input_view_layer(const Depsgraph *graph)
{
const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
return deg_graph->view_layer;
}
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
{
const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
return deg_graph->mode;
}
float DEG_get_ctime(const Depsgraph *graph)
{
const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
return deg_graph->ctime;
}
bool DEG_id_type_tagged(Main *bmain, short id_type)
{
return bmain->id_tag_update[BKE_idcode_to_index(id_type)] != 0;

View File

@ -425,20 +425,6 @@ void deg_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, int flag)
id_tag_update_ntree_special(bmain, graph, id, flag);
}
/* TODO(sergey): Consider storing scene and view layer at depsgraph allocation
* time.
*/
void deg_ensure_scene_view_layer(Depsgraph *graph,
Scene *scene,
ViewLayer *view_layer)
{
if (!graph->need_update) {
return;
}
graph->scene = scene;
graph->view_layer = view_layer;
}
void deg_id_tag_update(Main *bmain, ID *id, int flag)
{
deg_graph_id_tag_update(bmain, NULL, id, flag);
@ -449,11 +435,6 @@ void deg_id_tag_update(Main *bmain, ID *id, int flag)
view_layer,
false);
if (depsgraph != NULL) {
/* Make sure depsgraph is pointing to a correct scene and
* view layer. This is mainly required in cases when depsgraph
* was not built yet.
*/
deg_ensure_scene_view_layer(depsgraph, scene, view_layer);
deg_graph_id_tag_update(bmain, depsgraph, id, flag);
}
}

View File

@ -646,7 +646,7 @@ static int bake(
const char *identifier, ScrArea *sa, const char *uv_layer)
{
EvaluationContext *eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER);
Depsgraph *depsgraph = DEG_graph_new();
Depsgraph *depsgraph = DEG_graph_new(scene, view_layer, DAG_EVAL_RENDER);
DEG_evaluation_context_init_from_view_layer_for_render(eval_ctx, depsgraph, scene, view_layer);
int op_result = OPERATOR_CANCELLED;

View File

@ -79,11 +79,11 @@ NodeGroup *BlenderFileLoader::Load()
_z_offset = 0.f;
}
EvaluationContext *eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER);
Depsgraph *depsgraph = DEG_graph_new();
ViewLayer *view_layer = (ViewLayer*)BLI_findstring(&_re->scene->view_layers, _view_layer->name, offsetof(ViewLayer, name));
EvaluationContext *eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER);
Depsgraph *depsgraph = DEG_graph_new(_re->scene, view_layer, DAG_EVAL_RENDER);
DEG_evaluation_context_init_from_view_layer_for_render(
eval_ctx,
depsgraph,

View File

@ -77,7 +77,6 @@ const char *BlenderStrokeRenderer::uvNames[] = {"along_stroke", "along_stroke_ti
BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : StrokeRenderer()
{
freestyle_bmain = re->freestyle_bmain;
freestyle_depsgraph = DEG_graph_new();
// for stroke mesh generation
_width = re->winx;
@ -142,7 +141,6 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str
}
BKE_scene_set_background(freestyle_bmain, freestyle_scene);
DEG_graph_id_tag_update(freestyle_bmain, freestyle_depsgraph, &freestyle_scene->id, 0);
// Scene layer.
ViewLayer *view_layer = (ViewLayer *)freestyle_scene->view_layers.first;
@ -150,7 +148,6 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str
// Camera
Object *object_camera = BKE_object_add(freestyle_bmain, freestyle_scene, view_layer, OB_CAMERA, NULL);
DEG_graph_id_tag_update(freestyle_bmain, freestyle_depsgraph, &object_camera->id, 0);
Camera *camera = (Camera *)object_camera->data;
camera->type = CAM_ORTHO;
@ -179,7 +176,10 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str
else
_nodetree_hash = NULL;
// New IDs were added, tag relations for update.
// Depsgraph
freestyle_depsgraph = DEG_graph_new(re->scene, view_layer, DAG_EVAL_RENDER);
DEG_graph_id_tag_update(freestyle_bmain, freestyle_depsgraph, &freestyle_scene->id, 0);
DEG_graph_id_tag_update(freestyle_bmain, freestyle_depsgraph, &object_camera->id, 0);
DEG_graph_tag_relations_update(freestyle_depsgraph);
}

View File

@ -5948,7 +5948,7 @@ void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, ViewLayer *view_l
RE_init_threadcount(re);
EvaluationContext *eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER);
Depsgraph *depsgraph = DEG_graph_new();
Depsgraph *depsgraph = DEG_graph_new(scene, view_layer, DAG_EVAL_RENDER);
DEG_evaluation_context_init_from_view_layer_for_render(eval_ctx, depsgraph, scene, view_layer);
DEG_graph_build_from_view_layer(depsgraph, bmain, scene, view_layer);
BKE_scene_graph_update_tagged(eval_ctx,

View File

@ -530,21 +530,24 @@ RenderData *RE_engine_get_render_data(Render *re)
/* Depsgraph */
static void engine_depsgraph_init(RenderEngine *engine, ViewLayer *view_layer)
{
Main *bmain = engine->re->main;
Scene *scene = engine->re->scene;
engine->eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER);
engine->depsgraph = DEG_graph_new();
engine->depsgraph = DEG_graph_new(scene, view_layer, DAG_EVAL_RENDER);
engine->view_layer = view_layer;
DEG_evaluation_context_init_from_view_layer_for_render(
engine->eval_ctx,
engine->depsgraph,
engine->re->scene,
scene,
view_layer);
BKE_scene_graph_update_tagged(
engine->eval_ctx,
engine->depsgraph,
engine->re->main,
engine->re->scene,
bmain,
scene,
view_layer);
}