Fix #124298: Cryptomatte node makes UI very slow

The Cryptomatte node makes the UI very slow in Image mode. That's
because the node updates its available Cryptomatte layers on every
redraw, which is a blocking operation that is not very fast.

To fix this, we only update the layers when engine layers change for
the Scene mode, and when image settings change for Image mode.

Pull Request: https://projects.blender.org/blender/blender/pulls/124738
This commit is contained in:
Omar Emara
2024-07-17 09:40:28 +02:00
committed by Omar Emara
parent 0e7f80b262
commit f0ec207e9c
3 changed files with 14 additions and 2 deletions

View File

@@ -3247,7 +3247,6 @@ static const EnumPropertyItem *rna_NodeCryptomatte_layer_name_itemf(bContext * /
EnumPropertyItem temp = {0, "", 0, "", ""};
int totitem = 0;
ntreeCompositCryptomatteUpdateLayerNames(node);
int layer_index;
LISTBASE_FOREACH_INDEX (CryptomatteLayer *, layer, &storage->runtime.layers, layer_index) {
temp.value = layer_index;
@@ -8820,6 +8819,7 @@ static void def_cmp_cryptomatte(StructRNA *srna)
RNA_def_property_enum_items(prop, cryptomatte_source_items);
RNA_def_property_enum_funcs(prop, nullptr, "rna_NodeCryptomatte_source_set", nullptr);
RNA_def_property_ui_text(prop, "Source", "Where the Cryptomatte passes are loaded from");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update_relations");
prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_funcs(
@@ -8840,7 +8840,7 @@ static void def_cmp_cryptomatte(StructRNA *srna)
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
RNA_def_property_ui_text(prop, "Image", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update_relations");
RNA_def_struct_sdna_from(srna, "NodeCryptomatte", "storage");
def_cmp_cryptomatte_common(srna);

View File

@@ -202,6 +202,11 @@ void ntreeCompositUpdateRLayers(bNodeTree *ntree)
if (node->type == CMP_NODE_R_LAYERS) {
node_cmp_rlayers_outputs(ntree, node);
}
else if (node->type == CMP_NODE_CRYPTOMATTE &&
node->custom1 == CMP_NODE_CRYPTOMATTE_SOURCE_RENDER)
{
node->typeinfo->updatefunc(ntree, node);
}
}
}

View File

@@ -489,6 +489,12 @@ static bool node_poll_cryptomatte(const blender::bke::bNodeType * /*ntype*/,
return false;
}
static void node_update_cryptomatte(bNodeTree *ntree, bNode *node)
{
cmp_node_update_default(ntree, node);
ntreeCompositCryptomatteUpdateLayerNames(node);
}
using namespace blender::realtime_compositor;
using namespace blender::nodes::node_composite_base_cryptomatte_cc;
@@ -755,6 +761,7 @@ void register_node_type_cmp_cryptomatte()
ntype.initfunc = file_ns::node_init_cryptomatte;
ntype.initfunc_api = file_ns::node_init_api_cryptomatte;
ntype.poll = file_ns::node_poll_cryptomatte;
ntype.updatefunc = file_ns::node_update_cryptomatte;
blender::bke::node_type_storage(
&ntype, "NodeCryptomatte", file_ns::node_free_cryptomatte, file_ns::node_copy_cryptomatte);
ntype.get_compositor_operation = file_ns::get_compositor_operation;