[Bf-blender-cvs] [b117fe78171] virtual-array-attributes: fix some bugs

Jacques Lucke noreply at git.blender.org
Thu Apr 15 17:14:44 CEST 2021


Commit: b117fe78171b4e3a146d09bc6a43aee7c144f5de
Author: Jacques Lucke
Date:   Thu Apr 15 16:41:59 2021 +0200
Branches: virtual-array-attributes
https://developer.blender.org/rBb117fe78171b4e3a146d09bc6a43aee7c144f5de

fix some bugs

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

M	source/blender/blenkernel/intern/geometry_set_instances.cc
M	source/blender/blenlib/BLI_virtual_array.hh
M	source/blender/functions/intern/generic_virtual_array.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
M	source/blender/nodes/intern/node_geometry_exec.cc
M	source/blender/nodes/intern/type_conversions.cc

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

diff --git a/source/blender/blenkernel/intern/geometry_set_instances.cc b/source/blender/blenkernel/intern/geometry_set_instances.cc
index 9bf399496e2..e5cb9c6e693 100644
--- a/source/blender/blenkernel/intern/geometry_set_instances.cc
+++ b/source/blender/blenkernel/intern/geometry_set_instances.cc
@@ -460,7 +460,7 @@ static void join_attributes(Span<GeometryInstanceGroup> set_groups,
               name, domain_output, data_type_output);
 
           if (source_attribute) {
-            fn::GSpan src_span = source_attribute->get_span();
+            fn::GVArray_GSpan src_span{*source_attribute};
             const void *src_buffer = src_span.data();
             for (const int UNUSED(i) : set_group.transforms.index_range()) {
               void *dst_buffer = dst_span[offset];
diff --git a/source/blender/blenlib/BLI_virtual_array.hh b/source/blender/blenlib/BLI_virtual_array.hh
index e50e1a19f8e..ff32f8d95c6 100644
--- a/source/blender/blenlib/BLI_virtual_array.hh
+++ b/source/blender/blenlib/BLI_virtual_array.hh
@@ -392,6 +392,7 @@ template<typename T> class VArray_Span final : public Span<T> {
  public:
   VArray_Span(const VArray<T> &varray) : Span<T>(), varray_(varray)
   {
+    this->size_ = varray_.size();
     if (varray_.is_span()) {
       this->data_ = varray_.get_span().data();
     }
@@ -401,7 +402,6 @@ template<typename T> class VArray_Span final : public Span<T> {
       varray_.materialize_to_uninitialized(owned_data_);
       this->data_ = owned_data_.data();
     }
-    this->size_ = varray_.size();
   }
 };
 
@@ -416,6 +416,7 @@ template<typename T> class VMutableArray_Span final : public MutableSpan<T> {
   VMutableArray_Span(VMutableArray<T> &varray, const bool materialize = true)
       : MutableSpan<T>(), varray_(varray)
   {
+    this->size_ = varray_.size();
     if (varray_.is_span()) {
       this->data_ = varray_.get_span().data();
     }
@@ -430,7 +431,6 @@ template<typename T> class VMutableArray_Span final : public MutableSpan<T> {
       }
       this->data_ = owned_data_.data();
     }
-    this->size_ = varray_.size();
   }
 
   ~VMutableArray_Span()
diff --git a/source/blender/functions/intern/generic_virtual_array.cc b/source/blender/functions/intern/generic_virtual_array.cc
index c6ae97b99ec..81ea0c6fb8c 100644
--- a/source/blender/functions/intern/generic_virtual_array.cc
+++ b/source/blender/functions/intern/generic_virtual_array.cc
@@ -222,6 +222,7 @@ GVArray_For_SingleValue::~GVArray_For_SingleValue()
 
 GVArray_GSpan::GVArray_GSpan(const GVArray &varray) : GSpan(varray.type()), varray_(varray)
 {
+  size_ = varray_.size();
   if (varray_.is_span()) {
     data_ = varray_.get_span().data();
   }
@@ -230,7 +231,6 @@ GVArray_GSpan::GVArray_GSpan(const GVArray &varray) : GSpan(varray.type()), varr
     varray_.materialize_to_uninitialized(IndexRange(size_), owned_data_);
     data_ = owned_data_;
   }
-  size_ = varray_.size();
 }
 
 GVArray_GSpan::~GVArray_GSpan()
@@ -248,6 +248,7 @@ GVArray_GSpan::~GVArray_GSpan()
 GVMutableArray_GSpan::GVMutableArray_GSpan(GVMutableArray &varray, const bool materialize)
     : GMutableSpan(varray.type()), varray_(varray)
 {
+  size_ = varray_.size();
   if (varray_.is_span()) {
     data_ = varray_.get_span().data();
   }
@@ -261,7 +262,6 @@ GVMutableArray_GSpan::GVMutableArray_GSpan(GVMutableArray &varray, const bool ma
     }
     data_ = owned_data_;
   }
-  size_ = varray_.size();
 }
 
 GVMutableArray_GSpan::~GVMutableArray_GSpan()
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 11adb16862f..0a4aec778a3 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
@@ -88,14 +88,11 @@ static void do_math_operation(const VArray<float> &input_a,
 {
   const int size = input_a.size();
 
-  Span<float> span_a = input_a.get_span();
-  Span<float> span_b = input_b.get_span();
-
   if (try_dispatch_float_math_fl_fl_to_bool(
           operation, [&](auto math_function, const FloatMathOperationInfo &UNUSED(info)) {
             for (const int i : IndexRange(size)) {
-              const float a = span_a[i];
-              const float b = span_b[i];
+              const float a = input_a[i];
+              const float b = input_b[i];
               const bool out = math_function(a, b);
               span_result[i] = out;
             }
@@ -274,7 +271,7 @@ static void attribute_compare_calc(GeometryComponent &component, const GeoNodeEx
     return;
   }
 
-  VMutableArray_Span<bool> result_span{*attribute_result};
+  MutableSpan<bool> result_span = attribute_result.as_span();
 
   /* Use specific types for correct equality operations, but for other operations we use implicit
    * conversions and float comparison. In other words, the comparison is not element-wise. */
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc b/source/blender/nodes/intern/node_geometry_exec.cc
index aee3df9723e..80805191ab4 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -22,6 +22,7 @@
 
 #include "NOD_geometry_exec.hh"
 #include "NOD_type_callbacks.hh"
+#include "NOD_type_conversions.hh"
 
 #include "node_geometry_util.hh"
 
@@ -85,21 +86,25 @@ std::unique_ptr<GVArray> GeoNodeExecParams::get_input_attribute(const StringRef
     return std::make_unique<fn::GVArray_For_SingleValue>(*cpp_type, domain_size, default_value);
   }
   /* TODO */
-  // if (found_socket->type == SOCK_FLOAT) {
-  //   const float value = this->get_input<float>(found_socket->identifier);
-  //   return component.attribute_get_constant_for_read_converted(
-  //       domain, CD_PROP_FLOAT, type, &value);
-  // }
-  // if (found_socket->type == SOCK_VECTOR) {
-  //   const float3 value = this->get_input<float3>(found_socket->identifier);
-  //   return component.attribute_get_constant_for_read_converted(
-  //       domain, CD_PROP_FLOAT3, type, &value);
-  // }
-  // if (found_socket->type == SOCK_RGBA) {
-  //   const Color4f value = this->get_input<Color4f>(found_socket->identifier);
-  //   return component.attribute_get_constant_for_read_converted(
-  //       domain, CD_PROP_COLOR, type, &value);
-  // }
+  const DataTypeConversions &conversions = get_implicit_type_conversions();
+  if (found_socket->type == SOCK_FLOAT) {
+    const float value = this->get_input<float>(found_socket->identifier);
+    BUFFER_FOR_CPP_TYPE_VALUE(*cpp_type, buffer);
+    conversions.convert_to_uninitialized(CPPType::get<float>(), *cpp_type, &value, buffer);
+    return std::make_unique<fn::GVArray_For_SingleValue>(*cpp_type, domain_size, buffer);
+  }
+  if (found_socket->type == SOCK_VECTOR) {
+    const float3 value = this->get_input<float3>(found_socket->identifier);
+    BUFFER_FOR_CPP_TYPE_VALUE(*cpp_type, buffer);
+    conversions.convert_to_uninitialized(CPPType::get<float3>(), *cpp_type, &value, buffer);
+    return std::make_unique<fn::GVArray_For_SingleValue>(*cpp_type, domain_size, buffer);
+  }
+  if (found_socket->type == SOCK_RGBA) {
+    const Color4f value = this->get_input<Color4f>(found_socket->identifier);
+    BUFFER_FOR_CPP_TYPE_VALUE(*cpp_type, buffer);
+    conversions.convert_to_uninitialized(CPPType::get<Color4f>(), *cpp_type, &value, buffer);
+    return std::make_unique<fn::GVArray_For_SingleValue>(*cpp_type, domain_size, buffer);
+  }
   BLI_assert(false);
   return std::make_unique<fn::GVArray_For_SingleValue>(*cpp_type, domain_size, default_value);
 }
diff --git a/source/blender/nodes/intern/type_conversions.cc b/source/blender/nodes/intern/type_conversions.cc
index a0a93aafa23..7329b1bad78 100644
--- a/source/blender/nodes/intern/type_conversions.cc
+++ b/source/blender/nodes/intern/type_conversions.cc
@@ -228,6 +228,11 @@ void DataTypeConversions::convert_to_uninitialized(const CPPType &from_type,
                                                    const void *from_value,
                                                    void *to_value) const
 {
+  if (from_type == to_type) {
+    from_type.copy_to_uninitialized(from_value, to_value);
+    return;
+  }
+
   const ConversionFunctions *functions = this->get_conversion_functions(
       MFDataType::ForSingle(from_type), MFDataType::ForSingle(to_type));
   BLI_assert(functions != nullptr);



More information about the Bf-blender-cvs mailing list