[Bf-blender-cvs] [6b2c1016dfa] temp-multi-function-eval-varray: progress

Jacques Lucke noreply at git.blender.org
Wed Apr 6 16:18:13 CEST 2022


Commit: 6b2c1016dfac46aaaa7f8e978a931bb7d5d01cb6
Author: Jacques Lucke
Date:   Wed Apr 6 13:50:59 2022 +0200
Branches: temp-multi-function-eval-varray
https://developer.blender.org/rB6b2c1016dfac46aaaa7f8e978a931bb7d5d01cb6

progress

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

M	source/blender/blenlib/intern/generic_virtual_array.cc
M	source/blender/functions/intern/field.cc
M	source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc

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

diff --git a/source/blender/blenlib/intern/generic_virtual_array.cc b/source/blender/blenlib/intern/generic_virtual_array.cc
index 8a6ef8e792f..974c40fecd1 100644
--- a/source/blender/blenlib/intern/generic_virtual_array.cc
+++ b/source/blender/blenlib/intern/generic_virtual_array.cc
@@ -231,6 +231,16 @@ class GVArrayImpl_For_SingleValueRef : public GVArrayImpl {
   {
     type_->copy_assign(value_, r_value);
   }
+
+  void materialize(const IndexMask mask, void *dst) const override
+  {
+    type_->fill_assign_indices(value_, dst, mask);
+  }
+
+  void materialize_to_uninitialized(const IndexMask mask, void *dst) const override
+  {
+    type_->fill_construct_indices(value_, dst, mask);
+  }
 };
 
 class GVArrayImpl_For_SingleValueRef_final final : public GVArrayImpl_For_SingleValueRef {
diff --git a/source/blender/functions/intern/field.cc b/source/blender/functions/intern/field.cc
index 986d6ddc19e..944674c23a9 100644
--- a/source/blender/functions/intern/field.cc
+++ b/source/blender/functions/intern/field.cc
@@ -468,16 +468,21 @@ Vector<GVArray> evaluate_fields(ResourceScope &scope,
       /* Still have to copy over the data in the destination provided by the caller. */
       if (dst_varray.is_span()) {
         /* Materialize into a span. */
-        computed_varray.materialize_to_uninitialized(mask, dst_varray.get_internal_span().data());
+        threading::parallel_for(mask.index_range(), 2048, [&](const IndexRange range) {
+          computed_varray.materialize_to_uninitialized(mask.slice(range),
+                                                       dst_varray.get_internal_span().data());
+        });
       }
       else {
         /* Slower materialize into a different structure. */
         const CPPType &type = computed_varray.type();
-        BUFFER_FOR_CPP_TYPE_VALUE(type, buffer);
-        for (const int i : mask) {
-          computed_varray.get_to_uninitialized(i, buffer);
-          dst_varray.set_by_relocate(i, buffer);
-        }
+        threading::parallel_for(mask.index_range(), 2048, [&](const IndexRange range) {
+          BUFFER_FOR_CPP_TYPE_VALUE(type, buffer);
+          for (const int i : mask.slice(range)) {
+            computed_varray.get_to_uninitialized(i, buffer);
+            dst_varray.set_by_relocate(i, buffer);
+          }
+        });
       }
       r_varrays[out_index] = dst_varray;
     }
diff --git a/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc b/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
index 5b0816fa3e3..a2a2e56d465 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_store_named_attribute.cc
@@ -91,18 +91,33 @@ static void try_capture_field_on_geometry(GeometryComponent &component,
   const int domain_size = component.attribute_domain_size(domain);
   const IndexMask mask{IndexMask(domain_size)};
 
-  const CustomDataType data_type = bke::cpp_type_to_custom_data_type(field.cpp_type());
+  const CPPType &type = field.cpp_type();
+  const CustomDataType data_type = bke::cpp_type_to_custom_data_type(type);
+
+  void *buffer = MEM_mallocN(type.size() * domain_size, __func__);
 
   /* Don't use #add_with_destination because the field might depend on an attribute
    * with that name, and changing it as part of evaluation might affect the result. */
   fn::FieldEvaluator evaluator{field_context, &mask};
-  evaluator.add(field);
+  evaluator.add_with_destination(field, GMutableSpan{type, buffer, domain_size});
   evaluator.evaluate();
-  const GVArray &result = evaluator.get_evaluated(0);
-  OutputAttribute attribute = component.attribute_try_get_for_output_only(name, domain, data_type);
-  if (attribute) {
-    result.materialize(attribute.as_span().data());
-    attribute.save();
+
+  component.attribute_try_delete(name);
+  if (component.attribute_exists(name)) {
+    WriteAttributeLookup write_attribute = component.attribute_try_get_for_write(name);
+    if (write_attribute && write_attribute.domain == domain &&
+        write_attribute.varray.type() == type) {
+      write_attribute.varray.set_all(buffer);
+      write_attribute.tag_modified_fn();
+    }
+    else {
+      /* Cannot change type of built-in attribute. */
+    }
+    type.destruct_n(buffer, domain_size);
+    MEM_freeN(buffer);
+  }
+  else {
+    component.attribute_try_create(name, domain, data_type, AttributeInitMove{buffer});
   }
 }



More information about the Bf-blender-cvs mailing list