[Bf-blender-cvs] [2963be588de] temp-geometry-nodes-fields: cleanup

Jacques Lucke noreply at git.blender.org
Mon Sep 6 12:53:10 CEST 2021


Commit: 2963be588de843c14b79468430598875867e444a
Author: Jacques Lucke
Date:   Mon Sep 6 12:53:03 2021 +0200
Branches: temp-geometry-nodes-fields
https://developer.blender.org/rB2963be588de843c14b79468430598875867e444a

cleanup

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

M	source/blender/blenkernel/BKE_anonymous_attribute.h
M	source/blender/blenkernel/BKE_anonymous_attribute.hh
M	source/blender/blenkernel/BKE_attribute_access.hh
M	source/blender/blenkernel/intern/anonymous_attribute.cc
M	source/blender/blenkernel/intern/attribute_access.cc
M	source/blender/blenkernel/intern/curve_eval.cc
M	source/blender/blenkernel/intern/customdata.c
M	source/blender/functions/FN_field.hh
M	source/blender/functions/intern/field.cc
M	source/blender/makesdna/DNA_customdata_types.h

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

diff --git a/source/blender/blenkernel/BKE_anonymous_attribute.h b/source/blender/blenkernel/BKE_anonymous_attribute.h
index 6ac9a514ec9..ebdb0b05160 100644
--- a/source/blender/blenkernel/BKE_anonymous_attribute.h
+++ b/source/blender/blenkernel/BKE_anonymous_attribute.h
@@ -16,6 +16,12 @@
 
 #pragma once
 
+/** \file
+ * \ingroup bke
+ *
+ * An #AnonymousAttributeID is used to identify attributes that are not explicitly named.
+ */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/source/blender/blenkernel/BKE_anonymous_attribute.hh b/source/blender/blenkernel/BKE_anonymous_attribute.hh
index 444ba9b0fbf..201fa2b2f52 100644
--- a/source/blender/blenkernel/BKE_anonymous_attribute.hh
+++ b/source/blender/blenkernel/BKE_anonymous_attribute.hh
@@ -26,6 +26,11 @@
 
 namespace blender::bke {
 
+/**
+ * Wrapper for #AnonymousAttributeID with RAII semantics.
+ * This class should typically not be used directly. Instead use #StrongAnonymousAttributeID or
+ * #WeakAnonymousAttributeID.
+ */
 template<bool IsStrongReference> class OwnedAnonymousAttributeID {
  private:
   const AnonymousAttributeID *data_ = nullptr;
@@ -35,6 +40,7 @@ template<bool IsStrongReference> class OwnedAnonymousAttributeID {
  public:
   OwnedAnonymousAttributeID() = default;
 
+  /** Create a new anonymous attribute id. */
   explicit OwnedAnonymousAttributeID(StringRefNull debug_name)
   {
     if constexpr (IsStrongReference) {
@@ -45,7 +51,10 @@ template<bool IsStrongReference> class OwnedAnonymousAttributeID {
     }
   }
 
-  /* This transfers ownership, so no incref is necessary. */
+  /**
+   * This transfers ownership, so no incref is necessary.
+   * The caller has to make sure that it owned the anonymous id.
+   */
   explicit OwnedAnonymousAttributeID(const AnonymousAttributeID *anonymous_id)
       : data_(anonymous_id)
   {
@@ -111,6 +120,7 @@ template<bool IsStrongReference> class OwnedAnonymousAttributeID {
     return BKE_anonymous_attribute_id_has_strong_references(data_);
   }
 
+  /** Extract the onwership of the currently wrapped anonymous id. */
   const AnonymousAttributeID *extract()
   {
     const AnonymousAttributeID *extracted_data = data_;
@@ -119,6 +129,7 @@ template<bool IsStrongReference> class OwnedAnonymousAttributeID {
     return extracted_data;
   }
 
+  /** Get the wrapped anonymous id, without taking ownership. */
   const AnonymousAttributeID *get() const
   {
     return data_;
@@ -155,71 +166,4 @@ template<bool IsStrongReference> class OwnedAnonymousAttributeID {
 using StrongAnonymousAttributeID = OwnedAnonymousAttributeID<true>;
 using WeakAnonymousAttributeID = OwnedAnonymousAttributeID<false>;
 
-class AttributeIDRef {
- private:
-  StringRef name_;
-  const AnonymousAttributeID *anonymous_id_ = nullptr;
-
- public:
-  AttributeIDRef() = default;
-
-  AttributeIDRef(StringRef name) : name_(name)
-  {
-  }
-
-  AttributeIDRef(StringRefNull name) : name_(name)
-  {
-  }
-
-  AttributeIDRef(const char *name) : name_(name)
-  {
-  }
-
-  AttributeIDRef(const std::string &name) : name_(name)
-  {
-  }
-
-  /* The anonymous id is only borrowed, the caller has to keep a reference to it. */
-  AttributeIDRef(const AnonymousAttributeID *anonymous_id) : anonymous_id_(anonymous_id)
-  {
-  }
-
-  operator bool() const
-  {
-    return this->is_named() || this->is_anonymous();
-  }
-
-  friend bool operator==(const AttributeIDRef &a, const AttributeIDRef &b)
-  {
-    return a.anonymous_id_ == b.anonymous_id_ && a.name_ == b.name_;
-  }
-
-  uint64_t hash() const
-  {
-    return get_default_hash_2(name_, anonymous_id_);
-  }
-
-  bool is_named() const
-  {
-    return !name_.is_empty();
-  }
-
-  bool is_anonymous() const
-  {
-    return anonymous_id_ != nullptr;
-  }
-
-  StringRef name() const
-  {
-    BLI_assert(this->is_named());
-    return name_;
-  }
-
-  const AnonymousAttributeID &anonymous_id() const
-  {
-    BLI_assert(this->is_anonymous());
-    return *anonymous_id_;
-  }
-};
-
 }  // namespace blender::bke
diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh
index 5e0f664c542..532afbf769b 100644
--- a/source/blender/blenkernel/BKE_attribute_access.hh
+++ b/source/blender/blenkernel/BKE_attribute_access.hh
@@ -30,6 +30,81 @@
 #include "BLI_float3.hh"
 #include "BLI_function_ref.hh"
 
+namespace blender::bke {
+
+/**
+ * Identifies an attribute that is either named or anonymous. It does not own the identifier, so it
+ * is just a reference.
+ */
+class AttributeIDRef {
+ private:
+  StringRef name_;
+  const AnonymousAttributeID *anonymous_id_ = nullptr;
+
+ public:
+  AttributeIDRef() = default;
+
+  AttributeIDRef(StringRef name) : name_(name)
+  {
+  }
+
+  AttributeIDRef(StringRefNull name) : name_(name)
+  {
+  }
+
+  AttributeIDRef(const char *name) : name_(name)
+  {
+  }
+
+  AttributeIDRef(const std::string &name) : name_(name)
+  {
+  }
+
+  /* The anonymous id is only borrowed, the caller has to keep a reference to it. */
+  AttributeIDRef(const AnonymousAttributeID *anonymous_id) : anonymous_id_(anonymous_id)
+  {
+  }
+
+  operator bool() const
+  {
+    return this->is_named() || this->is_anonymous();
+  }
+
+  friend bool operator==(const AttributeIDRef &a, const AttributeIDRef &b)
+  {
+    return a.anonymous_id_ == b.anonymous_id_ && a.name_ == b.name_;
+  }
+
+  uint64_t hash() const
+  {
+    return get_default_hash_2(name_, anonymous_id_);
+  }
+
+  bool is_named() const
+  {
+    return !name_.is_empty();
+  }
+
+  bool is_anonymous() const
+  {
+    return anonymous_id_ != nullptr;
+  }
+
+  StringRef name() const
+  {
+    BLI_assert(this->is_named());
+    return name_;
+  }
+
+  const AnonymousAttributeID &anonymous_id() const
+  {
+    BLI_assert(this->is_anonymous());
+    return *anonymous_id_;
+  }
+};
+
+}  // namespace blender::bke
+
 /**
  * Contains information about an attribute in a geometry component.
  * More information can be added in the future. E.g. whether the attribute is builtin and how it is
diff --git a/source/blender/blenkernel/intern/anonymous_attribute.cc b/source/blender/blenkernel/intern/anonymous_attribute.cc
index 7088dff3db9..73e2a656a7f 100644
--- a/source/blender/blenkernel/intern/anonymous_attribute.cc
+++ b/source/blender/blenkernel/intern/anonymous_attribute.cc
@@ -19,12 +19,30 @@
 using namespace blender::bke;
 
 struct AnonymousAttributeID {
-  mutable std::atomic<int> refcount_weak = 0;
+  /**
+   * Total number of references to this attribute id. Once this reaches zero, the struct can be
+   * freed.
+   */
+  mutable std::atomic<int> refcount_tot = 0;
+
+  /**
+   * Number of strong references to this attribute id. When this is zero, the corresponding
+   * attributes can be removed from geometries automatically.
+   */
   mutable std::atomic<int> refcount_strong = 0;
+
+  /**
+   * Only used to identify this struct in a debugging session.
+   */
   std::string debug_name;
+
+  /**
+   * Unique name of the this attribute id during the current session.
+   */
   std::string internal_name;
 };
 
+/** Every time this function is called, it outputs a different name. */
 static std::string get_new_internal_name()
 {
   static std::atomic<int> index = 0;
@@ -37,7 +55,7 @@ AnonymousAttributeID *BKE_anonymous_attribute_id_new_weak(const char *debug_name
   AnonymousAttributeID *anonymous_id = new AnonymousAttributeID();
   anonymous_id->debug_name = debug_name;
   anonymous_id->internal_name = get_new_internal_name();
-  anonymous_id->refcount_weak.store(1);
+  anonymous_id->refcount_tot.store(1);
   return anonymous_id;
 }
 
@@ -46,7 +64,7 @@ AnonymousAttributeID *BKE_anonymous_attribute_id_new_strong(const char *debug_na
   AnonymousAttributeID *anonymous_id = new AnonymousAttributeID();
   anonymous_id->debug_name = debug_name;
   anonymous_id->internal_name = get_new_internal_name();
-  anonymous_id->refcount_weak.store(1);
+  anonymous_id->refcount_tot.store(1);
   anonymous_id->refcount_strong.store(1);
   return anonymous_id;
 }
@@ -58,18 +76,18 @@ bool BKE_anonymous_attribute_id_has_strong_references(const AnonymousAttributeID
 
 void BKE_anonymous_attribute_id_increment_weak(const AnonymousAttributeID *anonymous_id)
 {
-  anonymous_id->refcount_weak.fetch_add(1);
+  anonymous_id->refcount_tot.fetch_add(1);
 }
 
 void BKE_anonymous_attribute_id_increment_strong(const AnonymousAttributeID *anonymous_id)
 {
-  anonymous_id->refcount_weak.fetch_add(1);
+  anonymous_id->refcount_tot.fetch_add(1);
   anonymous_id->refcount_strong.fetch_add(1);
 }
 
 void BKE_anonymous_attribute_id_decrement_weak(const AnonymousAttributeID *anonymous_id)
 {
-  const int new_refcount = anonymous_id->refcount_weak.fetch_sub(1) - 1;
+  const int new_refcount = anonymous_id->refcount_tot.fetch_sub(1) - 1;
   if (new_refcount == 0) {
     delete anonymous_id;
   }
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc
index 16624320c71..8416ca84340 100644
--- a/source/blender/blenkernel/intern/attribute_access.cc
+++ b/source/blender/blenkernel/intern/attribute_access.cc
@@ -44,6 +44,8 @@ using blender::float3;
 using blender::Set;
 using blender::StringRef;
 using blender::StringRefNull;
+using blender::bke::AttributeIDRef;
+using blender::bke::OutputAttribute;
 using blender::fn::GMutableSpan;
 using blender::fn::GSpan;
 using blender::fn::GVArray_For_GSpan;
@@ -730,7 +732,7 @@ bool CustomDataAttributes::create(const AttributeIDRef &attribute_id,
   return result != nullptr;
 }
 
-bool CustomDataAttributes::create_by_move(const blender::bke::AttributeIDRef &attribute_id,
+bool CustomDataAttributes::create_by_move(const AttributeIDRef &attribute_id,
                                           const CustomDataType data_type,
                                           void *buffer)
 {
@@ -739,7 +741,7 @@ bool CustomDataAttributes::create_by_move(const blender::bke::AttributeIDRef &at
   return result != nullptr;
 }
 
-bool CustomDataAttributes::remove(const blender::bke::AttributeIDRef &attribute_id)
+bool CustomDataAttributes::remove(const AttributeIDRef &attribute_id)
 {
   bool result = false;
   for (const int i : IndexRange(data.totlayer)) {
@@ -814,7 +816,7 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list