Move base flags evaluation to its own function

No need to have iterator loop in the view layer evaluation,
this only makes it more difficult to have base flags covered
by the dependency graph.

Other good thing is that we don't need to worry about whether
base has been removed from the evaluated view layer or not.

Reviewers: brecht

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D4414
This commit is contained in:
Sergey Sharybin
2019-02-26 15:58:37 +01:00
parent 8a432c1a40
commit 05dc3d43ca
7 changed files with 63 additions and 58 deletions

View File

@@ -114,11 +114,6 @@ bool BKE_layer_collection_set_visible(struct ViewLayer *view_layer, struct Layer
/* evaluation */
void BKE_layer_eval_view_layer(
struct Depsgraph *depsgraph,
struct Scene *scene,
struct ViewLayer *view_layer);
void BKE_layer_eval_view_layer_indexed(
struct Depsgraph *depsgraph,
struct Scene *scene,

View File

@@ -260,7 +260,7 @@ void BKE_object_data_select_update(
struct Depsgraph *depsgraph,
struct ID *object_data);
void BKE_object_eval_flush_base_flags(
void BKE_object_eval_eval_base_flags(
struct Depsgraph *depsgraph,
struct Scene *scene, const int view_layer_index,
struct Object *object, int base_index,

View File

@@ -1462,18 +1462,13 @@ void BKE_view_layer_bases_in_mode_iterator_end(BLI_Iterator *UNUSED(iter))
/* Evaluation */
void BKE_layer_eval_view_layer(
static void layer_eval_view_layer(
struct Depsgraph *depsgraph,
struct Scene *UNUSED(scene),
ViewLayer *view_layer)
{
DEG_debug_print_eval(depsgraph, __func__, view_layer->name, view_layer);
/* Visibility based on depsgraph mode. */
const eEvaluationMode mode = DEG_get_mode(depsgraph);
const int base_enabled_flag = (mode == DAG_EVAL_VIEWPORT)
? BASE_ENABLED_VIEWPORT
: BASE_ENABLED_RENDER;
/* Create array of bases, for fast index-based lookup. */
const int num_object_bases = BLI_listbase_count(&view_layer->object_bases);
MEM_SAFE_FREE(view_layer->object_bases_array);
@@ -1481,37 +1476,8 @@ void BKE_layer_eval_view_layer(
num_object_bases, sizeof(Base *), "view_layer->object_bases_array");
int base_index = 0;
for (Base *base = view_layer->object_bases.first; base; base = base->next) {
/* Compute visibility for depsgraph evaluation mode. */
if (base->flag & base_enabled_flag) {
base->flag |= BASE_ENABLED;
/* When rendering, visibility is controlled by the enable/disable option. */
if (mode == DAG_EVAL_RENDER) {
base->flag |= BASE_VISIBLE;
}
}
else {
base->flag &= ~(BASE_ENABLED | BASE_VISIBLE | BASE_SELECTABLE);
}
/* If base is not selectabled, clear select. */
if ((base->flag & BASE_SELECTABLE) == 0) {
base->flag &= ~BASE_SELECTED;
}
view_layer->object_bases_array[base_index++] = base;
}
/* Flush back base flag to the original view layer for editing. */
if (DEG_is_active(depsgraph) && (view_layer == DEG_get_evaluated_view_layer(depsgraph))) {
ViewLayer *view_layer_orig = DEG_get_input_view_layer(depsgraph);
Base *base_orig = view_layer_orig->object_bases.first;
const Base *base_eval = view_layer->object_bases.first;
while (base_orig != NULL) {
if (base_orig->flag & base_enabled_flag) {
base_orig->flag = base_eval->flag;
base_eval = base_eval->next;
}
base_orig = base_orig->next;
}
}
}
void BKE_layer_eval_view_layer_indexed(
@@ -1522,5 +1488,5 @@ void BKE_layer_eval_view_layer_indexed(
BLI_assert(view_layer_index >= 0);
ViewLayer *view_layer = BLI_findlink(&scene->view_layers, view_layer_index);
BLI_assert(view_layer != NULL);
BKE_layer_eval_view_layer(depsgraph, scene, view_layer);
layer_eval_view_layer(depsgraph, scene, view_layer);
}

View File

@@ -405,10 +405,10 @@ void BKE_object_data_select_update(Depsgraph *depsgraph, ID *object_data)
}
}
void BKE_object_eval_flush_base_flags(Depsgraph *depsgraph,
Scene *scene, const int view_layer_index,
Object *object, int base_index,
const bool is_from_set)
void BKE_object_eval_eval_base_flags(Depsgraph *depsgraph,
Scene *scene, const int view_layer_index,
Object *object, int base_index,
const bool is_from_set)
{
/* TODO(sergey): Avoid list lookup. */
BLI_assert(view_layer_index >= 0);
@@ -422,6 +422,28 @@ void BKE_object_eval_flush_base_flags(Depsgraph *depsgraph,
DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
/* Visibility based on depsgraph mode. */
const eEvaluationMode mode = DEG_get_mode(depsgraph);
const int base_enabled_flag = (mode == DAG_EVAL_VIEWPORT)
? BASE_ENABLED_VIEWPORT
: BASE_ENABLED_RENDER;
/* Compute visibility for depsgraph evaluation mode. */
if (base->flag & base_enabled_flag) {
base->flag |= BASE_ENABLED;
/* When rendering, visibility is controlled by the enable/disable option. */
if (mode == DAG_EVAL_RENDER) {
base->flag |= BASE_VISIBLE;
}
}
else {
base->flag &= ~(BASE_ENABLED | BASE_VISIBLE | BASE_SELECTABLE);
}
/* If base is not selectable, clear select. */
if ((base->flag & BASE_SELECTABLE) == 0) {
base->flag &= ~BASE_SELECTED;
}
/* Copy flags and settings from base. */
object->base_flag = base->flag;
if (is_from_set) {
@@ -438,4 +460,12 @@ void BKE_object_eval_flush_base_flags(Depsgraph *depsgraph,
BKE_particle_batch_cache_dirty_tag(psys, BKE_PARTICLE_BATCH_DIRTY_ALL);
}
}
/* Copy base flag back to the original view layer for editing. */
if (DEG_is_active(depsgraph) && (view_layer == DEG_get_evaluated_view_layer(depsgraph))) {
Base *base_orig = base->base_orig;
BLI_assert(base_orig != NULL);
BLI_assert(base_orig->object != NULL);
base_orig->flag = base->flag;
}
}

View File

@@ -658,7 +658,7 @@ void DepsgraphNodeBuilder::build_object_flags(
add_operation_node(&object->id,
NodeType::OBJECT_FROM_LAYER,
OperationCode::OBJECT_BASE_FLAGS,
function_bind(BKE_object_eval_flush_base_flags,
function_bind(BKE_object_eval_eval_base_flags,
_1,
scene_cow,
view_layer_index_,

View File

@@ -368,12 +368,7 @@ void view_layer_remove_disabled_bases(const Depsgraph *depsgraph,
const int base_enabled_flag = (depsgraph->mode == DAG_EVAL_VIEWPORT) ?
BASE_ENABLED_VIEWPORT : BASE_ENABLED_RENDER;
ListBase enabled_bases = {NULL, NULL};
for (Base *base = reinterpret_cast<Base *>(view_layer->object_bases.first),
*base_next;
base != NULL;
base = base_next)
{
base_next = base->next;
LISTBASE_FOREACH_MUTABLE (Base *, base, &view_layer->object_bases) {
const bool is_object_enabled = (base->flag & base_enabled_flag);
if (is_object_enabled) {
BLI_addtail(&enabled_bases, base);
@@ -388,12 +383,26 @@ void view_layer_remove_disabled_bases(const Depsgraph *depsgraph,
view_layer->object_bases = enabled_bases;
}
void scene_cleanup_view_layers(const Depsgraph *depsgraph, Scene *scene_cow)
void view_layer_update_orig_base_pointers(ViewLayer *view_layer_orig,
ViewLayer *view_layer_eval)
{
Base *base_orig =
reinterpret_cast<Base *>(view_layer_orig->object_bases.first);
LISTBASE_FOREACH (Base *, base_eval, &view_layer_eval->object_bases) {
base_eval->base_orig = base_orig;
base_orig = base_orig->next;
}
}
void scene_setup_view_layers_after_copy(const Depsgraph *depsgraph,
Scene *scene_cow)
{
scene_remove_unused_view_layers(depsgraph, scene_cow);
view_layer_remove_disabled_bases(
depsgraph,
reinterpret_cast<ViewLayer *>(scene_cow->view_layers.first));
ViewLayer *view_layer_orig = depsgraph->view_layer;
ViewLayer *view_layer_eval =
reinterpret_cast<ViewLayer *>(scene_cow->view_layers.first);
view_layer_update_orig_base_pointers(view_layer_orig, view_layer_eval);
view_layer_remove_disabled_bases(depsgraph, view_layer_eval);
/* TODO(sergey): Remove objects from collections as well.
* Not a HUGE deal for now, nobody is looking into those CURRENTLY.
* Still not an excuse to have those. */
@@ -720,7 +729,7 @@ ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph,
{
done = scene_copy_inplace_no_main((Scene *)id_orig, (Scene *)id_cow);
if (done) {
scene_cleanup_view_layers(depsgraph, (Scene *)id_cow);
scene_setup_view_layers_after_copy(depsgraph, (Scene *)id_cow);
}
break;
}

View File

@@ -36,6 +36,11 @@ typedef struct Base {
struct Object *object;
unsigned int lay DNA_DEPRECATED;
int flag_legacy;
/* Pointer to an original base. Is initialized for evaluated view layer.
* NOTE: Only allowed to be accessed from within active dependency graph. */
struct Base *base_orig;
void *_pad;
} Base;
typedef struct ViewLayerEngineData {