Blender V5.0
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
5#pragma once
6
22
23#include <variant>
24
27
29#include "NOD_multi_function.hh"
30#include "NOD_nested_node_id.hh"
31
35
36#include "BKE_bake_items.hh"
38
39struct Object;
40struct Depsgraph;
41struct Scene;
42
43namespace blender::nodes {
44
45using lf::LazyFunction;
46using mf::MultiFunction;
48
50namespace sim_input {
51
56struct PassThrough {};
57
65
75
76using Behavior = std::variant<PassThrough, OutputCopy, OutputMove>;
77
78} // namespace sim_input
79
81namespace sim_output {
82
87struct PassThrough {};
88
94 std::function<void(bke::bake::BakeState state)> store_fn;
95};
96
103
113
117struct ReadError {
118 std::string message;
119};
120
121using Behavior = std::variant<PassThrough, StoreNewState, ReadSingle, ReadInterpolated, ReadError>;
122
123} // namespace sim_output
124
131
133 public:
139 virtual SimulationZoneBehavior *get(const int zone_id) const = 0;
140};
141
147
149 public:
150 virtual BakeNodeBehavior *get(const int id) const = 0;
151};
152
161
167 const Object *self_object = nullptr;
169 Depsgraph *depsgraph = nullptr;
170};
171
174 const Depsgraph *active = nullptr;
179 Depsgraph *extra = nullptr;
180
182
189 const ID *get_evaluated_id(const ID &id_orig) const;
190};
191
213
261
282
284 private:
289 mutable std::optional<geo_eval_log::GeoTreeLogger *> tree_logger_;
290
291 public:
293
299 {
300 if (!tree_logger_.has_value()) {
301 this->ensure_tree_logger(user_data);
302 }
303 return *tree_logger_;
304 }
305
306 private:
307 void ensure_tree_logger(const GeoNodesUserData &user_data) const;
308};
309
325
331
361
407
432
433std::unique_ptr<LazyFunction> get_simulation_output_lazy_function(
434 const bNode &node, GeometryNodesLazyFunctionGraphInfo &own_lf_graph_info);
435std::unique_ptr<LazyFunction> get_simulation_input_lazy_function(
436 const bNodeTree &node_tree,
437 const bNode &node,
438 GeometryNodesLazyFunctionGraphInfo &own_lf_graph_info);
439std::unique_ptr<LazyFunction> get_switch_node_lazy_function(const bNode &node);
440std::unique_ptr<LazyFunction> get_index_switch_node_lazy_function(
441 const bNode &node, GeometryNodesLazyFunctionGraphInfo &lf_graph_info);
442std::unique_ptr<LazyFunction> get_bake_lazy_function(
443 const bNode &node, GeometryNodesLazyFunctionGraphInfo &own_lf_graph_info);
444std::unique_ptr<LazyFunction> get_menu_switch_node_lazy_function(
445 const bNode &node, GeometryNodesLazyFunctionGraphInfo &lf_graph_info);
446std::unique_ptr<LazyFunction> get_menu_switch_node_socket_usage_lazy_function(const bNode &node);
447std::unique_ptr<LazyFunction> get_warning_node_lazy_function(const bNode &node);
448std::unique_ptr<LazyFunction> get_enable_output_node_lazy_function(
449 const bNode &node, GeometryNodesLazyFunctionGraphInfo &own_lf_graph_info);
450
459 const int lf_index,
460 const bNodeSocket &bsocket);
461void construct_socket_default_value(const bke::bNodeSocketType &stype, void *r_value);
462
465 StringRef socket_name);
466
467std::optional<FoundNestedNodeID> find_nested_node_id(const GeoNodesUserData &user_data,
468 const int node_id);
469
476 const bNodeTree &btree);
477
483 private:
484 lf::Context &context_;
486
487 public:
488 ScopedComputeContextTimer(lf::Context &entered_context) : context_(entered_context)
489 {
490 start_ = geo_eval_log::Clock::now();
491 }
492
494 {
495 const geo_eval_log::TimePoint end = geo_eval_log::Clock::now();
496 auto &user_data = static_cast<GeoNodesUserData &>(*context_.user_data);
497 auto &local_user_data = static_cast<GeoNodesLocalUserData &>(*context_.local_user_data);
498 if (geo_eval_log::GeoTreeLogger *tree_logger = local_user_data.try_get_tree_logger(user_data))
499 {
500 tree_logger->execution_time += (end - start_);
501 }
502 }
503};
504
509 private:
510 const lf::Context &context_;
511 const bNode &node_;
513
514 public:
515 ScopedNodeTimer(const lf::Context &context, const bNode &node) : context_(context), node_(node)
516 {
517 start_ = geo_eval_log::Clock::now();
518 }
519
521 {
522 const geo_eval_log::TimePoint end = geo_eval_log::Clock::now();
523 auto &user_data = static_cast<GeoNodesUserData &>(*context_.user_data);
524 auto &local_user_data = static_cast<GeoNodesLocalUserData &>(*context_.local_user_data);
525 if (geo_eval_log::GeoTreeLogger *tree_logger = local_user_data.try_get_tree_logger(user_data))
526 {
527 tree_logger->node_execution_times.append(*tree_logger->allocator,
528 {node_.identifier, start_, end});
529 }
530 }
531};
532
533bool should_log_socket_values_for_context(const GeoNodesUserData &user_data,
535
541 public:
542 LazyFunctionForLogicalOr(const int inputs_num);
543
544 void execute_impl(lf::Params &params, const lf::Context &context) const override;
545};
546
560
568
578
580 const bNodeTree &btree,
581 const bke::bNodeTreeZone &zone,
582 ZoneBuildInfo &zone_info,
583 const ZoneBodyFunction &body_fn);
584
586 const bNodeTree &btree,
587 const bke::bNodeTreeZone &zone,
588 ZoneBuildInfo &zone_info,
589 const ZoneBodyFunction &body_fn);
590
592 const bNodeTree &btree,
593 const bke::bNodeTreeZone &zone,
594 ZoneBuildInfo &zone_info,
595 const ZoneBodyFunction &body_fn);
596
608
613
615 const bNode &bnode);
616
618 ZoneBuildInfo &zone_info,
619 const ZoneBodyFunction &body_fn,
620 bool expose_all_reference_sets,
621 Vector<lf::Input> &r_inputs,
622 Vector<lf::Output> &r_outputs);
623
624std::string zone_wrapper_input_name(const ZoneBuildInfo &zone_info,
625 const bke::bNodeTreeZone &zone,
627 const int lf_socket_i);
628
629std::string zone_wrapper_output_name(const ZoneBuildInfo &zone_info,
630 const bke::bNodeTreeZone &zone,
632 const int lf_socket_i);
633
640void report_from_multi_function(const mf::Context &context,
641 NodeWarningType type,
642 std::string message);
643
644} // namespace blender::nodes
eObjectMode
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)
#define main()
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
static ulong state[N]
QuaternionBase< float > Quaternion
std::variant< PassThrough, OutputCopy, OutputMove > 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)
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_socket_values_for_context(const GeoNodesUserData &user_data, const ComputeContextHash hash)
LazyFunction & build_closure_zone_lazy_function(ResourceScope &scope, const bNodeTree &btree, const bke::bNodeTreeZone &zone, ZoneBuildInfo &zone_info, const ZoneBodyFunction &body_fn)
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 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_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)
std::unique_ptr< T, DestructValueAtAddress< T > > destruct_ptr
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
VecBase< float, 3 > float3
static blender::bke::bNodeSocketTemplate outputs[]
static blender::bke::bNodeSocketTemplate inputs[]
#define hash
Definition noise_c.cc:154
Definition DNA_ID.h:414
Defines a socket type.
Definition BKE_node.hh:158
const Set< ComputeContextHash > * socket_log_contexts
const GeoNodesSideEffectNodes * side_effect_nodes
geo_eval_log::GeoTreeLogger * 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
Map< const bke::bNodeTreeZone *, const lf::FunctionNode * > zone_node_map
MultiValueMap< const lf::Socket *, const bNodeSocket * > bsockets_by_lf_socket_map
Map< const bNode *, const lf::FunctionNode * > possible_side_effect_node_map
Map< const bNode *, const lf::FunctionNode * > group_node_map
struct blender::nodes::GeometryNodesGroupFunction::@176034106072117145033162003214300177076220367077::@201205044241144324034052062053171123334141114245 references_to_propagate
std::function< void(bke::bake::BakeState state)> store_fn