[Bf-blender-cvs] [a99fddf98ea] temp-geometry-nodes-evaluator-refactor: log more information of values
Jacques Lucke
noreply at git.blender.org
Sun Sep 4 12:53:40 CEST 2022
Commit: a99fddf98ea219ea189fac492bd6791bedd6de1b
Author: Jacques Lucke
Date: Sun Sep 4 11:44:18 2022 +0200
Branches: temp-geometry-nodes-evaluator-refactor
https://developer.blender.org/rBa99fddf98ea219ea189fac492bd6791bedd6de1b
log more information of values
===================================================================
M source/blender/editors/space_node/node_draw.cc
M source/blender/nodes/NOD_geometry_nodes_log.hh
M source/blender/nodes/intern/geometry_nodes_log.cc
===================================================================
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index 8f654dd2001..9dbe405fd26 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -469,7 +469,7 @@ static std::optional<std::string> create_socket_inspection_string(TreeDrawContex
return std::nullopt;
}
if (GenericValueLog *generic_value_log = dynamic_cast<GenericValueLog *>(value_log)) {
- const GPointer value = generic_value_log->value();
+ const GPointer value = generic_value_log->value;
return value.type()->to_string(value.get());
}
diff --git a/source/blender/nodes/NOD_geometry_nodes_log.hh b/source/blender/nodes/NOD_geometry_nodes_log.hh
index 1b78c7856f2..3e9954e1090 100644
--- a/source/blender/nodes/NOD_geometry_nodes_log.hh
+++ b/source/blender/nodes/NOD_geometry_nodes_log.hh
@@ -10,11 +10,16 @@
#include "BLI_multi_value_map.hh"
#include "BKE_attribute.h"
+#include "BKE_geometry_set.hh"
+
+#include "FN_field.hh"
#include "DNA_node_types.h"
namespace blender::nodes::geo_eval_log {
+using fn::GField;
+
enum class NodeWarningType {
Error,
Warning,
@@ -40,23 +45,26 @@ class ValueLog {
};
class GenericValueLog : public ValueLog {
- private:
- GMutablePointer data_;
-
public:
- GenericValueLog(const GMutablePointer data) : data_(data)
+ GMutablePointer value;
+
+ GenericValueLog(const GMutablePointer value) : value(value)
{
}
~GenericValueLog()
{
- data_.destruct();
+ this->value.destruct();
}
+};
- GPointer value() const
- {
- return data_;
- }
+class GFieldValueLog : public ValueLog {
+ public:
+ GField field;
+ const CPPType &type;
+ Vector<std::string> input_tooltips;
+
+ GFieldValueLog(const GField &field, bool log_full_field);
};
struct GeometryAttributeInfo {
@@ -66,6 +74,38 @@ struct GeometryAttributeInfo {
std::optional<eCustomDataType> data_type;
};
+class GeometryValueLog : public ValueLog {
+ public:
+ Vector<GeometryAttributeInfo> attributes;
+ Vector<GeometryComponentType> component_types;
+ std::unique_ptr<GeometrySet> full_geometry;
+
+ struct MeshInfo {
+ int verts_num, edges_num, faces_num;
+ };
+ struct CurveInfo {
+ int splines_num;
+ };
+ struct PointCloudInfo {
+ int points_num;
+ };
+ struct InstancesInfo {
+ int instances_num;
+ };
+ struct EditDataInfo {
+ bool has_deformed_positions;
+ bool has_deform_matrices;
+ };
+
+ std::optional<MeshInfo> mesh_info;
+ std::optional<CurveInfo> curve_info;
+ std::optional<PointCloudInfo> pointcloud_info;
+ std::optional<InstancesInfo> instances_info;
+ std::optional<EditDataInfo> edit_data_info;
+
+ GeometryValueLog(const GeometrySet &geometry_set, bool log_full_geometry);
+};
+
using Clock = std::chrono::steady_clock;
using TimePoint = Clock::time_point;
diff --git a/source/blender/nodes/intern/geometry_nodes_log.cc b/source/blender/nodes/intern/geometry_nodes_log.cc
index 18496b2254d..f387c84dfeb 100644
--- a/source/blender/nodes/intern/geometry_nodes_log.cc
+++ b/source/blender/nodes/intern/geometry_nodes_log.cc
@@ -3,19 +3,158 @@
#include "NOD_geometry_nodes_log.hh"
#include "NOD_geometry_nodes_to_lazy_function_graph.hh"
+#include "BKE_curves.hh"
+
+#include "FN_field_cpp_type.hh"
+
namespace blender::nodes::geo_eval_log {
-void GeoTreeLogger::log_value(const bNode &node, const bNodeSocket &socket, GPointer value)
+using fn::FieldInput;
+using fn::FieldInputs;
+
+GFieldValueLog::GFieldValueLog(const GField &field, const bool log_full_field)
+ : type(field.cpp_type())
+{
+ const std::shared_ptr<const fn::FieldInputs> &field_input_nodes = field.node().field_inputs();
+
+ /* Put the deduplicated field inputs into a vector so that they can be sorted below. */
+ Vector<std::reference_wrapper<const FieldInput>> field_inputs;
+ if (field_input_nodes) {
+ field_inputs.extend(field_input_nodes->deduplicated_nodes.begin(),
+ field_input_nodes->deduplicated_nodes.end());
+ }
+
+ std::sort(
+ field_inputs.begin(), field_inputs.end(), [](const FieldInput &a, const FieldInput &b) {
+ const int index_a = (int)a.category();
+ const int index_b = (int)b.category();
+ if (index_a == index_b) {
+ return a.socket_inspection_name().size() < b.socket_inspection_name().size();
+ }
+ return index_a < index_b;
+ });
+
+ for (const FieldInput &field_input : field_inputs) {
+ this->input_tooltips.append(field_input.socket_inspection_name());
+ }
+
+ if (log_full_field) {
+ this->field = std::move(field);
+ }
+}
+
+GeometryValueLog::GeometryValueLog(const GeometrySet &geometry_set, const bool log_full_geometry)
+{
+ static std::array all_component_types = {GEO_COMPONENT_TYPE_CURVE,
+ GEO_COMPONENT_TYPE_INSTANCES,
+ GEO_COMPONENT_TYPE_MESH,
+ GEO_COMPONENT_TYPE_POINT_CLOUD,
+ GEO_COMPONENT_TYPE_VOLUME};
+
+ /* Keep track handled attribute names to make sure that we do not return the same name twice.
+ * Currently #GeometrySet::attribute_foreach does not do that. Note that this will merge
+ * attributes with the same name but different domains or data types on separate components. */
+ Set<StringRef> names;
+
+ geometry_set.attribute_foreach(
+ all_component_types,
+ true,
+ [&](const bke::AttributeIDRef &attribute_id,
+ const bke::AttributeMetaData &meta_data,
+ const GeometryComponent &UNUSED(component)) {
+ if (attribute_id.is_named() && names.add(attribute_id.name())) {
+ this->attributes.append({attribute_id.name(), meta_data.domain, meta_data.data_type});
+ }
+ });
+
+ for (const GeometryComponent *component : geometry_set.get_components_for_read()) {
+ this->component_types.append(component->type());
+ switch (component->type()) {
+ case GEO_COMPONENT_TYPE_MESH: {
+ const MeshComponent &mesh_component = *(const MeshComponent *)component;
+ MeshInfo &info = this->mesh_info.emplace();
+ info.verts_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_POINT);
+ info.edges_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_EDGE);
+ info.faces_num = mesh_component.attribute_domain_size(ATTR_DOMAIN_FACE);
+ break;
+ }
+ case GEO_COMPONENT_TYPE_CURVE: {
+ const CurveComponent &curve_component = *(const CurveComponent *)component;
+ CurveInfo &info = this->curve_info.emplace();
+ info.splines_num = curve_component.attribute_domain_size(ATTR_DOMAIN_CURVE);
+ break;
+ }
+ case GEO_COMPONENT_TYPE_POINT_CLOUD: {
+ const PointCloudComponent &pointcloud_component = *(const PointCloudComponent *)component;
+ PointCloudInfo &info = this->pointcloud_info.emplace();
+ info.points_num = pointcloud_component.attribute_domain_size(ATTR_DOMAIN_POINT);
+ break;
+ }
+ case GEO_COMPONENT_TYPE_INSTANCES: {
+ const InstancesComponent &instances_component = *(const InstancesComponent *)component;
+ InstancesInfo &info = this->instances_info.emplace();
+ info.instances_num = instances_component.instances_num();
+ break;
+ }
+ case GEO_COMPONENT_TYPE_EDIT: {
+ const GeometryComponentEditData &edit_component = *(
+ const GeometryComponentEditData *)component;
+ if (const bke::CurvesEditHints *curve_edit_hints =
+ edit_component.curves_edit_hints_.get()) {
+ EditDataInfo &info = this->edit_data_info.emplace();
+ info.has_deform_matrices = curve_edit_hints->deform_mats.has_value();
+ info.has_deformed_positions = curve_edit_hints->positions.has_value();
+ }
+ break;
+ }
+ case GEO_COMPONENT_TYPE_VOLUME: {
+ break;
+ }
+ }
+ }
+ if (log_full_geometry) {
+ this->full_geometry = std::make_unique<GeometrySet>(geometry_set);
+ this->full_geometry->ensure_owns_direct_data();
+ }
+}
+
+void GeoTreeLogger::log_value(const bNode &node, const bNodeSocket &socket, const GPointer value)
{
const CPPType &type = *value.type();
- void *buffer = this->allocator.allocate(type.size(), type.alignment());
- type.copy_construct(value.get(), buffer);
- destruct_ptr<GenericValueLog> value_log = this->allocator.construct<GenericValueLog>(
- GMutablePointer{type, buffer});
- auto &socket_values = socket.in_out == SOCK_IN ? this->input_socket_values :
- this->output_socket_values;
- socket_values.append({node.name, socket.identifier, value_log.get()});
- this->socket_values_owner.append(std::move(value_log));
+
+ auto store_logged_value = [&](destruct_ptr<ValueLog> value_log) {
+ auto &socket_values = socket.in_out == SOCK_IN ? this->input_socket_values :
+ this->output_socket_values;
+ socket_values.append({node.name, socket.identifier, value_log.get()});
+ this->socket_values_owner.append(std::move(value_log));
+ };
+
+ auto log_generic_value = [&](const CPPType &type, const void *value) {
+ void *buffer = this->allocator.allocate(type.size(), type.alignment());
+ type.copy_construct(value, buffer);
+ store_logged_value(this->allocator.construct<GenericValueLog>(GMutablePointer{type, buffer}));
+ };
+
+ if (type.is<GeometrySet>()) {
+ const GeometrySet &geometry = *value.get<GeometrySet>();
+ store_logged_value(this->allocator.construct<GeometryValueLog>(geometry, false));
+ }
+ else if (const auto *value_or_field_type = dynamic_cast<const fn::ValueOrFieldCPPType *>(
+ &type)) {
+ const void *value_or_field = value.get();
+ if (value_or_field_type->is_field(value_or_field)) {
+ const GField *field = value_or_field_type->get_field_ptr(value_or_field);
+ store_logged_value(this->allocator.construct<GFieldValueLog>(*field, false));
+ }
+ else {
+ const CPPType &base_type = value_or_field_type->base_type();
+ const void *value =
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list