[Bf-blender-cvs] [99289e8d51e] virtual-array-attributes: cleanup

Jacques Lucke noreply at git.blender.org
Tue Apr 13 13:25:47 CEST 2021


Commit: 99289e8d51e367440d782c75ddca2bd00c1dec6b
Author: Jacques Lucke
Date:   Tue Apr 13 12:23:04 2021 +0200
Branches: virtual-array-attributes
https://developer.blender.org/rB99289e8d51e367440d782c75ddca2bd00c1dec6b

cleanup

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

M	source/blender/blenkernel/BKE_attribute_access.hh
M	source/blender/functions/FN_generic_virtual_array.hh
M	source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_clamp.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_convert.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_map_range.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc

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

diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh
index 041b66517f4..1048143b942 100644
--- a/source/blender/blenkernel/BKE_attribute_access.hh
+++ b/source/blender/blenkernel/BKE_attribute_access.hh
@@ -67,6 +67,7 @@ class OutputAttribute {
   std::unique_ptr<GVMutableArray> varray_;
   AttributeDomain domain_;
   SaveF save_;
+  std::optional<fn::GVMutableArray_Span> optional_span_varray_;
 
  public:
   OutputAttribute() = default;
@@ -111,7 +112,21 @@ class OutputAttribute {
     return cpp_type_to_custom_data_type(this->cpp_type());
   }
 
-  void save_if_necessary();
+  fn::GMutableSpan as_span()
+  {
+    if (!optional_span_varray_.has_value()) {
+      optional_span_varray_.emplace(*varray_);
+    }
+    fn::GVMutableArray_Span &span_varray = *optional_span_varray_;
+    return span_varray.get_span();
+  }
+
+  template<typename T> MutableSpan<T> as_span()
+  {
+    return this->as_span().typed<T>();
+  }
+
+  void save();
 };
 
 template<typename T> class OutputAttribute_Typed {
@@ -164,9 +179,14 @@ template<typename T> class OutputAttribute_Typed {
     return cpp_type_to_custom_data_type(this->cpp_type());
   }
 
-  void save_if_necessary()
+  MutableSpan<T> as_span()
+  {
+    return attribute_.as_span<T>();
+  }
+
+  void save()
   {
-    attribute_.save_if_necessary();
+    attribute_.save();
   }
 };
 
diff --git a/source/blender/functions/FN_generic_virtual_array.hh b/source/blender/functions/FN_generic_virtual_array.hh
index 991044617fe..e94e6595fc1 100644
--- a/source/blender/functions/FN_generic_virtual_array.hh
+++ b/source/blender/functions/FN_generic_virtual_array.hh
@@ -534,6 +534,11 @@ class GVArray_Span final : public GVArray_For_GSpan {
 
   GSpan as_span() const;
   operator GSpan() const;
+
+  const void *data() const
+  {
+    return data_;
+  }
 };
 
 class GVMutableArray_Span final : public GVMutableArray_For_GMutableSpan {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc b/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc
index a412dfe2274..ffcbae6b5cd 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc
@@ -166,7 +166,7 @@ static void align_rotations_on_component(GeometryComponent &component,
     align_rotations_fixed_pivot(vectors, factors, local_main_axis, local_pivot_axis, *rotations);
   }
 
-  rotations.save_if_necessary();
+  rotations.save();
 }
 
 static void geo_node_align_rotation_to_vector_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_clamp.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_clamp.cc
index d93c2aa00f3..2bd36cfd119 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_clamp.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_clamp.cc
@@ -113,7 +113,7 @@ template<> inline Color4f clamp_value(const Color4f val, const Color4f min, cons
 
 template<typename T>
 static void clamp_attribute(const VArray<T> &inputs,
-                            VMutableArray<T> &outputs,
+                            const MutableSpan<T> &outputs,
                             const T min,
                             const T max)
 {
@@ -185,33 +185,31 @@ static void clamp_attribute(GeometryComponent &component, const GeoNodeExecParam
           std::swap(min.z, max.z);
         }
       }
-      clamp_attribute<float3>(
-          *attribute_input->typed<float3>(), *attribute_result->typed<float3>(), min, max);
+      MutableSpan<float3> results = attribute_result.as_span<float3>();
+      clamp_attribute<float3>(*attribute_input->typed<float3>(), results, min, max);
       break;
     }
     case CD_PROP_FLOAT: {
       const float min = params.get_input<float>("Min_001");
       const float max = params.get_input<float>("Max_001");
+      MutableSpan<float> results = attribute_result.as_span<float>();
       if (operation == NODE_CLAMP_RANGE && min > max) {
-        clamp_attribute<float>(
-            *attribute_input->typed<float>(), *attribute_result->typed<float>(), max, min);
+        clamp_attribute<float>(*attribute_input->typed<float>(), results, max, min);
       }
       else {
-        clamp_attribute<float>(
-            *attribute_input->typed<float>(), *attribute_result->typed<float>(), min, max);
+        clamp_attribute<float>(*attribute_input->typed<float>(), results, min, max);
       }
       break;
     }
     case CD_PROP_INT32: {
       const int min = params.get_input<int>("Min_002");
       const int max = params.get_input<int>("Max_002");
+      MutableSpan<int> results = attribute_result.as_span<int>();
       if (operation == NODE_CLAMP_RANGE && min > max) {
-        clamp_attribute<int>(
-            *attribute_input->typed<int>(), *attribute_result->typed<int>(), max, min);
+        clamp_attribute<int>(*attribute_input->typed<int>(), results, max, min);
       }
       else {
-        clamp_attribute<int>(
-            *attribute_input->typed<int>(), *attribute_result->typed<int>(), min, max);
+        clamp_attribute<int>(*attribute_input->typed<int>(), results, min, max);
       }
       break;
     }
@@ -232,8 +230,8 @@ static void clamp_attribute(GeometryComponent &component, const GeoNodeExecParam
           std::swap(min.a, max.a);
         }
       }
-      clamp_attribute<Color4f>(
-          *attribute_input->typed<Color4f>(), *attribute_result->typed<Color4f>(), min, max);
+      MutableSpan<Color4f> results = attribute_result.as_span<Color4f>();
+      clamp_attribute<Color4f>(*attribute_input->typed<Color4f>(), results, min, max);
       break;
     }
     default: {
@@ -242,7 +240,7 @@ static void clamp_attribute(GeometryComponent &component, const GeoNodeExecParam
     }
   }
 
-  attribute_result.save_if_necessary();
+  attribute_result.save();
 }
 
 static void geo_node_attribute_clamp_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc
index 64fb3308149..bc70505888a 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc
@@ -90,7 +90,7 @@ static void execute_on_component(const GeoNodeExecParams &params, GeometryCompon
   }
 
   results.apply();
-  attribute_result.save_if_necessary();
+  attribute_result.save();
 }
 
 static void geo_node_attribute_color_ramp_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
index f78f19a01a3..a43a053d769 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
@@ -322,7 +322,7 @@ static void attribute_compare_calc(GeometryComponent &component, const GeoNodeEx
         attribute_a->typed<float>(), attribute_b->typed<float>(), operation, result_span);
   }
 
-  attribute_result.save_if_necessary();
+  attribute_result.save();
 }
 
 static void geo_node_attribute_compare_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_convert.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_convert.cc
index ddb917b5d0b..885860af7e8 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_convert.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_convert.cc
@@ -92,21 +92,16 @@ static void attribute_convert_calc(GeometryComponent &component,
     return;
   }
 
-  fn::GSpan source_span = source_attribute->get_span();
-  fn::GVMutableArray_Span result_span{*result_attribute};
-  if (source_span.is_empty() || result_span.is_empty()) {
-    return;
-  }
+  fn::GVArray_Span source_span{*source_attribute};
+  fn::GMutableSpan result_span = result_attribute.as_span();
+
   BLI_assert(source_span.size() == result_span.size());
 
   const CPPType *cpp_type = bke::custom_data_type_to_cpp_type(result_type);
   BLI_assert(cpp_type != nullptr);
 
-  cpp_type->copy_to_initialized_n(
-      source_span.data(), result_span.get_span().data(), result_span.size());
-
-  result_span.apply();
-  result_attribute.save_if_necessary();
+  cpp_type->copy_to_initialized_n(source_span.data(), result_span.data(), result_span.size());
+  result_attribute.save();
 }
 
 static void geo_node_attribute_convert_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
index 9b2c8820734..51f19b3b1aa 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
@@ -129,7 +129,7 @@ static void fill_attribute(GeometryComponent &component, const GeoNodeExecParams
       break;
   }
 
-  attribute.save_if_necessary();
+  attribute.save();
 }
 
 static void geo_node_attribute_fill_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_map_range.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_map_range.cc
index de3b4ae3c78..27a50a54df7 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_map_range.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_map_range.cc
@@ -193,7 +193,7 @@ static float map_smootherstep(const float value,
 }
 
 static void map_range_float(const VArray<float> &attribute_input,
-                            VMutableArray<float> &attribute_result,
+                            MutableSpan<float> results,
                             const GeoNodeExecParams &params)
 {
   const bNode &node = params.node();
@@ -205,31 +205,30 @@ static void map_range_float(const VArray<float> &attribute_input,
   const float max_to = params.get_input<float>("To Max");
 
   VArray_Span<float> span{attribute_input};
-  VMutableArray_Span<float> result_span{attribute_result};
 
   switch (interpolation_type) {
     case NODE_MAP_RANGE_LINEAR: {
       for (int i : span

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list