34struct BundleSocketValue;
35using BundleSocketValuePtr = std::shared_ptr<BundleSocketValue>;
37struct FallbackValue {};
40struct DanglingValue {};
43 bNode *node =
nullptr;
44 bNodeSocket *socket =
nullptr;
47struct PrimitiveSocketValue {
48 std::variant<int, float, bool, ColorGeometry4f, float3, MenuValue, std::string> value;
50 const void *buffer()
const
52 return std::visit([](
auto &&value) ->
const void * {
return &value; }, value);
57 return const_cast<void *
>(
const_cast<const PrimitiveSocketValue *
>(
this)->buffer());
60 static PrimitiveSocketValue from_value(
const GPointer value)
62 const CPPType &type = *value.type();
64 return {*
static_cast<const int *
>(value.get())};
66 if (type.is<
float>()) {
67 return {*
static_cast<const float *
>(value.get())};
69 if (type.is<
bool>()) {
70 return {*
static_cast<const bool *
>(value.get())};
76 return {*
static_cast<const float3 *
>(value.get())};
78 if (type.is<MenuValue>()) {
79 return {*
static_cast<const MenuValue *
>(value.get())};
81 if (type.is<std::string>()) {
82 return {*
static_cast<const std::string *
>(value.get())};
90struct LinkedSocketValue {
91 bNode *node =
nullptr;
92 bNodeSocket *socket =
nullptr;
96struct InputSocketValue {
97 const bNodeSocket *socket =
nullptr;
100struct ClosureZoneValue {
101 const bke::bNodeTreeZone *zone =
nullptr;
102 const ComputeContext *closure_creation_context =
nullptr;
105struct MultiInputValue {
106 Vector<SocketValue, 0> values;
115 std::variant<FallbackValue,
119 PrimitiveSocketValue,
121 BundleSocketValuePtr,
126 std::optional<PrimitiveSocketValue> to_primitive(
const bke::bNodeSocketType &type)
const
128 if (
const auto *primitive_value = std::get_if<PrimitiveSocketValue>(&this->value)) {
129 return *primitive_value;
131 if (
const auto *input_socket_value = std::get_if<InputSocketValue>(&this->value)) {
132 const bNodeSocket &socket = *input_socket_value->socket;
134 if (!socket.runtime->declaration) {
140 switch (socket.typeinfo->type) {
142 return PrimitiveSocketValue{socket.default_value_typed<bNodeSocketValueFloat>()->value};
144 return PrimitiveSocketValue{socket.default_value_typed<bNodeSocketValueInt>()->value};
146 return PrimitiveSocketValue{
147 bool(socket.default_value_typed<bNodeSocketValueBoolean>()->value)};
149 return PrimitiveSocketValue{
150 float3(socket.default_value_typed<bNodeSocketValueVector>()->value)};
152 return PrimitiveSocketValue{
153 ColorGeometry4f(socket.default_value_typed<bNodeSocketValueRGBA>()->value)};
155 return PrimitiveSocketValue{
156 MenuValue(socket.default_value_typed<bNodeSocketValueMenu>()->value)};
158 return PrimitiveSocketValue{
159 std::string(socket.default_value_typed<bNodeSocketValueString>()->value)};
164 if (std::get_if<FallbackValue>(&this->value)) {
173 return PrimitiveSocketValue::from_value(
174 {type.base_cpp_type, type.base_cpp_type->default_value()});
183struct BundleSocketValue {
187 const bke::bNodeSocketType *socket_type =
nullptr;
193struct PreservedZone {
194 bNode *input_node =
nullptr;
195 bNode *output_node =
nullptr;
203constexpr int preserved_repeat_zone_iteration = -1;
205class ShaderNodesInliner {
208 ResourceScope scope_;
210 const bNodeTree &src_tree_;
212 bNodeTree &dst_tree_;
214 InlineShaderNodeTreeParams ¶ms_;
216 bke::ComputeContextCache compute_context_cache_;
221 Map<const ComputeContext *, const ComputeContext *> parent_zone_contexts_;
223 Map<SocketInContext, SocketValue> value_by_socket_;
228 Map<NodeInContext, PreservedZone> copied_zone_by_zone_output_node_;
230 Stack<SocketInContext> scheduled_sockets_stack_;
232 const bke::DataTypeConversions &data_type_conversions_;
234 int dst_node_counter_ = 0;
236 struct FailedToInlineRepeatZone {
237 const ComputeContext *parent_ctx =
nullptr;
238 int output_node_id = 0;
240 friend bool operator==(
const FailedToInlineRepeatZone &a,
241 const FailedToInlineRepeatZone &
b) =
default;
265 Set<FailedToInlineRepeatZone> repeat_zones_to_force_inline_;
271 Set<const ComputeContext *> handled_side_effect_contexts_;
274 ShaderNodesInliner(
const bNodeTree &src_tree,
276 InlineShaderNodeTreeParams ¶ms)
277 : src_tree_(src_tree),
286 src_tree_.ensure_topology_cache();
287 if (src_tree_.has_available_link_cycle()) {
291 const Vector<SocketInContext> final_output_sockets = this->find_final_output_sockets();
295 for (
const SocketInContext &socket : final_output_sockets) {
296 this->schedule_socket(socket);
299 this->schedule_side_effect_nodes_in_context(src_tree_,
nullptr,
nullptr);
301 for (
const SocketInContext &socket : final_output_sockets) {
302 this->schedule_side_effect_nodes_in_context(socket->owner_tree(),
nullptr, socket.context);
310 while (!scheduled_sockets_stack_.is_empty()) {
311 const SocketInContext socket = scheduled_sockets_stack_.peek();
312 const int old_stack_size = scheduled_sockets_stack_.size();
314 this->handle_socket(socket);
316 if (scheduled_sockets_stack_.size() == old_stack_size) {
319 BLI_assert(socket == scheduled_sockets_stack_.peek());
320 scheduled_sockets_stack_.pop();
325 Map<NodeInContext, bNode *> final_output_nodes;
326 for (
const SocketInContext &socket : final_output_sockets) {
327 const NodeInContext src_node = socket.owner_node();
328 bNode *copied_node = final_output_nodes.lookup_or_add_cb(src_node, [&]() {
329 Map<const bNodeSocket *, bNodeSocket *> socket_map;
332 this->node_copy_flag(),
334 this->get_next_node_identifier(),
336 copied_node->parent =
nullptr;
339 bNodeSocket *copied_socket =
static_cast<bNodeSocket *
>(
340 BLI_findlink(&copied_node->inputs, socket.socket->index()));
341 this->set_input_socket_value(
342 src_node, *copied_node, *copied_socket, value_by_socket_.lookup(socket));
345 this->restore_zones_in_output_tree();
346 this->position_nodes_in_output_tree();
350 Vector<SocketInContext> find_final_output_sockets()
352 Vector<TreeInContext> trees;
353 this->find_trees_potentially_containing_shader_outputs_recursive(
nullptr, src_tree_, trees);
355 auto get_engine_target = [](
const bNode *output_node) {
357 "ShaderNodeOutputMaterial",
358 "ShaderNodeOutputLight",
359 "ShaderNodeOutputWorld"))
366 Vector<SocketInContext> output_sockets;
367 auto add_output_type = [&](
const UString output_type) {
368 for (
const TreeInContext &tree : trees) {
369 const bke::bNodeTreeZones &zones = *tree->zones();
370 for (
const bNode *
node : tree->nodes_by_type(output_type)) {
374 const bke::bNodeTreeZone *zone = zones.get_zone_by_node(
node->identifier);
377 TIP_(
"Output node must not be in zone"),
381 for (
const bNodeSocket *socket :
node->input_sockets()) {
382 output_sockets.append({tree.context, socket});
389 ID_Type tree_type = src_tree_.owner_id ? src_tree_.owner_id->id_type() :
ID_MA;
393 add_output_type(
"ShaderNodeOutputMaterial"_ustr);
394 add_output_type(
"ShaderNodeOutputLight"_ustr);
395 add_output_type(
"ShaderNodeOutputAOV"_ustr);
398 add_output_type(
"ShaderNodeOutputWorld"_ustr);
399 add_output_type(
"ShaderNodeOutputAOV"_ustr);
402 add_output_type(
"ShaderNodeOutputLight"_ustr);
405 add_output_type(
"ShaderNodeOutputLineStyle"_ustr);
411 return output_sockets;
414 void find_trees_potentially_containing_shader_outputs_recursive(
const ComputeContext *context,
415 const bNodeTree &tree,
416 Vector<TreeInContext> &r_trees)
418 const bke::bNodeTreeZones *zones = tree.zones();
422 if (tree.has_available_link_cycle()) {
425 r_trees.append({
context, &tree});
426 for (
const bNode *group_node : tree.group_nodes()) {
427 if (group_node->is_muted()) {
430 const bNodeTree *group = id_cast<const bNodeTree *>(group_node->id);
434 group->ensure_topology_cache();
435 const bke::bNodeTreeZone *zone = zones->get_zone_by_node(group_node->identifier);
440 const ComputeContext &group_context = compute_context_cache_.for_group_node(
441 context, group_node->identifier, &tree);
442 this->find_trees_potentially_containing_shader_outputs_recursive(
443 &group_context, *group, r_trees);
447 void handle_socket(
const SocketInContext &socket)
449 if (!socket->is_available()) {
452 if (value_by_socket_.contains(socket)) {
456 if (socket->is_input()) {
457 this->handle_input_socket(socket);
460 this->handle_output_socket(socket);
464 bool should_use_link(
const bNodeLink &link)
const
467 !this->socket_is_ignored(*link.fromsock);
470 void handle_input_socket(
const SocketInContext &socket)
472 if (socket->is_multi_input()) {
473 this->handle_multi_input_socket(socket);
477 const bNodeLink *used_link =
nullptr;
478 for (
const bNodeLink *link : socket->directly_linked_links()) {
479 if (!this->should_use_link(*link) || link->fromnode ==
nullptr ||
480 link->fromnode->is_undefined())
488 if (this->input_socket_may_have_dangling_value(socket)) {
489 this->store_socket_value(socket, {DanglingValue{}});
492 this->store_socket_value(socket, {InputSocketValue{socket.socket}});
497 const ComputeContext *
from_context = this->get_link_source_context(*used_link, socket);
498 const SocketInContext origin_socket = {
from_context, used_link->fromsock};
499 if (
const auto *value = value_by_socket_.lookup_ptr(origin_socket)) {
500 if (std::holds_alternative<DanglingValue>(value->value)) {
501 if (this->input_socket_may_have_dangling_value(socket)) {
502 this->store_socket_value(socket, {DanglingValue{}});
506 this->store_socket_value(socket, {InputSocketValue{socket.socket}});
512 this->store_socket_value(socket,
513 this->handle_implicit_conversion(*value,
514 *used_link->fromsock->typeinfo,
515 *used_link->tosock->typeinfo));
519 this->schedule_socket(origin_socket);
522 void handle_multi_input_socket(
const SocketInContext &socket)
524 bool all_links_ready =
true;
525 Vector<SocketValue, 0> values;
526 for (
const bNodeLink *link : socket->directly_linked_links()) {
527 if (!this->should_use_link(*link)) {
530 const ComputeContext *
from_context = this->get_link_source_context(*link, socket);
531 const SocketInContext origin_socket = {
from_context, link->fromsock};
532 const SocketValue *value = value_by_socket_.lookup_ptr(origin_socket);
534 this->schedule_socket(origin_socket);
535 all_links_ready =
false;
538 values.append(*value);
540 if (!all_links_ready) {
543 this->store_socket_value(socket, {MultiInputValue{std::move(values)}});
551 bool input_socket_may_have_dangling_value(
const SocketInContext &socket)
554 const NodeInContext
node = socket.owner_node();
555 return node->is_reroute() ||
node->is_muted();
558 const ComputeContext *get_link_source_context(
const bNodeLink &link,
559 const SocketInContext &to_socket)
561 const bNodeTree &tree = to_socket->owner_tree();
562 const bke::bNodeTreeZones *zones = tree.zones();
566 const bke::bNodeTreeZone *to_zone = zones->get_zone_by_socket(*to_socket);
567 const bke::bNodeTreeZone *from_zone = zones->get_zone_by_socket(*link.fromsock);
568 const ComputeContext *
context = to_socket.context;
569 for (
const bke::bNodeTreeZone *zone = to_zone; zone != from_zone; zone = zone->parent_zone) {
570 context = parent_zone_contexts_.lookup(context);
575 void handle_output_socket(
const SocketInContext &socket)
577 const NodeInContext
node = socket.owner_node();
578 if (
node->is_reroute()) {
579 this->handle_output_socket__reroute(socket);
582 if (
node->is_muted()) {
583 if (!this->handle_output_socket__internal_links(socket)) {
585 this->store_socket_value_dangling(socket);
589 if (
node->is_group()) {
590 this->handle_output_socket__group(socket);
593 if (
node->is_group_input()) {
594 this->handle_output_socket__group_input(socket);
597 if (
node->is_type(
"GeometryNodeRepeatOutput"_ustr)) {
598 if (this->should_preserve_repeat_zone_node(
node.context, *
node)) {
599 this->handle_output_socket__preserved_repeat_output(socket);
602 this->handle_output_socket__repeat_output(socket);
605 if (
node->is_type(
"GeometryNodeRepeatInput"_ustr)) {
606 const auto *
context =
dynamic_cast<const bke::RepeatZoneComputeContext *
>(socket.context);
609 this->store_socket_value_fallback(socket);
612 if (
context->iteration() == preserved_repeat_zone_iteration) {
613 this->handle_output_socket__preserved_repeat_input(socket);
616 this->handle_output_socket__repeat_input(socket);
619 if (
node->is_type(
"NodeClosureOutput"_ustr)) {
620 this->handle_output_socket__closure_output(socket);
623 if (
node->is_type(
"NodeClosureInput"_ustr)) {
624 this->handle_output_socket__closure_input(socket);
627 if (
node->is_type(
"NodeEvaluateClosure"_ustr)) {
628 this->handle_output_socket__evaluate_closure(socket);
631 if (
node->is_type(
"NodeCombineBundle"_ustr)) {
632 this->handle_output_socket__combine_bundle(socket);
635 if (
node->is_type(
"NodeSeparateBundle"_ustr)) {
636 this->handle_output_socket__separate_bundle(socket);
639 if (
node->is_type(
"GeometryNodeMenuSwitch"_ustr)) {
640 this->handle_output_socket__menu_switch(socket);
643 if (
node->is_type(
"GeometryNodeIndexSwitch"_ustr)) {
644 this->handle_output_socket__index_switch(socket);
647 if (
node->is_type(
"GeometryNodeSwitch"_ustr)) {
648 this->handle_output_socket__switch(socket);
651 if (
node->is_type(
"FunctionNodeInputMenu"_ustr)) {
652 this->handle_output_socket__input_menu(socket);
655 if (
node->is_type(
"NodeJoinBundle"_ustr)) {
656 this->handle_output_socket__join_bundle(socket);
659 if (
node->is_type(
"NodeImplicitConversion"_ustr)) {
660 this->handle_output_socket__implicit_conversion(socket);
663 if (
node->is_type(
"GeometryNodeWarning"_ustr)) {
664 this->handle_output_socket__warning(socket);
667 if (
node->is_type(
"NodeEnableOutput"_ustr)) {
668 this->handle_output_socket__enable_output(socket);
671 this->handle_output_socket__eval(socket);
674 void handle_output_socket__reroute(
const SocketInContext &socket)
676 const NodeInContext
node = socket.owner_node();
677 const SocketInContext input_socket =
node.input_socket(0);
678 this->forward_value_or_schedule(socket, input_socket);
682 [[nodiscard]]
bool handle_output_socket__internal_links(
const SocketInContext &socket)
684 const NodeInContext
node = socket.owner_node();
685 for (
const bNodeInternalLink &internal_link :
node->internal_links()) {
686 if (internal_link.out == socket.socket) {
687 const SocketInContext src_socket = {socket.context, internal_link.in};
688 if (src_socket->is_multi_input()) {
689 const bNodeLink *src_link =
nullptr;
690 for (
const bNodeLink *link : src_socket->directly_linked_links()) {
691 if (this->should_use_link(*link)) {
699 const ComputeContext *
from_context = this->get_link_source_context(*src_link,
701 const SocketInContext origin_socket = {
from_context, src_link->fromsock};
702 this->forward_value_or_schedule(socket, origin_socket);
705 if (
const SocketValue *value = value_by_socket_.lookup_ptr(src_socket)) {
708 this->store_socket_value(socket,
709 this->handle_implicit_conversion(*value,
710 *internal_link.in->typeinfo,
711 *internal_link.out->typeinfo));
714 this->schedule_socket(src_socket);
721 void handle_output_socket__group(
const SocketInContext &socket)
723 const NodeInContext
node = socket.owner_node();
724 const bNodeTree *group =
reinterpret_cast<const bNodeTree *
>(
node->id);
726 this->store_socket_value_fallback(socket);
730 this->store_socket_value_fallback(socket);
732 TIP_(
"Nodes stack limit reached (too many levels of nested nodes)"),
736 group->ensure_interface_cache();
737 group->ensure_topology_cache();
738 const bNode *group_output_node = group->group_output_node();
739 if (!group_output_node) {
740 this->store_socket_value_fallback(socket);
745 const ComputeContext &group_compute_context = compute_context_cache_.for_group_node(
746 socket.context,
node->identifier, &
node->owner_tree());
747 const SocketInContext group_output_socket_ctx = {
748 &group_compute_context, &group_output_node->input_socket(socket->index())};
749 this->schedule_side_effect_nodes_in_context(*group,
nullptr, &group_compute_context);
750 this->forward_value_or_schedule(socket, group_output_socket_ctx);
753 void handle_output_socket__group_input(
const SocketInContext &socket)
755 if (
const auto *group_node_compute_context =
756 dynamic_cast<const bke::GroupNodeComputeContext *
>(socket.context))
760 const ComputeContext *parent_compute_context = group_node_compute_context->parent();
761 const bNode *group_node = group_node_compute_context->node();
763 const bNodeSocket &group_node_input = group_node->input_socket(socket->index());
764 const SocketInContext group_input_socket_ctx = {parent_compute_context, &group_node_input};
765 this->forward_value_or_schedule(socket, group_input_socket_ctx);
768 this->store_socket_value_fallback(socket);
778 bool should_preserve_repeat_zone_node(
const ComputeContext *outer_ctx,
779 const bNode &repeat_zone_node)
const
781 BLI_assert(repeat_zone_node.is_type(
"GeometryNodeRepeatOutput"_ustr) ||
782 repeat_zone_node.is_type(
"GeometryNodeRepeatInput"_ustr));
783 if (!params_.allow_preserving_repeat_zones) {
786 const bNodeTree &tree = repeat_zone_node.owner_tree();
787 const bke::bNodeTreeZones *zones = tree.zones();
791 const bke::bNodeTreeZone *zone = zones->get_zone_by_node(repeat_zone_node.identifier);
795 const bNode *repeat_zone_input_node = zone->input_node();
796 const bNode *repeat_zone_output_node = zone->output_node();
797 if (!repeat_zone_input_node || !repeat_zone_output_node) {
800 if (repeat_zones_to_force_inline_.contains({outer_ctx, *zone->output_node_id})) {
803 const auto &
storage = *
static_cast<const NodeGeometryRepeatOutput *
>(
804 repeat_zone_output_node->storage);
806 const NodeRepeatItem &item =
storage.items[i];
815 bool is_inliner_evaluation_node(
const bNode &
node)
const
817 const UString idname =
node.typeinfo->idname;
819 "FunctionNodeFindInString"_ustr,
820 "FunctionNodeFormatString"_ustr,
821 "FunctionNodeInputSpecialCharacters"_ustr,
822 "FunctionNodeInputString"_ustr,
823 "FunctionNodeMatchString"_ustr,
824 "FunctionNodeReplaceString"_ustr,
825 "FunctionNodeReverseString"_ustr,
826 "FunctionNodeSetStringCase"_ustr,
827 "FunctionNodeSliceString"_ustr,
828 "FunctionNodeStringLength"_ustr,
829 "FunctionNodeStringToValue"_ustr,
830 "FunctionNodeTrimString"_ustr,
831 "FunctionNodeValueToString"_ustr);
834 void handle_output_socket__repeat_output(
const SocketInContext &socket)
836 const bNode &repeat_output_node = socket->owner_node();
837 const bNodeTree &tree = socket->owner_tree();
839 const bke::bNodeTreeZones *zones = tree.zones();
841 this->store_socket_value_fallback(socket);
844 const bke::bNodeTreeZone *zone = zones->get_zone_by_node(repeat_output_node.identifier);
846 this->store_socket_value_fallback(socket);
849 const NodeInContext repeat_input_node = {socket.context, zone->input_node()};
850 const SocketInContext iterations_input = repeat_input_node.input_socket(0);
851 const SocketValue *iterations_socket_value = value_by_socket_.lookup_ptr(iterations_input);
852 if (!iterations_socket_value) {
854 this->schedule_socket(iterations_input);
857 const std::optional<PrimitiveSocketValue> iterations_value_opt =
858 iterations_socket_value->to_primitive(*iterations_input->typeinfo);
859 if (!iterations_value_opt) {
860 this->add_dynamic_repeat_zone_iterations_error(repeat_input_node);
862 const int iterations = iterations_value_opt.has_value() ?
863 std::get<int>(iterations_value_opt->value) :
865 if (iterations <= 0) {
868 const SocketInContext origin_socket = repeat_input_node.input_socket(1 + socket->index());
869 this->forward_value_or_schedule(socket, origin_socket);
873 const ComputeContext &last_iteration_context = compute_context_cache_.for_repeat_zone(
874 socket.context, repeat_output_node, iterations - 1);
875 parent_zone_contexts_.add(&last_iteration_context, socket.context);
876 this->schedule_side_effect_nodes_in_context(tree, zone, &last_iteration_context);
877 const SocketInContext origin_socket = {&last_iteration_context,
878 &repeat_output_node.input_socket(socket->index())};
879 this->forward_value_or_schedule(socket, origin_socket);
882 void handle_output_socket__preserved_repeat_output(
const SocketInContext &socket)
884 const bNodeTree &tree = socket->owner_tree();
885 const NodeInContext repeat_output_node = socket.owner_node();
886 const bke::bNodeTreeZones &zones = *tree.zones();
887 const bke::bNodeTreeZone &zone = *zones.get_zone_by_node(repeat_output_node->identifier);
888 const bNode &repeat_input_node = *zone.input_node();
890 const ComputeContext *out_context = socket.context;
891 const ComputeContext &in_context = compute_context_cache_.for_repeat_zone(
892 socket.context, repeat_output_node->identifier, preserved_repeat_zone_iteration);
893 parent_zone_contexts_.add(&in_context, out_context);
901 [&]() { this->schedule_side_effect_nodes_in_context(tree, &zone, &in_context); });
903 const EnsureInputsResult ensured_inputs = this->ensure_node_inputs(
904 {&in_context, &socket->owner_node()});
905 if (ensured_inputs.has_missing_inputs) {
909 const NodeInContext
node = socket.owner_node();
910 bNode &copied_node = this->handle_output_socket__eval_copy_node(
911 *
node, &in_context, out_context);
912 PreservedZone &preserved_zone = copied_zone_by_zone_output_node_.lookup_or_add_default(
914 preserved_zone.output_node = &copied_node;
916 this->schedule_socket({&in_context, &repeat_input_node.output_socket(0)});
919 void handle_output_socket__preserved_repeat_input(
const SocketInContext &socket)
921 const ComputeContext &out_context = *socket.context;
922 const ComputeContext *in_context = out_context.parent();
923 BLI_assert(
dynamic_cast<const bke::RepeatZoneComputeContext &
>(out_context).iteration() ==
924 preserved_repeat_zone_iteration);
926 const EnsureInputsResult ensured_inputs = this->ensure_node_inputs(
927 {in_context, &socket->owner_node()});
928 if (ensured_inputs.has_missing_inputs) {
932 const bNodeTree &tree = socket->owner_tree();
933 const NodeInContext
node = socket.owner_node();
934 bNode &copied_node = this->handle_output_socket__eval_copy_node(
935 *
node, in_context, &out_context);
936 const auto &
storage = *
static_cast<const NodeGeometryRepeatInput *
>(
node->storage);
937 const NodeInContext repeat_output_node{in_context, tree.node_by_id(
storage.output_node_id)};
938 PreservedZone &preserved_zone = copied_zone_by_zone_output_node_.lookup_or_add_default(
940 preserved_zone.input_node = &copied_node;
943 void add_dynamic_repeat_zone_iterations_error(
const NodeInContext &repeat_input_node)
946 TIP_(
"Iterations input has to be a constant value"),
950 void handle_output_socket__repeat_input(
const SocketInContext &socket)
952 const bNodeTree &tree = socket->owner_tree();
953 const bNode &repeat_input_node = socket->owner_node();
954 const auto *repeat_zone_context =
dynamic_cast<const bke::RepeatZoneComputeContext *
>(
956 if (!repeat_zone_context) {
957 this->store_socket_value_fallback(socket);
961 const int iteration = repeat_zone_context->iteration();
963 if (socket->index() == 0) {
965 this->store_socket_value_primitive(socket, iteration);
969 if (iteration == 0) {
971 const SocketInContext origin_socket = {repeat_zone_context->parent(),
972 &repeat_input_node.input_socket(socket->index())};
973 this->forward_value_or_schedule(socket, origin_socket);
978 const bke::bNodeTreeZones &zones = *tree.zones();
979 const bke::bNodeTreeZone &zone = *zones.get_zone_by_node(repeat_input_node.identifier);
980 const bNode &repeat_output_node = *repeat_input_node.owner_tree().node_by_id(
981 repeat_zone_context->output_node_id());
982 const int previous_iteration = iteration - 1;
983 const ComputeContext &previous_iteration_context = compute_context_cache_.for_repeat_zone(
984 repeat_zone_context->parent(), repeat_output_node, previous_iteration);
985 parent_zone_contexts_.add(&previous_iteration_context, repeat_zone_context->parent());
986 this->schedule_side_effect_nodes_in_context(tree, &zone, &previous_iteration_context);
987 const SocketInContext origin_socket = {&previous_iteration_context,
988 &repeat_output_node.input_socket(socket->index() - 1)};
989 this->forward_value_or_schedule(socket, origin_socket);
992 void handle_output_socket__closure_output(
const SocketInContext &socket)
994 const bNode &
node = socket->owner_node();
995 const bke::bNodeTreeZones *zones =
node.owner_tree().zones();
997 this->store_socket_value_fallback(socket);
1000 const bke::bNodeTreeZone *zone = zones->get_zone_by_node(
node.identifier);
1002 this->store_socket_value_fallback(socket);
1006 this->store_socket_value(socket, {ClosureZoneValue{zone, socket.context}});
1009 void handle_output_socket__evaluate_closure(
const SocketInContext &socket)
1011 const NodeInContext evaluate_closure_node = socket.owner_node();
1012 const SocketInContext closure_input_socket = evaluate_closure_node.input_socket(0);
1013 const SocketValue *closure_input_value = value_by_socket_.lookup_ptr(closure_input_socket);
1014 if (!closure_input_value) {
1017 this->schedule_socket(closure_input_socket);
1020 const ClosureZoneValue *closure_zone_value = std::get_if<ClosureZoneValue>(
1021 &closure_input_value->value);
1022 if (!closure_zone_value) {
1024 if (!this->handle_output_socket__internal_links(socket)) {
1025 this->store_socket_value_fallback(socket);
1030 this->store_socket_value_fallback(socket);
1032 TIP_(
"Nodes stack limit reached (too many levels of nested nodes)"),
1037 const auto *evaluate_closure_storage =
static_cast<const NodeEvaluateClosure *
>(
1038 evaluate_closure_node->storage);
1039 const bNode &closure_output_node = *closure_zone_value->zone->output_node();
1040 const auto &closure_storage = *
static_cast<const NodeClosureOutput *
>(
1041 closure_output_node.storage);
1042 const StringRef key = evaluate_closure_storage->output_items.items[socket->index()].name;
1044 const bNodeTree &closure_tree = closure_output_node.owner_tree();
1045 const ClosureSourceLocation closure_source_location{
1047 closure_output_node.identifier,
1048 closure_zone_value->closure_creation_context ?
1049 closure_zone_value->closure_creation_context->hash() :
1050 ComputeContextHash{},
1051 closure_zone_value->closure_creation_context};
1052 const bke::EvaluateClosureComputeContext &closure_eval_context =
1053 compute_context_cache_.for_evaluate_closure(socket.context,
1054 evaluate_closure_node->identifier,
1055 &socket->owner_tree(),
1056 closure_source_location);
1057 parent_zone_contexts_.add(&closure_eval_context, closure_zone_value->closure_creation_context);
1058 this->schedule_side_effect_nodes_in_context(
1059 closure_tree, closure_zone_value->zone, &closure_eval_context);
1061 for (
const int i :
IndexRange(closure_storage.output_items.items_num)) {
1062 const NodeClosureOutputItem &item = closure_storage.output_items.items[i];
1063 if (key != item.name) {
1067 const SocketInContext origin_socket = {&closure_eval_context,
1068 &closure_output_node.input_socket(i)};
1069 this->forward_value_or_schedule(socket, origin_socket);
1072 this->store_socket_value_fallback(socket);
1075 void handle_output_socket__closure_input(
const SocketInContext &socket)
1077 const bNode &closure_input_node = socket->owner_node();
1078 const auto *closure_eval_context =
dynamic_cast<const bke::EvaluateClosureComputeContext *
>(
1080 if (!closure_eval_context) {
1081 this->store_socket_value_fallback(socket);
1084 const bNode &closure_output_node = *closure_input_node.owner_tree().node_by_id(
1085 closure_eval_context->closure_source_location()->closure_output_node_id);
1086 const NodeInContext closure_eval_node = {closure_eval_context->parent(),
1087 closure_eval_context->node()};
1089 const auto &closure_storage = *
static_cast<const NodeClosureOutput *
>(
1090 closure_output_node.storage);
1091 const auto &eval_closure_storage = *
static_cast<const NodeEvaluateClosure *
>(
1092 closure_eval_node->storage);
1094 const StringRef key = closure_storage.input_items.items[socket->index()].name;
1095 for (
const int i :
IndexRange(eval_closure_storage.input_items.items_num)) {
1096 const NodeEvaluateClosureInputItem &item = eval_closure_storage.input_items.items[i];
1097 if (key != item.name) {
1102 const SocketInContext origin_socket = closure_eval_node.input_socket(i + 1);
1103 this->forward_value_or_schedule(socket, origin_socket);
1106 this->store_socket_value_fallback(socket);
1109 void handle_output_socket__combine_bundle(
const SocketInContext &socket)
1111 const NodeInContext
node = socket.owner_node();
1112 const auto &
storage = *
static_cast<const NodeCombineBundle *
>(
node->storage);
1114 bool all_inputs_available =
true;
1115 for (
const bNodeSocket *input_socket :
node->input_sockets()) {
1116 const SocketInContext input_socket_ctx = {socket.context, input_socket};
1117 if (!value_by_socket_.lookup_ptr(input_socket_ctx)) {
1118 this->schedule_socket(input_socket_ctx);
1119 all_inputs_available =
false;
1122 if (!all_inputs_available) {
1127 auto bundle_value = std::make_shared<BundleSocketValue>();
1129 const SocketInContext input_socket =
node.input_socket(i);
1130 const NodeCombineBundleItem &item =
storage.items[i];
1131 const StringRef key = item.name;
1132 const auto &socket_value = value_by_socket_.lookup(input_socket);
1133 bundle_value->items.append({key, socket_value, input_socket->typeinfo});
1135 this->store_socket_value(socket, {bundle_value});
1138 void handle_output_socket__separate_bundle(
const SocketInContext &socket)
1140 const NodeInContext
node = socket.owner_node();
1141 const auto &
storage = *
static_cast<const NodeSeparateBundle *
>(
node->storage);
1143 const SocketInContext input_socket =
node.input_socket(0);
1144 const SocketValue *socket_value = value_by_socket_.lookup_ptr(input_socket);
1145 if (!socket_value) {
1147 this->schedule_socket(input_socket);
1150 const auto *bundle_value_ptr = std::get_if<BundleSocketValuePtr>(&socket_value->value);
1151 if (!bundle_value_ptr) {
1153 this->store_socket_value_fallback(socket);
1156 const BundleSocketValue &bundle_value = **bundle_value_ptr;
1158 const StringRef key =
storage.items[socket->index()].name;
1159 for (
const BundleSocketValue::Item &item : bundle_value.items) {
1160 if (key != item.key) {
1164 const SocketValue converted_value = this->handle_implicit_conversion(
1165 item.value, *item.socket_type, *socket->typeinfo);
1166 this->store_socket_value(socket, converted_value);
1170 this->store_socket_value_fallback(socket);
1173 void handle_output_socket__join_bundle(
const SocketInContext &socket)
1175 const NodeInContext
node = socket.owner_node();
1176 const SocketInContext input_socket =
node.input_socket(0);
1177 const SocketValue *socket_value = value_by_socket_.lookup_ptr(input_socket);
1178 if (!socket_value) {
1180 this->schedule_socket(input_socket);
1183 const auto &multi_input_value = *std::get_if<MultiInputValue>(&socket_value->value);
1184 if (multi_input_value.values.is_empty()) {
1186 this->store_socket_value_fallback(socket);
1190 Set<StringRef> existing_keys;
1191 auto joined_bundle = std::make_shared<BundleSocketValue>();
1192 for (
const SocketValue &value : multi_input_value.values) {
1193 const auto *bundle_value = std::get_if<BundleSocketValuePtr>(&value.value);
1194 if (!bundle_value || !*bundle_value) {
1198 for (
const BundleSocketValue::Item &item : (*bundle_value)->items) {
1199 if (existing_keys.add(item.key)) {
1200 joined_bundle->items.append(item);
1204 this->store_socket_value(socket, {BundleSocketValuePtr{joined_bundle}});
1207 void handle_output_socket__menu_switch(
const SocketInContext &socket)
1209 const NodeInContext
node = socket.owner_node();
1210 const auto &
storage = *
static_cast<const NodeMenuSwitch *
>(
node->storage);
1212 const SocketInContext menu_input =
node.input_socket(0);
1213 const SocketValue *menu_socket_value = value_by_socket_.lookup_ptr(menu_input);
1214 if (!menu_socket_value) {
1216 this->schedule_socket(menu_input);
1220 const std::optional<PrimitiveSocketValue> menu_value_opt = menu_socket_value->to_primitive(
1221 *menu_input->typeinfo);
1222 if (!menu_value_opt) {
1225 this->store_socket_value_fallback(socket);
1226 this->report_required_constant_input_or_backtrack(
1227 node,
TIP_(
"Menu value has to be a constant value"));
1230 const MenuValue menu_value = std::get<MenuValue>(menu_value_opt->value);
1232 std::optional<int> selected_index;
1234 const NodeEnumItem &item =
storage.enum_definition.items_array[item_i];
1235 if (
MenuValue(item.identifier) == menu_value) {
1236 selected_index = item_i;
1240 if (!selected_index.has_value()) {
1242 this->store_socket_value_fallback(socket);
1245 if (socket->index() == 0) {
1247 this->forward_value_or_schedule(socket,
node.input_socket(*selected_index + 1));
1251 const bool is_selected = selected_index == socket->index() - 1;
1252 this->store_socket_value_primitive(socket, is_selected);
1255 struct MixNodeInfo {
1256 bNode *node =
nullptr;
1257 bNodeSocket *factor_in =
nullptr;
1258 bNodeSocket *a_in =
nullptr;
1259 bNodeSocket *b_in =
nullptr;
1260 bNodeSocket *result_out =
nullptr;
1266 switch (socket_type) {
1272 auto find_socket_by_name =
1274 for (bNodeSocket &socket : in_out ==
SOCK_IN ?
node.inputs :
node.outputs) {
1275 if (socket.is_available()) {
1276 if (socket.name == name) {
1286 auto &mix_storage = *
static_cast<NodeShaderMix *
>(
mix.node->storage);
1287 mix_storage.data_type = socket_type;
1288 mix_storage.clamp_result =
false;
1290 mix_storage.clamp_factor =
true;
1292 mix.node->typeinfo->updatefunc(&dst_tree_,
mix.node);
1293 mix.factor_in = find_socket_by_name(*
mix.node,
SOCK_IN,
"Factor");
1296 mix.result_out = find_socket_by_name(*
mix.node,
SOCK_OUT,
"Result");
1300 mix.node = this->
add_node(
"ShaderNodeMixShader"_ustr);
1301 mix.factor_in =
mix.node->inputs.first();
1302 mix.a_in =
mix.factor_in->next;
1303 mix.b_in =
mix.a_in->next;
1304 mix.result_out =
mix.node->outputs.first();
1318 std::optional<eNodeSocketDatatype> get_internal_mix_socket_type(
1321 switch (socket_type) {
1333 return std::nullopt;
1337 void handle_output_socket__index_switch(
const SocketInContext &socket)
1339 const NodeInContext
node = socket.owner_node();
1340 const auto &
storage = *
static_cast<const NodeIndexSwitch *
>(
node->storage);
1343 this->store_socket_value_fallback(socket);
1347 const SocketInContext index_input =
node.input_socket(0);
1348 const SocketValue *index_input_value = value_by_socket_.lookup_ptr(index_input);
1349 if (!index_input_value) {
1351 this->schedule_socket(index_input);
1355 if (
const std::optional<PrimitiveSocketValue> primitive_index_value_opt =
1356 index_input_value->to_primitive(*index_input->typeinfo))
1358 const int index = std::get<int>(primitive_index_value_opt->value);
1359 if (index < 0 || index >=
storage.items_num) {
1360 this->store_socket_value_fallback(socket);
1362 fmt::format(
"{}: {}",
TIP_(
"Index out of range"), index),
1366 this->forward_value_or_schedule(socket,
node.input_socket(index + 1));
1373 const std::optional<eNodeSocketDatatype> internal_mix_type =
1374 this->get_internal_mix_socket_type(
storage.data_type);
1375 if (!internal_mix_type) {
1376 this->report_required_constant_input_or_backtrack(
1377 node,
TIP_(
"Index must be a constant value for this data type"));
1378 this->store_socket_value_fallback(socket);
1382 const EnsureInputsResult ensured_inputs = this->ensure_node_inputs(
node);
1383 if (ensured_inputs.has_missing_inputs) {
1389 bNode &truncate_math_node = *this->
add_node(
"ShaderNodeMath"_ustr);
1391 bNodeSocket &truncate_input = *truncate_math_node.inputs.first();
1392 bNodeSocket &truncate_output = *truncate_math_node.outputs.first();
1393 this->set_input_socket_value(
node, truncate_math_node, truncate_input, *index_input_value);
1395 bNode *prev_mix =
nullptr;
1396 bNodeSocket *prev_mix_result =
nullptr;
1399 const int index_to_factor_offset = 1 - i;
1401 bNode *factor_node =
nullptr;
1402 bNodeSocket *factor_out =
nullptr;
1403 if (index_to_factor_offset == 0) {
1405 factor_node = &truncate_math_node;
1406 factor_out = &truncate_output;
1409 bNode &add_math_node = *this->
add_node(
"ShaderNodeMath"_ustr);
1411 bNodeSocket &add_in_1 = *add_math_node.inputs.first();
1412 bNodeSocket &add_in_2 = *add_in_1.next;
1414 dst_tree_, truncate_math_node, truncate_output, add_math_node, add_in_1);
1415 static_cast<bNodeSocketValueFloat *
>(add_in_2.default_value)->value =
1416 index_to_factor_offset;
1417 factor_node = &add_math_node;
1418 factor_out = add_math_node.outputs.first();
1421 const MixNodeInfo
mix = this->create_mix_node(*internal_mix_type);
1424 this->set_input_socket_value(
node, *
mix.node, *
mix.a_in, {FallbackValue{}});
1430 const SocketInContext input_socket =
node.input_socket(i + 1);
1431 const SocketValue &input_value = value_by_socket_.lookup(input_socket);
1432 const SocketValue converted_value = this->handle_implicit_conversion(
1433 input_value, *input_socket->typeinfo, *
mix.b_in->typeinfo);
1434 this->set_input_socket_value(
node, *
mix.node, *
mix.b_in, converted_value);
1437 this->set_input_socket_value(
node, *
mix.node, *
mix.b_in, {FallbackValue{}});
1440 prev_mix =
mix.node;
1441 prev_mix_result =
mix.result_out;
1444 this->store_socket_value(socket, {LinkedSocketValue{prev_mix, prev_mix_result}});
1450 const auto &
storage = *
static_cast<const NodeSwitch *
>(
node->storage);
1453 const SocketValue *switch_input_value = value_by_socket_.lookup_ptr(switch_input);
1454 if (!switch_input_value) {
1456 this->schedule_socket(switch_input);
1460 if (
const std::optional<PrimitiveSocketValue> primitive_switch_value_opt =
1461 switch_input_value->to_primitive(*switch_input->typeinfo))
1463 const bool condition = std::get<bool>(primitive_switch_value_opt->value);
1464 this->forward_value_or_schedule(socket,
node.input_socket(
condition ? 2 : 1));
1471 const std::optional<eNodeSocketDatatype> internal_mix_type =
1472 this->get_internal_mix_socket_type(
storage.input_type);
1473 if (!internal_mix_type) {
1474 this->report_required_constant_input_or_backtrack(
1475 node,
TIP_(
"Switch must be a constant value for this data type"));
1476 this->store_socket_value_fallback(socket);
1480 const EnsureInputsResult ensured_inputs = this->ensure_node_inputs(
node);
1481 if (ensured_inputs.has_missing_inputs) {
1486 const MixNodeInfo
mix = this->create_mix_node(*internal_mix_type);
1487 this->set_input_socket_value(
node,
1490 this->handle_implicit_conversion(*switch_input_value,
1491 *switch_input->typeinfo,
1492 *
mix.factor_in->typeinfo));
1496 const SocketValue &false_value = value_by_socket_.lookup(false_input);
1497 const SocketValue &true_value = value_by_socket_.lookup(true_input);
1498 this->set_input_socket_value(
node,
1501 this->handle_implicit_conversion(
1502 false_value, *false_input->typeinfo, *
mix.a_in->typeinfo));
1503 this->set_input_socket_value(
1507 this->handle_implicit_conversion(true_value, *true_input->typeinfo, *
mix.b_in->typeinfo));
1509 this->store_socket_value(socket, {LinkedSocketValue{
mix.node,
mix.result_out}});
1515 const auto &
storage = *
static_cast<const NodeInputMenu *
>(
node->storage);
1517 this->store_socket_value(output_socket,
1518 {PrimitiveSocketValue::from_value(
1519 {output_socket->typeinfo->base_cpp_type, &
storage.value})});
1522 void handle_output_socket__implicit_conversion(
const SocketInContext &socket)
1527 const SocketValue *socket_value = value_by_socket_.lookup_ptr(input_socket);
1528 if (!socket_value) {
1530 this->schedule_socket(input_socket);
1533 const SocketValue converted_value = this->handle_implicit_conversion(
1534 *socket_value, *socket->typeinfo, *socket->typeinfo);
1535 this->store_socket_value(socket, converted_value);
1543 const SocketValue *show_value = value_by_socket_.lookup_ptr(show_input_socket);
1546 this->schedule_socket(show_input_socket);
1549 const std::optional<PrimitiveSocketValue> primitive_show = show_value->to_primitive(
1550 *show_input_socket->typeinfo);
1551 if (!primitive_show) {
1554 this->store_socket_value_fallback(socket);
1557 const bool show = std::get<bool>(primitive_show->value);
1560 const SocketValue *message_value = value_by_socket_.lookup_ptr(message_socket);
1561 if (!message_value) {
1563 this->schedule_socket(message_socket);
1566 if (
const std::optional<PrimitiveSocketValue> primitive_message =
1567 message_value->to_primitive(*message_socket->typeinfo))
1570 const StringRef message = std::get<std::string>(primitive_message->value);
1575 TIP_(
"Warnings only work when inputs are constant values"),
1579 this->forward_value_or_schedule(socket, show_input_socket);
1582 void handle_output_socket__enable_output(
const SocketInContext &socket)
1588 const SocketValue *enable_value = value_by_socket_.lookup_ptr(enable_socket);
1589 if (!enable_value) {
1591 this->schedule_socket(enable_socket);
1594 const std::optional<PrimitiveSocketValue> enable_primitive = enable_value->to_primitive(
1595 *enable_socket->typeinfo);
1596 if (enable_primitive.has_value()) {
1597 const bool enable = std::get<bool>(enable_primitive->value);
1599 this->forward_value_or_schedule(socket, value_input_socket);
1602 this->store_socket_value_fallback(socket);
1605 const std::optional<eNodeSocketDatatype> internal_mix_type =
1606 this->get_internal_mix_socket_type(value_input_socket->type);
1607 if (!internal_mix_type) {
1608 this->report_required_constant_input_or_backtrack(
1609 node,
TIP_(
"Enable input must be a constant value for this data type"));
1610 this->store_socket_value_fallback(socket);
1613 const SocketValue *value = value_by_socket_.lookup_ptr(value_input_socket);
1616 this->schedule_socket(value_input_socket);
1619 const MixNodeInfo
mix = this->create_mix_node(*internal_mix_type);
1620 this->set_input_socket_value(
node,
1623 this->handle_implicit_conversion(*enable_value,
1624 *enable_socket->typeinfo,
1625 *
mix.factor_in->typeinfo));
1626 this->set_input_socket_value(
node, *
mix.node, *
mix.a_in, {FallbackValue{}});
1627 this->set_input_socket_value(
node,
1630 this->handle_implicit_conversion(
1631 *value, *value_input_socket->typeinfo, *
mix.b_in->typeinfo));
1632 this->store_socket_value(socket, {LinkedSocketValue{
mix.node,
mix.result_out}});
1640 void schedule_side_effect_nodes_in_context(
const bNodeTree &tree,
1641 const bke::bNodeTreeZone *zone,
1642 const ComputeContext *context)
1644 if (!handled_side_effect_contexts_.add(context)) {
1647 const bke::bNodeTreeZones *zones = tree.zones();
1652 for (
const bNode *warning_node : tree.nodes_by_type(
"GeometryNodeWarning"_ustr)) {
1653 if (warning_node->is_muted()) {
1656 const bke::bNodeTreeZone *warning_zone = zones->get_zone_by_node(warning_node->identifier);
1657 if (warning_zone == zone) {
1658 SocketInContext warning_output_socket{
context, &warning_node->output_socket(0)};
1659 if (!warning_output_socket->is_directly_linked()) {
1661 this->schedule_socket(warning_output_socket);
1671 void handle_output_socket__eval(
const SocketInContext &socket)
1673 const NodeInContext
node = socket.owner_node();
1674 const EnsureInputsResult ensured_inputs = this->ensure_node_inputs(
node);
1675 if (ensured_inputs.has_missing_inputs) {
1679 const bke::bNodeType &node_type = *
node->typeinfo;
1680 if (node_type.build_multi_function && ensured_inputs.all_inputs_primitive) {
1682 this->handle_output_socket__eval_multi_function(
node);
1687 if (this->is_inliner_evaluation_node(*
node)) {
1688 this->report_required_constant_input_or_backtrack(
1689 node,
TIP_(
"Node requires constant input values"));
1690 this->store_socket_value_fallback(socket);
1693 if (this->try_short_circuit(
node)) {
1697 this->handle_output_socket__eval_copy_node(*
node,
node.context,
node.context);
1700 [[nodiscard]]
bool try_short_circuit(
const NodeInContext &
node)
1702 if (
node->is_type(
"FunctionNodeBooleanMath"_ustr)) {
1703 return this->try_short_circuit__boolean_math(
node);
1705 if (
node->is_type(
"ShaderNodeMath"_ustr)) {
1706 return this->try_short_circuit__float_math(
node);
1708 if (
node->is_type(
"FunctionNodeIntegerMath"_ustr)) {
1709 return this->try_short_circuit__integer_math(
node);
1711 if (
node->is_type(
"ShaderNodeVectorMath"_ustr)) {
1712 return this->try_short_circuit__vector_math(
node);
1714 if (
node->is_type(
"ShaderNodeMixShader"_ustr)) {
1715 return this->try_short_circuit__mix_shader(
node);
1720 [[nodiscard]]
bool try_short_circuit__boolean_math(
const NodeInContext &
node)
1723 const SocketInContext output_socket =
node.output_socket(0);
1727 const std::optional<bool> a = this->try_get_input<bool>(
node,
"Boolean"_ustr);
1728 const std::optional<bool>
b = this->try_get_input<bool>(
node,
"Boolean_001"_ustr);
1729 if (a ==
false ||
b ==
false) {
1730 this->store_socket_value_primitive(output_socket,
false);
1734 this->store_socket_value(output_socket, this->get_input_value(
node,
"Boolean_001"_ustr));
1738 this->store_socket_value(output_socket, this->get_input_value(
node,
"Boolean"_ustr));
1744 const std::optional<bool> a = this->try_get_input<bool>(
node,
"Boolean"_ustr);
1745 const std::optional<bool>
b = this->try_get_input<bool>(
node,
"Boolean_001"_ustr);
1746 if (a ==
true ||
b ==
true) {
1747 this->store_socket_value_primitive(output_socket,
true);
1751 this->store_socket_value(output_socket, this->get_input_value(
node,
"Boolean_001"_ustr));
1755 this->store_socket_value(output_socket, this->get_input_value(
node,
"Boolean"_ustr));
1761 const std::optional<bool> a = this->try_get_input<bool>(
node,
"Boolean"_ustr);
1762 const std::optional<bool>
b = this->try_get_input<bool>(
node,
"Boolean_001"_ustr);
1763 if (a ==
false ||
b ==
false) {
1764 this->store_socket_value_primitive(output_socket,
true);
1768 this->store_socket_value(
1770 this->invert_bool_value(
node, this->get_input_value(
node,
"Boolean_001"_ustr)));
1774 this->store_socket_value(
1776 this->invert_bool_value(
node, this->get_input_value(
node,
"Boolean"_ustr)));
1782 const std::optional<bool> a = this->try_get_input<bool>(
node,
"Boolean"_ustr);
1783 const std::optional<bool>
b = this->try_get_input<bool>(
node,
"Boolean_001"_ustr);
1784 if (a ==
true ||
b ==
true) {
1785 this->store_socket_value_primitive(output_socket,
false);
1789 this->store_socket_value(
1791 this->invert_bool_value(
node, this->get_input_value(
node,
"Boolean_001"_ustr)));
1795 this->store_socket_value(
1797 this->invert_bool_value(
node, this->get_input_value(
node,
"Boolean"_ustr)));
1803 const std::optional<bool> a = this->try_get_input<bool>(
node,
"Boolean"_ustr);
1804 const std::optional<bool>
b = this->try_get_input<bool>(
node,
"Boolean_001"_ustr);
1805 if (a ==
false ||
b ==
true) {
1806 this->store_socket_value_primitive(output_socket,
true);
1810 this->store_socket_value(output_socket, this->get_input_value(
node,
"Boolean_001"_ustr));
1814 this->store_socket_value(
1816 this->invert_bool_value(
node, this->get_input_value(
node,
"Boolean"_ustr)));
1822 const std::optional<bool> a = this->try_get_input<bool>(
node,
"Boolean"_ustr);
1823 const std::optional<bool>
b = this->try_get_input<bool>(
node,
"Boolean_001"_ustr);
1824 if (a ==
false ||
b ==
true) {
1825 this->store_socket_value_primitive(output_socket,
false);
1829 this->store_socket_value(
1831 this->invert_bool_value(
node, this->get_input_value(
node,
"Boolean_001"_ustr)));
1835 this->store_socket_value(output_socket, this->get_input_value(
node,
"Boolean"_ustr));
1849 SocketValue invert_bool_value(
const NodeInContext &
node,
const SocketValue &value)
1851 static bke::bNodeSocketType &bool_type = *bke::node_socket_type_find_static(SOCK_BOOLEAN);
1852 if (
const std::optional<PrimitiveSocketValue> primitive = value.to_primitive(bool_type)) {
1853 return {PrimitiveSocketValue{!std::get<bool>(primitive->value)}};
1855 bNode *not_node = this->
add_node(
"FunctionNodeBooleanMath"_ustr);
1857 this->set_input_socket_value(
node, *not_node, *not_node->inputs.first(), value);
1858 return {LinkedSocketValue{not_node, not_node->outputs.first()}};
1861 [[nodiscard]]
bool try_short_circuit__float_math(
const NodeInContext &
node)
1863 const SocketInContext output_socket =
node.output_socket(0);
1869 const std::optional<float> a = this->try_get_input<float>(
node,
"Value"_ustr);
1870 const std::optional<float>
b = this->try_get_input<float>(
node,
"Value_001"_ustr);
1871 if (a == 0.0f ||
b == 0.0f) {
1872 this->store_socket_value_primitive(output_socket, 0.0f);
1884 [[nodiscard]]
bool try_short_circuit__integer_math(
const NodeInContext &
node)
1886 const SocketInContext output_socket =
node.output_socket(0);
1892 const std::optional<int> a = this->try_get_input<int>(
node,
"Value"_ustr);
1893 const std::optional<int>
b = this->try_get_input<int>(
node,
"Value_001"_ustr);
1894 if (a == 0 ||
b == 0) {
1895 this->store_socket_value_primitive(output_socket, 0);
1907 [[nodiscard]]
bool try_short_circuit__vector_math(
const NodeInContext &
node)
1911 auto output_socket = [&](
const UString identifier) -> SocketInContext {
1912 return {
node.context,
node->output_by_identifier(identifier)};
1919 const std::optional<float3> a = this->try_get_input<float3>(
node,
"Vector"_ustr);
1920 const std::optional<float3>
b = this->try_get_input<float3>(
node,
"Vector_001"_ustr);
1922 this->store_socket_value_primitive(output_socket(
"Vector"_ustr),
float3(0.0f));
1928 const std::optional<float3> a = this->try_get_input<float3>(
node,
"Vector"_ustr);
1929 const std::optional<float3>
b = this->try_get_input<float3>(
node,
"Vector_001"_ustr);
1931 this->store_socket_value_primitive(output_socket(
"Value"_ustr), 0.0f);
1937 const std::optional<float3> a = this->try_get_input<float3>(
node,
"Vector"_ustr);
1938 const std::optional<float>
scale = this->try_get_input<float>(
node,
"Scale"_ustr);
1940 this->store_socket_value_primitive(output_socket(
"Vector"_ustr),
float3(0.0f));
1952 [[nodiscard]]
bool try_short_circuit__mix_shader(
const NodeInContext &
node)
1954 const SocketInContext output_socket =
node.output_socket(0);
1955 const std::optional<float> factor = this->try_get_input<float>(
node,
"Fac"_ustr);
1956 if (factor == 0.0f) {
1957 this->store_socket_value(output_socket, this->get_input_value(
node,
"Shader"_ustr));
1960 if (factor == 1.0f) {
1961 this->store_socket_value(output_socket, this->get_input_value(
node,
"Shader_001"_ustr));
1967 template<
typename T>
1968 std::optional<T> try_get_input(
const NodeInContext &
node,
const bNodeSocket &socket)
1970 const SocketValue &value = this->get_input_value(
node, socket);
1971 if (
const std::optional<PrimitiveSocketValue> primitive = value.to_primitive(*socket.typeinfo))
1973 return std::get<T>(primitive->value);
1975 return std::nullopt;
1978 template<
typename T>
1979 std::optional<T> try_get_input(
const NodeInContext &
node,
const UString identifier)
1981 return this->try_get_input<T>(
node, *
node->input_by_identifier(identifier));
1984 SocketValue get_input_value(
const NodeInContext &
node,
const bNodeSocket &socket)
1986 return value_by_socket_.lookup({
node.context, &socket});
1989 SocketValue get_input_value(
const NodeInContext &
node,
const UString identifier)
1991 return this->get_input_value(
node, *
node->input_by_identifier(identifier));
2002 void report_required_constant_input_or_backtrack(
const NodeInContext
node,
2003 const StringRef message)
2006 for (
const ComputeContext *ctx =
node.context; ctx; ctx = ctx->parent()) {
2007 if (
const auto *repeat_zone_ctx =
dynamic_cast<const bke::RepeatZoneComputeContext *
>(ctx)) {
2008 if (repeat_zone_ctx->iteration() == preserved_repeat_zone_iteration) {
2009 repeat_zones_to_force_inline_.add(
2010 {repeat_zone_ctx->parent(), repeat_zone_ctx->output_node_id()});
2018 struct EnsureInputsResult {
2019 bool has_missing_inputs =
false;
2020 bool all_inputs_primitive =
false;
2023 EnsureInputsResult ensure_node_inputs(
const NodeInContext &
node)
2025 EnsureInputsResult
result;
2026 result.has_missing_inputs =
false;
2027 result.all_inputs_primitive =
true;
2028 for (
const bNodeSocket *input_socket :
node->input_sockets()) {
2029 if (this->socket_is_ignored(*input_socket)) {
2032 const SocketInContext input_socket_ctx = {
node.context, input_socket};
2033 const SocketValue *value = value_by_socket_.lookup_ptr(input_socket_ctx);
2035 this->schedule_socket(input_socket_ctx);
2036 result.has_missing_inputs =
true;
2039 if (!value->to_primitive(*input_socket->typeinfo)) {
2040 result.all_inputs_primitive =
false;
2046 void handle_output_socket__eval_multi_function(
const NodeInContext &
node)
2048 NodeMultiFunctionBuilder builder{*
node.node,
node->owner_tree()};
2049 node->typeinfo->build_multi_function(builder);
2050 const mf::MultiFunction &fn = builder.function();
2052 ShaderNodesMultiFunctionUserData user_data;
2053 context.user_data(&user_data);
2055 mf::ParamsBuilder params{fn, &
mask};
2058 for (
const bNodeSocket *input_socket :
node->input_sockets()) {
2059 if (this->socket_is_ignored(*input_socket)) {
2062 const SocketInContext input_socket_ctx = {
node.context, input_socket};
2063 const PrimitiveSocketValue value =
2064 *value_by_socket_.lookup(input_socket_ctx).to_primitive(*input_socket->typeinfo);
2065 params.add_readonly_single_input(
2066 GVArray::from_single(*input_socket->typeinfo->base_cpp_type, 1, value.buffer()));
2070 Vector<void *> output_values;
2071 for (
const bNodeSocket *output_socket :
node->output_sockets()) {
2072 if (this->socket_is_ignored(*output_socket)) {
2075 void *value = scope_.allocate_owned(*output_socket->typeinfo->base_cpp_type);
2076 output_values.append(value);
2077 params.add_uninitialized_single_output(
2078 GMutableSpan(output_socket->typeinfo->base_cpp_type, value, 1));
2081 fn.call(
mask, params, context);
2084 int current_output_i = 0;
2085 for (
const bNodeSocket *output_socket :
node->output_sockets()) {
2086 if (this->socket_is_ignored(*output_socket)) {
2089 const void *value = output_values[current_output_i++];
2090 this->store_socket_value(
2091 {
node.context, output_socket},
2092 {PrimitiveSocketValue::from_value({output_socket->typeinfo->base_cpp_type, value})});
2095 for (
const NodeWarning &warning : user_data.warnings) {
2100 bNode &handle_output_socket__eval_copy_node(
const bNode &
node,
2101 const ComputeContext *in_context,
2102 const ComputeContext *out_context)
2104 Map<const bNodeSocket *, bNodeSocket *> socket_map;
2107 const int identifier = this->get_next_node_identifier();
2108 const std::string unique_name = fmt::format(
"{}_{}", identifier,
node.name);
2109 bNode &copied_node = *bke::node_copy_with_mapping(
2112 this->node_copy_flag(),
2113 unique_name.size() <
sizeof(bNode::name) ? std::make_optional<StringRefNull>(unique_name) :
2119 copied_node.parent =
nullptr;
2122 for (
const bNodeSocket *src_input_socket :
node.input_sockets()) {
2123 if (this->socket_is_ignored(*src_input_socket)) {
2126 bNodeSocket &dst_input_socket = *socket_map.lookup(src_input_socket);
2127 const SocketInContext input_socket_ctx = {in_context, src_input_socket};
2128 const SocketValue &value = value_by_socket_.lookup(input_socket_ctx);
2129 this->set_input_socket_value({in_context, &
node}, copied_node, dst_input_socket, value);
2131 for (
const bNodeSocket *src_output_socket :
node.output_sockets()) {
2132 if (this->socket_is_ignored(*src_output_socket)) {
2135 bNodeSocket &dst_output_socket = *socket_map.lookup(src_output_socket);
2136 const SocketInContext output_socket_ctx = {out_context, src_output_socket};
2137 this->store_socket_value(output_socket_ctx,
2138 {LinkedSocketValue{&copied_node, &dst_output_socket}});
2144 SocketValue handle_implicit_conversion(
const SocketValue &src_value,
2145 const bke::bNodeSocketType &from_socket_type,
2146 const bke::bNodeSocketType &to_socket_type)
2148 if (from_socket_type.type == to_socket_type.type) {
2151 if (std::get_if<LinkedSocketValue>(&src_value.value)) {
2152 if (to_socket_type.type == SOCK_BOOLEAN) {
2153 if (
ELEM(from_socket_type.type, SOCK_FLOAT, SOCK_INT, SOCK_RGBA)) {
2155 return {this->insert_float_to_bool_conversion(src_value)};
2157 if (from_socket_type.type == SOCK_VECTOR) {
2158 return {this->insert_vector_to_bool_conversion(src_value)};
2163 if (std::get_if<DanglingValue>(&src_value.value)) {
2166 const std::optional<PrimitiveSocketValue> src_primitive_value = src_value.to_primitive(
2168 if (src_primitive_value && to_socket_type.base_cpp_type) {
2169 if (data_type_conversions_.is_convertible(*from_socket_type.base_cpp_type,
2170 *to_socket_type.base_cpp_type))
2172 const void *src_buffer = src_primitive_value->buffer();
2174 data_type_conversions_.convert_to_uninitialized(*from_socket_type.base_cpp_type,
2175 *to_socket_type.base_cpp_type,
2179 PrimitiveSocketValue::from_value(GPointer{to_socket_type.base_cpp_type, dst_buffer})};
2182 if (src_primitive_value && to_socket_type.type == SOCK_SHADER) {
2183 const CPPType &from_cpp_type = *from_socket_type.base_cpp_type;
2184 const CPPType &to_cpp_type = CPPType::get<ColorGeometry4f>();
2185 if (from_cpp_type == to_cpp_type ||
2186 data_type_conversions_.is_convertible(from_cpp_type, to_cpp_type))
2189 bNode *color_node = this->
add_node(
"ShaderNodeRGB"_ustr);
2190 const void *src_buffer = src_primitive_value->buffer();
2192 data_type_conversions_.convert_to_uninitialized(
2193 from_cpp_type, to_cpp_type, src_buffer, &color);
2194 bNodeSocket *output_socket = color_node->outputs.first();
2195 auto *socket_storage =
static_cast<bNodeSocketValueRGBA *
>(output_socket->default_value);
2197 socket_storage->value[3] = 1.0f;
2198 return {LinkedSocketValue{color_node, output_socket}};
2202 return SocketValue{FallbackValue{}};
2210 LinkedSocketValue insert_float_to_bool_conversion(
const SocketValue &src_value)
2212 bNode &math_node = *this->
add_node(
"ShaderNodeMath"_ustr);
2214 bNodeSocket &value_in = *math_node.inputs.first();
2215 bNodeSocket &threshold_in = *value_in.next;
2216 bNodeSocket &value_out = *math_node.outputs.first();
2217 this->set_input_socket_value({}, math_node, value_in, src_value);
2218 static_cast<bNodeSocketValueFloat *
>(threshold_in.default_value)->value = 0.0f;
2219 return {&math_node, &value_out};
2223 LinkedSocketValue insert_vector_to_bool_conversion(
const SocketValue &src_value)
2225 bNode &length_node = *this->
add_node(
"ShaderNodeVectorMath"_ustr);
2227 length_node.typeinfo->updatefunc(&dst_tree_, &length_node);
2228 bNodeSocket &vector_in = *length_node.inputs.first();
2229 bNodeSocket &length_out = *bke::node_find_socket(length_node, SOCK_OUT,
"Value"_ustr);
2230 this->set_input_socket_value({}, length_node, vector_in, src_value);
2231 return this->insert_float_to_bool_conversion({LinkedSocketValue{&length_node, &length_out}});
2234 void set_input_socket_value(
const NodeInContext &original_node,
2236 bNodeSocket &dst_socket,
2237 const SocketValue &value)
2240 if (dst_socket.flag & SOCK_HIDE_VALUE) {
2241 if (
const auto *input_socket_value = std::get_if<InputSocketValue>(&value.value)) {
2242 if (input_socket_value->socket->flag & SOCK_HIDE_VALUE) {
2248 if (
const std::optional<PrimitiveSocketValue> primitive_value = value.to_primitive(
2249 *dst_socket.typeinfo))
2251 if (dst_socket.flag & SOCK_HIDE_VALUE) {
2254 const NodeAndSocket node_and_socket = this->try_primitive_value_to_output_socket(
2256 if (!node_and_socket.socket) {
2258 this->set_primitive_value_on_socket(dst_socket, *primitive_value);
2260 else if (dst_tree_.typeinfo->validate_link(node_and_socket.socket->typeinfo->type,
2261 dst_socket.typeinfo->type))
2264 dst_tree_, *node_and_socket.node, *node_and_socket.socket, dst_node, dst_socket);
2268 this->set_primitive_value_on_socket(dst_socket, *primitive_value);
2272 if (!params_.allow_preserving_repeat_zones) {
2273 const bool is_iterations_input = dst_node.inputs.first_ == &dst_socket &&
2274 dst_node.is_type(
"GeometryNodeRepeatInput"_ustr);
2275 if (is_iterations_input) {
2276 this->add_dynamic_repeat_zone_iterations_error(original_node);
2277 this->set_primitive_value_on_socket(dst_socket, PrimitiveSocketValue{0});
2281 if (std::get_if<InputSocketValue>(&value.value)) {
2285 if (std::get_if<FallbackValue>(&value.value)) {
2289 if (std::get_if<DanglingValue>(&value.value)) {
2295 if (std::get_if<BundleSocketValuePtr>(&value.value)) {
2300 if (std::get_if<ClosureZoneValue>(&value.value)) {
2305 if (std::get_if<MultiInputValue>(&value.value)) {
2310 if (
const auto *src_socket_value = std::get_if<LinkedSocketValue>(&value.value)) {
2311 if (dst_tree_.typeinfo->validate_link(src_socket_value->socket->typeinfo->type,
2312 dst_socket.typeinfo->type))
2315 dst_tree_, *src_socket_value->node, *src_socket_value->socket, dst_node, dst_socket);
2322 NodeAndSocket try_primitive_value_to_output_socket(
const PrimitiveSocketValue &value)
2324 if (
const float *value_float = std::get_if<float>(&value.value)) {
2326 bNodeSocket *socket =
node->outputs.first();
2327 socket->default_value_typed<bNodeSocketValueFloat>()->value = *value_float;
2328 return {
node, socket};
2330 if (
const int *value_int = std::get_if<int>(&value.value)) {
2331 bNode *
node = this->
add_node(
"FunctionNodeInputInt"_ustr);
2332 auto &
storage = *
static_cast<NodeInputInt *
>(
node->storage);
2334 return {
node,
node->outputs.first()};
2336 if (
const bool *value_bool = std::get_if<bool>(&value.value)) {
2337 bNode *
node = this->
add_node(
"FunctionNodeInputBool"_ustr);
2338 auto &
storage = *
static_cast<NodeInputBool *
>(
node->storage);
2339 storage.boolean = int(*value_bool);
2340 return {
node,
node->outputs.first()};
2342 if (
const float3 *value_float3 = std::get_if<float3>(&value.value)) {
2343 bNode *
node = this->
add_node(
"FunctionNodeInputVector"_ustr);
2344 auto &
storage = *
static_cast<NodeInputVector *
>(
node->storage);
2347 return {
node,
node->outputs.first()};
2349 if (
const ColorGeometry4f *value_color = std::get_if<ColorGeometry4f>(&value.value)) {
2351 bNodeSocket *output_socket =
node->outputs.first();
2352 auto *socket_storage =
static_cast<bNodeSocketValueRGBA *
>(output_socket->default_value);
2353 copy_v3_v3(socket_storage->value, *value_color);
2354 socket_storage->value[3] = 1.0f;
2355 return {
node, output_socket};
2357 if (std::get_if<std::string>(&value.value) || std::get_if<MenuValue>(&value.value)) {
2365 bNode *
add_node(
const UString idname)
2367 return bke::node_add_node(
nullptr, dst_tree_, idname, this->get_next_node_identifier());
2370 int get_next_node_identifier()
2372 return ++dst_node_counter_;
2375 void set_primitive_value_on_socket(bNodeSocket &socket,
const PrimitiveSocketValue &value)
2377 switch (socket.type) {
2379 socket.default_value_typed<bNodeSocketValueFloat>()->value = std::get<float>(value.value);
2383 socket.default_value_typed<bNodeSocketValueInt>()->value = std::get<int>(value.value);
2387 socket.default_value_typed<bNodeSocketValueBoolean>()->value = std::get<bool>(value.value);
2391 copy_v3_v3(socket.default_value_typed<bNodeSocketValueVector>()->value,
2392 std::get<float3>(value.value));
2396 copy_v4_v4(socket.default_value_typed<bNodeSocketValueRGBA>()->value,
2397 std::get<ColorGeometry4f>(value.value));
2401 socket.default_value_typed<bNodeSocketValueMenu>()->value =
2402 std::get<nodes::MenuValue>(value.value).value;
2406 STRNCPY_UTF8(socket.default_value_typed<bNodeSocketValueString>()->value,
2407 std::get<std::string>(value.value).c_str());
2417 void restore_zones_in_output_tree()
2419 for (
const PreservedZone &copied_zone : copied_zone_by_zone_output_node_.values()) {
2420 if (!copied_zone.input_node || !copied_zone.output_node) {
2423 const bke::bNodeZoneType *zone_type = bke::zone_type_by_node_type(
2424 copied_zone.input_node->type_legacy);
2428 int &output_id = zone_type->get_corresponding_output_id(*copied_zone.input_node);
2429 output_id = copied_zone.output_node->identifier;
2433 void position_nodes_in_output_tree()
2435 bNodeTree &tree = dst_tree_;
2436 tree.ensure_topology_cache();
2438 Map<int, int> num_by_depth;
2439 Map<bNode *, int> depth_by_node;
2443 for (bNode *
node : tree.toposort_right_to_left()) {
2445 for (bNodeSocket *socket :
node->output_sockets()) {
2446 for (bNodeSocket *target : socket->directly_linked_sockets()) {
2447 depth = std::max(depth, depth_by_node.lookup(&target->owner_node()) + 1);
2450 depth_by_node.add_new(
node, depth);
2451 const int index_at_depth = num_by_depth.lookup_or_add(depth, 0)++;
2452 node->location[0] = 200 - depth * 200;
2453 node->location[1] = -index_at_depth * 300;
2461 void forward_value_or_schedule(
const SocketInContext &socket,
const SocketInContext &origin)
2463 if (
const SocketValue *value = value_by_socket_.lookup_ptr(origin)) {
2464 if (socket->type == origin->type) {
2465 this->store_socket_value(socket, *value);
2468 this->store_socket_value(
2469 socket, this->handle_implicit_conversion(*value, *origin->typeinfo, *socket->typeinfo));
2472 this->schedule_socket(origin);
2475 template<
typename T>
void store_socket_value_primitive(
const SocketInContext &socket,
T value)
2477 value_by_socket_.add_new(socket, {PrimitiveSocketValue{value}});
2480 void store_socket_value(
const SocketInContext &socket, SocketValue value)
2482 value_by_socket_.add_new(socket, std::move(value));
2485 void store_socket_value_fallback(
const SocketInContext &socket)
2487 value_by_socket_.add_new(socket, {FallbackValue{}});
2490 void store_socket_value_dangling(
const SocketInContext &socket)
2492 value_by_socket_.add_new(socket, {DanglingValue{}});
2495 void schedule_socket(
const SocketInContext &socket)
2497 scheduled_sockets_stack_.push(socket);
2500 int node_copy_flag()
const
2502 const bool use_refcounting = !(dst_tree_.id.tag &
ID_TAG_NO_MAIN);
2506 bool socket_is_ignored(
const bNodeSocket &socket)
const
2508 return !socket.is_available() || socket.typeinfo->idname ==
"NodeSocketVirtual"_ustr;
2511 void report_error(
const NodeInContext &
node,
const StringRef message,
const NodeWarningType type)
2513 Vector<NodeInContext> nodes;
2515 for (
const ComputeContext *context =
node.context; context; context =
context->parent()) {
2519 if (
const auto *group_context =
dynamic_cast<const bke::GroupNodeComputeContext *
>(context))
2521 nodes.append({
context->parent(), group_context->node()});
2524 for (
const NodeInContext &
node : nodes) {
2525 params_.r_error_messages.append({&*
node, message, type});
2536 ShaderNodesInliner inliner(src_tree, dst_tree, params);
2538 if (inliner.do_inline()) {
2542 sock.
link =
nullptr;
2545 sock.
link =
nullptr;
#define BUFFER_FOR_CPP_TYPE_VALUE(type, variable_name)
#define BLI_SCOPED_DEFER(function_to_defer)
#define STRNCPY_UTF8(dst, src)
#define BLI_assert_unreachable()
constexpr IndexRange()=default
#define storage(slot, qualifiers)
float3x3 scale(float3x3 mat, float2 scale)
@ NODE_BOOLEAN_MATH_IMPLY
@ NODE_BOOLEAN_MATH_NIMPLY
@ NODE_INTEGER_MATH_MULTIPLY
@ NODE_INTEGER_MATH_DIVIDE
@ NODE_VECTOR_MATH_LENGTH
@ NODE_VECTOR_MATH_CROSS_PRODUCT
@ NODE_VECTOR_MATH_DOT_PRODUCT
@ NODE_VECTOR_MATH_DIVIDE
@ NODE_VECTOR_MATH_MULTIPLY
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
ccl_device_inline void copy_v3_v3(ccl_private float *r, const float3 val)
ccl_device_inline void copy_v4_v4(ccl_private float *r, const float4 val)
const DataTypeConversions & get_implicit_type_conversions()
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
bNode * node_copy_with_mapping(bNodeTree *dst_tree, const bNode &node_src, int flag, std::optional< StringRefNull > dst_unique_name, std::optional< int > dst_unique_identifier, Map< const bNodeSocket *, bNodeSocket * > &new_socket_map, bool allow_duplicate_names=false)
int context(const bContext *C, const char *member, bContextDataResult *result)
GreasePencil * from_context(bContext &C)
bNode * add_node(const bContext &C, const UString idname, const float2 &location)
bool inline_shader_node_tree(const bNodeTree &src_tree, bNodeTree &dst_tree, InlineShaderNodeTreeParams ¶ms)
bool operator==(const BundleSignature &a, const BundleSignature &b)
bool warning_is_propagated(const NodeWarningPropagation propagation, const NodeWarningType warning_type)
void report_error(const StringRefNull error)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
@ LIB_ID_CREATE_NO_USER_REFCOUNT
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
@ NODE_DEFAULT_INPUT_VALUE
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
bke::bNodeSocketType * typeinfo
ListBaseT< bNodeLink > links
bke::bNodeTreeType * typeinfo
bool(*) validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)