[Bf-blender-cvs] [d445ee4c736] temp-geometry-nodes-fields--fields-jacques: rename to GField

Jacques Lucke noreply at git.blender.org
Tue Aug 31 13:22:56 CEST 2021


Commit: d445ee4c736d615a34f94a0a7a34fe92fe82f9c4
Author: Jacques Lucke
Date:   Tue Aug 31 09:58:12 2021 +0200
Branches: temp-geometry-nodes-fields--fields-jacques
https://developer.blender.org/rBd445ee4c736d615a34f94a0a7a34fe92fe82f9c4

rename to GField

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

M	source/blender/functions/FN_field.hh
M	source/blender/functions/intern/field.cc
M	source/blender/functions/tests/FN_field_test.cc

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

diff --git a/source/blender/functions/FN_field.hh b/source/blender/functions/FN_field.hh
index 38aefde5e9f..18a4c6a7734 100644
--- a/source/blender/functions/FN_field.hh
+++ b/source/blender/functions/FN_field.hh
@@ -47,12 +47,7 @@ class FieldFunction;
  * Descibes the output of a function. Generally corresponds to the combination of an output socket
  * and link combination in a node graph.
  */
-class Field {
-  /**
-   * The type of this field's result.
-   */
-  const fn::CPPType *type_;
-
+class GField {
   /**
    * The function that calculates this field's values. Many fields can share the same function,
    * since a function can have many outputs, just like a node graph, where a single output can be
@@ -68,35 +63,31 @@ class Field {
   std::shared_ptr<FieldInput> input_;
 
  public:
-  Field(const fn::CPPType &type, std::shared_ptr<FieldFunction> function, const int output_index)
-      : type_(&type), function_(function), output_index_(output_index)
+  GField(std::shared_ptr<FieldFunction> function, const int output_index)
+      : function_(std::move(function)), output_index_(output_index)
   {
   }
 
-  Field(const fn::CPPType &type, std::shared_ptr<FieldInput> input) : type_(&type), input_(input)
+  GField(std::shared_ptr<FieldInput> input) : input_(std::move(input))
   {
   }
 
-  const fn::CPPType &type() const
-  {
-    BLI_assert(type_ != nullptr);
-    return *type_;
-  }
+  const fn::CPPType &cpp_type() const;
 
   bool is_input() const
   {
-    return input_ != nullptr;
+    return input_.get() != nullptr;
   }
   const FieldInput &input() const
   {
-    BLI_assert(function_ == nullptr);
-    BLI_assert(input_ != nullptr);
+    BLI_assert(!function_);
+    BLI_assert(input_);
     return *input_;
   }
 
   bool is_function() const
   {
-    return function_ != nullptr;
+    return function_.get() != nullptr;
   }
   const FieldFunction &function() const
   {
@@ -113,28 +104,45 @@ class Field {
   }
 };
 
+template<typename T> class Field {
+ private:
+  GField field_;
+
+ public:
+  Field(GField field) : field_(field)
+  {
+  }
+
+  const GField *operator->() const
+  {
+    return &field_;
+  }
+};
+
 /**
  * An operation acting on data described by fields. Generally corresponds
  * to a node or a subset of a node in a node graph.
  */
 class FieldFunction {
   /**
-   * The function used to calculate the
+   * The function used to calculate the field.
    */
-  std::unique_ptr<MultiFunction> function_;
+  std::unique_ptr<const MultiFunction> owned_function_;
+  const MultiFunction *function_;
 
   /**
    * References to descriptions of the results from the functions this function depends on.
    */
-  blender::Vector<Field> inputs_;
+  blender::Vector<GField> inputs_;
 
  public:
-  FieldFunction(std::unique_ptr<MultiFunction> function, Vector<Field> &&inputs)
-      : function_(std::move(function)), inputs_(std::move(inputs))
+  FieldFunction(std::unique_ptr<const MultiFunction> function, Vector<GField> &&inputs)
+      : owned_function_(std::move(function)), inputs_(std::move(inputs))
   {
+    function_ = owned_function_.get();
   }
 
-  Span<Field> inputs() const
+  Span<GField> inputs() const
   {
     return inputs_;
   }
@@ -143,22 +151,38 @@ class FieldFunction {
   {
     return *function_;
   }
+
+  const CPPType &cpp_type_of_output_index(int index) const
+  {
+    MFParamType param_type = function_->param_type(index);
+    MFDataType data_type = param_type.data_type();
+    BLI_assert(param_type.interface_type() == MFParamType::Output);
+    BLI_assert(data_type.is_single());
+    return data_type.single_type();
+  }
 };
 
 class FieldInput {
  protected:
-  StringRef name_;
+  const CPPType *type_;
+  std::string debug_name_;
 
  public:
-  FieldInput(StringRef name = "") : name_(name)
+  FieldInput(const CPPType &type, std::string debug_name = "")
+      : type_(&type), debug_name_(std::move(debug_name))
   {
   }
 
   virtual GVArrayPtr get_varray_generic_context(IndexMask mask) const = 0;
 
-  blender::StringRef name() const
+  blender::StringRef debug_name() const
   {
-    return name_;
+    return debug_name_;
+  }
+
+  const CPPType &cpp_type() const
+  {
+    return *type_;
   }
 };
 
@@ -166,8 +190,20 @@ class FieldInput {
  * Evaluate more than one field at a time, as an optimization
  * in case they share inputs or various intermediate values.
  */
-void evaluate_fields(blender::Span<Field> fields,
+void evaluate_fields(blender::Span<GField> fields,
                      blender::IndexMask mask,
                      blender::Span<GMutableSpan> outputs);
 
-}  // namespace blender::fn
\ No newline at end of file
+/* --------------------------------------------------------------------
+ * GField inline methods.
+ */
+
+inline const CPPType &GField::cpp_type() const
+{
+  if (this->is_function()) {
+    return function_->cpp_type_of_output_index(output_index_);
+  }
+  return input_->cpp_type();
+}
+
+}  // namespace blender::fn
diff --git a/source/blender/functions/intern/field.cc b/source/blender/functions/intern/field.cc
index 0066a7973b2..151751e9ded 100644
--- a/source/blender/functions/intern/field.cc
+++ b/source/blender/functions/intern/field.cc
@@ -34,7 +34,7 @@ struct InputOrFunction {
   InputOrFunction(const blender::fn::FieldInput &input) : ptr(&input)
   {
   }
-  InputOrFunction(const blender::fn::Field &field) /* Maybe this is too clever. */
+  InputOrFunction(const blender::fn::GField &field) /* Maybe this is too clever. */
   {
     if (field.is_function()) {
       ptr = &field.function();
@@ -81,7 +81,7 @@ using VariableMap = Map<InputOrFunction, Vector<FieldVariable>>;
  */
 using ComputedInputMap = Map<const MFVariable *, GVArrayPtr>;
 
-static FieldVariable &get_field_variable(const Field &field, VariableMap &unique_variables)
+static FieldVariable &get_field_variable(const GField &field, VariableMap &unique_variables)
 {
   if (field.is_input()) {
     const FieldInput &input = field.input();
@@ -92,7 +92,7 @@ static FieldVariable &get_field_variable(const Field &field, VariableMap &unique
   return function_outputs[field.function_output_index()];
 }
 
-static const FieldVariable &get_field_variable(const Field &field,
+static const FieldVariable &get_field_variable(const GField &field,
                                                const VariableMap &unique_variables)
 {
   if (field.is_input()) {
@@ -107,25 +107,25 @@ static const FieldVariable &get_field_variable(const Field &field,
 /**
  * TODO: Merge duplicate input nodes, not just fields pointing to the same FieldInput.
  */
-static void add_variables_for_input(const Field &field,
-                                    Stack<const Field *> &fields_to_visit,
+static void add_variables_for_input(const GField &field,
+                                    Stack<const GField *> &fields_to_visit,
                                     MFProcedureBuilder &builder,
                                     VariableMap &unique_variables)
 {
   fields_to_visit.pop();
   const FieldInput &input = field.input();
-  MFVariable &variable = builder.add_input_parameter(MFDataType::ForSingle(field.type()),
-                                                     input.name());
+  MFVariable &variable = builder.add_input_parameter(MFDataType::ForSingle(field.cpp_type()),
+                                                     input.debug_name());
   unique_variables.add(input, {variable});
 }
 
-static void add_variables_for_function(const Field &field,
-                                       Stack<const Field *> &fields_to_visit,
+static void add_variables_for_function(const GField &field,
+                                       Stack<const GField *> &fields_to_visit,
                                        MFProcedureBuilder &builder,
                                        VariableMap &unique_variables)
 {
   const FieldFunction &function = field.function();
-  for (const Field &input_field : function.inputs()) {
+  for (const GField &input_field : function.inputs()) {
     if (!unique_variables.contains(input_field)) {
       /* The field for this input hasn't been handled yet. Handle it now, so that we know all
        * of this field's function inputs already have variables. TODO: Verify that this is the
@@ -139,7 +139,7 @@ static void add_variables_for_function(const Field &field,
 
   Vector<MFVariable *> inputs;
   Set<FieldVariable *> unique_inputs;
-  for (const Field &input_field : function.inputs()) {
+  for (const GField &input_field : function.inputs()) {
     FieldVariable &input = get_field_variable(input_field, unique_variables);
     unique_inputs.add(&input);
     inputs.append(input.mf_variable);
@@ -152,17 +152,17 @@ static void add_variables_for_function(const Field &field,
   }
 }
 
-static void add_unique_variables(const Span<Field> fields,
+static void add_unique_variables(const Span<GField> fields,
                                  MFProcedureBuilder &builder,
                                  VariableMap &unique_variables)
 {
-  Stack<const Field *> fields_to_visit;
-  for (const Field &field : fields) {
+  Stack<const GField *> fields_to_visit;
+  for (const GField &field : fields) {
     fields_to_visit.push(&field);
   }
 
   while (!fields_to_visit.is_empty()) {
-    const Field &field = *fields_to_visit.peek();
+    const GField &field = *fields_to_visit.peek();
     if (unique_variables.contains(field)) {
       fields_to_visit.pop();
       continue;
@@ -183,28 +183,28 @@ static void add_unique_variables(const Span<Field> fields,
  * optimal, but properly ordering destructs should be combined with reordering function calls to
  * use variables more optimally.
  */
-static void add_destructs(const Span<Field> fields,
+static void add_destructs(const Span<GField> fields,
                           MFProcedureBuilder &builder,
                           VariableMap &unique_variables)
 {
   Set<MFVariable *> destructed_variables;
   Set<FieldVariable *> outputs;
-  for (const Field &field : fields) {
+  for (const GField &field : fields) {
     /* Currently input fields are handled separately in the evaluator. */
     BLI_assert(!field.is_input());
     outputs.add(&get_field_variable(field, unique_variables));
   }
 
-

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list