From c980ed27f09fbb88e4073f8b142830210cf6b28a Mon Sep 17 00:00:00 2001 From: MOD Date: Wed, 25 May 2022 13:55:22 +0200 Subject: Geometry Nodes: skip Capture Attribute node if output is not needed This results in a speedup if the capture attribute is only needed under specific circumstances (e.g. when a switch further down the line is true). Previously, the input field was always evaluated. Differential Revision: https://developer.blender.org/D15018 --- .../geometry/nodes/node_geo_attribute_capture.cc | 56 ++++++++++++++++++---- 1 file changed, 46 insertions(+), 10 deletions(-) (limited to 'source/blender/nodes') diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc index 18cf005c965..16967d32673 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc @@ -126,30 +126,66 @@ static void try_capture_field_on_geometry(GeometryComponent &component, output_attribute.save(); } +static StringRefNull identifier_suffix(CustomDataType data_type) +{ + switch (data_type) { + case CD_PROP_FLOAT: + return "_001"; + case CD_PROP_INT32: + return "_004"; + case CD_PROP_COLOR: + return "_002"; + case CD_PROP_BOOL: + return "_003"; + case CD_PROP_FLOAT3: + return ""; + default: + BLI_assert_unreachable(); + return ""; + } +} + static void node_geo_exec(GeoNodeExecParams params) { GeometrySet geometry_set = params.extract_input("Geometry"); + if (!params.output_is_required("Geometry")) { + params.error_message_add( + NodeWarningType::Info, + TIP_("The attribute output can not be used without the geometry output")); + params.set_default_remaining_outputs(); + return; + } + const NodeGeometryAttributeCapture &storage = node_storage(params.node()); const CustomDataType data_type = static_cast(storage.data_type); const AttributeDomain domain = static_cast(storage.domain); + const std::string output_identifier = "Attribute" + identifier_suffix(data_type); + + if (!params.output_is_required(output_identifier)) { + params.set_output("Geometry", geometry_set); + return; + } + + const std::string input_identifier = "Value" + identifier_suffix(data_type); GField field; + switch (data_type) { case CD_PROP_FLOAT: - field = params.get_input>("Value_001"); + field = params.get_input>(input_identifier); break; case CD_PROP_FLOAT3: - field = params.get_input>("Value"); + field = params.get_input>(input_identifier); break; case CD_PROP_COLOR: - field = params.get_input>("Value_002"); + field = params.get_input>(input_identifier); break; case CD_PROP_BOOL: - field = params.get_input>("Value_003"); + field = params.get_input>(input_identifier); break; case CD_PROP_INT32: - field = params.get_input>("Value_004"); + field = params.get_input>(input_identifier); break; default: break; @@ -185,23 +221,23 @@ static void node_geo_exec(GeoNodeExecParams params) switch (data_type) { case CD_PROP_FLOAT: { - params.set_output("Attribute_001", Field(output_field)); + params.set_output(output_identifier, Field(output_field)); break; } case CD_PROP_FLOAT3: { - params.set_output("Attribute", Field(output_field)); + params.set_output(output_identifier, Field(output_field)); break; } case CD_PROP_COLOR: { - params.set_output("Attribute_002", Field(output_field)); + params.set_output(output_identifier, Field(output_field)); break; } case CD_PROP_BOOL: { - params.set_output("Attribute_003", Field(output_field)); + params.set_output(output_identifier, Field(output_field)); break; } case CD_PROP_INT32: { - params.set_output("Attribute_004", Field(output_field)); + params.set_output(output_identifier, Field(output_field)); break; } default: -- cgit v1.2.3