Blender V4.5
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);
448
457 const int lf_index,
458 const bNodeSocket &bsocket);
459void construct_socket_default_value(const bke::bNodeSocketType &stype, void *r_value);
460
463 StringRef socket_name);
464
465std::optional<FoundNestedNodeID> find_nested_node_id(const GeoNodesUserData &user_data,
466 const int node_id);
467
474 const bNodeTree &btree);
475
481 private:
482 lf::Context &context_;
484
485 public:
486 ScopedComputeContextTimer(lf::Context &entered_context) : context_(entered_context)
487 {
488 start_ = geo_eval_log::Clock::now();
489 }
490
492 {
493 const geo_eval_log::TimePoint end = geo_eval_log::Clock::now();
494 auto &user_data = static_cast<GeoNodesUserData &>(*context_.user_data);
495 auto &local_user_data = static_cast<GeoNodesLocalUserData &>(*context_.local_user_data);
496 if (geo_eval_log::GeoTreeLogger *tree_logger = local_user_data.try_get_tree_logger(user_data))
497 {
498 tree_logger->execution_time += (end - start_);
499 }
500 }
501};
502
507 private:
508 const lf::Context &context_;
509 const bNode &node_;
511
512 public:
513 ScopedNodeTimer(const lf::Context &context, const bNode &node) : context_(context), node_(node)
514 {
515 start_ = geo_eval_log::Clock::now();
516 }
517
519 {
520 const geo_eval_log::TimePoint end = geo_eval_log::Clock::now();
521 auto &user_data = static_cast<GeoNodesUserData &>(*context_.user_data);
522 auto &local_user_data = static_cast<GeoNodesLocalUserData &>(*context_.local_user_data);
523 if (geo_eval_log::GeoTreeLogger *tree_logger = local_user_data.try_get_tree_logger(user_data))
524 {
525 tree_logger->node_execution_times.append(*tree_logger->allocator,
526 {node_.identifier, start_, end});
527 }
528 }
529};
530
531bool should_log_socket_values_for_context(const GeoNodesUserData &user_data,
533
539 public:
540 LazyFunctionForLogicalOr(const int inputs_num);
541
542 void execute_impl(lf::Params &params, const lf::Context &context) const override;
543};
544
558
566
576
578 const bNodeTree &btree,
579 const bke::bNodeTreeZone &zone,
580 ZoneBuildInfo &zone_info,
581 const ZoneBodyFunction &body_fn);
582
584 const bNodeTree &btree,
585 const bke::bNodeTreeZone &zone,
586 ZoneBuildInfo &zone_info,
587 const ZoneBodyFunction &body_fn);
588
590 const bNodeTree &btree,
591 const bke::bNodeTreeZone &zone,
592 ZoneBuildInfo &zone_info,
593 const ZoneBodyFunction &body_fn);
594
606
611
613 const bNode &bnode);
614
616 ZoneBuildInfo &zone_info,
617 const ZoneBodyFunction &body_fn,
618 bool expose_all_reference_sets,
619 Vector<lf::Input> &r_inputs,
620 Vector<lf::Output> &r_outputs);
621
622std::string zone_wrapper_input_name(const ZoneBuildInfo &zone_info,
623 const bke::bNodeTreeZone &zone,
625 const int lf_socket_i);
626
627std::string zone_wrapper_output_name(const ZoneBuildInfo &zone_info,
628 const bke::bNodeTreeZone &zone,
630 const int lf_socket_i);
631
636[[nodiscard]] bool implicitly_convert_socket_value(const bke::bNodeSocketType &from_type,
637 const void *from_value,
639 void *r_to_value);
640
647 ResourceScope &scope);
648
655void report_from_multi_function(const mf::Context &context,
656 NodeWarningType type,
657 std::string message);
658
659} // 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]
static Type to_type(const eGPUType type)
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)
bool implicitly_convert_socket_value(const bke::bNodeSocketType &from_type, const void *from_value, const bke::bNodeSocketType &to_type, void *r_to_value)
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)
const LazyFunction * build_implicit_conversion_lazy_function(const bke::bNodeSocketType &from_type, const bke::bNodeSocketType &to_type, ResourceScope &scope)
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:404
Defines a socket type.
Definition BKE_node.hh:152
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::@311217322151273055243347055333132220230004041004::@376313040076355172126342102314323105254352264056 references_to_propagate
std::function< void(bke::bake::BakeState state)> store_fn