[Bf-blender-cvs] [af504c01b7a] virtual-array-attributes: progress

Jacques Lucke noreply at git.blender.org
Mon Apr 12 18:27:57 CEST 2021


Commit: af504c01b7a00902608691d9ec27ef55befbdb07
Author: Jacques Lucke
Date:   Mon Apr 12 17:53:18 2021 +0200
Branches: virtual-array-attributes
https://developer.blender.org/rBaf504c01b7a00902608691d9ec27ef55befbdb07

progress

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

M	source/blender/blenkernel/BKE_attribute_access.hh
M	source/blender/blenlib/BLI_virtual_array.hh
M	source/blender/functions/FN_generic_virtual_array.hh
M	source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_combine_xyz.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc

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

diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh
index 78e758e94f0..9e0f0d68cce 100644
--- a/source/blender/blenkernel/BKE_attribute_access.hh
+++ b/source/blender/blenkernel/BKE_attribute_access.hh
@@ -88,6 +88,11 @@ class MaybeUnsavedWriteAttribute {
     return *varray_;
   }
 
+  GVMutableArray *operator->()
+  {
+    return varray_;
+  }
+
   GVMutableArray &varray()
   {
     return *varray_;
diff --git a/source/blender/blenlib/BLI_virtual_array.hh b/source/blender/blenlib/BLI_virtual_array.hh
index 3da03e8e171..dab5aabc0e2 100644
--- a/source/blender/blenlib/BLI_virtual_array.hh
+++ b/source/blender/blenlib/BLI_virtual_array.hh
@@ -462,6 +462,11 @@ template<typename T> class VMutableArray_Span final : public VMutableArray_For_M
   {
     return this->get_span();
   }
+
+  operator MutableSpan<T>()
+  {
+    return this->get_span();
+  }
 };
 
 /**
diff --git a/source/blender/functions/FN_generic_virtual_array.hh b/source/blender/functions/FN_generic_virtual_array.hh
index 0752ce49b04..385061d01a8 100644
--- a/source/blender/functions/FN_generic_virtual_array.hh
+++ b/source/blender/functions/FN_generic_virtual_array.hh
@@ -29,6 +29,8 @@
 
 namespace blender::fn {
 
+template<typename T> class GVArray_Typed;
+
 /* A generically typed version of `VArray<T>`. */
 class GVArray {
  protected:
@@ -131,6 +133,11 @@ class GVArray {
     return (const VArray<T> *)this->try_get_internal_varray_impl();
   }
 
+  template<typename T> GVArray_Typed<T> typed()
+  {
+    return GVArray_Typed<T>(*this);
+  }
+
  protected:
   virtual void get_impl(const int64_t index, void *r_value) const;
   virtual void get_to_uninitialized_impl(const int64_t index, void *r_value) const = 0;
@@ -681,7 +688,7 @@ template<typename T> class GVArray_Typed {
   std::unique_ptr<GVArray> owned_gvarray_;
 
  public:
-  GVArray_Typed(const GVArray &gvarray)
+  explicit GVArray_Typed(const GVArray &gvarray)
   {
     BLI_assert(gvarray.type().is<T>());
     if (gvarray.is_span()) {
@@ -704,7 +711,7 @@ template<typename T> class GVArray_Typed {
     }
   }
 
-  GVArray_Typed(std::unique_ptr<GVArray> gvarray) : GVArray_Typed(*gvarray)
+  explicit GVArray_Typed(std::unique_ptr<GVArray> gvarray) : GVArray_Typed(*gvarray)
   {
     owned_gvarray_ = std::move(gvarray);
   }
@@ -728,6 +735,11 @@ template<typename T> class GVArray_Typed {
   {
     return varray_->get(index);
   }
+
+  int64_t size() const
+  {
+    return varray_->size();
+  }
 };
 
 template<typename T> class GVMutableArray_Typed {
@@ -738,7 +750,7 @@ template<typename T> class GVMutableArray_Typed {
   std::unique_ptr<GVMutableArray> owned_gvarray_;
 
  public:
-  GVMutableArray_Typed(GVMutableArray &gvarray)
+  explicit GVMutableArray_Typed(GVMutableArray &gvarray)
   {
     BLI_assert(gvarray.type().is<T>());
     if (gvarray.is_span()) {
@@ -755,7 +767,8 @@ template<typename T> class GVMutableArray_Typed {
     }
   }
 
-  GVMutableArray_Typed(std::unique_ptr<GVMutableArray> gvarray) : GVMutableArray_Typed(*gvarray)
+  explicit GVMutableArray_Typed(std::unique_ptr<GVMutableArray> gvarray)
+      : GVMutableArray_Typed(*gvarray)
   {
     owned_gvarray_ = std::move(gvarray);
   }
@@ -779,6 +792,11 @@ template<typename T> class GVMutableArray_Typed {
   {
     return varray_->get(index);
   }
+
+  int64_t size() const
+  {
+    return varray_->size();
+  }
 };
 
 }  // namespace blender::fn
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 2b913beb670..95946a517ac 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
@@ -47,15 +47,15 @@ static AttributeDomain get_result_domain(const GeometryComponent &component,
                                          StringRef result_name)
 {
   /* Use the domain of the result attribute if it already exists. */
-  ReadAttributePtr result_attribute = component.attribute_try_get_for_read(result_name);
+  ReadAttributeLookup result_attribute = component.attribute_try_get_for_read(result_name);
   if (result_attribute) {
-    return result_attribute->domain();
+    return result_attribute.domain;
   }
 
   /* Otherwise use the input attribute's domain if it exists. */
-  ReadAttributePtr input_attribute = component.attribute_try_get_for_read(input_name);
+  ReadAttributeLookup input_attribute = component.attribute_try_get_for_read(input_name);
   if (input_attribute) {
-    return input_attribute->domain();
+    return input_attribute.domain;
   }
 
   return ATTR_DOMAIN_POINT;
@@ -74,24 +74,23 @@ static void execute_on_component(const GeoNodeExecParams &params, GeometryCompon
   const CustomDataType result_type = CD_PROP_COLOR;
   const AttributeDomain result_domain = get_result_domain(component, input_name, result_name);
 
-  OutputAttributePtr attribute_result = component.attribute_try_get_for_output(
+  MaybeUnsavedWriteAttribute attribute_result = component.attribute_try_get_for_output(
       result_name, result_domain, result_type);
   if (!attribute_result) {
     return;
   }
 
-  FloatReadAttribute attribute_in = component.attribute_get_for_read<float>(
+  GVArray_Typed<float> attribute_in = component.attribute_get_for_read<float>(
       input_name, result_domain, 0.0f);
 
-  Span<float> data_in = attribute_in.get_span();
-  MutableSpan<Color4f> data_out = attribute_result->get_span_for_write_only<Color4f>();
-
   ColorBand *color_ramp = &node_storage->color_ramp;
-  for (const int i : data_in.index_range()) {
-    BKE_colorband_evaluate(color_ramp, data_in[i], data_out[i]);
+  for (const int i : IndexRange(attribute_in.size())) {
+    Color4f color;
+    BKE_colorband_evaluate(color_ramp, attribute_in[i], color);
+    attribute_result->set_by_copy(i, &color);
   }
 
-  attribute_result.apply_span_and_save();
+  attribute_result.save_if_necessary();
 }
 
 static void geo_node_attribute_color_ramp_exec(GeoNodeExecParams params)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_combine_xyz.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_combine_xyz.cc
index e9e07d34c17..94557353360 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_combine_xyz.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_combine_xyz.cc
@@ -77,9 +77,9 @@ static AttributeDomain get_result_domain(const GeometryComponent &component,
                                          StringRef result_name)
 {
   /* Use the domain of the result attribute if it already exists. */
-  ReadAttributePtr result_attribute = component.attribute_try_get_for_read(result_name);
+  ReadAttributeLookup result_attribute = component.attribute_try_get_for_read(result_name);
   if (result_attribute) {
-    return result_attribute->domain();
+    return result_attribute.domain;
   }
 
   /* Otherwise use the highest priority domain from existing input attributes, or the default. */
@@ -94,27 +94,27 @@ static void combine_attributes(GeometryComponent &component, const GeoNodeExecPa
   }
   const AttributeDomain result_domain = get_result_domain(component, params, result_name);
 
-  OutputAttributePtr attribute_result = component.attribute_try_get_for_output(
+  MaybeUnsavedWriteAttribute attribute_result = component.attribute_try_get_for_output(
       result_name, result_domain, CD_PROP_FLOAT3);
   if (!attribute_result) {
     return;
   }
-  FloatReadAttribute attribute_x = params.get_input_attribute<float>(
+  GVArray_Typed<float> attribute_x = params.get_input_attribute<float>(
       "X", component, result_domain, 0.0f);
-  FloatReadAttribute attribute_y = params.get_input_attribute<float>(
+  GVArray_Typed<float> attribute_y = params.get_input_attribute<float>(
       "Y", component, result_domain, 0.0f);
-  FloatReadAttribute attribute_z = params.get_input_attribute<float>(
+  GVArray_Typed<float> attribute_z = params.get_input_attribute<float>(
       "Z", component, result_domain, 0.0f);
 
-  MutableSpan<float3> results = attribute_result->get_span_for_write_only<float3>();
-  for (const int i : results.index_range()) {
+  GVMutableArray_Typed<float3> results{*attribute_result};
+
+  for (const int i : IndexRange(results.size())) {
     const float x = attribute_x[i];
     const float y = attribute_y[i];
     const float z = attribute_z[i];
-    const float3 result = float3(x, y, z);
-    results[i] = result;
+    results->set(i, {x, y, z});
   }
-  attribute_result.apply_span_and_save();
+  attribute_result.save_if_necessary();
 }
 
 static void geo_node_attribute_combine_xyz_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 fe4045c39a6..8bf3293050b 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
@@ -81,8 +81,8 @@ static void geo_node_attribute_compare_update(bNodeTree *UNUSED(ntree), bNode *n
   nodeSetSocketAvailability(socket_threshold, operation_tests_equality(*node_storage));
 }
 
-static void do_math_operation(const FloatReadAttribute &input_a,
-                              const FloatReadAttribute &input_b,
+static void do_math_operation(const VArray<float> &input_a,
+                              const VArray<float> &input_b,
                               const FloatCompareOperation operation,
                               MutableSpan<bool> span_result)
 {
@@ -107,8 +107,8 @@ static void do_math_operation(const FloatReadAttribute &input_a,
   BLI_assert(false);
 }
 
-static void do_equal_operation_float(const FloatReadAttribute &input_a,
-                                     const FloatReadAttribute &input_b,
+static void do_equal_operation_float(const VArray<float> &input_a,
+                                     const VArray<float> &input_b,
                                      const float threshold,
                                      MutableSpan<bool> span_result)
 {
@@ -120,8 +120,8 @@ static void do_equal_operation_float(const FloatReadAttr

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list