[Bf-blender-cvs] [5d9ade27de5] master: BLI: improve span access to virtual arrays

Jacques Lucke noreply at git.blender.org
Sat Jul 2 11:46:07 CEST 2022


Commit: 5d9ade27de54b6910ed32f92d20d8f692959603c
Author: Jacques Lucke
Date:   Sat Jul 2 11:45:57 2022 +0200
Branches: master
https://developer.blender.org/rB5d9ade27de54b6910ed32f92d20d8f692959603c

BLI: improve span access to virtual arrays

* Make the class names more consistent.
* Implement missing move-constructors and assignment-operators.

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

M	source/blender/blenkernel/BKE_attribute_access.hh
M	source/blender/blenkernel/intern/attribute_access.cc
M	source/blender/blenkernel/intern/curve_eval.cc
M	source/blender/blenkernel/intern/curve_to_mesh_convert.cc
M	source/blender/blenkernel/intern/curves_geometry.cc
M	source/blender/blenkernel/intern/geometry_component_curve.cc
M	source/blender/blenlib/BLI_generic_virtual_array.hh
M	source/blender/blenlib/BLI_virtual_array.hh
M	source/blender/blenlib/intern/generic_virtual_array.cc
M	source/blender/blenlib/tests/BLI_virtual_array_test.cc
M	source/blender/editors/curves/intern/curves_ops.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_add.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_density.cc
M	source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
M	source/blender/editors/sculpt_paint/paint_vertex_color_ops.cc
M	source/blender/geometry/intern/realize_instances.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc
M	source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
M	source/blender/nodes/geometry/nodes/node_geo_dual_mesh.cc
M	source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
M	source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
M	source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc

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

diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh
index fef91d6f75d..9648b5b7cde 100644
--- a/source/blender/blenkernel/BKE_attribute_access.hh
+++ b/source/blender/blenkernel/BKE_attribute_access.hh
@@ -218,7 +218,7 @@ struct WriteAttributeLookup {
  * Supported convenience features:
  * - Implicit type conversion when writing to builtin attributes.
  * - Supports simple access to a span containing the attribute values (that avoids the use of
- *   VMutableArray_Span in many cases).
+ *   MutableVArraySpan in many cases).
  * - An output attribute can live side by side with an existing attribute with a different domain
  *   or data type. The old attribute will only be overwritten when the #save function is called.
  *
@@ -234,7 +234,7 @@ class OutputAttribute {
   GVMutableArray varray_;
   eAttrDomain domain_ = ATTR_DOMAIN_AUTO;
   SaveFn save_;
-  std::unique_ptr<GVMutableArray_GSpan> optional_span_varray_;
+  std::unique_ptr<GMutableVArraySpan> optional_span_varray_;
   bool ignore_old_values_ = false;
   bool save_has_been_called_ = false;
 
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 409941623d2..ee9358eb97e 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -155,10 +155,9 @@ GMutableSpan OutputAttribute::as_span()
 {
   if (!optional_span_varray_) {
     const bool materialize_old_values = !ignore_old_values_;
-    optional_span_varray_ = std::make_unique<GVMutableArray_GSpan>(varray_,
-                                                                   materialize_old_values);
+    optional_span_varray_ = std::make_unique<GMutableVArraySpan>(varray_, materialize_old_values);
   }
-  GVMutableArray_GSpan &span_varray = *optional_span_varray_;
+  GMutableVArraySpan &span_varray = *optional_span_varray_;
   return span_varray;
 }
 
diff --git a/source/blender/blenkernel/intern/curve_eval.cc b/source/blender/blenkernel/intern/curve_eval.cc
index dd2bd982506..c01a184c6f9 100644
--- a/source/blender/blenkernel/intern/curve_eval.cc
+++ b/source/blender/blenkernel/intern/curve_eval.cc
@@ -21,14 +21,14 @@ using blender::Array;
 using blender::float3;
 using blender::float4x4;
 using blender::GVArray;
-using blender::GVArray_GSpan;
+using blender::GVArraySpan;
 using blender::IndexRange;
 using blender::Map;
 using blender::MutableSpan;
 using blender::Span;
 using blender::StringRefNull;
 using blender::VArray;
-using blender::VArray_Span;
+using blender::VArraySpan;
 using blender::Vector;
 using blender::bke::AttributeIDRef;
 using blender::bke::OutputAttribute;
@@ -360,7 +360,7 @@ static void copy_attributes_between_components(const GeometryComponent &src_comp
         if (!src_attribute) {
           return true;
         }
-        GVArray_GSpan src_attribute_data{src_attribute};
+        GVArraySpan src_attribute_data{src_attribute};
 
         OutputAttribute dst_attribute = dst_component.attribute_try_get_for_output_only(
             id, meta_data.domain, meta_data.data_type);
@@ -383,16 +383,16 @@ std::unique_ptr<CurveEval> curves_to_curve_eval(const Curves &curves_id)
   VArray<int> resolution = curves.resolution();
   VArray<int8_t> normal_mode = curves.normal_mode();
 
-  VArray_Span<float> nurbs_weights{
+  VArraySpan<float> nurbs_weights{
       src_component.attribute_get_for_read<float>("nurbs_weight", ATTR_DOMAIN_POINT, 0.0f)};
-  VArray_Span<int8_t> nurbs_orders{
+  VArraySpan<int8_t> nurbs_orders{
       src_component.attribute_get_for_read<int8_t>("nurbs_order", ATTR_DOMAIN_CURVE, 4)};
-  VArray_Span<int8_t> nurbs_knots_modes{
+  VArraySpan<int8_t> nurbs_knots_modes{
       src_component.attribute_get_for_read<int8_t>("knots_mode", ATTR_DOMAIN_CURVE, 0)};
 
-  VArray_Span<int8_t> handle_types_right{
+  VArraySpan<int8_t> handle_types_right{
       src_component.attribute_get_for_read<int8_t>("handle_type_right", ATTR_DOMAIN_POINT, 0)};
-  VArray_Span<int8_t> handle_types_left{
+  VArraySpan<int8_t> handle_types_left{
       src_component.attribute_get_for_read<int8_t>("handle_type_left", ATTR_DOMAIN_POINT, 0)};
 
   /* Create splines with the correct size and type. */
diff --git a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
index 58380a1a35f..78e5d07da96 100644
--- a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
+++ b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
@@ -228,8 +228,8 @@ struct CurvesInfo {
   const CurvesGeometry &profile;
 
   /* Make sure these are spans because they are potentially accessed many times. */
-  VArray_Span<bool> main_cyclic;
-  VArray_Span<bool> profile_cyclic;
+  VArraySpan<bool> main_cyclic;
+  VArraySpan<bool> profile_cyclic;
 };
 static CurvesInfo get_curves_info(const CurvesGeometry &main, const CurvesGeometry &profile)
 {
@@ -700,8 +700,8 @@ Mesh *curve_to_mesh_sweep(const CurvesGeometry &main,
 
   if (profile.curve_type_counts()[CURVE_TYPE_BEZIER] > 0) {
     const VArray<int8_t> curve_types = profile.curve_types();
-    const VArray_Span<int8_t> handle_types_left{profile.handle_types_left()};
-    const VArray_Span<int8_t> handle_types_right{profile.handle_types_right()};
+    const VArraySpan<int8_t> handle_types_left{profile.handle_types_left()};
+    const VArraySpan<int8_t> handle_types_right{profile.handle_types_right()};
 
     foreach_curve_combination(curves_info, offsets, [&](const CombinationInfo &info) {
       if (curve_types[info.i_profile] == CURVE_TYPE_BEZIER) {
diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc
index 0326afca202..8d955a46275 100644
--- a/source/blender/blenkernel/intern/curves_geometry.cc
+++ b/source/blender/blenkernel/intern/curves_geometry.cc
@@ -477,8 +477,8 @@ static void calculate_evaluated_offsets(const CurvesGeometry &curves,
   VArray<int> resolution = curves.resolution();
   VArray<bool> cyclic = curves.cyclic();
 
-  VArray_Span<int8_t> handle_types_left{curves.handle_types_left()};
-  VArray_Span<int8_t> handle_types_right{curves.handle_types_right()};
+  VArraySpan<int8_t> handle_types_left{curves.handle_types_left()};
+  VArraySpan<int8_t> handle_types_right{curves.handle_types_right()};
 
   VArray<int8_t> nurbs_orders = curves.nurbs_orders();
   VArray<int8_t> nurbs_knots_modes = curves.nurbs_knots_modes();
@@ -1013,8 +1013,8 @@ void CurvesGeometry::calculate_bezier_auto_handles()
     return;
   }
   const VArray<bool> cyclic = this->cyclic();
-  const VArray_Span<int8_t> types_left{this->handle_types_left()};
-  const VArray_Span<int8_t> types_right{this->handle_types_right()};
+  const VArraySpan<int8_t> types_left{this->handle_types_left()};
+  const VArraySpan<int8_t> types_right{this->handle_types_right()};
   const Span<float3> positions = this->positions();
   MutableSpan<float3> positions_left = this->handle_positions_left_for_write();
   MutableSpan<float3> positions_right = this->handle_positions_right_for_write();
diff --git a/source/blender/blenkernel/intern/geometry_component_curve.cc b/source/blender/blenkernel/intern/geometry_component_curve.cc
index 898869c3c44..5725c6043b2 100644
--- a/source/blender/blenkernel/intern/geometry_component_curve.cc
+++ b/source/blender/blenkernel/intern/geometry_component_curve.cc
@@ -17,7 +17,7 @@
 using blender::GMutableSpan;
 using blender::GSpan;
 using blender::GVArray;
-using blender::GVArray_GSpan;
+using blender::GVArraySpan;
 
 /* -------------------------------------------------------------------- */
 /** \name Geometry Component Implementation
@@ -231,7 +231,7 @@ template<typename T> class VArray_For_SplineToPoint final : public VArrayImpl<T>
   GVArray original_varray_;
   /* Store existing data materialized if it was not already a span. This is expected
    * to be worth it because a single spline's value will likely be accessed many times. */
-  VArray_Span<T> original_data_;
+  VArraySpan<T> original_data_;
   Array<int> offsets_;
 
  public:
@@ -645,8 +645,8 @@ static bool create_point_attribute(GeometryComponent &component,
   GVArray source_varray = varray_from_initializer(initializer, data_type, splines);
   /* TODO: When we can call a variant of #set_all with a virtual array argument,
    * this theoretically unnecessary materialize step could be removed. */
-  GVArray_GSpan source_varray_span{source_varray};
-  write_attribute.varray.set_all(source_varray_span.data());
+  GVArraySpan source_VArraySpan{source_varray};
+  write_attribute.varray.set_all(source_VArraySpan.data());
 
   if (initializer.type == AttributeInit::Type::MoveArray) {
     MEM_freeN(static_cast<const AttributeInitMove &>(initializer).data);
diff --git a/source/blender/blenlib/BLI_generic_virtual_array.hh b/source/blender/blenlib/BLI_generic_virtual_array.hh
index 95305a0561d..3526925c2e2 100644
--- a/source/blender/blenlib/BLI_generic_virtual_array.hh
+++ b/source/blender/blenlib/BLI_generic_virtual_array.hh
@@ -257,22 +257,24 @@ class GVMutableArray : public GVArrayCommon {
 /** \} */
 
 /* -------------------------------------------------------------------- */
-/** \name #GVArray_GSpan and #GVMutableArray_GSpan.
+/** \name #GVArraySpan and #GMutableVArraySpan.
  * \{ */
 
-/* A generic version of VArray_Span. */
-class GVArray_GSpan : public GSpan {
+/* A generic version of VArraySpan. */
+class GVArraySpan : public GSpan {
  private:
   GVArray varray_;
   void *owned_data_ = nullptr;
 
  public:
-  GVArray_GSpan(GVArray varray);
-  ~GVArray_GSpan();
+  GVArraySpan(GVArray varray);
+  GVArraySpan(GVArraySpan &&other);
+  ~GVArraySpan();
+  GVArraySpan &operator=(GVArraySpan &&other);
 };
 
-/* A generic version of VMutableArray_Span. */
-class GVMutableArray_GSpan : public GMutableSpan, NonCopyable, NonMovable {
+/* A generic version of MutableVArraySpan. */
+class GMutableVArraySpan : public GMutableSpan, NonCopyable, NonMovable {
  private:
   GVMutableArray varray_;
   void *owned_data_ = nullptr;
@@ -280,8 +282,10 @@ class GVMutableArray_GSpan : public GMutableSpan, NonCopyable, NonMovable {
   bool show_not_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list