Blender V4.3
blender::nodes::partial_eval Namespace Reference

Classes

struct  NodeInContextDownstreamComparator
 
struct  NodeInContextUpstreamComparator
 
struct  UpstreamEvalTargets
 

Functions

bool is_supported_value_node (const bNode &node)
 
static Vector< intget_global_node_sort_vector_right_to_left (const ComputeContext *initial_context, const bNode &initial_node)
 
static Vector< intget_global_node_sort_vector_left_to_right (const ComputeContext *initial_context, const bNode &initial_node)
 
void eval_downstream (const Span< SocketInContext > initial_sockets, ResourceScope &scope, FunctionRef< void(const NodeInContext &ctx_node, Vector< const bNodeSocket * > &r_outputs_to_propagate)> evaluate_node_fn, FunctionRef< bool(const SocketInContext &ctx_from, const SocketInContext &ctx_to)> propagate_value_fn)
 
UpstreamEvalTargets eval_upstream (const Span< SocketInContext > initial_sockets, ResourceScope &scope, FunctionRef< void(const NodeInContext &ctx_node, Vector< const bNodeSocket * > &r_modified_inputs)> evaluate_node_fn, FunctionRef< bool(const SocketInContext &ctx_from, const SocketInContext &ctx_to)> propagate_value_fn, FunctionRef< void(const NodeInContext &ctx_node, Vector< const bNodeSocket * > &r_sockets)> get_inputs_to_propagate_fn)
 

Detailed Description

This header provides functionality that makes it relatively straight forward to evaluate parts of a node tree. The evaluator is designed to be flexible and simple to use in different contexts. It's not designed to be highly efficient and parallel. However, it has a lower start-up cost compared to e.g. the lazy-function evaluation for geometry nodes, which needs to convert the entire node graph into a lazy-function graph first. So it can be more efficient when only very few nodes of a larger graph have to be evaluated and those nodes are cheap.

The evaluator does not use recursion, so it can be used on node graphs of every size and depth.

Function Documentation

◆ eval_downstream()

void blender::nodes::partial_eval::eval_downstream ( const Span< SocketInContext > initial_sockets,
ResourceScope & scope,
FunctionRef< void(const NodeInContext &ctx_node, Vector< const bNodeSocket * > &r_outputs_to_propagate)> evaluate_node_fn,
FunctionRef< bool(const SocketInContext &ctx_from, const SocketInContext &ctx_to)> propagate_value_fn )

Evaluating part of a node tree from left-to-right. The part that's evaluated starts at the given sockets and is propagated downstream step-by-step. The caller is responsible for storing the socket values (a value per #SocketInContext).

Note
This handles node groups transparently, but does not handle e.g. repeat zones yet.
Parameters
initial_socketsSockets where the evaluation should start.
scopeIs used to construct compute contexts which the caller may want to outlive the entire evaluation.
evaluate_node_fnIs called when all (relevant) upstream nodes are already evaluated and evaluates the given node. This should updated the values the caller stores for the output sockets.
propagate_value_fnShould copy the value stored for one socket to the other socket. This may have to do type conversions. The return value indicates success. False indicates that the value was not propagated and as such the target node also shouldn't be evaluated (unless there are other reasons to evaluate it).

Definition at line 106 of file partial_eval.cc.

References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), BLI_assert, blender::Vector< T, InlineBufferCapacity, Allocator >::clear(), blender::ResourceScope::construct(), blender::nodes::NodeInContext::context, blender::nodes::NodeInContext::node, and node.

Referenced by blender::nodes::inverse_eval::foreach_element_on_inverse_eval_path().

◆ eval_upstream()

UpstreamEvalTargets blender::nodes::partial_eval::eval_upstream ( const Span< SocketInContext > initial_sockets,
ResourceScope & scope,
FunctionRef< void(const NodeInContext &ctx_node, Vector< const bNodeSocket * > &r_modified_inputs)> evaluate_node_fn,
FunctionRef< bool(const SocketInContext &ctx_from, const SocketInContext &ctx_to)> propagate_value_fn,
FunctionRef< void(const NodeInContext &ctx_node, Vector< const bNodeSocket * > &r_sockets)> get_inputs_to_propagate_fn )

Evaluates part of a node tree from right-to-left (inverse direction). The caller is responsible for storing the socket values (a value per #SocketInContext). Evaluation in the upstream direction is not always well defined, because output sockets may be linked to multiple inputs and nodes may not always have an inverse evaluation function. The caller is responsible for handling these cases gracefully in the given callbacks.

Note
This handles node groups transparently, but does not handle e.g. repeat zones yet.
Parameters
initial_socketsSockets where the evaluation should start.
scopeIs used to construct compute contexts which the caller may want to outlive the entire evaluation.
evaluate_node_fnCalled to evaluate the node in reverse, i.e. it's outputs are computed first, and the node evaluation computes the inputs.
propagate_value_fnShould copy the value from one socket to another, while optionally doing type conversions. This has to handle the case when multiple values are propagated to the same socket. Returning false indicates that no value was propagated.
get_inputs_to_propagate_fnGathers a list of input sockets that should be propagated further.
Returns
Places in the node tree that have gotten new values that can't be propagated further in the node tree.

Definition at line 248 of file partial_eval.cc.

References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), blender::Vector< T, InlineBufferCapacity, Allocator >::clear(), blender::ResourceScope::construct(), blender::nodes::NodeInContext::context, blender::nodes::partial_eval::UpstreamEvalTargets::group_inputs, bNode::id, is_supported_value_node(), blender::nodes::NodeInContext::node, blender::ComputeContext::parent(), blender::nodes::partial_eval::UpstreamEvalTargets::sockets, and blender::nodes::partial_eval::UpstreamEvalTargets::value_nodes.

Referenced by blender::nodes::inverse_eval::backpropagate_socket_values(), blender::nodes::inverse_eval::find_local_inverse_eval_targets(), and blender::nodes::inverse_eval::foreach_element_on_inverse_eval_path().

◆ get_global_node_sort_vector_left_to_right()

static Vector< int > blender::nodes::partial_eval::get_global_node_sort_vector_left_to_right ( const ComputeContext * initial_context,
const bNode & initial_node )
static

◆ get_global_node_sort_vector_right_to_left()

static Vector< int > blender::nodes::partial_eval::get_global_node_sort_vector_right_to_left ( const ComputeContext * initial_context,
const bNode & initial_node )
static

◆ is_supported_value_node()

bool blender::nodes::partial_eval::is_supported_value_node ( const bNode & node)

Definition at line 15 of file partial_eval.cc.

References ELEM, and SH_NODE_VALUE.

Referenced by eval_upstream(), and blender::ed::space_node::std_node_socket_draw().