[Bf-blender-cvs] [231cafa9113] temp-geometry-nodes-evaluator-refactor: socket value logging progress
Jacques Lucke
noreply at git.blender.org
Wed Aug 31 16:08:07 CEST 2022
Commit: 231cafa9113e1e29d9e5650aaee1128d01ce7c8e
Author: Jacques Lucke
Date: Tue Aug 23 13:39:23 2022 +0200
Branches: temp-geometry-nodes-evaluator-refactor
https://developer.blender.org/rB231cafa9113e1e29d9e5650aaee1128d01ce7c8e
socket value logging progress
===================================================================
M source/blender/editors/space_node/node_draw.cc
M source/blender/nodes/intern/geometry_nodes_to_lazy_function_graph.cc
===================================================================
diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc
index aed35fc74c4..23786826c63 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -321,6 +321,53 @@ float2 node_from_view(const bNode &node, const float2 &co)
return result;
}
+static GeoTreeLog *get_geo_tree_log(SpaceNode &snode)
+{
+ using namespace blender;
+ using namespace blender::nodes;
+ using namespace blender::nodes::geo_eval_log;
+
+ LinearAllocator<> allocator;
+ Vector<destruct_ptr<ContextStack>> contexts;
+
+ if (snode.id == nullptr) {
+ return nullptr;
+ }
+ if (GS(snode.id->name) != ID_OB) {
+ return nullptr;
+ }
+ Object *object = reinterpret_cast<Object *>(snode.id);
+ NodesModifierData *nmd = nullptr;
+ LISTBASE_FOREACH (ModifierData *, md_iter, &object->modifiers) {
+ if (md_iter->type == eModifierType_Nodes) {
+ NodesModifierData *nmd_iter = reinterpret_cast<NodesModifierData *>(md_iter);
+ if (nmd_iter->node_group == snode.nodetree) {
+ nmd = nmd_iter;
+ break;
+ }
+ }
+ }
+ if (nmd == nullptr) {
+ return nullptr;
+ }
+ if (nmd->runtime_eval_log == nullptr) {
+ return nullptr;
+ }
+ GeoModifierLog &modifier_log = *static_cast<GeoModifierLog *>(nmd->runtime_eval_log);
+ contexts.append(allocator.construct<ModifierContextStack>(nullptr, nmd->modifier.name));
+ Vector<const bNodeTreePath *> tree_path_vec{snode.treepath};
+ if (tree_path_vec.is_empty()) {
+ return nullptr;
+ }
+ for (const bNodeTreePath *path : tree_path_vec.as_span().drop_front(1)) {
+ contexts.append(allocator.construct<NodeGroupContextStack>(
+ &*contexts.last(), path->node_name, path->nodetree->id.name + 2));
+ }
+
+ const ContextStack &final_context = *contexts.last();
+ return &modifier_log.get_tree_log(final_context.hash());
+}
+
struct SocketTooltipData {
bNodeTree *ntree;
bNode *node;
@@ -341,8 +388,27 @@ static bool node_socket_has_tooltip(bNodeTree *ntree, bNodeSocket *socket)
return false;
}
-static std::optional<std::string> create_socket_inspection_string()
+static std::optional<std::string> create_socket_inspection_string(TreeDrawContext &tree_draw_ctx,
+ bNode &node,
+ bNodeSocket &socket)
{
+ using namespace blender::nodes::geo_eval_log;
+ tree_draw_ctx.geo_tree_log->ensure_socket_values();
+ GeoNodeLog *node_log = tree_draw_ctx.geo_tree_log->nodes.lookup_ptr(node.name);
+ if (node_log == nullptr) {
+ return std::nullopt;
+ }
+ ValueLog *value_log = socket.in_out == SOCK_IN ?
+ node_log->input_values_.lookup_default(socket.identifier, nullptr) :
+ node_log->output_values_.lookup_default(socket.identifier, nullptr);
+ if (value_log == nullptr) {
+ return std::nullopt;
+ }
+ if (GenericValueLog *generic_value_log = dynamic_cast<GenericValueLog *>(value_log)) {
+ const GPointer value = generic_value_log->value();
+ return value.type()->to_string(value.get());
+ }
+
return std::nullopt;
}
@@ -351,7 +417,14 @@ static char *node_socket_get_tooltip(bContext *C,
bNode *node,
bNodeSocket *socket)
{
- UNUSED_VARS(C, node);
+ SpaceNode *snode = CTX_wm_space_node(C);
+ TreeDrawContext tree_draw_ctx;
+ if (snode != nullptr) {
+ if (ntree->type == NTREE_GEOMETRY) {
+ tree_draw_ctx.geo_tree_log = get_geo_tree_log(*snode);
+ }
+ }
+
std::stringstream output;
if (socket->runtime->declaration != nullptr) {
const blender::nodes::SocketDeclaration &socket_decl = *socket->runtime->declaration;
@@ -361,12 +434,13 @@ static char *node_socket_get_tooltip(bContext *C,
}
}
- if (ntree->type == NTREE_GEOMETRY) {
+ if (ntree->type == NTREE_GEOMETRY && tree_draw_ctx.geo_tree_log != nullptr) {
if (!output.str().empty()) {
output << ".\n\n";
}
- std::optional<std::string> socket_inspection_str = create_socket_inspection_string();
+ std::optional<std::string> socket_inspection_str = create_socket_inspection_string(
+ tree_draw_ctx, *node, *socket);
if (socket_inspection_str.has_value()) {
output << *socket_inspection_str;
}
@@ -382,7 +456,7 @@ static char *node_socket_get_tooltip(bContext *C,
return BLI_strdup(output.str().c_str());
}
-static void node_socket_add_tooltip(TreeDrawContext *tree_draw_ctx,
+static void node_socket_add_tooltip(TreeDrawContext *UNUSED(tree_draw_ctx),
bNodeTree *ntree,
bNode *node,
bNodeSocket *sock,
@@ -1372,53 +1446,6 @@ static char *node_errors_tooltip_fn(bContext *UNUSED(C), void *argN, const char
return BLI_strdupn(complete_string.c_str(), complete_string.size());
}
-static GeoTreeLog *get_geo_tree_log(SpaceNode &snode)
-{
- using namespace blender;
- using namespace blender::nodes;
- using namespace blender::nodes::geo_eval_log;
-
- LinearAllocator<> allocator;
- Vector<destruct_ptr<ContextStack>> contexts;
-
- if (snode.id == nullptr) {
- return nullptr;
- }
- if (GS(snode.id->name) != ID_OB) {
- return nullptr;
- }
- Object *object = reinterpret_cast<Object *>(snode.id);
- NodesModifierData *nmd = nullptr;
- LISTBASE_FOREACH (ModifierData *, md_iter, &object->modifiers) {
- if (md_iter->type == eModifierType_Nodes) {
- NodesModifierData *nmd_iter = reinterpret_cast<NodesModifierData *>(md_iter);
- if (nmd_iter->node_group == snode.nodetree) {
- nmd = nmd_iter;
- break;
- }
- }
- }
- if (nmd == nullptr) {
- return nullptr;
- }
- if (nmd->runtime_eval_log == nullptr) {
- return nullptr;
- }
- GeoModifierLog &modifier_log = *static_cast<GeoModifierLog *>(nmd->runtime_eval_log);
- contexts.append(allocator.construct<ModifierContextStack>(nullptr, nmd->modifier.name));
- Vector<const bNodeTreePath *> tree_path_vec{snode.treepath};
- if (tree_path_vec.is_empty()) {
- return nullptr;
- }
- for (const bNodeTreePath *path : tree_path_vec.as_span().drop_front(1)) {
- contexts.append(allocator.construct<NodeGroupContextStack>(
- &*contexts.last(), path->node_name, path->nodetree->id.name + 2));
- }
-
- const ContextStack &final_context = *contexts.last();
- return &modifier_log.get_tree_log(final_context.hash());
-}
-
#define NODE_HEADER_ICON_SIZE (0.8f * U.widget_unit)
static void node_add_error_message_button(const bContext &C,
diff --git a/source/blender/nodes/intern/geometry_nodes_to_lazy_function_graph.cc b/source/blender/nodes/intern/geometry_nodes_to_lazy_function_graph.cc
index 40412e68edb..aedc88adb49 100644
--- a/source/blender/nodes/intern/geometry_nodes_to_lazy_function_graph.cc
+++ b/source/blender/nodes/intern/geometry_nodes_to_lazy_function_graph.cc
@@ -369,6 +369,7 @@ class LazyFunctionForMultiFunctionConversion : public LazyFunction {
class LazyFunctionForMultiFunctionNode : public LazyFunction {
private:
+ const NodeRef &node_;
const NodeMultiFunctions::Item fn_item_;
Vector<const ValueOrFieldCPPType *> input_types_;
Vector<const ValueOrFieldCPPType *> output_types_;
@@ -378,7 +379,7 @@ class LazyFunctionForMultiFunctionNode : public LazyFunction {
NodeMultiFunctions::Item fn_item,
Vector<const InputSocketRef *> &r_used_inputs,
Vector<const OutputSocketRef *> &r_used_outputs)
- : fn_item_(std::move(fn_item))
+ : node_(node), fn_item_(std::move(fn_item))
{
BLI_assert(fn_item_.fn != nullptr);
static_name_ = node.name().c_str();
@@ -391,8 +392,15 @@ class LazyFunctionForMultiFunctionNode : public LazyFunction {
}
}
- void execute_impl(lf::Params ¶ms, const lf::Context &UNUSED(context)) const override
+ void execute_impl(lf::Params ¶ms, const lf::Context &context) const override
{
+ GeoNodesLFUserData *user_data = dynamic_cast<GeoNodesLFUserData *>(context.user_data);
+ BLI_assert(user_data != nullptr);
+ const ContextStack *context_stack = user_data->context_stack;
+ BLI_assert(context_stack != nullptr);
+ geo_eval_log::GeoTreeLogger &logger =
+ user_data->modifier_data->eval_log->get_local_tree_logger(*context_stack);
+
Vector<const void *> inputs_values(inputs_.size());
Vector<void *> outputs_values(outputs_.size());
for (const int i : inputs_.index_range()) {
@@ -408,6 +416,17 @@ class LazyFunctionForMultiFunctionNode : public LazyFunction {
inputs_values,
outputs_values);
for (const int i : outputs_.index_range()) {
+ const CPPType &type = *this->outputs_[i].type;
+ void *buffer = logger.allocator.allocate(type.size(), type.alignment());
+ type.copy_construct(outputs_values[i], buffer);
+ destruct_ptr<geo_eval_log::GenericValueLog> value_log =
+ logger.allocator.construct<geo_eval_log::GenericValueLog>(GMutablePointer{type, buffer});
+ /* TODO: Take unavailable sockets into account. */
+ const int index = i;
+ logger.output_socket_values.append(
+ {node_.name(), node_.output(index).identifier(), value_log.get()});
+ logger.socket_values_owner.append(std::move(value_log));
+
params.output_set(i);
}
}
More information about the Bf-blender-cvs
mailing list