[Bf-blender-cvs] [244c87dd680] master: Geometry Nodes: avoid geometry copy if nothing is selected in Set Position node

Jacques Lucke noreply at git.blender.org
Fri Jan 20 21:28:53 CET 2023


Commit: 244c87dd680c4f5b5acfcd088aaae0e04298c4f5
Author: Jacques Lucke
Date:   Fri Jan 20 21:27:13 2023 +0100
Branches: master
https://developer.blender.org/rB244c87dd680c4f5b5acfcd088aaae0e04298c4f5

Geometry Nodes: avoid geometry copy if nothing is selected in Set Position node

This improves performance in cases where the Set Position node is "turned off"
by passing `false` into the selection input.

It's possible that the node still takes some time in this case currently, because
it is destructing the input fields which may reference geometries that need
to be destructed as well. We could potentially change this node (and others)
so that the field inputs are only requested when the selection is not a
constant `false`.

===================================================================

M	source/blender/nodes/geometry/nodes/node_geo_set_position.cc

===================================================================

diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_position.cc b/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
index 2ad126567d1..4f6a256620a 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
@@ -116,19 +116,22 @@ static void set_computed_position_and_offset(GeometryComponent &component,
   }
 }
 
-static void set_position_in_component(GeometryComponent &component,
+static void set_position_in_component(GeometrySet &geometry,
+                                      GeometryComponentType component_type,
                                       const Field<bool> &selection_field,
                                       const Field<float3> &position_field,
                                       const Field<float3> &offset_field)
 {
-  eAttrDomain domain = component.type() == GEO_COMPONENT_TYPE_INSTANCES ? ATTR_DOMAIN_INSTANCE :
-                                                                          ATTR_DOMAIN_POINT;
-  bke::GeometryFieldContext field_context{component, domain};
+  const GeometryComponent &component = *geometry.get_component_for_read(component_type);
+  const eAttrDomain domain = component.type() == GEO_COMPONENT_TYPE_INSTANCES ?
+                                 ATTR_DOMAIN_INSTANCE :
+                                 ATTR_DOMAIN_POINT;
   const int domain_size = component.attribute_domain_size(domain);
   if (domain_size == 0) {
     return;
   }
 
+  bke::GeometryFieldContext field_context{component, domain};
   fn::FieldEvaluator evaluator{field_context, domain_size};
   evaluator.set_selection(selection_field);
   evaluator.add(position_field);
@@ -136,10 +139,14 @@ static void set_position_in_component(GeometryComponent &component,
   evaluator.evaluate();
 
   const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
+  if (selection.is_empty()) {
+    return;
+  }
 
+  GeometryComponent &mutable_component = geometry.get_component_for_write(component_type);
   const VArray<float3> positions_input = evaluator.get_evaluated<float3>(0);
   const VArray<float3> offsets_input = evaluator.get_evaluated<float3>(1);
-  set_computed_position_and_offset(component, positions_input, offsets_input, selection);
+  set_computed_position_and_offset(mutable_component, positions_input, offsets_input, selection);
 }
 
 static void node_geo_exec(GeoNodeExecParams params)
@@ -154,8 +161,7 @@ static void node_geo_exec(GeoNodeExecParams params)
                                            GEO_COMPONENT_TYPE_CURVE,
                                            GEO_COMPONENT_TYPE_INSTANCES}) {
     if (geometry.has(type)) {
-      set_position_in_component(
-          geometry.get_component_for_write(type), selection_field, position_field, offset_field);
+      set_position_in_component(geometry, type, selection_field, position_field, offset_field);
     }
   }



More information about the Bf-blender-cvs mailing list