Blender V5.3
NOD_geometry_nodes_lazy_function.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
26
27#include <variant>
28
31
32#include "NOD_eval_log.hh"
33#include "NOD_multi_function.hh"
34#include "NOD_nested_node_id.hh"
35
39
40#include "BKE_bake_values.hh"
42
43namespace blender {
44
45struct Depsgraph;
46struct Object;
47struct Scene;
48
49namespace nodes {
50
51using lf::LazyFunction;
52using mf::MultiFunction;
54
56namespace sim_input {
57
62struct PassThrough {};
63
71
72using Behavior = std::variant<PassThrough, UseCache>;
73
74} // namespace sim_input
75
77namespace sim_output {
78
83struct PassThrough {};
84
90 std::function<void(bke::bake::BakeValues values)> store_fn;
91};
92
99
109
113struct ReadError {
114 std::string message;
115};
116
117using Behavior = std::variant<PassThrough, StoreNewState, ReadSingle, ReadInterpolated, ReadError>;
118
119} // namespace sim_output
120
127
129 public:
135 virtual SimulationZoneBehavior *get(const int zone_id) const = 0;
136};
137
143
145 public:
146 virtual BakeNodeBehavior *get(const int id) const = 0;
147};
148
157
163 const Object *self_object = nullptr;
165 Depsgraph *depsgraph = nullptr;
166};
167
170 const Depsgraph *active = nullptr;
175 Depsgraph *extra = nullptr;
176
178
185 const ID *get_evaluated_id(const ID &id_orig) const;
186};
187
213
267
275 const GeoNodesCallData *call_data = nullptr;
288 bool verbose_log = true;
289
291
293 {
294 return this->compute_context->parents_num() >= this->call_data->call_depth_limit;
295 }
296};
297
299 private:
304 mutable std::optional<eval_log::NodeTreeLogger *> tree_logger_;
305
306 public:
308
314 {
315 if (!tree_logger_.has_value()) {
316 this->ensure_tree_logger(user_data);
317 }
318 return *tree_logger_;
319 }
320
321 private:
322 void ensure_tree_logger(const GeoNodesUserData &user_data) const;
323};
324
340
346
377
423
465
466std::unique_ptr<LazyFunction> get_simulation_output_lazy_function(
467 const bNode &node, GeometryNodesLazyFunctionGraphInfo &own_lf_graph_info);
468std::unique_ptr<LazyFunction> get_simulation_input_lazy_function(
469 const bNodeTree &node_tree,
470 const bNode &node,
471 GeometryNodesLazyFunctionGraphInfo &own_lf_graph_info);
472std::unique_ptr<LazyFunction> get_switch_node_lazy_function(const bNode &node);
473std::unique_ptr<LazyFunction> get_index_switch_node_lazy_function(
474 const bNode &node, GeometryNodesLazyFunctionGraphInfo &lf_graph_info);
475std::unique_ptr<LazyFunction> get_bake_lazy_function(
476 const bNode &node, GeometryNodesLazyFunctionGraphInfo &own_lf_graph_info);
477std::unique_ptr<LazyFunction> get_menu_switch_node_lazy_function(
478 const bNode &node, GeometryNodesLazyFunctionGraphInfo &lf_graph_info);
479std::unique_ptr<LazyFunction> get_menu_switch_node_boolean_outputs_lazy_function(
480 const bNode &node, GeometryNodesLazyFunctionGraphInfo &lf_graph_info);
481std::unique_ptr<LazyFunction> get_menu_switch_node_socket_usage_lazy_function(const bNode &node);
482std::unique_ptr<LazyFunction> get_warning_node_lazy_function(const bNode &node);
483std::unique_ptr<LazyFunction> get_enable_output_node_lazy_function(
484 const bNode &node, GeometryNodesLazyFunctionGraphInfo &own_lf_graph_info);
485
492void set_default_remaining_node_outputs(lf::Params &params, const bNode &node);
493void set_default_value_for_output_socket(lf::Params &params,
494 const int lf_index,
495 const bNodeSocket &bsocket);
496void construct_socket_default_value(const bke::bNodeSocketType &stype, void *r_value);
497
500 StringRef socket_name);
501
502std::optional<FoundNestedNodeID> find_nested_node_id(const GeoNodesUserData &user_data,
503 const int node_id);
504
510const std::shared_ptr<const GeometryNodesLazyFunctionGraphInfo> &
512
516constexpr auto node_timer_log_threshold = std::chrono::microseconds(100);
517
523 private:
524 lf::Context &context_;
525 eval_log::TimePoint start_;
526
527 public:
528 ScopedComputeContextTimer(lf::Context &entered_context) : context_(entered_context)
529 {
530 start_ = eval_log::Clock::now();
531 }
532
534 {
535 const eval_log::TimePoint end = eval_log::Clock::now();
536 auto &user_data = static_cast<GeoNodesUserData &>(*context_.user_data);
537 auto &local_user_data = static_cast<GeoNodesLocalUserData &>(*context_.local_user_data);
538 const std::chrono::duration duration = end - start_;
539 if (user_data.verbose_log || duration > node_timer_log_threshold) {
540 if (eval_log::NodeTreeLogger *tree_logger = local_user_data.try_get_tree_logger(user_data)) {
541 tree_logger->execution_time += duration;
542 }
543 }
544 }
545};
546
551 private:
552 const lf::Context &context_;
553 const bNode &node_;
554 eval_log::TimePoint start_;
555
556 public:
557 ScopedNodeTimer(const lf::Context &context, const bNode &node) : context_(context), node_(node)
558 {
559 start_ = eval_log::Clock::now();
560 }
561
563 {
564 const eval_log::TimePoint end = eval_log::Clock::now();
565 auto &user_data = static_cast<GeoNodesUserData &>(*context_.user_data);
566 auto &local_user_data = static_cast<GeoNodesLocalUserData &>(*context_.local_user_data);
567 const std::chrono::duration duration = end - start_;
568 if (user_data.verbose_log || duration > node_timer_log_threshold) {
569 if (eval_log::NodeTreeLogger *tree_logger = local_user_data.try_get_tree_logger(user_data)) {
570 tree_logger->node_execution_times.append(*tree_logger->allocator,
571 {node_.identifier, start_, end});
572 }
573 }
574 }
575};
576
579
584class LazyFunctionForLogicalOr : public lf::LazyFunction {
585 public:
586 LazyFunctionForLogicalOr(const int inputs_num);
587
588 void execute_impl(lf::Params &params, const lf::Context &context) const override;
589};
590
604
607 const LazyFunction *lazy_function = nullptr;
608
611};
612
619 const LazyFunction *function = nullptr;
621};
622
624 const bNodeTree &btree,
625 const bke::bNodeTreeZone &zone,
626 ZoneBuildInfo &zone_info,
627 const ZoneBodyFunction &body_fn);
628
630 const bNodeTree &btree,
631 const bke::bNodeTreeZone &zone,
632 ZoneBuildInfo &zone_info,
633 const ZoneBodyFunction &body_fn);
634
636 ResourceScope &scope,
637 const bNodeTree &btree,
638 const bke::bNodeTreeZone &zone,
639 ZoneBuildInfo &zone_info,
640 const ZoneBodyFunction &body_fn,
641 std::shared_ptr<GeometryNodesLazyFunctionGraphInfo> &lf_graph_info);
642
654
659
661 const bNode &bnode);
662
664 ZoneBuildInfo &zone_info,
665 const ZoneBodyFunction &body_fn,
666 bool expose_all_reference_sets,
667 Vector<lf::Input> &r_inputs,
668 Vector<lf::Output> &r_outputs);
669
670std::string zone_wrapper_input_name(const ZoneBuildInfo &zone_info,
671 const bke::bNodeTreeZone &zone,
672 const Span<lf::Input> inputs,
673 const int lf_socket_i);
674
675std::string zone_wrapper_output_name(const ZoneBuildInfo &zone_info,
676 const bke::bNodeTreeZone &zone,
677 const Span<lf::Output> outputs,
678 const int lf_socket_i);
679
686void report_from_multi_function(const mf::Context &context,
687 NodeWarningType type,
688 std::string message);
689
690} // namespace nodes
691} // namespace blender
virtual BakeNodeBehavior * get(const int id) const =0
virtual SimulationZoneBehavior * get(const int zone_id) const =0
void execute_impl(lf::Params &params, const lf::Context &context) const override
ScopedNodeTimer(const lf::Context &context, const bNode &node)
QuaternionBase< float > Quaternion
Clock::time_point TimePoint
std::variant< PassThrough, UseCache > Behavior
std::variant< PassThrough, StoreNewState, ReadSingle, ReadInterpolated, ReadError > Behavior
void initialize_zone_wrapper(const bNodeTreeZone &zone, ZoneBuildInfo &zone_info, const ZoneBodyFunction &body_fn, const bool expose_all_reference_sets, Vector< lf::Input > &r_inputs, Vector< lf::Output > &r_outputs)
std::unique_ptr< LazyFunction > get_simulation_output_lazy_function(const bNode &node, GeometryNodesLazyFunctionGraphInfo &own_lf_graph_info)
std::unique_ptr< LazyFunction > get_index_switch_node_lazy_function(const bNode &node, GeometryNodesLazyFunctionGraphInfo &lf_graph_info)
LazyFunction & build_closure_zone_lazy_function(ResourceScope &scope, const bNodeTree &btree, const bke::bNodeTreeZone &zone, ZoneBuildInfo &zone_info, const ZoneBodyFunction &body_fn, std::shared_ptr< GeometryNodesLazyFunctionGraphInfo > &lf_graph_info)
std::unique_ptr< LazyFunction > get_warning_node_lazy_function(const bNode &node)
void construct_socket_default_value(const bke::bNodeSocketType &stype, void *r_value)
std::unique_ptr< LazyFunction > get_menu_switch_node_socket_usage_lazy_function(const bNode &node)
std::unique_ptr< LazyFunction > get_simulation_input_lazy_function(const bNodeTree &node_tree, const bNode &node, GeometryNodesLazyFunctionGraphInfo &own_lf_graph_info)
bool should_log_verbose_in_context(const GeoNodesUserData &user_data, const ComputeContextHash hash)
LazyFunction & build_repeat_zone_lazy_function(ResourceScope &scope, const bNodeTree &btree, const bke::bNodeTreeZone &zone, ZoneBuildInfo &zone_info, const ZoneBodyFunction &body_fn)
std::unique_ptr< LazyFunction > get_switch_node_lazy_function(const bNode &node)
std::string make_anonymous_attribute_socket_inspection_string(const bNodeSocket &socket)
std::unique_ptr< LazyFunction > get_bake_lazy_function(const bNode &node, GeometryNodesLazyFunctionGraphInfo &lf_graph_info)
const std::shared_ptr< const GeometryNodesLazyFunctionGraphInfo > & ensure_geometry_nodes_lazy_function_graph(const bNodeTree &btree)
std::optional< FoundNestedNodeID > find_nested_node_id(const GeoNodesUserData &user_data, const int node_id)
void set_default_remaining_node_outputs(lf::Params &params, const bNode &node)
void report_from_multi_function(const mf::Context &context, NodeWarningType type, std::string message)
std::unique_ptr< LazyFunction > get_menu_switch_node_boolean_outputs_lazy_function(const bNode &node, GeometryNodesLazyFunctionGraphInfo &lf_graph_info)
std::unique_ptr< LazyFunction > get_enable_output_node_lazy_function(const bNode &node, GeometryNodesLazyFunctionGraphInfo &own_lf_graph_info)
void set_default_value_for_output_socket(lf::Params &params, const int lf_index, const bNodeSocket &bsocket)
std::string zone_wrapper_output_name(const ZoneBuildInfo &zone_info, const bNodeTreeZone &zone, const Span< lf::Output > outputs, const int lf_socket_i)
std::unique_ptr< LazyFunction > get_menu_switch_node_lazy_function(const bNode &node, GeometryNodesLazyFunctionGraphInfo &lf_graph_info)
LazyFunction & build_foreach_geometry_element_zone_lazy_function(ResourceScope &scope, const bNodeTree &btree, const bke::bNodeTreeZone &zone, ZoneBuildInfo &zone_info, const ZoneBodyFunction &body_fn)
std::string zone_wrapper_input_name(const ZoneBuildInfo &zone_info, const bNodeTreeZone &zone, const Span< lf::Input > inputs, const int lf_socket_i)
EvaluateClosureFunction build_evaluate_closure_node_lazy_function(ResourceScope &scope, const bNode &bnode)
BMesh Iterators.
std::unique_ptr< T, DestructValueAtAddress< T > > destruct_ptr
MatBase< float, 4, 4 > float4x4
unsigned int uint32_t
Definition BKE_text.h:81
VecBase< int32_t, 2 > int2
VecBase< float, 3 > float3
#define hash
Definition noise_c.cc:156
Defines a socket type.
Definition BKE_node.hh:163
struct blender::nodes::EvaluateClosureFunctionIndices::@324113343356111377314152204355127102171256127351 inputs
struct blender::nodes::EvaluateClosureFunctionIndices::@302221204315171014370121113344001210164341345265 outputs
const Set< ComputeContextHash > * verbose_log_contexts
const GeoNodesSideEffectNodes * side_effect_nodes
eval_log::NodeTreeLogger * try_get_tree_logger(const GeoNodesUserData &user_data) const
MultiValueMap< std::pair< ComputeContextHash, int32_t >, int > iterations_by_iteration_zone
MultiValueMap< ComputeContextHash, const lf::FunctionNode * > nodes_by_context
destruct_ptr< fn::LocalUserData > get_local(LinearAllocator<> &allocator) override
MultiValueMap< const lf::Socket *, const bNodeSocket * > bsockets_by_lf_socket_map
struct blender::nodes::GeometryNodesGroupFunction::@172250372114350111302221310316304130074374314150::@173332351212022343301023354274103154246064347366 references_to_propagate
struct blender::nodes::GeometryNodesGroupFunction::@172250372114350111302221310316304130074374314150 inputs
struct blender::nodes::GeometryNodesGroupFunction::@275230106163054033107343230045175116316373002223 outputs
struct blender::nodes::ZoneFunctionIndices::@132143137367244025376024316142102322341106322023 outputs
struct blender::nodes::ZoneFunctionIndices::@342054057300321050315260123310012173322070035365 inputs
std::function< void(bke::bake::BakeValues values)> store_fn