Depsgraph: Begin work on making depsgraph per-scene-layer

This is a first step towards proper depsgraph "ownership", where
we would allow scene to be in multiple states dependent on active
workspace or scene layer.

This commit introduces a basic API to get proper dependency graph
for a given scene layer. It also renames scene->depsgraph to
depsgraph_legacy, so it's easier to search0-n-replace in the future.
This commit is contained in:
Sergey Sharybin 2017-07-13 15:43:36 +02:00
parent 065cd6e4e4
commit c9aef27326
17 changed files with 59 additions and 38 deletions

View File

@ -39,12 +39,14 @@ extern "C" {
struct AviCodecData;
struct BaseLegacy;
struct Depsgraph;
struct EvaluationContext;
struct Main;
struct Object;
struct Base;
struct QuicktimeCodecData;
struct RenderData;
struct SceneLayer;
struct SceneRenderLayer;
struct Scene;
struct SceneCollection;
@ -184,6 +186,9 @@ void BKE_scene_multiview_view_prefix_get(struct Scene *scene, const char
void BKE_scene_multiview_videos_dimensions_get(const struct RenderData *rd, const size_t width, const size_t height, size_t *r_width, size_t *r_height);
int BKE_scene_multiview_num_videos_get(const struct RenderData *rd);
/* depsgraph */
struct Depsgraph* BKE_scene_get_depsgraph(struct Scene *scene, struct SceneLayer *scene_layer);
#ifdef __cplusplus
}
#endif

View File

@ -2605,7 +2605,8 @@ static bool calc_modifiers_skip_orco(Scene *scene,
else if ((ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) != 0) {
return false;
}
else if ((DEG_get_eval_flags_for_id(scene->depsgraph, &ob->id) & DAG_EVAL_NEED_CPU) != 0) {
/* TODO(sergey): How do we get depsgraph here? */
else if ((DEG_get_eval_flags_for_id(scene->depsgraph_legacy, &ob->id) & DAG_EVAL_NEED_CPU) != 0) {
return false;
}
SubsurfModifierData *smd = (SubsurfModifierData *)last_md;

View File

@ -52,6 +52,7 @@
#include "BKE_context.h"
#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_sound.h"
#include "BKE_workspace.h"
@ -1225,5 +1226,6 @@ int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list)
Depsgraph *CTX_data_depsgraph(const bContext *C)
{
Scene *scene = CTX_data_scene(C);
return scene->depsgraph;
SceneLayer *scene_layer = CTX_data_scene_layer(C);
return BKE_scene_get_depsgraph(scene, scene_layer);
}

View File

@ -1740,8 +1740,9 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
}
if (!for_orco) {
/* TODO(sergey): How do we get depsgraph here? */
if ((cu->flag & CU_PATH) ||
DEG_get_eval_flags_for_id(scene->depsgraph, &ob->id) & DAG_EVAL_NEED_CURVE_PATH)
DEG_get_eval_flags_for_id(scene->depsgraph_legacy, &ob->id) & DAG_EVAL_NEED_CURVE_PATH)
{
calc_curvepath(ob, &nubase);
}

View File

@ -255,7 +255,7 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
scen->ed = NULL;
scen->theDag = NULL;
scen->depsgraph = NULL;
scen->depsgraph_legacy = NULL;
scen->obedit = NULL;
scen->fps_info = NULL;
@ -583,8 +583,8 @@ void BKE_scene_free_ex(Scene *sce, const bool do_id_user)
}
DEG_scene_graph_free(sce);
if (sce->depsgraph)
DEG_graph_free(sce->depsgraph);
if (sce->depsgraph_legacy)
DEG_graph_free(sce->depsgraph_legacy);
MEM_SAFE_FREE(sce->fps_info);
@ -1542,7 +1542,7 @@ void BKE_scene_update_tagged(EvaluationContext *eval_ctx, Main *bmain, Scene *sc
*
* in the future this should handle updates for all datablocks, not
* only objects and scenes. - brecht */
DEG_evaluate_on_refresh(eval_ctx, scene->depsgraph, scene);
DEG_evaluate_on_refresh(eval_ctx, scene->depsgraph_legacy, scene);
/* TODO(sergey): This is to beocme a node in new depsgraph. */
BKE_mask_update_scene(bmain, scene);
@ -1604,7 +1604,7 @@ void BKE_scene_update_for_newframe(EvaluationContext *eval_ctx, Main *bmain, Sce
BKE_main_id_tag_idcode(bmain, ID_LA, LIB_TAG_DOIT, false);
/* BKE_object_handle_update() on all objects, groups and sets */
DEG_evaluate_on_framechange(eval_ctx, bmain, sce->depsgraph, ctime);
DEG_evaluate_on_framechange(eval_ctx, bmain, sce->depsgraph_legacy, ctime);
/* update sound system animation (TODO, move to depsgraph) */
BKE_sound_update_scene(bmain, sce);
@ -2250,3 +2250,9 @@ int BKE_scene_multiview_num_videos_get(const RenderData *rd)
return BKE_scene_multiview_num_views_get(rd);
}
}
Depsgraph* BKE_scene_get_depsgraph(Scene *scene, SceneLayer *scene_layer)
{
(void) scene_layer;
return scene->depsgraph_legacy;
}

View File

@ -6093,7 +6093,7 @@ static void direct_link_scene(FileData *fd, Scene *sce, Main *bmain)
SceneRenderLayer *srl;
sce->theDag = NULL;
sce->depsgraph = NULL;
sce->depsgraph_legacy = NULL;
sce->obedit = NULL;
sce->fps_info = NULL;
sce->customdata_mask_modal = 0;

View File

@ -261,8 +261,8 @@ void DEG_relations_tag_update(Main *bmain)
scene != NULL;
scene = (Scene *)scene->id.next)
{
if (scene->depsgraph != NULL) {
DEG_graph_tag_relations_update(scene->depsgraph);
if (scene->depsgraph_legacy != NULL) {
DEG_graph_tag_relations_update(scene->depsgraph_legacy);
}
}
}
@ -272,14 +272,14 @@ void DEG_relations_tag_update(Main *bmain)
*/
void DEG_scene_relations_update(Main *bmain, Scene *scene)
{
if (scene->depsgraph == NULL) {
if (scene->depsgraph_legacy == NULL) {
/* Rebuild graph from scratch and exit. */
scene->depsgraph = DEG_graph_new();
DEG_graph_build_from_scene(scene->depsgraph, bmain, scene);
scene->depsgraph_legacy = DEG_graph_new();
DEG_graph_build_from_scene(scene->depsgraph_legacy, bmain, scene);
return;
}
DEG::Depsgraph *graph = reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph);
DEG::Depsgraph *graph = reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph_legacy);
if (!graph->need_update) {
/* Graph is up to date, nothing to do. */
return;
@ -301,17 +301,17 @@ void DEG_scene_relations_update(Main *bmain, Scene *scene)
/* Rebuild dependency graph only for a given scene. */
void DEG_scene_relations_rebuild(Main *bmain, Scene *scene)
{
if (scene->depsgraph != NULL) {
DEG_graph_tag_relations_update(scene->depsgraph);
if (scene->depsgraph_legacy != NULL) {
DEG_graph_tag_relations_update(scene->depsgraph_legacy);
}
DEG_scene_relations_update(bmain, scene);
}
void DEG_scene_graph_free(Scene *scene)
{
if (scene->depsgraph) {
DEG_graph_free(scene->depsgraph);
scene->depsgraph = NULL;
if (scene->depsgraph_legacy) {
DEG_graph_free(scene->depsgraph_legacy);
scene->depsgraph_legacy = NULL;
}
}

View File

@ -91,7 +91,7 @@ bool DEG_debug_scene_relations_validate(Main *bmain,
Depsgraph *depsgraph = DEG_graph_new();
bool valid = true;
DEG_graph_build_from_scene(depsgraph, bmain, scene);
if (!DEG_debug_compare(depsgraph, scene->depsgraph)) {
if (!DEG_debug_compare(depsgraph, scene->depsgraph_legacy)) {
fprintf(stderr, "ERROR! Depsgraph wasn't tagged for update when it should have!\n");
BLI_assert(!"This should not happen!");
valid = false;

View File

@ -230,8 +230,8 @@ void DEG_id_tag_update_ex(Main *bmain, ID *id, int flag)
scene != NULL;
scene = (Scene *)scene->id.next)
{
if (scene->depsgraph) {
Depsgraph *graph = scene->depsgraph;
if (scene->depsgraph_legacy) {
Depsgraph *graph = scene->depsgraph_legacy;
if (flag == 0) {
/* TODO(sergey): Currently blender is still tagging IDs
* for recalc just using flag=0. This isn't totally correct
@ -294,10 +294,10 @@ void DEG_id_type_tag(Main *bmain, short idtype)
void DEG_ids_flush_tagged(Main *bmain, Scene *scene)
{
/* TODO(sergey): Only visible scenes? */
if (scene->depsgraph != NULL) {
if (scene->depsgraph_legacy != NULL) {
DEG::deg_graph_flush_updates(
bmain,
reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph));
reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph_legacy));
}
}
@ -305,7 +305,7 @@ void DEG_ids_flush_tagged(Main *bmain, Scene *scene)
void DEG_graph_on_visible_update(Main *bmain, Scene *scene)
{
(void) bmain;
DEG::Depsgraph *graph = reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph);
DEG::Depsgraph *graph = reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph_legacy);
GHASH_FOREACH_BEGIN(DEG::IDDepsNode *, id_node, graph->id_hash)
{
id_node->tag_update(graph);
@ -319,7 +319,7 @@ void DEG_on_visible_update(Main *bmain, const bool UNUSED(do_time))
scene != NULL;
scene = (Scene *)scene->id.next)
{
if (scene->depsgraph != NULL) {
if (scene->depsgraph_legacy != NULL) {
DEG_graph_on_visible_update(bmain, scene);
}
}

View File

@ -360,7 +360,7 @@ void ED_draw_object_facemap(struct Scene *scene, struct Object *ob, const float
bool ED_view3d_context_activate(struct bContext *C);
void ED_view3d_draw_offscreen_init(struct Scene *scene, struct SceneLayer *sl, struct View3D *v3d);
void ED_view3d_draw_offscreen(
struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int winx, int winy, float viewmat[4][4],
struct Scene *scene, struct SceneLayer *sl, struct View3D *v3d, struct ARegion *ar, int winx, int winy, float viewmat[4][4],
float winmat[4][4], bool do_bgpic, bool do_sky, bool is_persp, const char *viewname,
struct GPUFX *fx, struct GPUFXSettings *fx_settings,
struct GPUOffScreen *ofs);

View File

@ -1947,7 +1947,7 @@ static void view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar)
* stuff like shadow buffers
*/
void ED_view3d_draw_offscreen(
Scene *scene, View3D *v3d, ARegion *ar, int winx, int winy,
Scene *scene, SceneLayer *sl, View3D *v3d, ARegion *ar, int winx, int winy,
float viewmat[4][4], float winmat[4][4],
bool do_bgpic, bool do_sky, bool is_persp, const char *viewname,
GPUFX *fx, GPUFXSettings *fx_settings,
@ -2043,7 +2043,8 @@ void ED_view3d_draw_offscreen(
}
else {
/* XXX, should take depsgraph as arg */
DRW_draw_render_loop_offscreen(scene->depsgraph, ar, v3d, ofs);
Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, sl);
DRW_draw_render_loop_offscreen(depsgraph, ar, v3d, ofs);
}
/* restore size */
@ -2137,7 +2138,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
if ((samples && full_samples) == 0) {
/* Single-pass render, common case */
ED_view3d_draw_offscreen(
scene, v3d, ar, sizex, sizey, NULL, winmat,
scene, sl, v3d, ar, sizex, sizey, NULL, winmat,
draw_background, draw_sky, !is_ortho, viewname,
fx, &fx_settings, ofs);
@ -2161,7 +2162,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
/* first sample buffer, also initializes 'rv3d->persmat' */
ED_view3d_draw_offscreen(
scene, v3d, ar, sizex, sizey, NULL, winmat,
scene, sl, v3d, ar, sizex, sizey, NULL, winmat,
draw_background, draw_sky, !is_ortho, viewname,
fx, &fx_settings, ofs);
GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, rect_temp);
@ -2180,7 +2181,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
(jit_ofs[j][1] * 2.0f) / sizey);
ED_view3d_draw_offscreen(
scene, v3d, ar, sizex, sizey, NULL, winmat_jitter,
scene, sl, v3d, ar, sizex, sizey, NULL, winmat_jitter,
draw_background, draw_sky, !is_ortho, viewname,
fx, &fx_settings, ofs);
GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, rect_temp);

View File

@ -1422,7 +1422,7 @@ static void gpu_update_lamps_shadows_world(Scene *scene, View3D *v3d)
/* no need to call ED_view3d_draw_offscreen_init since shadow buffers were already updated */
ED_view3d_draw_offscreen(
scene, v3d, &ar, winsize, winsize, viewmat, winmat,
scene, BKE_scene_layer_context_active(scene), v3d, &ar, winsize, winsize, viewmat, winmat,
false, false, true,
NULL, NULL, NULL, NULL);
GPU_lamp_shadow_buffer_unbind(shadow->lamp);

View File

@ -1697,7 +1697,7 @@ typedef struct Scene {
void *fps_info; /* (runtime) info/cache used for presenting playback framerate info to the user */
/* none of the dependency graph vars is mean to be saved */
struct Depsgraph *depsgraph;
struct Depsgraph *depsgraph_legacy;
void *pad1;
struct DagForest *theDag;
short dagflags;

View File

@ -9384,6 +9384,7 @@ void RNA_def_scene(BlenderRNA *brna)
/* Dependency Graph */
prop = RNA_def_property(srna, "depsgraph", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "depsgraph_legacy");
RNA_def_property_struct_type(prop, "Depsgraph");
RNA_def_property_ui_text(prop, "Dependency Graph", "Dependencies in the scene data");

View File

@ -135,7 +135,8 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
else if ((ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) != 0) {
modifier_setError(md, "OpenSubdiv is not supported in paint modes");
}
else if ((DEG_get_eval_flags_for_id(md->scene->depsgraph, &ob->id) & DAG_EVAL_NEED_CPU) == 0) {
/* TODO(sergey): How do we get depsgraph here? */
else if ((DEG_get_eval_flags_for_id(md->scene->depsgraph_legacy, &ob->id) & DAG_EVAL_NEED_CPU) == 0) {
subsurf_flags |= SUBSURF_USE_GPU_BACKEND;
do_cddm_convert = false;
}

View File

@ -231,7 +231,7 @@ static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *a
GPU_offscreen_bind(self->ofs, true); /* bind */
ED_view3d_draw_offscreen(
scene, v3d, ar, GPU_offscreen_width(self->ofs), GPU_offscreen_height(self->ofs),
scene, sl, v3d, ar, GPU_offscreen_width(self->ofs), GPU_offscreen_height(self->ofs),
(float(*)[4])py_mat_modelview->matrix, (float(*)[4])py_mat_projection->matrix,
false, true, true, "",
fx, &fx_settings,

View File

@ -64,6 +64,7 @@
#include "BKE_colortools.h"
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_library_remap.h"
#include "BKE_main.h"
@ -3795,6 +3796,8 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
void RE_PreviewRender(Render *re, Main *bmain, Scene *sce)
{
Object *camera;
/* TODO(sergey): Get proper scene layer here. */
SceneLayer *scene_layer = BKE_scene_layer_context_active_ex(bmain, sce);
int winx, winy;
winx = (sce->r.size * sce->r.xsch) / 100;
@ -3808,7 +3811,7 @@ void RE_PreviewRender(Render *re, Main *bmain, Scene *sce)
re->scene = sce;
re->scene_color_manage = BKE_scene_check_color_management_enabled(sce);
re->lay = sce->lay;
re->depsgraph = sce->depsgraph;
re->depsgraph = BKE_scene_get_depsgraph(sce, scene_layer);
camera = RE_GetCamera(re);
RE_SetCamera(re, camera);