[Bf-blender-cvs] [7d281a4f7d3] master: Functions: improve CPPType

Jacques Lucke noreply at git.blender.org
Mon Jun 28 13:16:47 CEST 2021


Commit: 7d281a4f7d354d270fc9c9f3c7a65b4409362aa0
Author: Jacques Lucke
Date:   Mon Jun 28 13:13:52 2021 +0200
Branches: master
https://developer.blender.org/rB7d281a4f7d354d270fc9c9f3c7a65b4409362aa0

Functions: improve CPPType

* Reduce code duplication.
* Give methods more standardized names (e.g. `move_to_initialized` -> `move_assign`).
* Support wrapping arbitrary C++ types, even those that e.g. are not copyable.

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

M	source/blender/blenkernel/BKE_geometry_set.hh
M	source/blender/blenkernel/intern/attribute_access.cc
M	source/blender/blenkernel/intern/geometry_set.cc
M	source/blender/blenkernel/intern/geometry_set_instances.cc
M	source/blender/functions/FN_cpp_type.hh
M	source/blender/functions/FN_cpp_type_make.hh
M	source/blender/functions/FN_generic_pointer.hh
M	source/blender/functions/FN_generic_value_map.hh
M	source/blender/functions/FN_generic_vector_array.hh
M	source/blender/functions/FN_generic_virtual_array.hh
M	source/blender/functions/FN_multi_function_builder.hh
M	source/blender/functions/intern/cpp_types.cc
M	source/blender/functions/intern/generic_vector_array.cc
M	source/blender/functions/intern/generic_virtual_array.cc
M	source/blender/functions/intern/generic_virtual_vector_array.cc
M	source/blender/functions/intern/multi_function_builder.cc
M	source/blender/functions/intern/multi_function_network_optimization.cc
M	source/blender/functions/tests/FN_cpp_type_test.cc
M	source/blender/modifiers/intern/MOD_nodes.cc
M	source/blender/modifiers/intern/MOD_nodes_evaluator.cc
M	source/blender/nodes/geometry/node_geometry_exec.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_convert.cc
M	source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
M	source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc
M	source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
M	source/blender/nodes/intern/node_socket.cc
M	source/blender/nodes/intern/type_conversions.cc

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

diff --git a/source/blender/blenkernel/BKE_geometry_set.hh b/source/blender/blenkernel/BKE_geometry_set.hh
index b2342a5fd96..82c9a31dfce 100644
--- a/source/blender/blenkernel/BKE_geometry_set.hh
+++ b/source/blender/blenkernel/BKE_geometry_set.hh
@@ -280,8 +280,6 @@ struct GeometrySet {
   void compute_boundbox_without_instances(blender::float3 *r_min, blender::float3 *r_max) const;
 
   friend std::ostream &operator<<(std::ostream &stream, const GeometrySet &geometry_set);
-  friend bool operator==(const GeometrySet &a, const GeometrySet &b);
-  uint64_t hash() const;
 
   void clear();
 
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 8bbb3014dac..aa0af294bc3 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -1197,7 +1197,7 @@ static blender::bke::OutputAttribute create_output_attribute(
       cpp_type->size() * domain_size, cpp_type->alignment(), __func__);
   if (ignore_old_values) {
     /* This does nothing for trivially constructible types, but is necessary for correctness. */
-    cpp_type->construct_default_n(data, domain);
+    cpp_type->default_construct_n(data, domain);
   }
   else {
     /* Fill the temporary array with values from the existing attribute. */
diff --git a/source/blender/blenkernel/intern/geometry_set.cc b/source/blender/blenkernel/intern/geometry_set.cc
index 3d85118deee..07b4e715ea9 100644
--- a/source/blender/blenkernel/intern/geometry_set.cc
+++ b/source/blender/blenkernel/intern/geometry_set.cc
@@ -199,20 +199,6 @@ std::ostream &operator<<(std::ostream &stream, const GeometrySet &geometry_set)
   return stream;
 }
 
-/* This generally should not be used. It is necessary currently, so that GeometrySet can by used by
- * the CPPType system. */
-bool operator==(const GeometrySet &UNUSED(a), const GeometrySet &UNUSED(b))
-{
-  return false;
-}
-
-/* This generally should not be used. It is necessary currently, so that GeometrySet can by used by
- * the CPPType system. */
-uint64_t GeometrySet::hash() const
-{
-  return reinterpret_cast<uint64_t>(this);
-}
-
 /* Remove all geometry components from the geometry set. */
 void GeometrySet::clear()
 {
diff --git a/source/blender/blenkernel/intern/geometry_set_instances.cc b/source/blender/blenkernel/intern/geometry_set_instances.cc
index 6921b102b20..3c50b966f04 100644
--- a/source/blender/blenkernel/intern/geometry_set_instances.cc
+++ b/source/blender/blenkernel/intern/geometry_set_instances.cc
@@ -535,7 +535,7 @@ static void join_attributes(Span<GeometryInstanceGroup> set_groups,
             const void *src_buffer = src_span.data();
             for (const int UNUSED(i) : set_group.transforms.index_range()) {
               void *dst_buffer = dst_span[offset];
-              cpp_type->copy_to_initialized_n(src_buffer, dst_buffer, domain_size);
+              cpp_type->copy_assign_n(src_buffer, dst_buffer, domain_size);
               offset += domain_size;
             }
           }
diff --git a/source/blender/functions/FN_cpp_type.hh b/source/blender/functions/FN_cpp_type.hh
index 14eab2704e9..4de0533a46d 100644
--- a/source/blender/functions/FN_cpp_type.hh
+++ b/source/blender/functions/FN_cpp_type.hh
@@ -19,10 +19,9 @@
 /** \file
  * \ingroup fn
  *
- * The CPPType class is the core of the runtime-type-system used by the functions system. It can
- * represent C++ types that are default-constructible, destructible, movable, copyable,
- * equality comparable and hashable. In the future we might want to make some of these properties
- * optional.
+ * The `CPPType` class is the core of a runtime-type-system. It allows working with arbitrary C++
+ * types in a generic way. An instance of `CPPType` wraps exactly one type like `int` or
+ * `std::string`.
  *
  * Every type has a size and an alignment. Every function dealing with C++ types in a generic way,
  * has to make sure that alignment rules are followed. The methods provided by a CPPType instance
@@ -35,11 +34,11 @@
  *
  * A CPPType instance comes with many methods that allow dealing with types in a generic way. Most
  * methods come in three variants. Using the construct-default methods as example:
- *  - construct_default(void *ptr):
+ *  - default_construct(void *ptr):
  *      Constructs a single instance of that type at the given pointer.
- *  - construct_default_n(void *ptr, int64_t n):
+ *  - default_construct_n(void *ptr, int64_t n):
  *      Constructs n instances of that type in an array that starts at the given pointer.
- *  - construct_default_indices(void *ptr, IndexMask mask):
+ *  - default_construct_indices(void *ptr, IndexMask mask):
  *      Constructs multiple instances of that type in an array that starts at the given pointer.
  *      Only the indices referenced by `mask` will by constructed.
  *
@@ -58,7 +57,7 @@
  * used now with explicit function pointers to work better. Here are some reasons:
  *  - If CPPType would be inherited once for every used C++ type, we would get a lot of classes
  *    that would only be instanced once each.
- *  - Methods like `construct_default` that operate on a single instance have to be fast. Even this
+ *  - Methods like `default_construct` that operate on a single instance have to be fast. Even this
  *    one necessary indirection using function pointers adds a lot of overhead. If all methods were
  *    virtual, there would be a second level of indirection that increases the overhead even more.
  *  - If it becomes necessary, we could pass the function pointers to C functions more easily than
@@ -73,177 +72,61 @@
 
 namespace blender::fn {
 
-class CPPType : NonCopyable, NonMovable {
- public:
-  using ConstructDefaultF = void (*)(void *ptr);
-  using ConstructDefaultNF = void (*)(void *ptr, int64_t n);
-  using ConstructDefaultIndicesF = void (*)(void *ptr, IndexMask mask);
-
-  using DestructF = void (*)(void *ptr);
-  using DestructNF = void (*)(void *ptr, int64_t n);
-  using DestructIndicesF = void (*)(void *ptr, IndexMask mask);
-
-  using CopyToInitializedF = void (*)(const void *src, void *dst);
-  using CopyToInitializedNF = void (*)(const void *src, void *dst, int64_t n);
-  using CopyToInitializedIndicesF = void (*)(const void *src, void *dst, IndexMask mask);
-
-  using CopyToUninitializedF = void (*)(const void *src, void *dst);
-  using CopyToUninitializedNF = void (*)(const void *src, void *dst, int64_t n);
-  using CopyToUninitializedIndicesF = void (*)(const void *src, void *dst, IndexMask mask);
+struct CPPTypeMembers {
+  int64_t size = 0;
+  int64_t alignment = 0;
+  uintptr_t alignment_mask = 0;
+  bool is_trivially_destructible = false;
+  bool has_special_member_functions = false;
 
-  using MoveToInitializedF = void (*)(void *src, void *dst);
-  using MoveToInitializedNF = void (*)(void *src, void *dst, int64_t n);
-  using MoveToInitializedIndicesF = void (*)(void *src, void *dst, IndexMask mask);
+  void (*default_construct)(void *ptr) = nullptr;
+  void (*default_construct_indices)(void *ptr, IndexMask mask) = nullptr;
 
-  using MoveToUninitializedF = void (*)(void *src, void *dst);
-  using MoveToUninitializedNF = void (*)(void *src, void *dst, int64_t n);
-  using MoveToUninitializedIndicesF = void (*)(void *src, void *dst, IndexMask mask);
+  void (*destruct)(void *ptr) = nullptr;
+  void (*destruct_indices)(void *ptr, IndexMask mask) = nullptr;
 
-  using RelocateToInitializedF = void (*)(void *src, void *dst);
-  using RelocateToInitializedNF = void (*)(void *src, void *dst, int64_t n);
-  using RelocateToInitializedIndicesF = void (*)(void *src, void *dst, IndexMask mask);
+  void (*copy_assign)(const void *src, void *dst) = nullptr;
+  void (*copy_assign_indices)(const void *src, void *dst, IndexMask mask) = nullptr;
 
-  using RelocateToUninitializedF = void (*)(void *src, void *dst);
-  using RelocateToUninitializedNF = void (*)(void *src, void *dst, int64_t n);
-  using RelocateToUninitializedIndicesF = void (*)(void *src, void *dst, IndexMask mask);
-
-  using FillInitializedF = void (*)(const void *value, void *dst, int64_t n);
-  using FillInitializedIndicesF = void (*)(const void *value, void *dst, IndexMask mask);
-
-  using FillUninitializedF = void (*)(const void *value, void *dst, int64_t n);
-  using FillUninitializedIndicesF = void (*)(const void *value, void *dst, IndexMask mask);
-
-  using DebugPrintF = void (*)(const void *value, std::stringstream &ss);
-  using IsEqualF = bool (*)(const void *a, const void *b);
-  using HashF = uint64_t (*)(const void *value);
-
- private:
-  int64_t size_;
-  int64_t alignment_;
-  uintptr_t alignment_mask_;
-  bool is_trivially_destructible_;
+  void (*copy_construct)(const void *src, void *dst) = nullptr;
+  void (*copy_construct_indices)(const void *src, void *dst, IndexMask mask) = nullptr;
 
-  ConstructDefaultF construct_default_;
-  ConstructDefaultNF construct_default_n_;
-  ConstructDefaultIndicesF construct_default_indices_;
+  void (*move_assign)(void *src, void *dst) = nullptr;
+  void (*move_assign_indices)(void *src, void *dst, IndexMask mask) = nullptr;
 
-  DestructF destruct_;
-  DestructNF destruct_n_;
-  DestructIndicesF destruct_indices_;
+  void (*move_construct)(void *src, void *dst) = nullptr;
+  void (*move_construct_indices)(void *src, void *dst, IndexMask mask) = nullptr;
 
-  CopyToInitializedF copy_to_initialized_;
-  CopyToInitializedNF copy_to_initialized_n_;
-  CopyToInitializedIndicesF copy_to_initialized_indices_;
+  void (*relocate_assign)(void *src, void *dst) = nullptr;
+  void (*relocate_assign_indices)(void *src, void *dst, IndexMask mask) = nullptr;
 
-  CopyToUninitializedF copy_to_uninitialized_;
-  CopyToUninitializedNF copy_to_uninitialized_n_;
-  CopyToUninitializedIndicesF copy_to_uninitialized_indices_;
+  void (*relocate_construct)(void *src, void *dst) = nullptr;
+  void (*relocate_construct_indices)(void *src, void *dst, IndexMask mask) = nullptr;
 
-  MoveToInitializedF move_to_initialized_;
-  MoveToInitializedNF move_to_initialized_n_;
-  MoveToInitializedIndicesF move_to_initialized_indices_;
+  void (*fill_assign_indices)(const void *value, void *dst, Inde

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list